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-2017, 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/utils/CImage.h>
16 #include <mrpt/utils/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  }
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::utils::CImage& img);
210 
211  /** Assigns a texture image and Z simultaneously, and disable transparency.
212  */
213  void assignImageAndZ(
214  const mrpt::utils::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 = -1.0f, float xMax = 1.0f,
236  float yMin = -1.0f, float yMax = 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),
248  m_colorMap(mrpt::utils::cmJET),
249  m_modified_Z(true),
250  m_modified_Image(false),
251  xMin(xMin),
252  xMax(xMax),
253  yMin(yMin),
254  yMax(yMax),
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 } // end namespace
267 
268 } // End of namespace
269 
270 #endif
void updateColorsMatrix() const
Called internally to assure C is updated.
Definition: CMeshFast.cpp:242
virtual ~CMeshFast()
Private, virtual destructor: only can be deleted from smart pointers.
Definition: CMeshFast.h:263
void setXMax(const float &nxm)
Definition: CMeshFast.h:149
float xMin
Mesh bounds.
Definition: CMeshFast.h:88
math::CMatrix C_r
Red Component of the Color [0,1] for each cell, updated by updateColorsMatrix.
Definition: CMeshFast.h:63
#define min(a, b)
mrpt::utils::CImage m_textureImage
Definition: CMeshFast.h:46
TColormap
Different colormaps for use in mrpt::utils::colormap()
Definition: color_maps.h:31
A class for storing images as grayscale or RGB bitmaps.
Definition: CImage.h:118
void setYBounds(const float &min, const float &max)
Definition: CMeshFast.h:184
A planar (XY) grid where each cell has an associated height and, optionally, a texture map...
Definition: CMeshFast.h:41
EIGEN_STRONG_INLINE void notifyChange() const
Must be called to notify that the object has changed (so, the display list must be updated) ...
void enableColorFromZ(bool v, mrpt::utils::TColormap colorMap=mrpt::utils::cmJET)
Definition: CMeshFast.h:124
void render_dl() const override
Render.
Definition: CMeshFast.cpp:59
void setYMin(const float &nym)
Definition: CMeshFast.h:155
void assignImageAndZ(const mrpt::utils::CImage &img, const mrpt::math::CMatrixTemplateNumeric< float > &in_Z)
Assigns a texture image and Z simultaneously, and disable transparency.
Definition: CMeshFast.cpp:151
bool m_modified_Z
Whether C is not up-to-date wrt to Z.
Definition: CMeshFast.h:79
CMeshFast(bool enableTransparency=false, float xMin=-1.0f, float xMax=1.0f, float yMin=-1.0f, float yMax=1.0f)
Constructor.
Definition: CMeshFast.h:234
mrpt::utils::TColormap m_colorMap
Used when m_colorFromZ is true.
Definition: CMeshFast.h:72
void setPointSize(float p)
By default is 1.0.
Definition: CMeshFast.h:95
A renderizable object suitable for rendering with OpenGL&#39;s display lists.
bool m_modified_Image
Whether C is not up-to-date wrt to the texture image.
Definition: CMeshFast.h:81
void getYBounds(float &min, float &max) const
Definition: CMeshFast.h:172
size_t getWidth() const override
Returns the width of the image in pixels.
Definition: CImage.cpp:869
void getGridLimits(float &xmin, float &xmax, float &ymin, float &ymax) const
Definition: CMeshFast.h:111
GLint GLvoid * img
Definition: glext.h:3763
bool pointsUpToDate
Whether the coordinates of the points needs to be recalculated.
Definition: CMeshFast.h:91
math::CMatrix Z
Z(x,y): Z-coordinate of the point (x,y)
Definition: CMeshFast.h:57
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:300
size_t getHeight() const override
Returns the height of the image in pixels.
Definition: CImage.cpp:897
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:288
mrpt::utils::TColor m_color
Color components in the range [0,255].
Definition: CRenderizable.h:54
float getYMax() const
Definition: CMeshFast.h:142
math::CMatrix Y
Y(x,y): Y-coordinate of the point (x,y)
Definition: CMeshFast.h:55
float getYMin() const
Definition: CMeshFast.h:141
math::CMatrix C_g
Green Component of the Color [0,1] for each cell, updated by updateColorsMatrix.
Definition: CMeshFast.h:66
math::CMatrix X
X(x,y): X-coordinate of the point (x,y)
Definition: CMeshFast.h:53
void enablePointSmooth(bool enable=true)
Definition: CMeshFast.h:97
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 assignImage(const mrpt::utils::CImage &img)
Assigns a texture image, and disable transparency.
Definition: CMeshFast.cpp:125
bool m_pointSmooth
Default: false.
Definition: CMeshFast.h:76
void enableTransparency(bool v)
Definition: CMeshFast.h:119
static Ptr Create(Args &&... args)
Definition: CMeshFast.h:43
math::CMatrix C
Grayscale Color [0,1] for each cell, updated by updateColorsMatrix.
Definition: CMeshFast.h:60
void adjustGridToImageAR()
Adjust grid limits according to the image aspect ratio, maintaining the X limits and resizing in the ...
Definition: CMeshFast.h:220
void updatePoints() const
Definition: CMeshFast.cpp:29
float getXMin() const
Definition: CMeshFast.h:139
float m_pointSize
By default is 1.0.
Definition: CMeshFast.h:74
void setXBounds(const float &min, const float &max)
Definition: CMeshFast.h:177
#define ASSERT_(f)
math::CMatrix C_b
Blue Component of the Color [0,1] for each cell, updated by updateColorsMatrix.
Definition: CMeshFast.h:69
void setGridLimits(float xmin, float xmax, float ymin, float ymax)
Definition: CMeshFast.h:102
float getPointSize() const
Definition: CMeshFast.h:96
Lightweight 3D point.
void setXMin(const float &nxm)
Definition: CMeshFast.h:143
This class is a "CSerializable" wrapper for "CMatrixFloat".
Definition: CMatrix.h:25
float getXMax() const
Definition: CMeshFast.h:140
GLfloat GLfloat p
Definition: glext.h:6305
void getZ(mrpt::math::CMatrixFloat &out) const
Returns a reference to the internal Z matrix, allowing changing it efficiently.
Definition: CMeshFast.h:138
void getXBounds(float &min, float &max) const
Definition: CMeshFast.h:167
void setYMax(const float &nym)
Definition: CMeshFast.h:161
std::shared_ptr< CMeshFast > Ptr
Definition: CMeshFast.h:43



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019