Main MRPT website > C++ reference for MRPT 1.9.9
CMesh.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2018, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #ifndef opengl_CMesh_H
11 #define opengl_CMesh_H
12 
14 #include <mrpt/math/CMatrix.h>
15 #include <mrpt/img/CImage.h>
16 #include <mrpt/img/color_maps.h>
18 
19 namespace mrpt
20 {
21 namespace opengl
22 {
23 /** A planar (XY) grid where each cell has an associated height and, optionally,
24  * a texture map.
25  * A typical usage example would be an elevation map or a 3D model of a
26  * terrain.
27  * \sa opengl::COpenGLScene
28  *
29  * <div align="center">
30  * <table border="0" cellspan="4" cellspacing="4" style="border-width: 1px;
31  * border-style: solid;">
32  * <tr> <td> mrpt::opengl::CMesh </td> <td> \image html preview_CMesh.png
33  * </td> </tr>
34  * </table>
35  * </div>
36  *
37  * \ingroup mrpt_opengl_grp
38  */
40 {
42  public:
44  {
45  size_t vind[3];
46  };
47 
48  protected:
50 
54  bool m_isImage;
55 
56  /** Z(x,y): Z-coordinate of the point (x,y) */
59  /** Texture coordinates */
61  /** Grayscale Color [0,1] for each cell, updated by updateColorsMatrix */
62  mutable math::CMatrix C;
63  /** Red Component of the Color [0,1] for each cell, updated by
64  * updateColorsMatrix */
65  mutable math::CMatrix C_r;
66  /** Green Component of the Color [0,1] for each cell, updated by
67  * updateColorsMatrix */
68  mutable math::CMatrix C_g;
69  /** Blue Component of the Color [0,1] for each cell, updated by
70  * updateColorsMatrix */
71  mutable math::CMatrix C_b;
72 
73  /** Used when m_colorFromZ is true */
75 
76  /** Whether C is not up-to-date wrt to Z */
77  mutable bool m_modified_Z;
78  /** Whether C is not up-to-date wrt to the texture image */
79  mutable bool m_modified_Image;
80 
81  /** Called internally to assure C is updated. */
82  void updateColorsMatrix() const;
83  /** Called internally to assure the triangle list is updated. */
84  void updateTriangles() const;
85  void updatePolygons() const; //<!Called internally to assure that the
86  // polygon list is updated.
87 
88  /** Mesh bounds */
89  float xMin, xMax, yMin, yMax;
90  /** List of triangles in the mesh */
91  mutable std::vector<
92  std::pair<CSetOfTriangles::TTriangle, TTriangleVertexIndices>>
94  /** The accumulated normals & counts for each vertex, so normals can be
95  * averaged. */
96  mutable std::vector<std::pair<mrpt::math::TPoint3D, size_t>> vertex_normals;
97  /**Whether the actual mesh needs to be recalculated */
98  mutable bool trianglesUpToDate;
99  mutable bool polygonsUpToDate; //<!Whether the polygon mesh (auxiliary
100  // structure for ray tracing) needs to be
101  // recalculated
102  mutable std::vector<mrpt::math::TPolygonWithPlane> tmpPolys;
103 
104  public:
105  void setGridLimits(float xmin, float xmax, float ymin, float ymax)
106  {
107  xMin = xmin;
108  xMax = xmax;
109  yMin = ymin;
110  yMax = ymax;
112  }
113 
114  void getGridLimits(float& xmin, float& xmax, float& ymin, float& ymax) const
115  {
116  xmin = xMin;
117  xmax = xMax;
118  ymin = yMin;
119  ymax = yMax;
120  }
121 
123  {
126  }
127  void enableWireFrame(bool v)
128  {
129  m_isWireFrame = v;
131  }
133  bool v, mrpt::img::TColormap colorMap = mrpt::img::cmHOT)
134  {
135  m_colorFromZ = v;
136  m_colorMap = colorMap;
138  }
139 
140  /** This method sets the matrix of heights for each position (cell) in the
141  * mesh grid */
143 
144  /** Returns a reference to the internal Z matrix, allowing changing it
145  * efficiently */
146  inline void getZ(mrpt::math::CMatrixFloat& out) const { out = Z; }
147  /** Returns a reference to the internal mask matrix, allowing changing it
148  * efficiently */
149  inline void getMask(mrpt::math::CMatrixFloat& out) const { out = mask; }
150  /** This method sets the boolean mask of valid heights for each position
151  * (cell) in the mesh grid */
153 
154  /** Sets the (u,v) texture coordinates (in range [0,1]) for each cell */
155  void setUV(
158 
159  inline float getXMin() const { return xMin; }
160  inline float getXMax() const { return xMax; }
161  inline float getYMin() const { return yMin; }
162  inline float getYMax() const { return yMax; }
163  inline void setXMin(const float nxm)
164  {
165  xMin = nxm;
166  trianglesUpToDate = false;
168  }
169  inline void setXMax(const float nxm)
170  {
171  xMax = nxm;
172  trianglesUpToDate = false;
174  }
175  inline void setYMin(const float nym)
176  {
177  yMin = nym;
178  trianglesUpToDate = false;
180  }
181  inline void setYMax(const float nym)
182  {
183  yMax = nym;
184  trianglesUpToDate = false;
186  }
187  inline void getXBounds(float& min, float& max) const
188  {
189  min = xMin;
190  max = xMax;
191  }
192  inline void getYBounds(float& min, float& max) const
193  {
194  min = yMin;
195  max = yMax;
196  }
197  inline void setXBounds(const float min, const float max)
198  {
199  xMin = min;
200  xMax = max;
201  trianglesUpToDate = false;
203  }
204  inline void setYBounds(const float min, const float max)
205  {
206  yMin = min;
207  yMax = max;
208  trianglesUpToDate = false;
210  }
211 
212  /** Class factory */
213  static CMesh::Ptr Create(
214  bool enableTransparency, float xMin = 0.0f, float xMax = 0.0f,
215  float yMin = 0.0f, float yMax = 0.0f);
216 
217  /** Render
218  */
219  void render_dl() const override;
220 
221  /** Evaluates the bounding box of this object (including possible children)
222  * in the coordinate frame of the object parent. */
223  void getBoundingBox(
224  mrpt::math::TPoint3D& bb_min,
225  mrpt::math::TPoint3D& bb_max) const override;
226 
227  /** Assigns a texture image, and disable transparency.
228  */
229  void assignImage(const mrpt::img::CImage& img);
230 
231  /** Assigns a texture image and Z simultaneously, and disable transparency.
232  */
233  void assignImageAndZ(
234  const mrpt::img::CImage& img,
236 
237  /** Adjust grid limits according to the image aspect ratio, maintaining the
238  * X limits and resizing in the Y direction.
239  */
240  inline void adjustGridToImageAR()
241  {
243  const float ycenter = 0.5 * (yMin + yMax);
244  const float xwidth = xMax - xMin;
245  const float newratio = float(m_textureImage.getWidth()) /
246  float(m_textureImage.getHeight());
247  yMax = ycenter + 0.5 * newratio * xwidth;
248  yMin = ycenter - 0.5 * newratio * xwidth;
250  }
251 
252  /** Trace ray
253  */
254  bool traceRay(const mrpt::poses::CPose3D& o, double& dist) const override;
255 
256  /** Constructor */
257  CMesh(
258  bool enableTransparency = false, float xMin = 0.0f, float xMax = 0.0f,
259  float yMin = 0.0f, float yMax = 0.0f);
260 
261  /** Private, virtual destructor: only can be deleted from smart pointers */
262  virtual ~CMesh();
263 };
264 
265 } // end namespace
266 
267 } // End of namespace
268 
269 #endif
mrpt::img::CImage::getWidth
size_t getWidth() const override
Returns the width of the image in pixels.
Definition: CImage.cpp:864
mrpt::img::TColormap
TColormap
Different colormaps for use in mrpt::img::colormap()
Definition: color_maps.h:31
mrpt::opengl::CMesh::actualMesh
std::vector< std::pair< CSetOfTriangles::TTriangle, TTriangleVertexIndices > > actualMesh
List of triangles in the mesh.
Definition: CMesh.h:93
mrpt::opengl::CMesh::updatePolygons
void updatePolygons() const
Definition: CMesh.cpp:574
mrpt::opengl::CMesh::CMesh
CMesh(bool enableTransparency=false, float xMin=0.0f, float xMax=0.0f, float yMin=0.0f, float yMax=0.0f)
Constructor
Definition: CMesh.cpp:29
mrpt::opengl::CMesh::adjustGridToImageAR
void adjustGridToImageAR()
Adjust grid limits according to the image aspect ratio, maintaining the X limits and resizing in the ...
Definition: CMesh.h:240
mrpt::opengl::CMesh::getYMax
float getYMax() const
Definition: CMesh.h:162
mrpt::opengl::CMesh::enableWireFrame
void enableWireFrame(bool v)
Definition: CMesh.h:127
mrpt::opengl::CMesh::traceRay
bool traceRay(const mrpt::poses::CPose3D &o, double &dist) const override
Trace ray.
Definition: CMesh.cpp:553
mrpt::opengl::CMesh::m_modified_Z
bool m_modified_Z
Whether C is not up-to-date wrt to Z.
Definition: CMesh.h:77
mrpt::opengl::CMesh::C_g
math::CMatrix C_g
Green Component of the Color [0,1] for each cell, updated by updateColorsMatrix.
Definition: CMesh.h:68
mrpt::opengl::CMesh::updateColorsMatrix
void updateColorsMatrix() const
Called internally to assure C is updated.
Definition: CMesh.cpp:454
mrpt::opengl::CMesh::assignImageAndZ
void assignImageAndZ(const mrpt::img::CImage &img, const mrpt::math::CMatrixTemplateNumeric< float > &in_Z)
Assigns a texture image and Z simultaneously, and disable transparency.
Definition: CMesh.cpp:372
CRenderizableDisplayList.h
mrpt::opengl::CMesh::enableTransparency
void enableTransparency(bool v)
Definition: CMesh.h:122
color_maps.h
mrpt::img::cmHOT
@ cmHOT
[New in MRPT 1.5.0]
Definition: color_maps.h:37
mrpt::opengl::CRenderizableDisplayList
A renderizable object suitable for rendering with OpenGL's display lists.
Definition: CRenderizableDisplayList.h:39
mrpt::opengl::CMesh::polygonsUpToDate
bool polygonsUpToDate
Definition: CMesh.h:99
mrpt::opengl::CMesh::xMin
float xMin
Mesh bounds.
Definition: CMesh.h:89
mrpt::opengl::CMesh::V
math::CMatrix V
Definition: CMesh.h:60
CMatrix.h
mrpt::opengl::CRenderizableDisplayList::notifyChange
EIGEN_STRONG_INLINE void notifyChange() const
Must be called to notify that the object has changed (so, the display list must be updated)
Definition: CRenderizableDisplayList.h:57
CSetOfTriangles.h
mrpt::opengl::CMesh::setXMax
void setXMax(const float nxm)
Definition: CMesh.h:169
mrpt::opengl::CMesh::U
math::CMatrix U
Texture coordinates.
Definition: CMesh.h:60
mrpt::opengl::CMesh::m_colorFromZ
bool m_colorFromZ
Definition: CMesh.h:52
mrpt::opengl::CMesh::Create
static Ptr Create(Args &&... args)
Definition: CMesh.h:41
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CKalmanFilterCapable.h:30
mrpt::opengl::CMesh::m_colorMap
mrpt::img::TColormap m_colorMap
Used when m_colorFromZ is true.
Definition: CMesh.h:74
ASSERT_
#define ASSERT_(f)
Defines an assertion mechanism.
Definition: exceptions.h:113
mrpt::opengl::CMesh::getGridLimits
void getGridLimits(float &xmin, float &xmax, float &ymin, float &ymax) const
Definition: CMesh.h:114
mrpt::opengl::CMesh::setYBounds
void setYBounds(const float min, const float max)
Definition: CMesh.h:204
mrpt::opengl::CMesh
A planar (XY) grid where each cell has an associated height and, optionally, a texture map.
Definition: CMesh.h:39
mrpt::opengl::CMesh::assignImage
void assignImage(const mrpt::img::CImage &img)
Assigns a texture image, and disable transparency.
Definition: CMesh.cpp:350
mrpt::opengl::CMesh::m_modified_Image
bool m_modified_Image
Whether C is not up-to-date wrt to the texture image.
Definition: CMesh.h:79
mrpt::opengl::CMesh::trianglesUpToDate
bool trianglesUpToDate
Whether the actual mesh needs to be recalculated.
Definition: CMesh.h:98
mrpt::opengl::CMesh::getZ
void getZ(mrpt::math::CMatrixFloat &out) const
Returns a reference to the internal Z matrix, allowing changing it efficiently.
Definition: CMesh.h:146
mrpt::math::CMatrixTemplateNumeric
A matrix of dynamic size.
Definition: CMatrixTemplateNumeric.h:37
mrpt::opengl::CMesh::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: CMesh.cpp:586
v
const GLdouble * v
Definition: glext.h:3678
mrpt::opengl::CMesh::getXMax
float getXMax() const
Definition: CMesh.h:160
mrpt::opengl::CMesh::render_dl
void render_dl() const override
Render.
Definition: CMesh.cpp:297
mrpt::opengl::CMesh::m_isWireFrame
bool m_isWireFrame
Definition: CMesh.h:53
mrpt::opengl::CMesh::m_enableTransparency
bool m_enableTransparency
Definition: CMesh.h:51
mrpt::opengl::CMesh::setZ
void setZ(const mrpt::math::CMatrixTemplateNumeric< float > &in_Z)
This method sets the matrix of heights for each position (cell) in the mesh grid.
Definition: CMesh.cpp:525
mrpt::math::CMatrix
This class is a "CSerializable" wrapper for "CMatrixFloat".
Definition: CMatrix.h:24
mrpt::opengl::CMesh::setYMax
void setYMax(const float nym)
Definition: CMesh.h:181
mrpt::poses::CPose3D
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:88
mrpt::opengl::CMesh::Z
math::CMatrix Z
Z(x,y): Z-coordinate of the point (x,y)
Definition: CMesh.h:57
mrpt::opengl::CMesh::C_b
math::CMatrix C_b
Blue Component of the Color [0,1] for each cell, updated by updateColorsMatrix.
Definition: CMesh.h:71
mrpt::opengl::CMesh::yMin
float yMin
Definition: CMesh.h:89
mrpt::opengl::CMesh::setXMin
void setXMin(const float nxm)
Definition: CMesh.h:163
mrpt::opengl::CMesh::m_textureImage
mrpt::img::CImage m_textureImage
Definition: CMesh.h:49
mrpt::opengl::CMesh::updateTriangles
void updateTriangles() const
Called internally to assure the triangle list is updated.
Definition: CMesh.cpp:61
mrpt::opengl::CMesh::~CMesh
virtual ~CMesh()
Private, virtual destructor: only can be deleted from smart pointers.
Definition: CMesh.cpp:60
mrpt::opengl::CMesh::m_isImage
bool m_isImage
Definition: CMesh.h:54
mrpt::img::CImage
A class for storing images as grayscale or RGB bitmaps.
Definition: img/CImage.h:130
mrpt::opengl::CMesh::TTriangleVertexIndices
Definition: CMesh.h:43
mrpt::math::TPoint3D
Lightweight 3D point.
Definition: lightweight_geom_data.h:378
mrpt::opengl::CMesh::setUV
void setUV(const mrpt::math::CMatrixTemplateNumeric< float > &in_U, const mrpt::math::CMatrixTemplateNumeric< float > &in_V)
Sets the (u,v) texture coordinates (in range [0,1]) for each cell.
Definition: CMesh.cpp:544
min
#define min(a, b)
Definition: rplidar_driver.cpp:42
mrpt::img::CImage::getHeight
size_t getHeight() const override
Returns the height of the image in pixels.
Definition: CImage.cpp:892
mrpt::opengl::CMesh::TTriangleVertexIndices::vind
size_t vind[3]
Definition: CMesh.h:45
img
GLint GLvoid * img
Definition: glext.h:3763
mrpt::opengl::CMesh::yMax
float yMax
Definition: CMesh.h:89
DEFINE_SERIALIZABLE
#define DEFINE_SERIALIZABLE(class_name)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
Definition: CSerializable.h:102
mrpt::opengl::CMesh::setMask
void setMask(const mrpt::math::CMatrixTemplateNumeric< float > &in_mask)
This method sets the boolean mask of valid heights for each position (cell) in the mesh grid.
Definition: CMesh.cpp:537
mrpt::opengl::CMesh::getYBounds
void getYBounds(float &min, float &max) const
Definition: CMesh.h:192
mrpt::opengl::CMesh::C_r
math::CMatrix C_r
Red Component of the Color [0,1] for each cell, updated by updateColorsMatrix.
Definition: CMesh.h:65
mrpt::opengl::CMesh::xMax
float xMax
Definition: CMesh.h:89
mrpt::opengl::CMesh::mask
math::CMatrix mask
Definition: CMesh.h:58
mrpt::opengl::CMesh::setXBounds
void setXBounds(const float min, const float max)
Definition: CMesh.h:197
mrpt::opengl::CMesh::getMask
void getMask(mrpt::math::CMatrixFloat &out) const
Returns a reference to the internal mask matrix, allowing changing it efficiently.
Definition: CMesh.h:149
mrpt::opengl::CMesh::getXMin
float getXMin() const
Definition: CMesh.h:159
mrpt::opengl::CMesh::setGridLimits
void setGridLimits(float xmin, float xmax, float ymin, float ymax)
Definition: CMesh.h:105
CImage.h
mrpt::opengl::CMesh::getXBounds
void getXBounds(float &min, float &max) const
Definition: CMesh.h:187
mrpt::opengl::CMesh::getYMin
float getYMin() const
Definition: CMesh.h:161
mrpt::opengl::CMesh::tmpPolys
std::vector< mrpt::math::TPolygonWithPlane > tmpPolys
Definition: CMesh.h:102
mrpt::opengl::CMesh::C
math::CMatrix C
Grayscale Color [0,1] for each cell, updated by updateColorsMatrix.
Definition: CMesh.h:62
mrpt::opengl::CMesh::Ptr
std::shared_ptr< CMesh > Ptr
Definition: CMesh.h:41
mrpt::opengl::CMesh::vertex_normals
std::vector< std::pair< mrpt::math::TPoint3D, size_t > > vertex_normals
The accumulated normals & counts for each vertex, so normals can be averaged.
Definition: CMesh.h:96
mrpt::opengl::CMesh::enableColorFromZ
void enableColorFromZ(bool v, mrpt::img::TColormap colorMap=mrpt::img::cmHOT)
Definition: CMesh.h:132
mrpt::opengl::CMesh::setYMin
void setYMin(const float nym)
Definition: CMesh.h:175



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST