MRPT  2.0.4
CSetOfTriangles.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #include "opengl-precomp.h" // Precompiled header
11 
14 #include <mrpt/opengl/opengl_api.h>
16 
17 using namespace mrpt;
18 using namespace mrpt::opengl;
19 using namespace mrpt::poses;
20 using namespace mrpt::math;
21 using namespace std;
22 
25 
27 {
28  // Nothing else to do, data is directly kept up-to-date in base class
29  // buffers.
30 }
31 
32 uint8_t CSetOfTriangles::serializeGetVersion() const { return 0; }
34 {
35  writeToStreamRender(out);
36  auto n = (uint32_t)m_triangles.size();
37  out << n;
38  for (size_t i = 0; i < n; i++) m_triangles[i].writeTo(out);
39 }
41  mrpt::serialization::CArchive& in, uint8_t version)
42 {
43  switch (version)
44  {
45  case 0:
46  {
47  readFromStreamRender(in);
48  uint32_t n;
49  in >> n;
50  m_triangles.assign(n, TTriangle());
51  for (size_t i = 0; i < n; i++) m_triangles[i].readFrom(in);
52  }
53  break;
54  default:
56  };
57  polygonsUpToDate = false;
59 }
60 
62  const mrpt::poses::CPose3D& o, double& dist) const
63 {
64  if (!polygonsUpToDate) updatePolygons();
65  return mrpt::math::traceRay(m_polygons, (o - this->m_pose).asTPose(), dist);
66 }
68 {
70  m_color = c;
71  for (auto& t : m_triangles) t.setColor(c);
72  return *this;
73 }
74 
76 {
78  m_color.R = r;
79  for (auto& t : m_triangles) t.setColor(m_color);
80  return *this;
81 }
82 
84 {
86  m_color.G = g;
87  for (auto& t : m_triangles) t.setColor(m_color);
88  return *this;
89 }
90 
92 {
94  m_color.B = b;
95  for (auto& t : m_triangles) t.setColor(m_color);
96  return *this;
97 }
98 
100 {
102  m_color.A = a;
103  for (auto& t : m_triangles) t.setColor(m_color);
104  return *this;
105 }
106 
108  std::vector<mrpt::math::TPolygon3D>& polys) const
109 {
110  if (!polygonsUpToDate) updatePolygons();
111  size_t N = m_polygons.size();
112  for (size_t i = 0; i < N; i++) polys[i] = m_polygons[i].poly;
113 }
114 
116 {
117  TPolygon3D tmp(3);
118  size_t N = m_triangles.size();
119  m_polygons.resize(N);
120  for (size_t i = 0; i < N; i++)
121  for (size_t j = 0; j < 3; j++)
122  {
123  const TTriangle& t = m_triangles[i];
124  tmp[j].x = t.x(j);
125  tmp[j].y = t.y(j);
126  tmp[j].z = t.z(j);
127  m_polygons[i] = tmp;
128  }
129  polygonsUpToDate = true;
131 }
132 
135 {
137  std::numeric_limits<double>::max(), std::numeric_limits<double>::max(),
138  std::numeric_limits<double>::max());
140  -std::numeric_limits<double>::max(),
141  -std::numeric_limits<double>::max(),
142  -std::numeric_limits<double>::max());
143 
144  for (const auto& t : m_triangles)
145  {
146  keep_min(bb_min.x, t.x(0));
147  keep_max(bb_max.x, t.x(0));
148  keep_min(bb_min.y, t.y(0));
149  keep_max(bb_max.y, t.y(0));
150  keep_min(bb_min.z, t.z(0));
151  keep_max(bb_max.z, t.z(0));
152 
153  keep_min(bb_min.x, t.x(1));
154  keep_max(bb_max.x, t.x(1));
155  keep_min(bb_min.y, t.y(1));
156  keep_max(bb_max.y, t.y(1));
157  keep_min(bb_min.z, t.z(1));
158  keep_max(bb_max.z, t.z(1));
159 
160  keep_min(bb_min.x, t.x(2));
161  keep_max(bb_max.x, t.x(2));
162  keep_min(bb_min.y, t.y(2));
163  keep_max(bb_max.y, t.y(2));
164  keep_min(bb_min.z, t.z(2));
165  keep_max(bb_max.z, t.z(2));
166  }
167 
168  // Convert to coordinates of my parent:
169  m_pose.composePoint(bb_min, bb_min);
170  m_pose.composePoint(bb_max, bb_max);
171 }
172 
174 {
175  reserve(m_triangles.size() + p->m_triangles.size());
176  m_triangles.insert(
177  m_triangles.end(), p->m_triangles.begin(), p->m_triangles.end());
178  polygonsUpToDate = false;
180 }
opengl_api.h
mrpt::math::TPoint3D
TPoint3D_< double > TPoint3D
Lightweight 3D point.
Definition: TPoint3D.h:268
mrpt::opengl::CRenderizable::notifyChange
void notifyChange() const
Call to enable calling renderUpdateBuffers() before the next render() rendering iteration.
Definition: CRenderizable.h:315
mrpt::opengl::CSetOfTriangles::insertTriangles
void insertTriangles(const InputIterator &begin, const InputIterator &end)
Inserts a set of triangles, bounded by iterators, into this set.
Definition: CSetOfTriangles.h:68
mrpt::math::TPoint3D_< double >
mrpt::opengl::CSetOfTriangles
A set of colored triangles, able to draw any solid, arbitrarily complex object without textures.
Definition: CSetOfTriangles.h:22
mrpt::opengl::CSetOfTriangles::traceRay
bool traceRay(const mrpt::poses::CPose3D &o, double &dist) const override
Simulation of ray-trace, given a pose.
Definition: CSetOfTriangles.cpp:61
mrpt::opengl::CRenderizable
The base class of 3D objects that can be directly rendered through OpenGL.
Definition: CRenderizable.h:48
mrpt::opengl::CSetOfTriangles::setColorR_u8
CRenderizable & setColorR_u8(const uint8_t r) override
Overwrite all triangles colors with the one provided.
Definition: CSetOfTriangles.cpp:75
mrpt::opengl::CSetOfTriangles::onUpdateBuffers_Triangles
void onUpdateBuffers_Triangles() override
Must be implemented in derived classes to update the geometric entities to be drawn in "m_*_buffer" f...
CSetOfTriangles.h
out
mrpt::vision::TStereoCalibResults out
Definition: chessboard_stereo_camera_calib_unittest.cpp:25
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: BaseAppDataSource.h:15
mrpt::poses
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
Definition: CHierarchicalMapMHPartition.h:22
mrpt::opengl::CSetOfTriangles::getBoundingBox
void getBoundingBox(mrpt::math::TPoint3D &bb_min, mrpt::math::TPoint3D &bb_max) const override
Evaluates the bounding box of this object (including possible children) in the coordinate frame of th...
Definition: CSetOfTriangles.cpp:133
mrpt::opengl::CSetOfTriangles::updatePolygons
void updatePolygons() const
Explicitly updates the internal polygon cache, with all triangles as polygons.
Definition: CSetOfTriangles.cpp:115
mrpt::opengl::CSetOfTriangles::setColor_u8
CRenderizable & setColor_u8(const mrpt::img::TColor &c) override
Overwrite all triangles colors with the one provided.
Definition: CSetOfTriangles.cpp:67
mrpt::math::traceRay
bool traceRay(const std::vector< TPolygonWithPlane > &vec, const mrpt::math::TPose3D &pose, double &dist)
Fast ray tracing method using polygons' properties.
Definition: geometry.cpp:2484
mrpt::serialization::CArchive
Virtual base class for "archives": classes abstracting I/O streams.
Definition: CArchive.h:54
bb_max
const auto bb_max
Definition: CPose3DPDFGrid_unittest.cpp:25
mrpt::opengl::CSetOfTriangles::setColorB_u8
CRenderizable & setColorB_u8(const uint8_t b) override
Overwrite all triangles colors with the one provided.
Definition: CSetOfTriangles.cpp:91
bb_min
const auto bb_min
Definition: CPose3DPDFGrid_unittest.cpp:23
mrpt::poses::CPose3D
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:85
mrpt::opengl::CSetOfTriangles::setColorA_u8
CRenderizable & setColorA_u8(const uint8_t a) override
Overwrite all triangles colors with the one provided.
Definition: CSetOfTriangles.cpp:99
mrpt::opengl::TTriangle::x
const float & x(size_t i) const
Definition: TTriangle.h:90
mrpt::img::TColor
A RGB color - 8bit.
Definition: TColor.h:25
mrpt::keep_max
void keep_max(T &var, const K test_val)
If the second argument is above the first one, set the first argument to this higher value.
Definition: core/include/mrpt/core/bits_math.h:152
mrpt::keep_min
void keep_min(T &var, const K test_val)
If the second argument is below the first one, set the first argument to this lower value.
Definition: core/include/mrpt/core/bits_math.h:145
mrpt::opengl::CSetOfTriangles::serializeTo
void serializeTo(mrpt::serialization::CArchive &out) const override
Pure virtual method for writing (serializing) to an abstract archive.
Definition: CSetOfTriangles.cpp:33
CMatrixDynamic.h
mrpt::math::TPolygon3D
3D polygon, inheriting from std::vector<TPoint3D>
Definition: TPolygon3D.h:20
mrpt::opengl::CSetOfTriangles::serializeFrom
void serializeFrom(mrpt::serialization::CArchive &in, uint8_t serial_version) override
Pure virtual method for reading (deserializing) from an abstract archive.
Definition: CSetOfTriangles.cpp:40
mrpt::opengl::CSetOfTriangles::setColorG_u8
CRenderizable & setColorG_u8(const uint8_t g) override
Overwrite all triangles colors with the one provided.
Definition: CSetOfTriangles.cpp:83
mrpt::opengl::TTriangle
A triangle (float coordinates) with RGBA colors (u8) and UV (texture coordinates) for each vertex.
Definition: TTriangle.h:35
mrpt::opengl::TTriangle::y
const float & y(size_t i) const
Definition: TTriangle.h:91
opengl-precomp.h
mrpt::opengl::TTriangle::z
const float & z(size_t i) const
Definition: TTriangle.h:92
mrpt::opengl::CSetOfTriangles::serializeGetVersion
uint8_t serializeGetVersion() const override
Must return the current versioning number of the object.
Definition: CSetOfTriangles.cpp:32
mrpt::opengl::CSetOfTriangles::Ptr
std::shared_ptr< mrpt::opengl ::CSetOfTriangles > Ptr
Definition: CSetOfTriangles.h:24
mrpt::math
This base provides a set of functions for maths stuff.
Definition: math/include/mrpt/math/bits_math.h:11
mrpt::opengl::CRenderizableShaderTriangles
Renderizable generic renderer for objects using the triangles shader.
Definition: CRenderizableShaderTriangles.h:25
CArchive.h
MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
Definition: exceptions.h:97
IMPLEMENTS_SERIALIZABLE
IMPLEMENTS_SERIALIZABLE(CSetOfTriangles, CRenderizableShaderTriangles, mrpt::opengl) void CSetOfTriangles
Definition: CSetOfTriangles.cpp:23
mrpt::opengl::CSetOfTriangles::getPolygons
void getPolygons(std::vector< mrpt::math::TPolygon3D > &polys) const
Gets the polygon cache.
Definition: CSetOfTriangles.cpp:107
mrpt::opengl
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:13



Page generated by Doxygen 1.8.17 for MRPT 2.0.4 at Sun Jul 19 15:15:43 UTC 2020