MRPT  1.9.9
CVectorField3D.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2019, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #pragma once
11 
12 #include <mrpt/math/CMatrixF.h>
14 
15 namespace mrpt::opengl
16 {
17 /** A 3D vector field representation, consisting of points and arrows drawn at
18  * any spatial position.
19  * This opengl object has been created to represent scene flow, and hence
20  * both the vector field and
21  * the coordinates of the points at which the vector field is represented
22  * are stored in matrices because
23  * they are computed from intensity and depth images.
24  * \sa opengl::COpenGLScene
25  *
26  * <div align="center">
27  * <table border="0" cellspan="4" cellspacing="4" style="border-width: 1px;
28  * border-style: solid;">
29  * <tr> <td> mrpt::opengl::CVectorField2D </td> <td> \image html
30  * preview_CVectorField2D.png </td> </tr>
31  * </table>
32  * </div>
33  *
34  * \ingroup mrpt_opengl_grp
35  */
36 
38 {
40  protected:
41  /** X component of the vector field */
43  /** Y component of the vector field */
45  /** Z component of the vector field */
47 
48  /** X coordinate of the points at which the vector field is plotted */
50  /** Y coordinate of the points at which the vector field is plotted */
52  /** Z coordinate of the points at which the vector field is plotted */
54 
55  /** By default it is 1.0 */
56  float m_LineWidth{1.0};
57  /** By default it is 1.0 */
58  float m_pointSize{1.0};
59  /** By default it is true */
60  bool m_antiAliasing{true};
61  /** By default it is false */
62  bool m_colorFromModule{false};
63  /** By default it is true */
64  bool m_showPoints{true};
65 
68 
69  /** Color associated to fields with null module */
71  /** Color associated to fields whose module is equal or larger than
72  * 'm_maxspeed' */
74  /** Value of the module of the motion field which will correspond to
75  * 'm_maxspeed_color' */
76  float m_maxspeed;
77 
78  public:
79  /**
80  * Clear the matrices
81  */
82  inline void clear()
83  {
84  x_vf.resize(0, 0);
85  y_vf.resize(0, 0);
86  z_vf.resize(0, 0);
87  x_p.resize(0, 0);
88  y_p.resize(0, 0);
89  z_p.resize(0, 0);
90 
92  }
93 
94  /**
95  * Set the point color in the range [0,1]
96  */
97  inline void setPointColor(
98  const float R, const float G, const float B, const float A = 1)
99  {
100  m_point_color = mrpt::img::TColor(R * 255, G * 255, B * 255, A * 255);
102  }
103 
104  /**
105  * Get the point color in the range [0,1]
106  */
108  {
110  }
111 
112  /**
113  * Set the arrow color in the range [0,1]
114  */
115  inline void setVectorFieldColor(
116  const float R, const float G, const float B, const float A = 1)
117  {
118  m_field_color = mrpt::img::TColor(R * 255, G * 255, B * 255, A * 255);
120  }
121 
122  /**
123  * Get the motion field min and max colors (colormap) in the range [0,1]
124  */
125  inline void getVectorFieldColor(
126  mrpt::img::TColorf Cmin, mrpt::img::TColorf Cmax) const
127  {
128  Cmin = m_still_color / 255;
129  Cmax = m_maxspeed_color / 255;
130  }
131 
132  /**
133  * Set the motion field min and max colors (colormap) in the range [0,1]
134  */
136  const float Rmin, const float Gmin, const float Bmin, const float Rmax,
137  const float Gmax, const float Bmax, const float Amin = 1,
138  const float Amax = 1)
139  {
140  m_still_color =
141  mrpt::img::TColor(Rmin * 255, Gmin * 255, Bmin * 255, Amin * 255);
143  mrpt::img::TColor(Rmax * 255, Gmax * 255, Bmax * 255, Amax * 255);
145  }
146 
147  /**
148  * Get the arrow color in the range [0,1]
149  */
151  {
153  }
154 
155  /**
156  * Set the size with which points will be drawn. By default 1.0
157  */
158  inline void setPointSize(const float p)
159  {
160  m_pointSize = p;
162  }
163 
164  /**
165  * Get the size with which points are drawn. By default 1.0
166  */
167  inline float getPointSize() const { return m_pointSize; }
168  /**
169  * Set the width with which lines will be drawn.
170  */
171  inline void setLineWidth(const float w)
172  {
173  m_LineWidth = w;
175  }
176 
177  /**
178  * Get the width with which lines are drawn.
179  */
180  float getLineWidth() const { return m_LineWidth; }
181  /**
182  * Set the max speed associated for the color map ( m_still_color,
183  * m_maxspeed_color)
184  */
185  inline void setMaxSpeedForColor(const float s)
186  {
187  m_maxspeed = s;
189  }
190 
191  /**
192  * Get the max_speed with which lines are drawn.
193  */
194  float getMaxSpeedForColor() const { return m_maxspeed; }
195  /**
196  * Get the vector field in three independent matrices: Matrix_x, Matrix_y
197  * and Matrix_z.
198  */
201  mrpt::math::CMatrixFloat& Matrix_z) const
202  {
203  Matrix_x = x_vf;
204  Matrix_y = y_vf;
205  Matrix_z = z_vf;
206  }
207 
208  template <class MATRIX>
210  MATRIX& Matrix_x, MATRIX& Matrix_y, MATRIX& Matrix_z) const
211  {
212  Matrix_x = x_vf;
213  Matrix_y = y_vf;
214  Matrix_z = z_vf;
215  }
216 
217  /**
218  * Get the coordiantes of the points at which the vector field is
219  * plotted: Coord_x, Coord_y and Coord_z.
220  */
223  mrpt::math::CMatrixFloat& Coord_z) const
224  {
225  Coord_x = x_p;
226  Coord_y = y_p;
227  Coord_z = z_p;
228  }
229 
230  template <class MATRIX>
232  MATRIX& Coord_x, MATRIX& Coord_y, MATRIX& Coord_z) const
233  {
234  Coord_x = x_p;
235  Coord_y = y_p;
236  Coord_z = z_p;
237  }
238 
239  /** Get the "x" component of the vector field as a matrix. */
241  {
242  return x_vf;
243  }
244  /** \overload */
246  /** Get the "y" component of the vector field as a matrix. */
248  {
249  return y_vf;
250  }
251  /** \overload */
253  /** Get the "z" component of the vector field as a matrix. */
255  {
256  return z_vf;
257  }
258  /** \overload */
260  /**
261  * Set the vector field with Matrix_x, Matrix_y and Matrix_z.
262  */
265  mrpt::math::CMatrixFloat& Matrix_z)
266  {
267  ASSERT_(
268  (Matrix_x.rows() == Matrix_y.rows()) &&
269  (Matrix_x.rows() == Matrix_z.rows()));
270  ASSERT_(
271  (Matrix_x.cols() == Matrix_y.cols()) &&
272  (Matrix_x.cols() == Matrix_z.cols()));
273  x_vf = Matrix_x;
274  y_vf = Matrix_y;
275  z_vf = Matrix_z;
277  }
278 
279  template <class MATRIX>
280  void setVectorField(MATRIX& Matrix_x, MATRIX& Matrix_y, MATRIX& Matrix_z)
281  {
282  ASSERT_(
283  (Matrix_x.rows() == Matrix_y.rows()) &&
284  (Matrix_x.rows() == Matrix_z.rows()));
285  ASSERT_(
286  (Matrix_x.cols() == Matrix_y.cols()) &&
287  (Matrix_x.cols() == Matrix_z.cols()));
288  x_vf = Matrix_x;
289  y_vf = Matrix_y;
290  z_vf = Matrix_z;
292  }
293 
294  /**
295  * Set the coordinates of the points at which the vector field is plotted
296  * with Matrix_x, Matrix_y and Matrix_z.
297  */
300  mrpt::math::CMatrixFloat& Matrix_z)
301  {
302  ASSERT_(
303  (Matrix_x.rows() == Matrix_y.rows()) &&
304  (Matrix_x.rows() == Matrix_z.rows()));
305  ASSERT_(
306  (Matrix_x.cols() == Matrix_y.cols()) &&
307  (Matrix_x.cols() == Matrix_z.cols()));
308  x_p = Matrix_x;
309  y_p = Matrix_y;
310  z_p = Matrix_z;
312  }
313 
314  template <class MATRIX>
316  MATRIX& Matrix_x, MATRIX& Matrix_y, MATRIX& Matrix_z)
317  {
318  ASSERT_(
319  (Matrix_x.rows() == Matrix_y.rows()) &&
320  (Matrix_x.rows() == Matrix_z.rows()));
321  ASSERT_(
322  (Matrix_x.cols() == Matrix_y.cols()) &&
323  (Matrix_x.cols() == Matrix_z.cols()));
324  x_p = Matrix_x;
325  y_p = Matrix_y;
326  z_p = Matrix_z;
328  }
329 
330  /**
331  * Resizes the set.
332  */
333  void resize(size_t rows, size_t cols)
334  {
335  x_vf.resize(rows, cols);
336  y_vf.resize(rows, cols);
337  z_vf.resize(rows, cols);
338  x_p.resize(rows, cols);
339  y_p.resize(rows, cols);
340  z_p.resize(rows, cols);
342  }
343 
344  /** Returns the total count of rows used to represent the vector field. */
345  inline size_t cols() const { return x_vf.cols(); }
346  /** Returns the total count of columns used to represent the vector field.
347  */
348  inline size_t rows() const { return x_vf.rows(); }
349  /** Render
350  */
351  void render_dl() const override;
352 
353  /** Evaluates the bounding box of this object (including possible children)
354  * in the coordinate frame of the object parent. */
355  void getBoundingBox(
357  mrpt::math::TPoint3D& bb_max) const override;
358 
359  void enableAntiAliasing(bool enable = true)
360  {
361  m_antiAliasing = enable;
363  }
364  void enableColorFromModule(bool enable = true)
365  {
366  m_colorFromModule = enable;
368  }
369  void enableShowPoints(bool enable = true)
370  {
371  m_showPoints = enable;
373  }
374  bool isAntiAliasingEnabled() const { return m_antiAliasing; }
376  /** Constructor */
377  CVectorField3D();
378  /** Constructor with a initial set of lines. */
383  /** Private, virtual destructor: only can be deleted from smart pointers. */
384  ~CVectorField3D() override = default;
385 };
386 
387 } // namespace mrpt::opengl
void notifyChange() const
Must be called to notify that the object has changed (so, the display list must be updated) ...
float m_LineWidth
By default it is 1.0.
float getPointSize() const
Get the size with which points are drawn.
void resize(size_t row, size_t col)
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)
mrpt::math::CMatrixF z_vf
Z component of the vector field.
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;.
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].
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:120
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
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::CMatrixF x_vf
X component of the vector field.
mrpt::math::CMatrixF z_p
Z coordinate of the points at which the vector field is plotted.
mrpt::math::CMatrixF y_p
Y coordinate of the points at which the vector field is plotted.
mrpt::img::TColor m_field_color
void setPointCoordinates(MATRIX &Matrix_x, MATRIX &Matrix_y, MATRIX &Matrix_z)
A 3D vector field representation, consisting of points and arrows drawn at any spatial position...
size_type rows() const
Number of rows in the matrix.
size_type cols() const
Number of columns in the matrix.
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.
~CVectorField3D() override=default
Private, virtual destructor: only can be deleted from smart pointers.
void enableAntiAliasing(bool enable=true)
This class is a "CSerializable" wrapper for "CMatrixFloat".
Definition: CMatrixF.h:22
void setLineWidth(const float w)
Set the width with which lines will be drawn.
bool m_colorFromModule
By default it is false.
mrpt::math::CMatrixF y_vf
Y component of the vector field.
const float R
mrpt::math::CMatrixF x_p
X coordinate of the points at which the vector field is plotted.
A RGB color - floats in the range [0,1].
Definition: TColor.h:78
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.
const auto bb_max
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) ...
#define DEFINE_SERIALIZABLE(class_name, NS)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
void setVectorField(MATRIX &Matrix_x, MATRIX &Matrix_y, MATRIX &Matrix_z)
const auto bb_min
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.
Definition: TPoint3D.h:90
This template class provides the basic functionality for a general 2D any-size, resizable container o...
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...
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].



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 4a95fd864 Fri Dec 13 00:48:40 2019 +0100 at vie dic 13 01:00:11 CET 2019