MRPT  1.9.9
CMeshFast.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2019, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #pragma once
11 
12 #include <mrpt/img/CImage.h>
13 #include <mrpt/img/color_maps.h>
14 #include <mrpt/math/CMatrixF.h>
16 
17 namespace mrpt::opengl
18 {
19 /** A planar (XY) grid where each cell has an associated height and, optionally,
20  * a texture map.
21  * To make it faster to render, instead of drawing lines and triangles it draws
22  * a point at each
23  * gridcell.
24  * A typical usage example would be an elevation map or a 3D model of a
25  * terrain.
26  * \sa opengl::COpenGLScene
27  *
28  * <div align="center">
29  * <table border="0" cellspan="4" cellspacing="4" style="border-width: 1px;
30  * border-style: solid;">
31  * <tr> <td> mrpt::opengl::CMeshFast </td> <td> \image html
32  * preview_CMeshFast.png </td> </tr>
33  * </table>
34  * </div>
35  *
36  * \ingroup mrpt_opengl_grp
37  */
39 {
41 
42  protected:
44 
46  bool m_colorFromZ{false};
47  bool m_isImage{false};
48 
49  /** X(x,y): X-coordinate of the point (x,y) */
50  mutable math::CMatrixF X;
51  /** Y(x,y): Y-coordinate of the point (x,y) */
52  mutable math::CMatrixF Y;
53  /** Z(x,y): Z-coordinate of the point (x,y) */
54  mutable math::CMatrixF Z;
55 
56  /** Grayscale Color [0,1] for each cell, updated by updateColorsMatrix */
57  mutable math::CMatrixF C;
58  /** Red Component of the Color [0,1] for each cell, updated by
59  * updateColorsMatrix */
61  /** Green Component of the Color [0,1] for each cell, updated by
62  * updateColorsMatrix */
64  /** Blue Component of the Color [0,1] for each cell, updated by
65  * updateColorsMatrix */
67 
68  /** Used when m_colorFromZ is true */
70  /** By default is 1.0 */
71  float m_pointSize;
72  /** Default: false */
74 
75  /** Whether C is not up-to-date wrt to Z */
76  mutable bool m_modified_Z{true};
77  /** Whether C is not up-to-date wrt to the texture image */
78  mutable bool m_modified_Image{false};
79 
80  /** Called internally to assure C is updated. */
81  void updateColorsMatrix() const;
82  void updatePoints() const;
83 
84  /** Mesh bounds */
85  float xMin, xMax, yMin, yMax;
86 
87  /**Whether the coordinates of the points needs to be recalculated */
88  mutable bool pointsUpToDate{false};
89 
90  public:
91  /** By default is 1.0 */
92  inline void setPointSize(float p) { m_pointSize = p; }
93  inline float getPointSize() const { return m_pointSize; }
94  inline void enablePointSmooth(bool enable = true)
95  {
96  m_pointSmooth = enable;
97  }
98  inline void disablePointSmooth() { m_pointSmooth = false; }
99  void setGridLimits(float xmin, float xmax, float ymin, float ymax)
100  {
101  xMin = xmin;
102  xMax = xmax;
103  yMin = ymin;
104  yMax = ymax;
106  }
107 
108  void getGridLimits(float& xmin, float& xmax, float& ymin, float& ymax) const
109  {
110  xmin = xMin;
111  xmax = xMax;
112  ymin = yMin;
113  ymax = yMax;
114  }
115 
116  void enableTransparency(bool v)
117  {
120  }
122  bool v, mrpt::img::TColormap colorMap = mrpt::img::cmJET)
123  {
124  m_colorFromZ = v;
125  m_colorMap = colorMap;
127  }
128 
129  /** This method sets the matrix of heights for each position (cell) in the
130  * mesh grid */
131  void setZ(const mrpt::math::CMatrixDynamic<float>& in_Z);
132 
133  /** Returns a reference to the internal Z matrix, allowing changing it
134  * efficiently */
135  inline void getZ(mrpt::math::CMatrixFloat& out) const { out = Z; }
136  inline float getXMin() const { return xMin; }
137  inline float getXMax() const { return xMax; }
138  inline float getYMin() const { return yMin; }
139  inline float getYMax() const { return yMax; }
140  inline void setXMin(float nxm)
141  {
142  xMin = nxm;
143  pointsUpToDate = false;
145  }
146  inline void setXMax(float nxm)
147  {
148  xMax = nxm;
149  pointsUpToDate = false;
151  }
152  inline void setYMin(float nym)
153  {
154  yMin = nym;
155  pointsUpToDate = false;
157  }
158  inline void setYMax(float nym)
159  {
160  yMax = nym;
161  pointsUpToDate = false;
163  }
164  inline void getXBounds(float& min, float& max) const
165  {
166  min = xMin;
167  max = xMax;
168  }
169  inline void getYBounds(float& min, float& max) const
170  {
171  min = yMin;
172  max = yMax;
173  }
174  inline void setXBounds(float min, float max)
175  {
176  xMin = min;
177  xMax = max;
178  pointsUpToDate = false;
180  }
181  inline void setYBounds(float min, float max)
182  {
183  yMin = min;
184  yMax = max;
185  pointsUpToDate = false;
187  }
188 
189  /** Render
190  */
191  void render_dl() const override;
192 
193  /** Evaluates the bounding box of this object (including possible children)
194  * in the coordinate frame of the object parent. */
195  void getBoundingBox(
197  mrpt::math::TPoint3D& bb_max) const override;
198 
199  /** Assigns a texture image, and disable transparency.
200  */
201  void assignImage(const mrpt::img::CImage& img);
202 
203  /** Assigns a texture image and Z simultaneously, and disable transparency.
204  */
205  void assignImageAndZ(
206  const mrpt::img::CImage& img,
208 
209  /** Adjust grid limits according to the image aspect ratio, maintaining the
210  * X limits and resizing in the Y direction.
211  */
212  inline void adjustGridToImageAR()
213  {
215  const float ycenter = 0.5 * (yMin + yMax);
216  const float xwidth = xMax - xMin;
217  const float newratio = float(m_textureImage.getWidth()) /
218  float(m_textureImage.getHeight());
219  yMax = ycenter + 0.5 * newratio * xwidth;
220  yMin = ycenter - 0.5 * newratio * xwidth;
222  }
223 
224  /** Constructor
225  */
227  bool enableTransparency = false, float xMin_p = -1.0f,
228  float xMax_p = 1.0f, float yMin_p = -1.0f, float yMax_p = 1.0f)
229  : m_textureImage(0, 0),
231  X(0, 0),
232  Y(0, 0),
233  Z(0, 0),
234  C(0, 0),
235  C_r(0, 0),
236  C_g(0, 0),
237  C_b(0, 0),
238  xMin(xMin_p),
239  xMax(xMax_p),
240  yMin(yMin_p),
241  yMax(yMax_p)
242  {
243  m_color.A = 255;
244  m_color.R = 0;
245  m_color.G = 0;
246  m_color.B = 150;
247  }
248  /** Private, virtual destructor: only can be deleted from smart pointers */
249  ~CMeshFast() override = default;
250 };
251 
252 } // namespace mrpt::opengl
void updateColorsMatrix() const
Called internally to assure C is updated.
Definition: CMeshFast.cpp:224
math::CMatrixF C_g
Green Component of the Color [0,1] for each cell, updated by updateColorsMatrix.
Definition: CMeshFast.h:63
void notifyChange() const
Must be called to notify that the object has changed (so, the display list must be updated) ...
float xMin
Mesh bounds.
Definition: CMeshFast.h:85
TColormap
Different colormaps for use in mrpt::img::colormap()
Definition: color_maps.h:29
void enableColorFromZ(bool v, mrpt::img::TColormap colorMap=mrpt::img::cmJET)
Definition: CMeshFast.h:121
void setYBounds(float min, float max)
Definition: CMeshFast.h:181
void setXBounds(float min, float max)
Definition: CMeshFast.h:174
void setXMax(float nxm)
Definition: CMeshFast.h:146
A planar (XY) grid where each cell has an associated height and, optionally, a texture map...
Definition: CMeshFast.h:38
math::CMatrixF C_r
Red Component of the Color [0,1] for each cell, updated by updateColorsMatrix.
Definition: CMeshFast.h:60
void assignImageAndZ(const mrpt::img::CImage &img, const mrpt::math::CMatrixDynamic< float > &in_Z)
Assigns a texture image and Z simultaneously, and disable transparency.
Definition: CMeshFast.cpp:144
math::CMatrixF Z
Z(x,y): Z-coordinate of the point (x,y)
Definition: CMeshFast.h:54
size_t getHeight() const override
Returns the height of the image in pixels.
Definition: CImage.cpp:845
uint8_t B
Definition: TColor.h:46
mrpt::img::TColormap m_colorMap
Used when m_colorFromZ is true.
Definition: CMeshFast.h:69
math::CMatrixF C_b
Blue Component of the Color [0,1] for each cell, updated by updateColorsMatrix.
Definition: CMeshFast.h:66
void render_dl() const override
Render.
Definition: CMeshFast.cpp:59
uint8_t G
Definition: TColor.h:46
void setXMin(float nxm)
Definition: CMeshFast.h:140
bool m_modified_Z
Whether C is not up-to-date wrt to Z.
Definition: CMeshFast.h:76
void setPointSize(float p)
By default is 1.0.
Definition: CMeshFast.h:92
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:78
math::CMatrixF C
Grayscale Color [0,1] for each cell, updated by updateColorsMatrix.
Definition: CMeshFast.h:57
void getYBounds(float &min, float &max) const
Definition: CMeshFast.h:169
#define ASSERT_(f)
Defines an assertion mechanism.
Definition: exceptions.h:120
size_t getWidth() const override
Returns the width of the image in pixels.
Definition: CImage.cpp:814
void getGridLimits(float &xmin, float &xmax, float &ymin, float &ymax) const
Definition: CMeshFast.h:108
bool pointsUpToDate
Whether the coordinates of the points needs to be recalculated.
Definition: CMeshFast.h:88
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:283
void setZ(const mrpt::math::CMatrixDynamic< float > &in_Z)
This method sets the matrix of heights for each position (cell) in the mesh grid. ...
Definition: CMeshFast.cpp:271
float getYMax() const
Definition: CMeshFast.h:139
float getYMin() const
Definition: CMeshFast.h:138
uint8_t R
Definition: TColor.h:46
void setYMin(float nym)
Definition: CMeshFast.h:152
mrpt::img::TColor m_color
Color components in the range [0,255].
Definition: CRenderizable.h:51
void enablePointSmooth(bool enable=true)
Definition: CMeshFast.h:94
This class is a "CSerializable" wrapper for "CMatrixFloat".
Definition: CMatrixF.h:22
void setYMax(float nym)
Definition: CMeshFast.h:158
math::CMatrixF Y
Y(x,y): Y-coordinate of the point (x,y)
Definition: CMeshFast.h:52
bool m_pointSmooth
Default: false.
Definition: CMeshFast.h:73
void enableTransparency(bool v)
Definition: CMeshFast.h:116
void adjustGridToImageAR()
Adjust grid limits according to the image aspect ratio, maintaining the X limits and resizing in the ...
Definition: CMeshFast.h:212
mrpt::vision::TStereoCalibResults out
void updatePoints() const
Definition: CMeshFast.cpp:30
float getXMin() const
Definition: CMeshFast.h:136
float m_pointSize
By default is 1.0.
Definition: CMeshFast.h:71
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:15
const auto bb_max
math::CMatrixF X
X(x,y): X-coordinate of the point (x,y)
Definition: CMeshFast.h:50
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:226
void setGridLimits(float xmin, float xmax, float ymin, float ymax)
Definition: CMeshFast.h:99
float getPointSize() const
Definition: CMeshFast.h:93
#define DEFINE_SERIALIZABLE(class_name, NS)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
const auto bb_min
Lightweight 3D point.
Definition: TPoint3D.h:90
mrpt::img::CImage m_textureImage
Definition: CMeshFast.h:43
float getXMax() const
Definition: CMeshFast.h:137
This template class provides the basic functionality for a general 2D any-size, resizable container o...
void assignImage(const mrpt::img::CImage &img)
Assigns a texture image, and disable transparency.
Definition: CMeshFast.cpp:122
~CMeshFast() override=default
Private, virtual destructor: only can be deleted from smart pointers.
void getZ(mrpt::math::CMatrixFloat &out) const
Returns a reference to the internal Z matrix, allowing changing it efficiently.
Definition: CMeshFast.h:135
uint8_t A
Definition: TColor.h:46
A class for storing images as grayscale or RGB bitmaps.
Definition: img/CImage.h:147
void getXBounds(float &min, float &max) const
Definition: CMeshFast.h:164



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 4a95fd864 Fri Dec 13 00:48:40 2019 +0100 at vie dic 13 01:00:11 CET 2019