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
mrpt::opengl::CVectorField3D::setPointCoordinates
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,...
Definition: CVectorField3D.h:302
mrpt::opengl::CVectorField3D::getVectorField_z
const mrpt::math::CMatrixFloat & getVectorField_z() const
Get the "z" component of the vector field as a matrix.
Definition: CVectorField3D.h:258
mrpt::opengl::CVectorField3D::rows
size_t rows() const
Returns the total count of columns used to represent the vector field.
Definition: CVectorField3D.h:352
mrpt::opengl::CVectorField3D::m_antiAliasing
bool m_antiAliasing
By default it is true.
Definition: CVectorField3D.h:64
mrpt::opengl::CVectorField3D::getVectorField_z
mrpt::math::CMatrixFloat & getVectorField_z()
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: CVectorField3D.h:263
mrpt::opengl::CVectorField3D::Ptr
std::shared_ptr< CVectorField3D > Ptr
Definition: CVectorField3D.h:43
mrpt::opengl::CVectorField3D::getPointColor
mrpt::img::TColorf getPointColor() const
Get the point color in the range [0,1].
Definition: CVectorField3D.h:111
s
GLdouble s
Definition: glext.h:3676
G
const double G
Definition: vision_stereo_rectify/test.cpp:31
mrpt::opengl::CVectorField3D::getMaxSpeedForColor
float getMaxSpeedForColor() const
Get the max_speed with which lines are drawn.
Definition: CVectorField3D.h:198
mrpt::opengl::CVectorField3D::getLineWidth
float getLineWidth() const
Get the width with which lines are drawn.
Definition: CVectorField3D.h:184
CRenderizableDisplayList.h
mrpt::opengl::CVectorField3D::isColorFromModuleEnabled
bool isColorFromModuleEnabled() const
Definition: CVectorField3D.h:389
mrpt::opengl::CVectorField3D::z_p
mrpt::math::CMatrix z_p
Z coordinate of the points at which the vector field is plotted.
Definition: CVectorField3D.h:57
mrpt::opengl::CVectorField3D::setLineWidth
void setLineWidth(const float w)
Set the width with which lines will be drawn.
Definition: CVectorField3D.h:175
mrpt::opengl::CVectorField3D::getVectorField_y
mrpt::math::CMatrixFloat & getVectorField_y()
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: CVectorField3D.h:256
mrpt::opengl::CVectorField3D::m_field_color
mrpt::img::TColor m_field_color
Definition: CVectorField3D.h:71
mrpt::opengl::CVectorField3D::getVectorFieldColor
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].
Definition: CVectorField3D.h:129
mrpt::opengl::CVectorField3D::x_vf
mrpt::math::CMatrix x_vf
X component of the vector field.
Definition: CVectorField3D.h:46
mrpt::opengl::CRenderizableDisplayList
A renderizable object suitable for rendering with OpenGL's display lists.
Definition: CRenderizableDisplayList.h:39
mrpt::opengl::CVectorField3D
A 3D vector field representation, consisting of points and arrows drawn at any spatial position.
Definition: CVectorField3D.h:41
CMatrix.h
mrpt::opengl::CRenderizableDisplayList::notifyChange
EIGEN_STRONG_INLINE void notifyChange() const
Must be called to notify that the object has changed (so, the display list must be updated)
Definition: CRenderizableDisplayList.h:57
mrpt::opengl::CVectorField3D::m_pointSize
float m_pointSize
By default it is 1.0.
Definition: CVectorField3D.h:62
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CKalmanFilterCapable.h:30
mrpt::opengl::CVectorField3D::Create
static Ptr Create(Args &&... args)
Definition: CVectorField3D.h:43
w
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:4178
mrpt::opengl::CVectorField3D::isAntiAliasingEnabled
bool isAntiAliasingEnabled() const
Definition: CVectorField3D.h:388
R
const float R
Definition: CKinematicChain.cpp:138
ASSERT_
#define ASSERT_(f)
Defines an assertion mechanism.
Definition: exceptions.h:113
p
GLfloat GLfloat p
Definition: glext.h:6305
mrpt::opengl::CVectorField3D::getPointCoordinates
void getPointCoordinates(MATRIX &Coord_x, MATRIX &Coord_y, MATRIX &Coord_z) const
Definition: CVectorField3D.h:235
mrpt::opengl::CVectorField3D::m_colorFromModule
bool m_colorFromModule
By default it is false.
Definition: CVectorField3D.h:66
mrpt::opengl::CVectorField3D::render_dl
void render_dl() const override
Render.
Definition: CVectorField3D.cpp:70
mrpt::opengl::CVectorField3D::getVectorField
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.
Definition: CVectorField3D.h:203
mrpt::opengl::CVectorField3D::cols
size_t cols() const
Returns the total count of rows used to represent the vector field.
Definition: CVectorField3D.h:349
lightweight_geom_data.h
mrpt::opengl::CVectorField3D::m_LineWidth
float m_LineWidth
By default it is 1.0.
Definition: CVectorField3D.h:60
mrpt::math::CMatrixTemplateNumeric
A matrix of dynamic size.
Definition: CMatrixTemplateNumeric.h:37
mrpt::opengl::CVectorField3D::CVectorField3D
CVectorField3D()
Constructor.
Definition: CVectorField3D.cpp:24
mrpt::opengl::CVectorField3D::clear
void clear()
Clear the matrices.
Definition: CVectorField3D.h:86
mrpt::opengl::CVectorField3D::getVectorField
void getVectorField(MATRIX &Matrix_x, MATRIX &Matrix_y, MATRIX &Matrix_z) const
Definition: CVectorField3D.h:213
mrpt::opengl::CVectorField3D::enableColorFromModule
void enableColorFromModule(bool enable=true)
Definition: CVectorField3D.h:378
mrpt::opengl::CVectorField3D::getVectorField_x
mrpt::math::CMatrixFloat & getVectorField_x()
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: CVectorField3D.h:249
mrpt::math::CMatrix
This class is a "CSerializable" wrapper for "CMatrixFloat".
Definition: CMatrix.h:24
mrpt::opengl::CVectorField3D::y_p
mrpt::math::CMatrix y_p
Y coordinate of the points at which the vector field is plotted.
Definition: CVectorField3D.h:55
mrpt::opengl::CVectorField3D::resize
void resize(size_t rows, size_t cols)
Resizes the set.
Definition: CVectorField3D.h:337
mrpt::img::TColorf
A RGB color - floats in the range [0,1].
Definition: TColor.h:79
mrpt::opengl::CVectorField3D::m_showPoints
bool m_showPoints
By default it is true.
Definition: CVectorField3D.h:68
mrpt::img::TColor
A RGB color - 8bit.
Definition: TColor.h:22
mrpt::opengl::CVectorField3D::setMotionFieldColormap
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].
Definition: CVectorField3D.h:139
mrpt::opengl::CVectorField3D::setPointSize
void setPointSize(const float p)
Set the size with which points will be drawn.
Definition: CVectorField3D.h:162
mrpt::opengl::CVectorField3D::setPointColor
void setPointColor(const float R, const float G, const float B, const float A=1)
Set the point color in the range [0,1].
Definition: CVectorField3D.h:101
mrpt::opengl::CVectorField3D::m_maxspeed
float m_maxspeed
Value of the module of the motion field which will correspond to 'm_maxspeed_color'.
Definition: CVectorField3D.h:80
mrpt::opengl::CVectorField3D::m_maxspeed_color
mrpt::img::TColor m_maxspeed_color
Color associated to fields whose module is equal or larger than 'm_maxspeed'.
Definition: CVectorField3D.h:77
mrpt::opengl::CVectorField3D::getVectorFieldColor
mrpt::img::TColorf getVectorFieldColor() const
Get the arrow color in the range [0,1].
Definition: CVectorField3D.h:154
mrpt::math::TPoint3D
Lightweight 3D point.
Definition: lightweight_geom_data.h:378
mrpt::opengl::CVectorField3D::getPointSize
float getPointSize() const
Get the size with which points are drawn.
Definition: CVectorField3D.h:171
mrpt::opengl::CVectorField3D::z_vf
mrpt::math::CMatrix z_vf
Z component of the vector field.
Definition: CVectorField3D.h:50
mrpt::opengl::CVectorField3D::getBoundingBox
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: CVectorField3D.cpp:228
mrpt::opengl::CVectorField3D::getVectorField_x
const mrpt::math::CMatrixFloat & getVectorField_x() const
Get the "x" component of the vector field as a matrix.
Definition: CVectorField3D.h:244
mrpt::opengl::CVectorField3D::setPointCoordinates
void setPointCoordinates(MATRIX &Matrix_x, MATRIX &Matrix_y, MATRIX &Matrix_z)
Definition: CVectorField3D.h:319
DEFINE_SERIALIZABLE
#define DEFINE_SERIALIZABLE(class_name)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
Definition: CSerializable.h:102
mrpt::opengl::CVectorField3D::setVectorField
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.
Definition: CVectorField3D.h:267
mrpt::opengl::CVectorField3D::m_still_color
mrpt::img::TColor m_still_color
Color associated to fields with null module.
Definition: CVectorField3D.h:74
mrpt::opengl::CVectorField3D::enableShowPoints
void enableShowPoints(bool enable=true)
Definition: CVectorField3D.h:383
mrpt::opengl::CVectorField3D::getPointCoordinates
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.
Definition: CVectorField3D.h:225
mrpt::opengl::CVectorField3D::enableAntiAliasing
void enableAntiAliasing(bool enable=true)
Definition: CVectorField3D.h:373
mrpt::opengl::CVectorField3D::setVectorField
void setVectorField(MATRIX &Matrix_x, MATRIX &Matrix_y, MATRIX &Matrix_z)
Definition: CVectorField3D.h:284
mrpt::opengl::CVectorField3D::y_vf
mrpt::math::CMatrix y_vf
Y component of the vector field.
Definition: CVectorField3D.h:48
mrpt::opengl::CVectorField3D::setMaxSpeedForColor
void setMaxSpeedForColor(const float s)
Set the max speed associated for the color map ( m_still_color, m_maxspeed_color)
Definition: CVectorField3D.h:189
mrpt::opengl::CVectorField3D::getVectorField_y
const mrpt::math::CMatrixFloat & getVectorField_y() const
Get the "y" component of the vector field as a matrix.
Definition: CVectorField3D.h:251
mrpt::opengl::CVectorField3D::x_p
mrpt::math::CMatrix x_p
X coordinate of the points at which the vector field is plotted.
Definition: CVectorField3D.h:53
mrpt::opengl::CVectorField3D::~CVectorField3D
virtual ~CVectorField3D()
Private, virtual destructor: only can be deleted from smart pointers.
Definition: CVectorField3D.h:398
mrpt::opengl::CVectorField3D::setVectorFieldColor
void setVectorFieldColor(const float R, const float G, const float B, const float A=1)
Set the arrow color in the range [0,1].
Definition: CVectorField3D.h:119
mrpt::opengl::CVectorField3D::m_point_color
mrpt::img::TColor m_point_color
Definition: CVectorField3D.h:70



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST