Main MRPT website > C++ reference for MRPT 1.9.9
CMeshFast.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_CMeshFast_H
11 #define opengl_CMeshFast_H
12 
14 #include <mrpt/math/CMatrix.h>
15 #include <mrpt/img/CImage.h>
16 #include <mrpt/img/color_maps.h>
17 
18 namespace mrpt
19 {
20 namespace opengl
21 {
22 /** A planar (XY) grid where each cell has an associated height and, optionally,
23  * a texture map.
24  * To make it faster to render, instead of drawing lines and triangles it draws
25  * a point at each
26  * gridcell.
27  * A typical usage example would be an elevation map or a 3D model of a
28  * terrain.
29  * \sa opengl::COpenGLScene
30  *
31  * <div align="center">
32  * <table border="0" cellspan="4" cellspacing="4" style="border-width: 1px;
33  * border-style: solid;">
34  * <tr> <td> mrpt::opengl::CMeshFast </td> <td> \image html
35  * preview_CMeshFast.png </td> </tr>
36  * </table>
37  * </div>
38  *
39  * \ingroup mrpt_opengl_grp
40  */
42 {
44 
45  protected:
47 
50  bool m_isImage;
51 
52  /** X(x,y): X-coordinate of the point (x,y) */
53  mutable math::CMatrix X;
54  /** Y(x,y): Y-coordinate of the point (x,y) */
55  mutable math::CMatrix Y;
56  /** Z(x,y): Z-coordinate of the point (x,y) */
57  mutable math::CMatrix Z;
58 
59  /** Grayscale Color [0,1] for each cell, updated by updateColorsMatrix */
60  mutable math::CMatrix C;
61  /** Red Component of the Color [0,1] for each cell, updated by
62  * updateColorsMatrix */
63  mutable math::CMatrix C_r;
64  /** Green Component of the Color [0,1] for each cell, updated by
65  * updateColorsMatrix */
66  mutable math::CMatrix C_g;
67  /** Blue Component of the Color [0,1] for each cell, updated by
68  * updateColorsMatrix */
69  mutable math::CMatrix C_b;
70 
71  /** Used when m_colorFromZ is true */
73  /** By default is 1.0 */
74  float m_pointSize;
75  /** Default: false */
77 
78  /** Whether C is not up-to-date wrt to Z */
79  mutable bool m_modified_Z;
80  /** Whether C is not up-to-date wrt to the texture image */
81  mutable bool m_modified_Image;
82 
83  /** Called internally to assure C is updated. */
84  void updateColorsMatrix() const;
85  void updatePoints() const;
86 
87  /** Mesh bounds */
88  float xMin, xMax, yMin, yMax;
89 
90  /**Whether the coordinates of the points needs to be recalculated */
91  mutable bool pointsUpToDate;
92 
93  public:
94  /** By default is 1.0 */
95  inline void setPointSize(float p) { m_pointSize = p; }
96  inline float getPointSize() const { return m_pointSize; }
97  inline void enablePointSmooth(bool enable = true)
98  {
99  m_pointSmooth = enable;
100  }
101  inline void disablePointSmooth() { m_pointSmooth = false; }
102  void setGridLimits(float xmin, float xmax, float ymin, float ymax)
103  {
104  xMin = xmin;
105  xMax = xmax;
106  yMin = ymin;
107  yMax = ymax;
109  }
110 
111  void getGridLimits(float& xmin, float& xmax, float& ymin, float& ymax) const
112  {
113  xmin = xMin;
114  xmax = xMax;
115  ymin = yMin;
116  ymax = yMax;
117  }
118 
120  {
123  }
125  bool v, mrpt::img::TColormap colorMap = mrpt::img::cmJET)
126  {
127  m_colorFromZ = v;
128  m_colorMap = colorMap;
130  }
131 
132  /** This method sets the matrix of heights for each position (cell) in the
133  * mesh grid */
135 
136  /** Returns a reference to the internal Z matrix, allowing changing it
137  * efficiently */
138  inline void getZ(mrpt::math::CMatrixFloat& out) const { out = Z; }
139  inline float getXMin() const { return xMin; }
140  inline float getXMax() const { return xMax; }
141  inline float getYMin() const { return yMin; }
142  inline float getYMax() const { return yMax; }
143  inline void setXMin(const float& nxm)
144  {
145  xMin = nxm;
146  pointsUpToDate = false;
148  }
149  inline void setXMax(const float& nxm)
150  {
151  xMax = nxm;
152  pointsUpToDate = false;
154  }
155  inline void setYMin(const float& nym)
156  {
157  yMin = nym;
158  pointsUpToDate = false;
160  }
161  inline void setYMax(const float& nym)
162  {
163  yMax = nym;
164  pointsUpToDate = false;
166  }
167  inline void getXBounds(float& min, float& max) const
168  {
169  min = xMin;
170  max = xMax;
171  }
172  inline void getYBounds(float& min, float& max) const
173  {
174  min = yMin;
175  max = yMax;
176  }
177  inline void setXBounds(const float& min, const float& max)
178  {
179  xMin = min;
180  xMax = max;
181  pointsUpToDate = false;
183  }
184  inline void setYBounds(const float& min, const float& max)
185  {
186  yMin = min;
187  yMax = max;
188  pointsUpToDate = false;
190  }
191 
192  /** Class factory */
193  static CMeshFast::Ptr Create(
194  bool enableTransparency, float xMin = -1.0f, float xMax = 1.0f,
195  float yMin = -1.0f, float yMax = 1.0f);
196 
197  /** Render
198  */
199  void render_dl() const override;
200 
201  /** Evaluates the bounding box of this object (including possible children)
202  * in the coordinate frame of the object parent. */
203  void getBoundingBox(
204  mrpt::math::TPoint3D& bb_min,
205  mrpt::math::TPoint3D& bb_max) const override;
206 
207  /** Assigns a texture image, and disable transparency.
208  */
209  void assignImage(const mrpt::img::CImage& img);
210 
211  /** Assigns a texture image and Z simultaneously, and disable transparency.
212  */
213  void assignImageAndZ(
214  const mrpt::img::CImage& img,
216 
217  /** Adjust grid limits according to the image aspect ratio, maintaining the
218  * X limits and resizing in the Y direction.
219  */
220  inline void adjustGridToImageAR()
221  {
223  const float ycenter = 0.5 * (yMin + yMax);
224  const float xwidth = xMax - xMin;
225  const float newratio = float(m_textureImage.getWidth()) /
226  float(m_textureImage.getHeight());
227  yMax = ycenter + 0.5 * newratio * xwidth;
228  yMin = ycenter - 0.5 * newratio * xwidth;
230  }
231 
232  /** Constructor
233  */
235  bool enableTransparency = false, float xMin_p = -1.0f,
236  float xMax_p = 1.0f, float yMin_p = -1.0f, float yMax_p = 1.0f)
237  : m_textureImage(0, 0),
239  m_colorFromZ(false),
240  m_isImage(false),
241  X(0, 0),
242  Y(0, 0),
243  Z(0, 0),
244  C(0, 0),
245  C_r(0, 0),
246  C_g(0, 0),
247  C_b(0, 0),
249  m_modified_Z(true),
250  m_modified_Image(false),
251  xMin(xMin_p),
252  xMax(xMax_p),
253  yMin(yMin_p),
254  yMax(yMax_p),
255  pointsUpToDate(false)
256  {
257  m_color.A = 255;
258  m_color.R = 0;
259  m_color.G = 0;
260  m_color.B = 150;
261  }
262  /** Private, virtual destructor: only can be deleted from smart pointers */
263  virtual ~CMeshFast() {}
264 };
265 
266 } // namespace opengl
267 
268 } // namespace mrpt
269 
270 #endif
mrpt::opengl::CMeshFast::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: CMeshFast.cpp:270
mrpt::opengl::CMeshFast::updatePoints
void updatePoints() const
Definition: CMeshFast.cpp:29
mrpt::opengl::CMeshFast::xMax
float xMax
Definition: CMeshFast.h:88
mrpt::opengl::CMeshFast::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: CMeshFast.cpp:282
mrpt::img::CImage::getWidth
size_t getWidth() const override
Returns the width of the image in pixels.
Definition: CImage.cpp:864
mrpt::opengl::CMeshFast::~CMeshFast
virtual ~CMeshFast()
Private, virtual destructor: only can be deleted from smart pointers.
Definition: CMeshFast.h:263
mrpt::opengl::CMeshFast::getXMin
float getXMin() const
Definition: CMeshFast.h:139
mrpt::img::TColormap
TColormap
Different colormaps for use in mrpt::img::colormap()
Definition: color_maps.h:31
mrpt::opengl::CMeshFast::getYMin
float getYMin() const
Definition: CMeshFast.h:141
mrpt::opengl::CMeshFast::enablePointSmooth
void enablePointSmooth(bool enable=true)
Definition: CMeshFast.h:97
mrpt::opengl::CMeshFast::setXMin
void setXMin(const float &nxm)
Definition: CMeshFast.h:143
mrpt::opengl::CMeshFast::yMin
float yMin
Definition: CMeshFast.h:88
mrpt::opengl::CMeshFast::xMin
float xMin
Mesh bounds.
Definition: CMeshFast.h:88
mrpt::opengl::CMeshFast::render_dl
void render_dl() const override
Render.
Definition: CMeshFast.cpp:58
mrpt::opengl::CMeshFast::getZ
void getZ(mrpt::math::CMatrixFloat &out) const
Returns a reference to the internal Z matrix, allowing changing it efficiently.
Definition: CMeshFast.h:138
mrpt::opengl::CMeshFast::setYMax
void setYMax(const float &nym)
Definition: CMeshFast.h:161
mrpt::opengl::CMeshFast::pointsUpToDate
bool pointsUpToDate
Whether the coordinates of the points needs to be recalculated.
Definition: CMeshFast.h:91
mrpt::opengl::CMeshFast::setYMin
void setYMin(const float &nym)
Definition: CMeshFast.h:155
CRenderizableDisplayList.h
mrpt::opengl::CMeshFast::m_enableTransparency
bool m_enableTransparency
Definition: CMeshFast.h:48
mrpt::opengl::CMeshFast::C_r
math::CMatrix C_r
Red Component of the Color [0,1] for each cell, updated by updateColorsMatrix.
Definition: CMeshFast.h:63
color_maps.h
mrpt::opengl::CMeshFast::assignImage
void assignImage(const mrpt::img::CImage &img)
Assigns a texture image, and disable transparency.
Definition: CMeshFast.cpp:121
mrpt::opengl::CRenderizableDisplayList
A renderizable object suitable for rendering with OpenGL's display lists.
Definition: CRenderizableDisplayList.h:39
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
mrpt::opengl::CMeshFast::enableColorFromZ
void enableColorFromZ(bool v, mrpt::img::TColormap colorMap=mrpt::img::cmJET)
Definition: CMeshFast.h:124
mrpt::opengl::CMeshFast::setGridLimits
void setGridLimits(float xmin, float xmax, float ymin, float ymax)
Definition: CMeshFast.h:102
mrpt::img::TColor::R
uint8_t R
Definition: TColor.h:48
mrpt::opengl::CMeshFast::m_modified_Image
bool m_modified_Image
Whether C is not up-to-date wrt to the texture image.
Definition: CMeshFast.h:81
mrpt::opengl::CMeshFast::updateColorsMatrix
void updateColorsMatrix() const
Called internally to assure C is updated.
Definition: CMeshFast.cpp:224
mrpt::opengl::CMeshFast::m_colorFromZ
bool m_colorFromZ
Definition: CMeshFast.h:49
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CKalmanFilterCapable.h:30
mrpt::opengl::CMeshFast::getYBounds
void getYBounds(float &min, float &max) const
Definition: CMeshFast.h:172
mrpt::opengl::CMeshFast::setYBounds
void setYBounds(const float &min, const float &max)
Definition: CMeshFast.h:184
mrpt::opengl::CMeshFast::CMeshFast
CMeshFast(bool enableTransparency=false, float xMin_p=-1.0f, float xMax_p=1.0f, float yMin_p=-1.0f, float yMax_p=1.0f)
Constructor.
Definition: CMeshFast.h:234
ASSERT_
#define ASSERT_(f)
Defines an assertion mechanism.
Definition: exceptions.h:113
mrpt::opengl::CMeshFast::C_b
math::CMatrix C_b
Blue Component of the Color [0,1] for each cell, updated by updateColorsMatrix.
Definition: CMeshFast.h:69
p
GLfloat GLfloat p
Definition: glext.h:6305
mrpt::opengl::CMeshFast::setPointSize
void setPointSize(float p)
By default is 1.0.
Definition: CMeshFast.h:95
mrpt::opengl::CMeshFast::enableTransparency
void enableTransparency(bool v)
Definition: CMeshFast.h:119
mrpt::math::CMatrixTemplateNumeric
A matrix of dynamic size.
Definition: CMatrixTemplateNumeric.h:37
v
const GLdouble * v
Definition: glext.h:3678
mrpt::opengl::CMeshFast::m_colorMap
mrpt::img::TColormap m_colorMap
Used when m_colorFromZ is true.
Definition: CMeshFast.h:72
mrpt::img::TColor::B
uint8_t B
Definition: TColor.h:48
mrpt::opengl::CMeshFast::Y
math::CMatrix Y
Y(x,y): Y-coordinate of the point (x,y)
Definition: CMeshFast.h:55
mrpt::opengl::CRenderizable::m_color
mrpt::img::TColor m_color
Color components in the range [0,255].
Definition: CRenderizable.h:54
mrpt::opengl::CMeshFast::m_pointSmooth
bool m_pointSmooth
Default: false.
Definition: CMeshFast.h:76
mrpt::opengl::CMeshFast::yMax
float yMax
Definition: CMeshFast.h:88
mrpt::opengl::CMeshFast::C_g
math::CMatrix C_g
Green Component of the Color [0,1] for each cell, updated by updateColorsMatrix.
Definition: CMeshFast.h:66
mrpt::math::CMatrix
This class is a "CSerializable" wrapper for "CMatrixFloat".
Definition: CMatrix.h:24
mrpt::opengl::CMeshFast::getXMax
float getXMax() const
Definition: CMeshFast.h:140
mrpt::opengl::CMeshFast::disablePointSmooth
void disablePointSmooth()
Definition: CMeshFast.h:101
mrpt::opengl::CMeshFast::m_isImage
bool m_isImage
Definition: CMeshFast.h:50
mrpt::opengl::CMeshFast::adjustGridToImageAR
void adjustGridToImageAR()
Adjust grid limits according to the image aspect ratio, maintaining the X limits and resizing in the ...
Definition: CMeshFast.h:220
mrpt::opengl::CMeshFast::Ptr
std::shared_ptr< CMeshFast > Ptr
Definition: CMeshFast.h:43
mrpt::opengl::CMeshFast::m_textureImage
mrpt::img::CImage m_textureImage
Definition: CMeshFast.h:46
mrpt::img::TColor::A
uint8_t A
Definition: TColor.h:48
mrpt::opengl::CMeshFast::getGridLimits
void getGridLimits(float &xmin, float &xmax, float &ymin, float &ymax) const
Definition: CMeshFast.h:111
mrpt::img::CImage
A class for storing images as grayscale or RGB bitmaps.
Definition: img/CImage.h:130
mrpt::math::TPoint3D
Lightweight 3D point.
Definition: lightweight_geom_data.h:378
mrpt::opengl::CMeshFast::m_modified_Z
bool m_modified_Z
Whether C is not up-to-date wrt to Z.
Definition: CMeshFast.h:79
mrpt::opengl::CMeshFast
A planar (XY) grid where each cell has an associated height and, optionally, a texture map.
Definition: CMeshFast.h:41
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
img
GLint GLvoid * img
Definition: glext.h:3763
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::img::TColor::G
uint8_t G
Definition: TColor.h:48
mrpt::opengl::CMeshFast::X
math::CMatrix X
X(x,y): X-coordinate of the point (x,y)
Definition: CMeshFast.h:53
mrpt::opengl::CMeshFast::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: CMeshFast.cpp:144
mrpt::opengl::CMeshFast::Create
static Ptr Create(Args &&... args)
Definition: CMeshFast.h:43
mrpt::opengl::CMeshFast::m_pointSize
float m_pointSize
By default is 1.0.
Definition: CMeshFast.h:74
mrpt::opengl::CMeshFast::Z
math::CMatrix Z
Z(x,y): Z-coordinate of the point (x,y)
Definition: CMeshFast.h:57
mrpt::opengl::CMeshFast::getXBounds
void getXBounds(float &min, float &max) const
Definition: CMeshFast.h:167
mrpt::img::cmJET
@ cmJET
Definition: color_maps.h:35
CImage.h
mrpt::opengl::CMeshFast::getPointSize
float getPointSize() const
Definition: CMeshFast.h:96
mrpt::opengl::CMeshFast::setXMax
void setXMax(const float &nxm)
Definition: CMeshFast.h:149
mrpt::opengl::CMeshFast::getYMax
float getYMax() const
Definition: CMeshFast.h:142
mrpt::opengl::CMeshFast::C
math::CMatrix C
Grayscale Color [0,1] for each cell, updated by updateColorsMatrix.
Definition: CMeshFast.h:60
mrpt::opengl::CMeshFast::setXBounds
void setXBounds(const float &min, const float &max)
Definition: CMeshFast.h:177



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