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



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 7d5e6d718 Fri Aug 24 01:51:28 2018 +0200 at lun nov 2 08:35:50 CET 2020