Main MRPT website > C++ reference for MRPT 1.5.6
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 
23 
24  // This must be added to any CSerializable derived class:
25  DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE( CMeshFast, CRenderizableDisplayList, OPENGL_IMPEXP )
26 
27  /** A planar (XY) grid where each cell has an associated height and, optionally, a texture map.
28  * To make it faster to render, instead of drawing lines and triangles it draws a point at each
29  * gridcell.
30  * A typical usage example would be an elevation map or a 3D model of a terrain.
31  * \sa opengl::COpenGLScene
32  *
33  * <div align="center">
34  * <table border="0" cellspan="4" cellspacing="4" style="border-width: 1px; border-style: solid;">
35  * <tr> <td> mrpt::opengl::CMeshFast </td> <td> \image html preview_CMeshFast.png </td> </tr>
36  * </table>
37  * </div>
38  *
39  * \ingroup mrpt_opengl_grp
40  */
42  {
44 
45  protected:
46  mrpt::utils::CImage m_textureImage;
47 
48  bool m_enableTransparency;
49  bool m_colorFromZ;
50  bool m_isImage;
51 
52  mutable math::CMatrix X; //!< X(x,y): X-coordinate of the point (x,y)
53  mutable math::CMatrix Y; //!< Y(x,y): Y-coordinate of the point (x,y)
54  mutable math::CMatrix Z; //!< Z(x,y): Z-coordinate of the point (x,y)
55 
56  mutable math::CMatrix C; //!< Grayscale Color [0,1] for each cell, updated by updateColorsMatrix
57  mutable math::CMatrix C_r; //!< Red Component of the Color [0,1] for each cell, updated by updateColorsMatrix
58  mutable math::CMatrix C_g; //!< Green Component of the Color [0,1] for each cell, updated by updateColorsMatrix
59  mutable math::CMatrix C_b; //!< Blue Component of the Color [0,1] for each cell, updated by updateColorsMatrix
60 
61  mrpt::utils::TColormap m_colorMap; //!< Used when m_colorFromZ is true
62  float m_pointSize; //!< By default is 1.0
63  bool m_pointSmooth; //!< Default: false
64 
65  mutable bool m_modified_Z; //!< Whether C is not up-to-date wrt to Z
66  mutable bool m_modified_Image; //!< Whether C is not up-to-date wrt to the texture image
67 
68  void updateColorsMatrix() const; //!< Called internally to assure C is updated.
69  void updatePoints() const;
70 
71  float xMin,xMax,yMin,yMax; //!< Mesh bounds
72 
73  mutable bool pointsUpToDate; //!<Whether the coordinates of the points needs to be recalculated
74 
75  public:
76 
77  inline void setPointSize(float p) { m_pointSize=p; } //!< By default is 1.0
78  inline float getPointSize() const { return m_pointSize; }
79 
80  inline void enablePointSmooth(bool enable=true) { m_pointSmooth=enable; }
81  inline void disablePointSmooth() { m_pointSmooth=false; }
82 
83  void setGridLimits(float xmin,float xmax, float ymin, float ymax)
84  {
85  xMin=xmin; xMax = xmax;
86  yMin=ymin; yMax = ymax;
88  }
89 
90  void getGridLimits(float &xmin,float &xmax, float &ymin, float &ymax) const
91  {
92  xmin=xMin; xmax=xMax;
93  ymin=yMin; ymax=yMax;
94  }
95 
96  void enableTransparency( bool v ) { m_enableTransparency = v; CRenderizableDisplayList::notifyChange(); }
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 mesh grid */
105  void setZ( const mrpt::math::CMatrixTemplateNumeric<float> &in_Z );
106 
107  /** Returns a reference to the internal Z matrix, allowing changing it efficiently */
108  inline void getZ(mrpt::math::CMatrixFloat &out) const { out=Z; }
109 
110  inline float getXMin() const { return xMin; }
111  inline float getXMax() const { return xMax; }
112  inline float getYMin() const { return yMin; }
113  inline float getYMax() const { return yMax; }
114  inline void setXMin(const float &nxm) {
115  xMin=nxm;
116  pointsUpToDate=false; CRenderizableDisplayList::notifyChange();
117  }
118  inline void setXMax(const float &nxm) {
119  xMax=nxm;
120  pointsUpToDate=false; CRenderizableDisplayList::notifyChange();
121  }
122  inline void setYMin(const float &nym) {
123  yMin=nym;
124  pointsUpToDate=false; CRenderizableDisplayList::notifyChange();
125  }
126  inline void setYMax(const float &nym) {
127  yMax=nym;
128  pointsUpToDate=false; CRenderizableDisplayList::notifyChange();
129  }
130  inline void getXBounds(float &min,float &max) const {
131  min=xMin;
132  max=xMax;
133  }
134  inline void getYBounds(float &min,float &max) const {
135  min=yMin;
136  max=yMax;
137  }
138  inline void setXBounds(const float &min,const float &max) {
139  xMin=min;
140  xMax=max;
141  pointsUpToDate=false; CRenderizableDisplayList::notifyChange();
142  }
143  inline void setYBounds(const float &min,const float &max) {
144  yMin=min;
145  yMax=max;
146  pointsUpToDate=false; CRenderizableDisplayList::notifyChange();
147  }
148 
149 
150  /** Class factory */
151  static CMeshFastPtr Create(bool enableTransparency, float xMin = -1.0f, float xMax = 1.0f, float yMin = -1.0f, float yMax = 1.0f );
152 
153  /** Render
154  */
155  void render_dl() const MRPT_OVERRIDE;
156 
157  /** Evaluates the bounding box of this object (including possible children) in the coordinate frame of the object parent. */
158  void getBoundingBox(mrpt::math::TPoint3D &bb_min, mrpt::math::TPoint3D &bb_max) const MRPT_OVERRIDE;
159 
160  /** Assigns a texture image, and disable transparency.
161  */
162  void assignImage(const mrpt::utils::CImage& img );
163 
164  /** Assigns a texture image and Z simultaneously, and disable transparency.
165  */
166  void assignImageAndZ( const mrpt::utils::CImage& img, const mrpt::math::CMatrixTemplateNumeric<float> &in_Z);
167 
168  /** Adjust grid limits according to the image aspect ratio, maintaining the X limits and resizing in the Y direction.
169  */
170  inline void adjustGridToImageAR() {
171  ASSERT_(m_isImage);
172  const float ycenter = 0.5*(yMin+yMax);
173  const float xwidth = xMax - xMin;
174  const float newratio = float(m_textureImage.getWidth())/float(m_textureImage.getHeight());
175  yMax = ycenter + 0.5*newratio*xwidth;
176  yMin = ycenter - 0.5*newratio*xwidth;
178  }
179 
180 
181  private:
182  /** Constructor
183  */
184  CMeshFast( bool enableTransparency = false, float xMin = -1.0f, float xMax = 1.0f, float yMin = -1.0f, float yMax = 1.0f ) :
185  m_textureImage(0,0),
186  m_enableTransparency(enableTransparency),
187  m_colorFromZ(false),
188  m_isImage(false),
189  X(0,0), Y(0,0), Z(0,0), C(0,0), C_r(0,0), C_g(0,0), C_b(0,0),
190  m_colorMap( mrpt::utils::cmJET ),
191  m_modified_Z(true),
192  m_modified_Image(false),
193  xMin(xMin), xMax(xMax), yMin(yMin), yMax(yMax),
194  pointsUpToDate(false)
195  {
196  m_color.A = 255;
197  m_color.R = 0;
198  m_color.G = 0;
199  m_color.B = 150;
200  }
201  /** Private, virtual destructor: only can be deleted from smart pointers */
202  virtual ~CMeshFast() { }
203 
204  };
205  DEFINE_SERIALIZABLE_POST_CUSTOM_BASE_LINKAGE( CMeshFast, CRenderizableDisplayList, OPENGL_IMPEXP )
206 
207  } // end namespace
208 
209 } // End of namespace
210 
211 #endif
virtual ~CMeshFast()
Private, virtual destructor: only can be deleted from smart pointers.
Definition: CMeshFast.h:202
const GLdouble * v
Definition: glew.h:1296
void getGridLimits(float &xmin, float &xmax, float &ymin, float &ymax) const
Definition: CMeshFast.h:90
void setXMax(const float &nxm)
Definition: CMeshFast.h:118
float getXMin() const
Definition: CMeshFast.h:110
#define min(a, b)
#define MRPT_OVERRIDE
C++11 "override" for virtuals:
TColormap
Different colormaps for use in mrpt::utils::colormap()
Definition: color_maps.h:30
void setYBounds(const float &min, const float &max)
Definition: CMeshFast.h:143
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:97
void setYMin(const float &nym)
Definition: CMeshFast.h:122
float getYMax() const
Definition: CMeshFast.h:113
CMeshFast(bool enableTransparency=false, float xMin=-1.0f, float xMax=1.0f, float yMin=-1.0f, float yMax=1.0f)
Constructor.
Definition: CMeshFast.h:184
A renderizable object suitable for rendering with OpenGL's display lists.
void getXBounds(float &min, float &max) const
Definition: CMeshFast.h:130
GLint GLvoid * img
Definition: glew.h:1290
#define DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE(class_name, base_name, _LINKAGE_)
This declaration must be inserted in all CSerializable classes definition, before the class declarati...
float getYMin() const
Definition: CMeshFast.h:112
GLfloat GLfloat p
Definition: glew.h:10113
void enablePointSmooth(bool enable=true)
Definition: CMeshFast.h:80
void getZ(mrpt::math::CMatrixFloat &out) const
Returns a reference to the internal Z matrix, allowing changing it efficiently.
Definition: CMeshFast.h:108
#define DEFINE_SERIALIZABLE(class_name)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
void enableTransparency(bool v)
Definition: CMeshFast.h:96
void setXBounds(const float &min, const float &max)
Definition: CMeshFast.h:138
#define ASSERT_(f)
void setGridLimits(float xmin, float xmax, float ymin, float ymax)
Definition: CMeshFast.h:83
float getXMax() const
Definition: CMeshFast.h:111
void setXMin(const float &nxm)
Definition: CMeshFast.h:114
float getPointSize() const
Definition: CMeshFast.h:78
#define DEFINE_SERIALIZABLE_POST_CUSTOM_BASE_LINKAGE(class_name, base_name, _LINKAGE_)
void getYBounds(float &min, float &max) const
Definition: CMeshFast.h:134
void setYMax(const float &nym)
Definition: CMeshFast.h:126
GLdouble GLdouble GLdouble GLdouble GLdouble GLdouble f
Definition: glew.h:5092



Page generated by Doxygen 1.8.6 for MRPT 1.5.6 Git: 4c65e84 Tue Apr 24 08:18:17 2018 +0200 at mar abr 24 08:26:17 CEST 2018