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::opengl
18 {
19 /** A 3D vector field representation, consisting of points and arrows drawn at
20  * any spatial position.
21  * This opengl object has been created to represent scene flow, and hence
22  * both the vector field and
23  * the coordinates of the points at which the vector field is represented
24  * are stored in matrices because
25  * they are computed from intensity and depth images.
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::CVectorField2D </td> <td> \image html
32  * preview_CVectorField2D.png </td> </tr>
33  * </table>
34  * </div>
35  *
36  * \ingroup mrpt_opengl_grp
37  */
38 
40 {
42  protected:
43  /** X component of the vector field */
45  /** Y component of the vector field */
47  /** Z component of the vector field */
49 
50  /** X coordinate of the points at which the vector field is plotted */
52  /** Y coordinate of the points at which the vector field is plotted */
54  /** Z coordinate of the points at which the vector field is plotted */
56 
57  /** By default it is 1.0 */
58  float m_LineWidth;
59  /** By default it is 1.0 */
60  float m_pointSize;
61  /** By default it is true */
63  /** By default it is false */
65  /** By default it is true */
67 
70 
71  /** Color associated to fields with null module */
73  /** Color associated to fields whose module is equal or larger than
74  * 'm_maxspeed' */
76  /** Value of the module of the motion field which will correspond to
77  * 'm_maxspeed_color' */
78  float m_maxspeed;
79 
80  public:
81  /**
82  * Clear the matrices
83  */
84  inline void clear()
85  {
86  x_vf.resize(0, 0);
87  y_vf.resize(0, 0);
88  z_vf.resize(0, 0);
89  x_p.resize(0, 0);
90  y_p.resize(0, 0);
91  z_p.resize(0, 0);
92 
94  }
95 
96  /**
97  * Set the point color in the range [0,1]
98  */
99  inline void setPointColor(
100  const float R, const float G, const float B, const float A = 1)
101  {
102  m_point_color = mrpt::img::TColor(R * 255, G * 255, B * 255, A * 255);
104  }
105 
106  /**
107  * Get the point color in the range [0,1]
108  */
110  {
112  }
113 
114  /**
115  * Set the arrow color in the range [0,1]
116  */
117  inline void setVectorFieldColor(
118  const float R, const float G, const float B, const float A = 1)
119  {
120  m_field_color = mrpt::img::TColor(R * 255, G * 255, B * 255, A * 255);
122  }
123 
124  /**
125  * Get the motion field min and max colors (colormap) in the range [0,1]
126  */
127  inline void getVectorFieldColor(
128  mrpt::img::TColorf Cmin, mrpt::img::TColorf Cmax) const
129  {
130  Cmin = m_still_color / 255;
131  Cmax = m_maxspeed_color / 255;
132  }
133 
134  /**
135  * Set the motion field min and max colors (colormap) in the range [0,1]
136  */
138  const float Rmin, const float Gmin, const float Bmin, const float Rmax,
139  const float Gmax, const float Bmax, const float Amin = 1,
140  const float Amax = 1)
141  {
142  m_still_color =
143  mrpt::img::TColor(Rmin * 255, Gmin * 255, Bmin * 255, Amin * 255);
145  mrpt::img::TColor(Rmax * 255, Gmax * 255, Bmax * 255, Amax * 255);
147  }
148 
149  /**
150  * Get the arrow color in the range [0,1]
151  */
153  {
155  }
156 
157  /**
158  * Set the size with which points will be drawn. By default 1.0
159  */
160  inline void setPointSize(const float p)
161  {
162  m_pointSize = p;
164  }
165 
166  /**
167  * Get the size with which points are drawn. By default 1.0
168  */
169  inline float getPointSize() const { return m_pointSize; }
170  /**
171  * Set the width with which lines will be drawn.
172  */
173  inline void setLineWidth(const float w)
174  {
175  m_LineWidth = w;
177  }
178 
179  /**
180  * Get the width with which lines are drawn.
181  */
182  float getLineWidth() const { return m_LineWidth; }
183  /**
184  * Set the max speed associated for the color map ( m_still_color,
185  * m_maxspeed_color)
186  */
187  inline void setMaxSpeedForColor(const float s)
188  {
189  m_maxspeed = s;
191  }
192 
193  /**
194  * Get the max_speed with which lines are drawn.
195  */
196  float getMaxSpeedForColor() const { return m_maxspeed; }
197  /**
198  * Get the vector field in three independent matrices: Matrix_x, Matrix_y
199  * and Matrix_z.
200  */
203  mrpt::math::CMatrixFloat& Matrix_z) const
204  {
205  Matrix_x = x_vf;
206  Matrix_y = y_vf;
207  Matrix_z = z_vf;
208  }
209 
210  template <class MATRIX>
212  MATRIX& Matrix_x, MATRIX& Matrix_y, MATRIX& Matrix_z) const
213  {
214  Matrix_x = x_vf;
215  Matrix_y = y_vf;
216  Matrix_z = z_vf;
217  }
218 
219  /**
220  * Get the coordiantes of the points at which the vector field is
221  * plotted: Coord_x, Coord_y and Coord_z.
222  */
225  mrpt::math::CMatrixFloat& Coord_z) const
226  {
227  Coord_x = x_p;
228  Coord_y = y_p;
229  Coord_z = z_p;
230  }
231 
232  template <class MATRIX>
234  MATRIX& Coord_x, MATRIX& Coord_y, MATRIX& Coord_z) const
235  {
236  Coord_x = x_p;
237  Coord_y = y_p;
238  Coord_z = z_p;
239  }
240 
241  /** Get the "x" component of the vector field as a matrix. */
243  {
244  return x_vf;
245  }
246  /** \overload */
248  /** Get the "y" component of the vector field as a matrix. */
250  {
251  return y_vf;
252  }
253  /** \overload */
255  /** Get the "z" component of the vector field as a matrix. */
257  {
258  return z_vf;
259  }
260  /** \overload */
262  /**
263  * Set the vector field with Matrix_x, Matrix_y and Matrix_z.
264  */
267  mrpt::math::CMatrixFloat& Matrix_z)
268  {
269  ASSERT_(
270  (Matrix_x.rows() == Matrix_y.rows()) &&
271  (Matrix_x.rows() == Matrix_z.rows()));
272  ASSERT_(
273  (Matrix_x.cols() == Matrix_y.cols()) &&
274  (Matrix_x.cols() == Matrix_z.cols()));
275  x_vf = Matrix_x;
276  y_vf = Matrix_y;
277  z_vf = Matrix_z;
279  }
280 
281  template <class MATRIX>
282  void setVectorField(MATRIX& Matrix_x, MATRIX& Matrix_y, MATRIX& Matrix_z)
283  {
284  ASSERT_(
285  (Matrix_x.rows() == Matrix_y.rows()) &&
286  (Matrix_x.rows() == Matrix_z.rows()));
287  ASSERT_(
288  (Matrix_x.cols() == Matrix_y.cols()) &&
289  (Matrix_x.cols() == Matrix_z.cols()));
290  x_vf = Matrix_x;
291  y_vf = Matrix_y;
292  z_vf = Matrix_z;
294  }
295 
296  /**
297  * Set the coordinates of the points at which the vector field is plotted
298  * with Matrix_x, Matrix_y and Matrix_z.
299  */
302  mrpt::math::CMatrixFloat& Matrix_z)
303  {
304  ASSERT_(
305  (Matrix_x.rows() == Matrix_y.rows()) &&
306  (Matrix_x.rows() == Matrix_z.rows()));
307  ASSERT_(
308  (Matrix_x.cols() == Matrix_y.cols()) &&
309  (Matrix_x.cols() == Matrix_z.cols()));
310  x_p = Matrix_x;
311  y_p = Matrix_y;
312  z_p = Matrix_z;
314  }
315 
316  template <class MATRIX>
318  MATRIX& Matrix_x, MATRIX& Matrix_y, MATRIX& Matrix_z)
319  {
320  ASSERT_(
321  (Matrix_x.rows() == Matrix_y.rows()) &&
322  (Matrix_x.rows() == Matrix_z.rows()));
323  ASSERT_(
324  (Matrix_x.cols() == Matrix_y.cols()) &&
325  (Matrix_x.cols() == Matrix_z.cols()));
326  x_p = Matrix_x;
327  y_p = Matrix_y;
328  z_p = Matrix_z;
330  }
331 
332  /**
333  * Resizes the set.
334  */
335  void resize(size_t rows, size_t cols)
336  {
337  x_vf.resize(rows, cols);
338  y_vf.resize(rows, cols);
339  z_vf.resize(rows, cols);
340  x_p.resize(rows, cols);
341  y_p.resize(rows, cols);
342  z_p.resize(rows, cols);
344  }
345 
346  /** Returns the total count of rows used to represent the vector field. */
347  inline size_t cols() const { return x_vf.cols(); }
348  /** Returns the total count of columns used to represent the vector field.
349  */
350  inline size_t rows() const { return x_vf.rows(); }
351  /**
352  * Class factory
353  */
355  const mrpt::math::CMatrixFloat x_vf_ini,
356  const mrpt::math::CMatrixFloat y_vf_ini,
357  const mrpt::math::CMatrixFloat z_vf_ini,
358  const mrpt::math::CMatrixFloat x_p_ini,
359  const mrpt::math::CMatrixFloat y_p_ini,
360  const mrpt::math::CMatrixFloat z_p_ini);
361  /** Render
362  */
363  void render_dl() const override;
364 
365  /** Evaluates the bounding box of this object (including possible children)
366  * in the coordinate frame of the object parent. */
367  void getBoundingBox(
368  mrpt::math::TPoint3D& bb_min,
369  mrpt::math::TPoint3D& bb_max) const override;
370 
371  void enableAntiAliasing(bool enable = true)
372  {
373  m_antiAliasing = enable;
375  }
376  void enableColorFromModule(bool enable = true)
377  {
378  m_colorFromModule = enable;
380  }
381  void enableShowPoints(bool enable = true)
382  {
383  m_showPoints = enable;
385  }
386  bool isAntiAliasingEnabled() const { return m_antiAliasing; }
388  /** Constructor */
389  CVectorField3D();
390  /** Constructor with a initial set of lines. */
395  /** Private, virtual destructor: only can be deleted from smart pointers. */
396  virtual ~CVectorField3D() {}
397 };
398 
399 }
400 #endif
401 
402 
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)
#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:77
void setPointColor(const float R, const float G, const float B, const float A=1)
Set the point color in the range [0,1].
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:15
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:20
Lightweight 3D point.
static Ptr Create(Args &&... args)
This class is a "CSerializable" wrapper for "CMatrixFloat".
Definition: CMatrix.h:22
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: 7d5e6d718 Fri Aug 24 01:51:28 2018 +0200 at lun nov 2 08:35:50 CET 2020