MRPT  2.0.4
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-2020, 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>
15 
16 namespace mrpt::opengl
17 {
18 /** A 3D vector field representation, consisting of points and arrows drawn at
19  * any spatial position.
20  * This opengl object has been created to represent scene flow, and hence
21  * both the vector field and
22  * the coordinates of the points at which the vector field is represented
23  * are stored in matrices because
24  * they are computed from intensity and depth images.
25  * \sa opengl::COpenGLScene
26  *
27  * <div align="center">
28  * <table border="0" cellspan="4" cellspacing="4" style="border-width: 1px;
29  * border-style: solid;">
30  * <tr> <td> mrpt::opengl::CVectorField2D </td> <td> \image html
31  * preview_CVectorField3D.png </td> </tr>
32  * </table>
33  * </div>
34  *
35  * \ingroup mrpt_opengl_grp
36  */
37 
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 false */
58  bool m_colorFromModule{false};
59  /** By default it is true */
60  bool m_showPoints{true};
61 
64 
65  /** Color associated to fields with null module */
67  /** Color associated to fields whose module is equal or larger than
68  * 'm_maxspeed' */
70  /** Value of the module of the motion field which will correspond to
71  * 'm_maxspeed_color' */
72  float m_maxspeed;
73 
74  public:
75  /** @name Renderizable shader API virtual methods
76  * @{ */
77  void render(const RenderContext& rc) const override;
78  void renderUpdateBuffers() const override;
79  void freeOpenGLResources() override
80  {
83  }
84 
85  virtual shader_list_t requiredShaders() const override
86  {
88  }
89  void onUpdateBuffers_Wireframe() override;
90  void onUpdateBuffers_Points() override;
91  /** @} */
92 
93  /**
94  * Clear the matrices
95  */
96  inline void clear()
97  {
98  x_vf.resize(0, 0);
99  y_vf.resize(0, 0);
100  z_vf.resize(0, 0);
101  x_p.resize(0, 0);
102  y_p.resize(0, 0);
103  z_p.resize(0, 0);
104 
106  }
107 
108  /**
109  * Set the point color in the range [0,1]
110  */
111  inline void setPointColor(
112  const float R, const float G, const float B, const float A = 1)
113  {
116  }
117 
118  /**
119  * Get the point color in the range [0,1]
120  */
122  {
124  }
125 
126  /**
127  * Set the arrow color in the range [0,1]
128  */
129  inline void setVectorFieldColor(
130  const float R, const float G, const float B, const float A = 1)
131  {
134  }
135 
136  /**
137  * Get the motion field min and max colors (colormap) in the range [0,1]
138  */
139  inline void getVectorFieldColor(
140  mrpt::img::TColorf Cmin, mrpt::img::TColorf Cmax) const
141  {
142  Cmin = m_still_color / 255;
143  Cmax = m_maxspeed_color / 255;
144  }
145 
146  /**
147  * Set the motion field min and max colors (colormap) in the range [0,1]
148  */
150  const float Rmin, const float Gmin, const float Bmin, const float Rmax,
151  const float Gmax, const float Bmax, const float Amin = 1,
152  const float Amax = 1)
153  {
154  m_still_color =
155  mrpt::img::TColor(f2u8(Rmin), f2u8(Gmin), f2u8(Bmin), f2u8(Amin));
157  mrpt::img::TColor(f2u8(Rmax), f2u8(Gmax), f2u8(Bmax), f2u8(Amax));
159  }
160 
161  /**
162  * Get the arrow color in the range [0,1]
163  */
165  {
167  }
168 
169  /**
170  * Set the max speed associated for the color map ( m_still_color,
171  * m_maxspeed_color)
172  */
173  inline void setMaxSpeedForColor(const float s)
174  {
175  m_maxspeed = s;
177  }
178 
179  /**
180  * Get the max_speed with which lines are drawn.
181  */
182  float getMaxSpeedForColor() const { return m_maxspeed; }
183  /**
184  * Get the vector field in three independent matrices: Matrix_x, Matrix_y
185  * and Matrix_z.
186  */
189  mrpt::math::CMatrixFloat& Matrix_z) const
190  {
191  Matrix_x = x_vf;
192  Matrix_y = y_vf;
193  Matrix_z = z_vf;
194  }
195 
196  template <class MATRIX>
198  MATRIX& Matrix_x, MATRIX& Matrix_y, MATRIX& Matrix_z) const
199  {
200  Matrix_x = x_vf;
201  Matrix_y = y_vf;
202  Matrix_z = z_vf;
203  }
204 
205  /**
206  * Get the coordiantes of the points at which the vector field is
207  * plotted: Coord_x, Coord_y and Coord_z.
208  */
211  mrpt::math::CMatrixFloat& Coord_z) const
212  {
213  Coord_x = x_p;
214  Coord_y = y_p;
215  Coord_z = z_p;
216  }
217 
218  template <class MATRIX>
220  MATRIX& Coord_x, MATRIX& Coord_y, MATRIX& Coord_z) const
221  {
222  Coord_x = x_p;
223  Coord_y = y_p;
224  Coord_z = z_p;
225  }
226 
227  /** Get the "x" component of the vector field as a matrix. */
229  {
230  return x_vf;
231  }
232  /** \overload */
234  /** Get the "y" component of the vector field as a matrix. */
236  {
237  return y_vf;
238  }
239  /** \overload */
241  /** Get the "z" component of the vector field as a matrix. */
243  {
244  return z_vf;
245  }
246  /** \overload */
248  /**
249  * Set the vector field with Matrix_x, Matrix_y and Matrix_z.
250  */
253  mrpt::math::CMatrixFloat& Matrix_z)
254  {
255  ASSERT_(
256  (Matrix_x.rows() == Matrix_y.rows()) &&
257  (Matrix_x.rows() == Matrix_z.rows()));
258  ASSERT_(
259  (Matrix_x.cols() == Matrix_y.cols()) &&
260  (Matrix_x.cols() == Matrix_z.cols()));
261  x_vf = Matrix_x;
262  y_vf = Matrix_y;
263  z_vf = Matrix_z;
265  }
266 
267  template <class MATRIX>
268  void setVectorField(MATRIX& Matrix_x, MATRIX& Matrix_y, MATRIX& Matrix_z)
269  {
270  ASSERT_(
271  (Matrix_x.rows() == Matrix_y.rows()) &&
272  (Matrix_x.rows() == Matrix_z.rows()));
273  ASSERT_(
274  (Matrix_x.cols() == Matrix_y.cols()) &&
275  (Matrix_x.cols() == Matrix_z.cols()));
276  x_vf = Matrix_x;
277  y_vf = Matrix_y;
278  z_vf = Matrix_z;
280  }
281 
282  /**
283  * Set the coordinates of the points at which the vector field is plotted
284  * with Matrix_x, Matrix_y and Matrix_z.
285  */
288  mrpt::math::CMatrixFloat& Matrix_z)
289  {
290  ASSERT_(
291  (Matrix_x.rows() == Matrix_y.rows()) &&
292  (Matrix_x.rows() == Matrix_z.rows()));
293  ASSERT_(
294  (Matrix_x.cols() == Matrix_y.cols()) &&
295  (Matrix_x.cols() == Matrix_z.cols()));
296  x_p = Matrix_x;
297  y_p = Matrix_y;
298  z_p = Matrix_z;
300  }
301 
302  template <class MATRIX>
304  MATRIX& Matrix_x, MATRIX& Matrix_y, MATRIX& 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  /**
319  * Resizes the set.
320  */
321  void resize(size_t rows, size_t cols)
322  {
323  x_vf.resize(rows, cols);
324  y_vf.resize(rows, cols);
325  z_vf.resize(rows, cols);
326  x_p.resize(rows, cols);
327  y_p.resize(rows, cols);
328  z_p.resize(rows, cols);
330  }
331 
332  /** Returns the total count of rows used to represent the vector field. */
333  inline size_t cols() const { return x_vf.cols(); }
334  /** Returns the total count of columns used to represent the vector field.
335  */
336  inline size_t rows() const { return x_vf.rows(); }
337 
338  void getBoundingBox(
340  mrpt::math::TPoint3D& bb_max) const override;
341 
342  void enableColorFromModule(bool enable = true)
343  {
344  m_colorFromModule = enable;
346  }
347  void enableShowPoints(bool enable = true)
348  {
349  m_showPoints = enable;
351  }
352  bool isAntiAliasingEnabled() const { return m_antiAliasing; }
354  /** Constructor */
355  CVectorField3D();
356  /** Constructor with a initial set of lines. */
361  /** Private, virtual destructor: only can be deleted from smart pointers. */
362  ~CVectorField3D() override = default;
363 };
364 
365 } // namespace mrpt::opengl
virtual shader_list_t requiredShaders() const override
Returns the ID of the OpenGL shader program required to render this class.
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 notifyChange() const
Call to enable calling renderUpdateBuffers() before the next render() rendering iteration.
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 render(const RenderContext &rc) const override
Implements the rendering of 3D objects in each class derived from CRenderizable.
void enableShowPoints(bool enable=true)
void freeOpenGLResources() override
Free opengl buffers.
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 freeOpenGLResources() override
Free opengl buffers.
void enableColorFromModule(bool enable=true)
void setVectorFieldColor(const float R, const float G, const float B, const float A=1)
Set the arrow color in the range [0,1].
std::vector< shader_id_t > shader_list_t
A list of shader IDs.
Definition: Shader.h:26
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.
Context for calls to render()
float getMaxSpeedForColor() const
Get the max_speed with which lines are drawn.
void onUpdateBuffers_Wireframe() override
Must be implemented in derived classes to update the geometric entities to be drawn in "m_*_buffer" f...
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].
static constexpr shader_id_t WIREFRAME
mrpt::math::CMatrixFloat & getVectorField_z()
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)
void renderUpdateBuffers() const override
Called whenever m_outdatedBuffers is true: used to re-generate OpenGL vertex buffers, etc.
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.
Renderizable generic renderer for objects using the points shader.
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.
This class is a "CSerializable" wrapper for "CMatrixFloat".
Definition: CMatrixF.h:22
uint8_t f2u8(const float f)
converts a float [0,1] into an uint8_t [0,255] (without checking for out of bounds) ...
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.
Renderizable generic renderer for objects using the wireframe shader.
An RGBA color - floats in the range [0,1].
Definition: TColor.h:88
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:13
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 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.
A RGB color - 8bit.
Definition: TColor.h:25
void freeOpenGLResources() override
Free opengl buffers.
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].
static constexpr shader_id_t POINTS
void onUpdateBuffers_Points() override
Must be implemented in derived classes to update the geometric entities to be drawn in "m_*_buffer" f...



Page generated by Doxygen 1.8.14 for MRPT 2.0.4 Git: 33de1d0ad Sat Jun 20 11:02:42 2020 +0200 at sáb jun 20 17:35:17 CEST 2020