Main MRPT website > C++ reference for MRPT 1.9.9
CVectorField3D.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_CVectorField3D_H
11 #define opengl_CVectorField3D_H
12 
15 #include <mrpt/math/CMatrix.h>
16 
17 namespace mrpt
18 {
19 namespace opengl
20 {
21 /** A 3D vector field representation, consisting of points and arrows drawn at
22  * any spatial position.
23  * This opengl object has been created to represent scene flow, and hence
24  * both the vector field and
25  * the coordinates of the points at which the vector field is represented
26  * are stored in matrices because
27  * they are computed from intensity and depth images.
28  * \sa opengl::COpenGLScene
29  *
30  * <div align="center">
31  * <table border="0" cellspan="4" cellspacing="4" style="border-width: 1px;
32  * border-style: solid;">
33  * <tr> <td> mrpt::opengl::CVectorField2D </td> <td> \image html
34  * preview_CVectorField2D.png </td> </tr>
35  * </table>
36  * </div>
37  *
38  * \ingroup mrpt_opengl_grp
39  */
40 
42 {
44  protected:
45  /** X component of the vector field */
47  /** Y component of the vector field */
49  /** Z component of the vector field */
51 
52  /** X coordinate of the points at which the vector field is plotted */
54  /** Y coordinate of the points at which the vector field is plotted */
56  /** Z coordinate of the points at which the vector field is plotted */
58 
59  /** By default it is 1.0 */
60  float m_LineWidth;
61  /** By default it is 1.0 */
62  float m_pointSize;
63  /** By default it is true */
65  /** By default it is false */
67  /** By default it is true */
69 
72 
73  /** Color associated to fields with null module */
75  /** Color associated to fields whose module is equal or larger than
76  * 'm_maxspeed' */
78  /** Value of the module of the motion field which will correspond to
79  * 'm_maxspeed_color' */
80  float m_maxspeed;
81 
82  public:
83  /**
84  * Clear the matrices
85  */
86  inline void clear()
87  {
88  x_vf.resize(0, 0);
89  y_vf.resize(0, 0);
90  z_vf.resize(0, 0);
91  x_p.resize(0, 0);
92  y_p.resize(0, 0);
93  z_p.resize(0, 0);
94 
96  }
97 
98  /**
99  * Set the point color in the range [0,1]
100  */
101  inline void setPointColor(
102  const float R, const float G, const float B, const float A = 1)
103  {
104  m_point_color = mrpt::img::TColor(R * 255, G * 255, B * 255, A * 255);
106  }
107 
108  /**
109  * Get the point color in the range [0,1]
110  */
112  {
114  }
115 
116  /**
117  * Set the arrow color in the range [0,1]
118  */
119  inline void setVectorFieldColor(
120  const float R, const float G, const float B, const float A = 1)
121  {
122  m_field_color = mrpt::img::TColor(R * 255, G * 255, B * 255, A * 255);
124  }
125 
126  /**
127  * Get the motion field min and max colors (colormap) in the range [0,1]
128  */
129  inline void getVectorFieldColor(
130  mrpt::img::TColorf Cmin, mrpt::img::TColorf Cmax) const
131  {
132  Cmin = m_still_color / 255;
133  Cmax = m_maxspeed_color / 255;
134  }
135 
136  /**
137  * Set the motion field min and max colors (colormap) in the range [0,1]
138  */
140  const float Rmin, const float Gmin, const float Bmin, const float Rmax,
141  const float Gmax, const float Bmax, const float Amin = 1,
142  const float Amax = 1)
143  {
144  m_still_color =
145  mrpt::img::TColor(Rmin * 255, Gmin * 255, Bmin * 255, Amin * 255);
147  mrpt::img::TColor(Rmax * 255, Gmax * 255, Bmax * 255, Amax * 255);
149  }
150 
151  /**
152  * Get the arrow color in the range [0,1]
153  */
155  {
157  }
158 
159  /**
160  * Set the size with which points will be drawn. By default 1.0
161  */
162  inline void setPointSize(const float p)
163  {
164  m_pointSize = p;
166  }
167 
168  /**
169  * Get the size with which points are drawn. By default 1.0
170  */
171  inline float getPointSize() const { return m_pointSize; }
172  /**
173  * Set the width with which lines will be drawn.
174  */
175  inline void setLineWidth(const float w)
176  {
177  m_LineWidth = w;
179  }
180 
181  /**
182  * Get the width with which lines are drawn.
183  */
184  float getLineWidth() const { return m_LineWidth; }
185  /**
186  * Set the max speed associated for the color map ( m_still_color,
187  * m_maxspeed_color)
188  */
189  inline void setMaxSpeedForColor(const float s)
190  {
191  m_maxspeed = s;
193  }
194 
195  /**
196  * Get the max_speed with which lines are drawn.
197  */
198  float getMaxSpeedForColor() const { return m_maxspeed; }
199  /**
200  * Get the vector field in three independent matrices: Matrix_x, Matrix_y
201  * and Matrix_z.
202  */
205  mrpt::math::CMatrixFloat& Matrix_z) const
206  {
207  Matrix_x = x_vf;
208  Matrix_y = y_vf;
209  Matrix_z = z_vf;
210  }
211 
212  template <class MATRIX>
214  MATRIX& Matrix_x, MATRIX& Matrix_y, MATRIX& Matrix_z) const
215  {
216  Matrix_x = x_vf;
217  Matrix_y = y_vf;
218  Matrix_z = z_vf;
219  }
220 
221  /**
222  * Get the coordiantes of the points at which the vector field is
223  * plotted: Coord_x, Coord_y and Coord_z.
224  */
227  mrpt::math::CMatrixFloat& Coord_z) const
228  {
229  Coord_x = x_p;
230  Coord_y = y_p;
231  Coord_z = z_p;
232  }
233 
234  template <class MATRIX>
236  MATRIX& Coord_x, MATRIX& Coord_y, MATRIX& Coord_z) const
237  {
238  Coord_x = x_p;
239  Coord_y = y_p;
240  Coord_z = z_p;
241  }
242 
243  /** Get the "x" component of the vector field as a matrix. */
245  {
246  return x_vf;
247  }
248  /** \overload */
250  /** Get the "y" component of the vector field as a matrix. */
252  {
253  return y_vf;
254  }
255  /** \overload */
257  /** Get the "z" component of the vector field as a matrix. */
259  {
260  return z_vf;
261  }
262  /** \overload */
264  /**
265  * Set the vector field with Matrix_x, Matrix_y and Matrix_z.
266  */
269  mrpt::math::CMatrixFloat& Matrix_z)
270  {
271  ASSERT_(
272  (Matrix_x.rows() == Matrix_y.rows()) &&
273  (Matrix_x.rows() == Matrix_z.rows()));
274  ASSERT_(
275  (Matrix_x.cols() == Matrix_y.cols()) &&
276  (Matrix_x.cols() == Matrix_z.cols()));
277  x_vf = Matrix_x;
278  y_vf = Matrix_y;
279  z_vf = Matrix_z;
281  }
282 
283  template <class MATRIX>
284  void setVectorField(MATRIX& Matrix_x, MATRIX& Matrix_y, MATRIX& Matrix_z)
285  {
286  ASSERT_(
287  (Matrix_x.rows() == Matrix_y.rows()) &&
288  (Matrix_x.rows() == Matrix_z.rows()));
289  ASSERT_(
290  (Matrix_x.cols() == Matrix_y.cols()) &&
291  (Matrix_x.cols() == Matrix_z.cols()));
292  x_vf = Matrix_x;
293  y_vf = Matrix_y;
294  z_vf = Matrix_z;
296  }
297 
298  /**
299  * Set the coordinates of the points at which the vector field is plotted
300  * with Matrix_x, Matrix_y and Matrix_z.
301  */
304  mrpt::math::CMatrixFloat& Matrix_z)
305  {
306  ASSERT_(
307  (Matrix_x.rows() == Matrix_y.rows()) &&
308  (Matrix_x.rows() == Matrix_z.rows()));
309  ASSERT_(
310  (Matrix_x.cols() == Matrix_y.cols()) &&
311  (Matrix_x.cols() == Matrix_z.cols()));
312  x_p = Matrix_x;
313  y_p = Matrix_y;
314  z_p = Matrix_z;
316  }
317 
318  template <class MATRIX>
320  MATRIX& Matrix_x, MATRIX& Matrix_y, MATRIX& Matrix_z)
321  {
322  ASSERT_(
323  (Matrix_x.rows() == Matrix_y.rows()) &&
324  (Matrix_x.rows() == Matrix_z.rows()));
325  ASSERT_(
326  (Matrix_x.cols() == Matrix_y.cols()) &&
327  (Matrix_x.cols() == Matrix_z.cols()));
328  x_p = Matrix_x;
329  y_p = Matrix_y;
330  z_p = Matrix_z;
332  }
333 
334  /**
335  * Resizes the set.
336  */
337  void resize(size_t rows, size_t cols)
338  {
339  x_vf.resize(rows, cols);
340  y_vf.resize(rows, cols);
341  z_vf.resize(rows, cols);
342  x_p.resize(rows, cols);
343  y_p.resize(rows, cols);
344  z_p.resize(rows, cols);
346  }
347 
348  /** Returns the total count of rows used to represent the vector field. */
349  inline size_t cols() const { return x_vf.cols(); }
350  /** Returns the total count of columns used to represent the vector field.
351  */
352  inline size_t rows() const { return x_vf.rows(); }
353  /**
354  * Class factory
355  */
357  const mrpt::math::CMatrixFloat x_vf_ini,
358  const mrpt::math::CMatrixFloat y_vf_ini,
359  const mrpt::math::CMatrixFloat z_vf_ini,
360  const mrpt::math::CMatrixFloat x_p_ini,
361  const mrpt::math::CMatrixFloat y_p_ini,
362  const mrpt::math::CMatrixFloat z_p_ini);
363  /** Render
364  */
365  void render_dl() const override;
366 
367  /** Evaluates the bounding box of this object (including possible children)
368  * in the coordinate frame of the object parent. */
369  void getBoundingBox(
370  mrpt::math::TPoint3D& bb_min,
371  mrpt::math::TPoint3D& bb_max) const override;
372 
373  void enableAntiAliasing(bool enable = true)
374  {
375  m_antiAliasing = enable;
377  }
378  void enableColorFromModule(bool enable = true)
379  {
380  m_colorFromModule = enable;
382  }
383  void enableShowPoints(bool enable = true)
384  {
385  m_showPoints = enable;
387  }
388  bool isAntiAliasingEnabled() const { return m_antiAliasing; }
390  /** Constructor */
391  CVectorField3D();
392  /** Constructor with a initial set of lines. */
397  /** Private, virtual destructor: only can be deleted from smart pointers. */
398  virtual ~CVectorField3D() {}
399 };
400 
401 } // namespace opengl
402 
403 } // namespace mrpt
404 
405 #endif
virtual ~CVectorField3D()
Private, virtual destructor: only can be deleted from smart pointers.
mrpt::math::CMatrix x_vf
X component of the vector field.
float m_LineWidth
By default it is 1.0.
float getPointSize() const
Get the size with which points are drawn.
void setMotionFieldColormap(const float Rmin, const float Gmin, const float Bmin, const float Rmax, const float Gmax, const float Bmax, const float Amin=1, const float Amax=1)
Set the motion field min and max colors (colormap) in the range [0,1].
void getVectorField(MATRIX &Matrix_x, MATRIX &Matrix_y, MATRIX &Matrix_z) const
const double G
mrpt::img::TColor m_still_color
Color associated to fields with null module.
void getPointCoordinates(mrpt::math::CMatrixFloat &Coord_x, mrpt::math::CMatrixFloat &Coord_y, mrpt::math::CMatrixFloat &Coord_z) const
Get the coordiantes of the points at which the vector field is plotted: Coord_x, Coord_y and Coord_z...
void enableShowPoints(bool enable=true)
EIGEN_STRONG_INLINE void notifyChange() const
Must be called to notify that the object has changed (so, the display list must be updated) ...
void clear()
Clear the matrices.
size_t cols() const
Returns the total count of rows used to represent the vector field.
float m_maxspeed
Value of the module of the motion field which will correspond to &#39;m_maxspeed_color&#39;.
GLdouble s
Definition: glext.h:3676
void enableColorFromModule(bool enable=true)
float m_pointSize
By default it is 1.0.
void setVectorFieldColor(const float R, const float G, const float B, const float A=1)
Set the arrow color in the range [0,1].
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:4178
void getVectorField(mrpt::math::CMatrixFloat &Matrix_x, mrpt::math::CMatrixFloat &Matrix_y, mrpt::math::CMatrixFloat &Matrix_z) const
Get the vector field in three independent matrices: Matrix_x, Matrix_y and Matrix_z.
float getMaxSpeedForColor() const
Get the max_speed with which lines are drawn.
A renderizable object suitable for rendering with OpenGL&#39;s display lists.
bool m_showPoints
By default it is true.
#define ASSERT_(f)
Defines an assertion mechanism.
Definition: exceptions.h:113
void setVectorField(mrpt::math::CMatrixFloat &Matrix_x, mrpt::math::CMatrixFloat &Matrix_y, mrpt::math::CMatrixFloat &Matrix_z)
Set the vector field with Matrix_x, Matrix_y and Matrix_z.
mrpt::img::TColor m_point_color
mrpt::math::CMatrix y_p
Y coordinate of the points at which the vector field is plotted.
void getVectorFieldColor(mrpt::img::TColorf Cmin, mrpt::img::TColorf Cmax) const
Get the motion field min and max colors (colormap) in the range [0,1].
void setPointSize(const float p)
Set the size with which points will be drawn.
mrpt::math::CMatrixFloat & getVectorField_z()
float getLineWidth() const
Get the width with which lines are drawn.
const mrpt::math::CMatrixFloat & getVectorField_y() const
Get the "y" component of the vector field as a matrix.
mrpt::math::CMatrix z_vf
Z component of the vector field.
mrpt::math::CMatrix y_vf
Y component of the vector field.
mrpt::img::TColor m_field_color
void setPointCoordinates(MATRIX &Matrix_x, MATRIX &Matrix_y, MATRIX &Matrix_z)
mrpt::math::CMatrix z_p
Z coordinate of the points at which the vector field is plotted.
A 3D vector field representation, consisting of points and arrows drawn at any spatial position...
const mrpt::math::CMatrixFloat & getVectorField_z() const
Get the "z" component of the vector field as a matrix.
void resize(size_t rows, size_t cols)
Resizes the set.
void enableAntiAliasing(bool enable=true)
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 setLineWidth(const float w)
Set the width with which lines will be drawn.
bool m_colorFromModule
By default it is false.
const float R
A RGB color - floats in the range [0,1].
Definition: TColor.h:79
void setPointColor(const float R, const float G, const float B, const float A=1)
Set the point color in the range [0,1].
const mrpt::math::CMatrixFloat & getVectorField_x() const
Get the "x" component of the vector field as a matrix.
size_t rows() const
Returns the total count of columns used to represent the vector field.
mrpt::math::CMatrixFloat & getVectorField_x()
void getPointCoordinates(MATRIX &Coord_x, MATRIX &Coord_y, MATRIX &Coord_z) const
void render_dl() const override
Render.
void setMaxSpeedForColor(const float s)
Set the max speed associated for the color map ( m_still_color, m_maxspeed_color) ...
void setVectorField(MATRIX &Matrix_x, MATRIX &Matrix_y, MATRIX &Matrix_z)
mrpt::math::CMatrixFloat & getVectorField_y()
mrpt::img::TColor m_maxspeed_color
Color associated to fields whose module is equal or larger than &#39;m_maxspeed&#39;.
void setPointCoordinates(mrpt::math::CMatrixFloat &Matrix_x, mrpt::math::CMatrixFloat &Matrix_y, mrpt::math::CMatrixFloat &Matrix_z)
Set the coordinates of the points at which the vector field is plotted with Matrix_x, Matrix_y and Matrix_z.
bool m_antiAliasing
By default it is true.
A RGB color - 8bit.
Definition: TColor.h:22
Lightweight 3D point.
static Ptr Create(Args &&... args)
This class is a "CSerializable" wrapper for "CMatrixFloat".
Definition: CMatrix.h:24
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...
GLfloat GLfloat p
Definition: glext.h:6305
mrpt::img::TColorf getVectorFieldColor() const
Get the arrow color in the range [0,1].
mrpt::img::TColorf getPointColor() const
Get the point color in the range [0,1].
mrpt::math::CMatrix x_p
X coordinate of the points at which the vector field is plotted.



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at lun oct 28 00:14:14 CET 2019