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-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_CVectorField3D_H
11 #define opengl_CVectorField3D_H
12 
15 #include <mrpt/math/CMatrix.h>
17 #include <Eigen/Dense>
18 
19 namespace mrpt
20 {
21 namespace opengl
22 {
23 class CVectorField3D;
24 
25 /** A 3D vector field representation, consisting of points and arrows drawn at
26  * any spatial position.
27  * This opengl object has been created to represent scene flow, and hence
28  * both the vector field and
29  * the coordinates of the points at which the vector field is represented
30  * are stored in matrices because
31  * they are computed from intensity and depth images.
32  * \sa opengl::COpenGLScene
33  *
34  * <div align="center">
35  * <table border="0" cellspan="4" cellspacing="4" style="border-width: 1px;
36  * border-style: solid;">
37  * <tr> <td> mrpt::opengl::CVectorField2D </td> <td> \image html
38  * preview_CVectorField2D.png </td> </tr>
39  * </table>
40  * </div>
41  *
42  * \ingroup mrpt_opengl_grp
43  */
44 
46 {
48  protected:
49  /** X component of the vector field */
51  /** Y component of the vector field */
53  /** Z component of the vector field */
55 
56  /** X coordinate of the points at which the vector field is plotted */
58  /** Y coordinate of the points at which the vector field is plotted */
60  /** Z coordinate of the points at which the vector field is plotted */
62 
63  /** By default it is 1.0 */
64  float m_LineWidth;
65  /** By default it is 1.0 */
66  float m_pointSize;
67  /** By default it is true */
69  /** By default it is false */
71  /** By default it is true */
73 
76 
77  /** Color associated to fields with null module */
79  /** Color associated to fields whose module is equal or larger than
80  * 'm_maxspeed' */
82  /** Value of the module of the motion field which will correspond to
83  * 'm_maxspeed_color' */
84  float m_maxspeed;
85 
86  public:
87  /**
88  * Clear the matrices
89  */
90  inline void clear()
91  {
92  x_vf.resize(0, 0);
93  y_vf.resize(0, 0);
94  z_vf.resize(0, 0);
95  x_p.resize(0, 0);
96  y_p.resize(0, 0);
97  z_p.resize(0, 0);
98 
100  }
101 
102  /**
103  * Set the point color in the range [0,1]
104  */
105  inline void setPointColor(
106  const float R, const float G, const float B, const float A = 1)
107  {
108  m_point_color = mrpt::utils::TColor(R * 255, G * 255, B * 255, A * 255);
110  }
111 
112  /**
113  * Get the point color in the range [0,1]
114  */
116  {
118  }
119 
120  /**
121  * Set the arrow color in the range [0,1]
122  */
123  inline void setVectorFieldColor(
124  const float R, const float G, const float B, const float A = 1)
125  {
126  m_field_color = mrpt::utils::TColor(R * 255, G * 255, B * 255, A * 255);
128  }
129 
130  /**
131  * Get the motion field min and max colors (colormap) in the range [0,1]
132  */
133  inline void getVectorFieldColor(
135  {
136  Cmin = m_still_color / 255;
137  Cmax = m_maxspeed_color / 255;
138  }
139 
140  /**
141  * Set the motion field min and max colors (colormap) in the range [0,1]
142  */
144  const float Rmin, const float Gmin, const float Bmin, const float Rmax,
145  const float Gmax, const float Bmax, const float Amin = 1,
146  const float Amax = 1)
147  {
148  m_still_color =
149  mrpt::utils::TColor(Rmin * 255, Gmin * 255, Bmin * 255, Amin * 255);
151  mrpt::utils::TColor(Rmax * 255, Gmax * 255, Bmax * 255, Amax * 255);
153  }
154 
155  /**
156  * Get the arrow color in the range [0,1]
157  */
159  {
161  }
162 
163  /**
164  * Set the size with which points will be drawn. By default 1.0
165  */
166  inline void setPointSize(const float p)
167  {
168  m_pointSize = p;
170  }
171 
172  /**
173  * Get the size with which points are drawn. By default 1.0
174  */
175  inline float getPointSize() const { return m_pointSize; }
176  /**
177  * Set the width with which lines will be drawn.
178  */
179  inline void setLineWidth(const float w)
180  {
181  m_LineWidth = w;
183  }
184 
185  /**
186  * Get the width with which lines are drawn.
187  */
188  float getLineWidth() const { return m_LineWidth; }
189  /**
190  * Set the max speed associated for the color map ( m_still_color,
191  * m_maxspeed_color)
192  */
193  inline void setMaxSpeedForColor(const float s)
194  {
195  m_maxspeed = s;
197  }
198 
199  /**
200  * Get the max_speed with which lines are drawn.
201  */
202  float getMaxSpeedForColor() const { return m_maxspeed; }
203  /**
204  * Get the vector field in three independent matrices: Matrix_x, Matrix_y
205  * and Matrix_z.
206  */
209  mrpt::math::CMatrixFloat& Matrix_z) const
210  {
211  Matrix_x = x_vf;
212  Matrix_y = y_vf;
213  Matrix_z = z_vf;
214  }
215 
217  Eigen::MatrixXf& Matrix_x, Eigen::MatrixXf& Matrix_y,
218  Eigen::MatrixXf& Matrix_z) const
219  {
220  Matrix_x = x_vf;
221  Matrix_y = y_vf;
222  Matrix_z = z_vf;
223  }
224 
225  /**
226  * Get the coordiantes of the points at which the vector field is
227  * plotted: Coord_x, Coord_y and Coord_z.
228  */
231  mrpt::math::CMatrixFloat& Coord_z) const
232  {
233  Coord_x = x_p;
234  Coord_y = y_p;
235  Coord_z = z_p;
236  }
237 
239  Eigen::MatrixXf& Coord_x, Eigen::MatrixXf& Coord_y,
240  Eigen::MatrixXf& Coord_z) const
241  {
242  Coord_x = x_p;
243  Coord_y = y_p;
244  Coord_z = z_p;
245  }
246 
247  /** Get the "x" component of the vector field as a matrix. */
249  {
250  return x_vf;
251  }
252  /** \overload */
254  /** Get the "y" component of the vector field as a matrix. */
256  {
257  return y_vf;
258  }
259  /** \overload */
261  /** Get the "z" component of the vector field as a matrix. */
263  {
264  return z_vf;
265  }
266  /** \overload */
268  /**
269  * Set the vector field with Matrix_x, Matrix_y and Matrix_z.
270  */
273  mrpt::math::CMatrixFloat& Matrix_z)
274  {
275  ASSERT_(
276  (Matrix_x.getRowCount() == Matrix_y.getRowCount()) &&
277  (Matrix_x.getRowCount() == Matrix_z.getRowCount()))
278  ASSERT_(
279  (Matrix_x.getColCount() == Matrix_y.getColCount()) &&
280  (Matrix_x.getColCount() == Matrix_z.getColCount()))
281  x_vf = Matrix_x;
282  y_vf = Matrix_y;
283  z_vf = Matrix_z;
285  }
286 
288  Eigen::MatrixXf& Matrix_x, Eigen::MatrixXf& Matrix_y,
289  Eigen::MatrixXf& Matrix_z)
290  {
291  ASSERT_(
292  (Matrix_x.getRowCount() == Matrix_y.getRowCount()) &&
293  (Matrix_x.getRowCount() == Matrix_z.getRowCount()))
294  ASSERT_(
295  (Matrix_x.getColCount() == Matrix_y.getColCount()) &&
296  (Matrix_x.getColCount() == Matrix_z.getColCount()))
297  x_vf = Matrix_x;
298  y_vf = Matrix_y;
299  z_vf = Matrix_z;
301  }
302 
303  /**
304  * Set the coordinates of the points at which the vector field is plotted
305  * with Matrix_x, Matrix_y and Matrix_z.
306  */
309  mrpt::math::CMatrixFloat& Matrix_z)
310  {
311  ASSERT_(
312  (Matrix_x.getRowCount() == Matrix_y.getRowCount()) &&
313  (Matrix_x.getRowCount() == Matrix_z.getRowCount()))
314  ASSERT_(
315  (Matrix_x.getColCount() == Matrix_y.getColCount()) &&
316  (Matrix_x.getColCount() == Matrix_z.getColCount()))
317  x_p = Matrix_x;
318  y_p = Matrix_y;
319  z_p = Matrix_z;
321  }
322 
324  Eigen::MatrixXf& Matrix_x, Eigen::MatrixXf& Matrix_y,
325  Eigen::MatrixXf& Matrix_z)
326  {
327  ASSERT_(
328  (Matrix_x.getRowCount() == Matrix_y.getRowCount()) &&
329  (Matrix_x.getRowCount() == Matrix_z.getRowCount()))
330  ASSERT_(
331  (Matrix_x.getColCount() == Matrix_y.getColCount()) &&
332  (Matrix_x.getColCount() == Matrix_z.getColCount()))
333  x_p = Matrix_x;
334  y_p = Matrix_y;
335  z_p = Matrix_z;
337  }
338 
339  /**
340  * Resizes the set.
341  */
342  void resize(size_t rows, size_t cols)
343  {
344  x_vf.resize(rows, cols);
345  y_vf.resize(rows, cols);
346  z_vf.resize(rows, cols);
347  x_p.resize(rows, cols);
348  y_p.resize(rows, cols);
349  z_p.resize(rows, cols);
351  }
352 
353  /** Returns the total count of rows used to represent the vector field. */
354  inline size_t getColCount() const { return x_vf.getColCount(); }
355  /** Returns the total count of columns used to represent the vector field.
356  */
357  inline size_t getRowCount() const { return x_vf.getRowCount(); }
358  /**
359  * Class factory
360  */
362  const mrpt::math::CMatrixFloat x_vf_ini,
363  const mrpt::math::CMatrixFloat y_vf_ini,
364  const mrpt::math::CMatrixFloat z_vf_ini,
365  const mrpt::math::CMatrixFloat x_p_ini,
366  const mrpt::math::CMatrixFloat y_p_ini,
367  const mrpt::math::CMatrixFloat z_p_ini);
368  /** Render
369  */
370  void render_dl() const override;
371 
372  /** Evaluates the bounding box of this object (including possible children)
373  * in the coordinate frame of the object parent. */
374  void getBoundingBox(
375  mrpt::math::TPoint3D& bb_min,
376  mrpt::math::TPoint3D& bb_max) const override;
377 
378  void enableAntiAliasing(bool enable = true)
379  {
380  m_antiAliasing = enable;
382  }
383  void enableColorFromModule(bool enable = true)
384  {
385  m_colorFromModule = enable;
387  }
388  void enableShowPoints(bool enable = true)
389  {
390  m_showPoints = enable;
392  }
393  bool isAntiAliasingEnabled() const { return m_antiAliasing; }
395  /** Constructor */
396  CVectorField3D();
397  /** Constructor with a initial set of lines. */
402  /** Private, virtual destructor: only can be deleted from smart pointers. */
403  virtual ~CVectorField3D() {}
404 };
405 
406 } // end namespace
407 
408 } // End of namespace
409 
410 #endif
virtual ~CVectorField3D()
Private, virtual destructor: only can be deleted from smart pointers.
void setPointCoordinates(Eigen::MatrixXf &Matrix_x, Eigen::MatrixXf &Matrix_y, Eigen::MatrixXf &Matrix_z)
mrpt::utils::TColor m_point_color
void getVectorField(Eigen::MatrixXf &Matrix_x, Eigen::MatrixXf &Matrix_y, Eigen::MatrixXf &Matrix_z) const
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 getVectorFieldColor(mrpt::utils::TColorf Cmin, mrpt::utils::TColorf Cmax) const
Get the motion field min and max colors (colormap) in the range [0,1].
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 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) ...
mrpt::utils::TColor m_still_color
Color associated to fields with null module.
mrpt::utils::TColor m_field_color
void clear()
Clear the matrices.
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 getPointCoordinates(Eigen::MatrixXf &Coord_x, Eigen::MatrixXf &Coord_y, Eigen::MatrixXf &Coord_z) const
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.
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::math::CMatrix y_p
Y coordinate of the points at which the vector field is plotted.
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.
void setVectorField(Eigen::MatrixXf &Matrix_x, Eigen::MatrixXf &Matrix_y, Eigen::MatrixXf &Matrix_z)
mrpt::math::CMatrix z_vf
Z component of the vector field.
A RGB color - 8bit.
Definition: TColor.h:25
mrpt::math::CMatrix y_vf
Y component of the vector field.
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...
mrpt::utils::TColorf getVectorFieldColor() const
Get the arrow color in the range [0,1].
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.
mrpt::utils::TColor m_maxspeed_color
Color associated to fields whose module is equal or larger than &#39;m_maxspeed&#39;.
bool m_colorFromModule
By default it is false.
const float R
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.
#define ASSERT_(f)
A RGB color - floats in the range [0,1].
Definition: TColor.h:78
mrpt::math::CMatrixFloat & getVectorField_x()
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) ...
mrpt::math::CMatrixFloat & getVectorField_y()
mrpt::utils::TColorf getPointColor() const
Get the point color in the range [0,1].
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.
Lightweight 3D point.
static Ptr Create(Args &&... args)
This class is a "CSerializable" wrapper for "CMatrixFloat".
Definition: CMatrix.h:25
size_t getColCount() const
Returns the total count of rows used to represent the vector field.
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
std::shared_ptr< CVectorField3D > Ptr
mrpt::math::CMatrix x_p
X coordinate of the points at which the vector field is plotted.
size_t getRowCount() const
Returns the total count of columns used to represent the vector field.



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019