MRPT  2.0.0
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-2020, 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  public:
43  /** @name Renderizable shader API virtual methods
44  * @{ */
45  void onUpdateBuffers_Points() override;
46  /** @} */
47 
48  /** Constructor
49  */
51  bool enableTransparency = false, float xMin_p = -1.0f,
52  float xMax_p = 1.0f, float yMin_p = -1.0f, float yMax_p = 1.0f)
53  : m_textureImage(0, 0),
55  X(0, 0),
56  Y(0, 0),
57  Z(0, 0),
58  C(0, 0),
59  C_r(0, 0),
60  C_g(0, 0),
61  C_b(0, 0),
62  xMin(xMin_p),
63  xMax(xMax_p),
64  yMin(yMin_p),
65  yMax(yMax_p)
66  {
67  m_color.A = 255;
68  m_color.R = 0;
69  m_color.G = 0;
70  m_color.B = 150;
71  }
72  virtual ~CMeshFast() override = default;
73 
74  void setGridLimits(float xmin, float xmax, float ymin, float ymax)
75  {
76  xMin = xmin;
77  xMax = xmax;
78  yMin = ymin;
79  yMax = ymax;
81  }
82 
83  void getGridLimits(float& xmin, float& xmax, float& ymin, float& ymax) const
84  {
85  xmin = xMin;
86  xmax = xMax;
87  ymin = yMin;
88  ymax = yMax;
89  }
90 
91  void enableTransparency(bool v)
92  {
95  }
97  bool v, mrpt::img::TColormap colorMap = mrpt::img::cmJET)
98  {
99  m_colorFromZ = v;
100  m_colorMap = colorMap;
102  }
103 
104  /** This method sets the matrix of heights for each position (cell) in the
105  * mesh grid */
106  void setZ(const mrpt::math::CMatrixDynamic<float>& in_Z);
107 
108  /** Returns a reference to the internal Z matrix, allowing changing it
109  * efficiently */
110  inline void getZ(mrpt::math::CMatrixFloat& out) const { out = Z; }
111  inline float getXMin() const { return xMin; }
112  inline float getXMax() const { return xMax; }
113  inline float getYMin() const { return yMin; }
114  inline float getYMax() const { return yMax; }
115  inline void setXMin(float nxm)
116  {
117  xMin = nxm;
118  pointsUpToDate = false;
120  }
121  inline void setXMax(float nxm)
122  {
123  xMax = nxm;
124  pointsUpToDate = false;
126  }
127  inline void setYMin(float nym)
128  {
129  yMin = nym;
130  pointsUpToDate = false;
132  }
133  inline void setYMax(float nym)
134  {
135  yMax = nym;
136  pointsUpToDate = false;
138  }
139  inline void getXBounds(float& min, float& max) const
140  {
141  min = xMin;
142  max = xMax;
143  }
144  inline void getYBounds(float& min, float& max) const
145  {
146  min = yMin;
147  max = yMax;
148  }
149  inline void setXBounds(float min, float max)
150  {
151  xMin = min;
152  xMax = max;
153  pointsUpToDate = false;
155  }
156  inline void setYBounds(float min, float max)
157  {
158  yMin = min;
159  yMax = max;
160  pointsUpToDate = false;
162  }
163 
164  void getBoundingBox(
166  mrpt::math::TPoint3D& bb_max) const override;
167 
168  /** Assigns a texture image, and disable transparency.
169  */
170  void assignImage(const mrpt::img::CImage& img);
171 
172  /** Assigns a texture image and Z simultaneously, and disable transparency.
173  */
174  void assignImageAndZ(
175  const mrpt::img::CImage& img,
177 
178  /** Adjust grid limits according to the image aspect ratio, maintaining the
179  * X limits and resizing in the Y direction.
180  */
181  inline void adjustGridToImageAR()
182  {
184  const float ycenter = 0.5f * (yMin + yMax);
185  const float xwidth = xMax - xMin;
186  const float newratio = float(m_textureImage.getWidth()) /
187  float(m_textureImage.getHeight());
188  yMax = ycenter + 0.5f * newratio * xwidth;
189  yMin = ycenter - 0.5f * newratio * xwidth;
191  }
192 
193  protected:
195 
197  bool m_colorFromZ{false};
198  bool m_isImage{false};
199 
200  /** X(x,y): X-coordinate of the point (x,y) */
201  mutable math::CMatrixF X;
202  /** Y(x,y): Y-coordinate of the point (x,y) */
203  mutable math::CMatrixF Y;
204  /** Z(x,y): Z-coordinate of the point (x,y) */
205  mutable math::CMatrixF Z;
206 
207  /** Grayscale or RGB components [0,255] for each cell, updated by
208  * updateColorsMatrix */
210 
211  /** Used when m_colorFromZ is true */
213 
214  /** Whether C is not up-to-date wrt to Z */
215  mutable bool m_modified_Z{true};
216  /** Whether C is not up-to-date wrt to the texture image */
217  mutable bool m_modified_Image{false};
218 
219  /** Called internally to assure C is updated. */
220  void updateColorsMatrix() const;
221  void updatePoints() const;
222 
223  /** Mesh bounds */
224  float xMin, xMax, yMin, yMax;
225 
226  /**Whether the coordinates of the points needs to be recalculated */
227  mutable bool pointsUpToDate{false};
228 };
229 
230 } // namespace mrpt::opengl
void updateColorsMatrix() const
Called internally to assure C is updated.
Definition: CMeshFast.cpp:195
float xMin
Mesh bounds.
Definition: CMeshFast.h:224
TColormap
Different colormaps for use in mrpt::img::colormap()
Definition: color_maps.h:30
void enableColorFromZ(bool v, mrpt::img::TColormap colorMap=mrpt::img::cmJET)
Definition: CMeshFast.h:96
void setYBounds(float min, float max)
Definition: CMeshFast.h:156
void setXBounds(float min, float max)
Definition: CMeshFast.h:149
math::CMatrix_u8 C_r
Definition: CMeshFast.h:209
void setXMax(float nxm)
Definition: CMeshFast.h:121
void notifyChange() const
Call to enable calling renderUpdateBuffers() before the next render() rendering iteration.
A planar (XY) grid where each cell has an associated height and, optionally, a texture map...
Definition: CMeshFast.h:38
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:117
math::CMatrixF Z
Z(x,y): Z-coordinate of the point (x,y)
Definition: CMeshFast.h:205
size_t getHeight() const override
Returns the height of the image in pixels.
Definition: CImage.cpp:849
uint8_t B
Definition: TColor.h:51
mrpt::img::TColormap m_colorMap
Used when m_colorFromZ is true.
Definition: CMeshFast.h:212
uint8_t G
Definition: TColor.h:51
virtual ~CMeshFast() override=default
void setXMin(float nxm)
Definition: CMeshFast.h:115
bool m_modified_Z
Whether C is not up-to-date wrt to Z.
Definition: CMeshFast.h:215
math::CMatrix_u8 C_g
Definition: CMeshFast.h:209
math::CMatrix_u8 C
Grayscale or RGB components [0,255] for each cell, updated by updateColorsMatrix. ...
Definition: CMeshFast.h:209
bool m_modified_Image
Whether C is not up-to-date wrt to the texture image.
Definition: CMeshFast.h:217
void getYBounds(float &min, float &max) const
Definition: CMeshFast.h:144
#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:818
void getGridLimits(float &xmin, float &xmax, float &ymin, float &ymax) const
Definition: CMeshFast.h:83
bool pointsUpToDate
Whether the coordinates of the points needs to be recalculated.
Definition: CMeshFast.h:227
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:256
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:244
float getYMax() const
Definition: CMeshFast.h:114
void onUpdateBuffers_Points() override
Must be implemented in derived classes to update the geometric entities to be drawn in "m_*_buffer" f...
Definition: CMeshFast.cpp:55
float getYMin() const
Definition: CMeshFast.h:113
uint8_t R
Definition: TColor.h:51
void setYMin(float nym)
Definition: CMeshFast.h:127
Renderizable generic renderer for objects using the points shader.
mrpt::img::TColor m_color
Color components in the range [0,255].
Definition: CRenderizable.h:59
This class is a "CSerializable" wrapper for "CMatrixFloat".
Definition: CMatrixF.h:22
void setYMax(float nym)
Definition: CMeshFast.h:133
math::CMatrixF Y
Y(x,y): Y-coordinate of the point (x,y)
Definition: CMeshFast.h:203
void enableTransparency(bool v)
Definition: CMeshFast.h:91
void adjustGridToImageAR()
Adjust grid limits according to the image aspect ratio, maintaining the X limits and resizing in the ...
Definition: CMeshFast.h:181
mrpt::vision::TStereoCalibResults out
void updatePoints() const
Definition: CMeshFast.cpp:29
float getXMin() const
Definition: CMeshFast.h:111
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:13
const auto bb_max
math::CMatrixF X
X(x,y): X-coordinate of the point (x,y)
Definition: CMeshFast.h:201
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:50
void setGridLimits(float xmin, float xmax, float ymin, float ymax)
Definition: CMeshFast.h:74
#define DEFINE_SERIALIZABLE(class_name, NS)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
const auto bb_min
mrpt::img::CImage m_textureImage
Definition: CMeshFast.h:194
float getXMax() const
Definition: CMeshFast.h:112
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:95
void getZ(mrpt::math::CMatrixFloat &out) const
Returns a reference to the internal Z matrix, allowing changing it efficiently.
Definition: CMeshFast.h:110
math::CMatrix_u8 C_b
Definition: CMeshFast.h:209
uint8_t A
Definition: TColor.h:51
A class for storing images as grayscale or RGB bitmaps.
Definition: img/CImage.h:148
void getXBounds(float &min, float &max) const
Definition: CMeshFast.h:139



Page generated by Doxygen 1.8.14 for MRPT 2.0.0 Git: b38439d21 Tue Mar 31 19:58:06 2020 +0200 at miƩ abr 1 00:50:30 CEST 2020