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
void setXMax(const float nxm)
Definition: CMesh.h:169
virtual ~CMesh()
Private, virtual destructor: only can be deleted from smart pointers.
Definition: CMesh.cpp:60
mrpt::img::CImage m_textureImage
Definition: CMesh.h:49
TColormap
Different colormaps for use in mrpt::img::colormap()
Definition: color_maps.h:31
std::vector< mrpt::math::TPolygonWithPlane > tmpPolys
Definition: CMesh.h:102
#define min(a, b)
void adjustGridToImageAR()
Adjust grid limits according to the image aspect ratio, maintaining the X limits and resizing in the ...
Definition: CMesh.h:240
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
float xMin
Mesh bounds.
Definition: CMesh.h:89
void enableTransparency(bool v)
Definition: CMesh.h:122
void setXMin(const float nxm)
Definition: CMesh.h:163
bool m_enableTransparency
Definition: CMesh.h:51
void enableWireFrame(bool v)
Definition: CMesh.h:127
size_t getHeight() const override
Returns the height of the image in pixels.
Definition: CImage.cpp:892
static Ptr Create(Args &&... args)
Definition: CMesh.h:41
void render_dl() const override
Render.
Definition: CMesh.cpp:297
EIGEN_STRONG_INLINE void notifyChange() const
Must be called to notify that the object has changed (so, the display list must be updated) ...
bool m_isWireFrame
Definition: CMesh.h:53
void getXBounds(float &min, float &max) const
Definition: CMesh.h:187
bool m_modified_Z
Whether C is not up-to-date wrt to Z.
Definition: CMesh.h:77
mrpt::img::TColormap m_colorMap
Used when m_colorFromZ is true.
Definition: CMesh.h:74
void getGridLimits(float &xmin, float &xmax, float &ymin, float &ymax) const
Definition: CMesh.h:114
void setYMax(const float nym)
Definition: CMesh.h:181
float getYMin() const
Definition: CMesh.h:161
void assignImage(const mrpt::img::CImage &img)
Assigns a texture image, and disable transparency.
Definition: CMesh.cpp:350
A renderizable object suitable for rendering with OpenGL&#39;s display lists.
math::CMatrix C_b
Blue Component of the Color [0,1] for each cell, updated by updateColorsMatrix.
Definition: CMesh.h:71
bool m_colorFromZ
Definition: CMesh.h:52
#define ASSERT_(f)
Defines an assertion mechanism.
Definition: exceptions.h:113
math::CMatrix C_g
Green Component of the Color [0,1] for each cell, updated by updateColorsMatrix.
Definition: CMesh.h:68
size_t getWidth() const override
Returns the width of the image in pixels.
Definition: CImage.cpp:864
float getXMax() const
Definition: CMesh.h:160
[New in MRPT 1.5.0]
Definition: color_maps.h:37
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
GLint GLvoid * img
Definition: glext.h:3763
bool traceRay(const mrpt::poses::CPose3D &o, double &dist) const override
Trace ray.
Definition: CMesh.cpp:553
void setYBounds(const float min, const float max)
Definition: CMesh.h:204
void enableColorFromZ(bool v, mrpt::img::TColormap colorMap=mrpt::img::cmHOT)
Definition: CMesh.h:132
void updatePolygons() const
Definition: CMesh.cpp:574
math::CMatrix Z
Z(x,y): Z-coordinate of the point (x,y)
Definition: CMesh.h:57
float getYMax() const
Definition: CMesh.h:162
void setGridLimits(float xmin, float xmax, float ymin, float ymax)
Definition: CMesh.h:105
bool polygonsUpToDate
Definition: CMesh.h:99
const GLdouble * v
Definition: glext.h:3678
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
#define DEFINE_SERIALIZABLE(class_name)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
void getZ(mrpt::math::CMatrixFloat &out) const
Returns a reference to the internal Z matrix, allowing changing it efficiently.
Definition: CMesh.h:146
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
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
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:88
math::CMatrix C_r
Red Component of the Color [0,1] for each cell, updated by updateColorsMatrix.
Definition: CMesh.h:65
float getXMin() const
Definition: CMesh.h:159
void updateColorsMatrix() const
Called internally to assure C is updated.
Definition: CMesh.cpp:454
void getYBounds(float &min, float &max) const
Definition: CMesh.h:192
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
void setXBounds(const float min, const float max)
Definition: CMesh.h:197
math::CMatrix V
Definition: CMesh.h:60
math::CMatrix mask
Definition: CMesh.h:58
A planar (XY) grid where each cell has an associated height and, optionally, a texture map...
Definition: CMesh.h:39
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
Lightweight 3D point.
This class is a "CSerializable" wrapper for "CMatrixFloat".
Definition: CMatrix.h:24
math::CMatrix U
Texture coordinates.
Definition: CMesh.h:60
void updateTriangles() const
Called internally to assure the triangle list is updated.
Definition: CMesh.cpp:61
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
std::vector< std::pair< CSetOfTriangles::TTriangle, TTriangleVertexIndices > > actualMesh
List of triangles in the mesh.
Definition: CMesh.h:93
bool m_modified_Image
Whether C is not up-to-date wrt to the texture image.
Definition: CMesh.h:79
void getMask(mrpt::math::CMatrixFloat &out) const
Returns a reference to the internal mask matrix, allowing changing it efficiently.
Definition: CMesh.h:149
A class for storing images as grayscale or RGB bitmaps.
Definition: img/CImage.h:130
void setYMin(const float nym)
Definition: CMesh.h:175
math::CMatrix C
Grayscale Color [0,1] for each cell, updated by updateColorsMatrix.
Definition: CMesh.h:62
bool trianglesUpToDate
Whether the actual mesh needs to be recalculated.
Definition: CMesh.h:98



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at lun oct 28 00:14:14 CET 2019