Main MRPT website > C++ reference for MRPT 1.5.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  {
24 
25  // This must be added to any CSerializable derived class:
27 
28  /** A 3D vector field representation, consisting of points and arrows drawn at any spatial position.
29  * This opengl object has been created to represent scene flow, and hence both the vector field and
30  * the coordinates of the points at which the vector field is represented 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; border-style: solid;">
36  * <tr> <td> mrpt::opengl::CVectorField2D </td> <td> \image html preview_CVectorField2D.png </td> </tr>
37  * </table>
38  * </div>
39  *
40  * \ingroup mrpt_opengl_grp
41  */
42 
44  {
46  protected:
47  mrpt::math::CMatrix x_vf; //!< X component of the vector field
48  mrpt::math::CMatrix y_vf; //!< Y component of the vector field
49  mrpt::math::CMatrix z_vf; //!< Z component of the vector field
50 
51  mrpt::math::CMatrix x_p; //!< X coordinate of the points at which the vector field is plotted
52  mrpt::math::CMatrix y_p; //!< Y coordinate of the points at which the vector field is plotted
53  mrpt::math::CMatrix z_p; //!< Z coordinate of the points at which the vector field is plotted
54 
55  float m_LineWidth; //!< By default it is 1.0
56  float m_pointSize; //!< By default it is 1.0
57  bool m_antiAliasing; //!< By default it is true
58  bool m_colorFromModule; //!< By default it is false
59  bool m_showPoints; //!< By default it is true
60 
63 
64  mrpt::utils::TColor m_still_color; //!< Color associated to fields with null module
65  mrpt::utils::TColor m_maxspeed_color; //!< Color associated to fields whose module is equal or larger than 'm_maxspeed'
66  float m_maxspeed; //!< Value of the module of the motion field which will correspond to 'm_maxspeed_color'
67 
68  public:
69  /**
70  * Clear the matrices
71  */
72  inline void clear() {
73  x_vf.resize(0,0); y_vf.resize(0,0); z_vf.resize(0,0);
74  x_p.resize(0,0); y_p.resize(0,0); z_p.resize(0,0);
75 
77  }
78 
79  /**
80  * Set the point color in the range [0,1]
81  */
82  inline void setPointColor( const float R, const float G, const float B, const float A = 1)
83  {
84  m_point_color = mrpt::utils::TColor(R*255,G*255,B*255,A*255);
86  }
87 
88  /**
89  * Get the point color in the range [0,1]
90  */
91  inline mrpt::utils::TColorf getPointColor() const { return mrpt::utils::TColorf(m_point_color); }
92 
93  /**
94  * Set the arrow color in the range [0,1]
95  */
96  inline void setVectorFieldColor( const float R, const float G, const float B, const float A = 1)
97  {
98  m_field_color = mrpt::utils::TColor(R*255,G*255,B*255,A*255);
100  }
101 
102  /**
103  * Get the motion field min and max colors (colormap) in the range [0,1]
104  */
106  {
107  Cmin = m_still_color/255;
108  Cmax = m_maxspeed_color/255;
109  }
110 
111  /**
112  * Set the motion field min and max colors (colormap) in the range [0,1]
113  */
114  inline 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)
115  {
116  m_still_color = mrpt::utils::TColor(Rmin*255,Gmin*255,Bmin*255,Amin*255);
117  m_maxspeed_color = mrpt::utils::TColor(Rmax*255,Gmax*255,Bmax*255,Amax*255);
119  }
120 
121  /**
122  * Get the arrow color in the range [0,1]
123  */
124  inline mrpt::utils::TColorf getVectorFieldColor() const { return mrpt::utils::TColorf(m_field_color); }
125 
126  /**
127  * Set the size with which points will be drawn. By default 1.0
128  */
129  inline void setPointSize(const float p) { m_pointSize=p; CRenderizableDisplayList::notifyChange(); }
130 
131  /**
132  * Get the size with which points are drawn. By default 1.0
133  */
134  inline float getPointSize() const { return m_pointSize; }
135 
136  /**
137  * Set the width with which lines will be drawn.
138  */
139  inline void setLineWidth(const float w) { m_LineWidth = w; CRenderizableDisplayList::notifyChange(); }
140 
141  /**
142  * Get the width with which lines are drawn.
143  */
144  float getLineWidth() const {return m_LineWidth; }
145 
146  /**
147  * Set the max speed associated for the color map ( m_still_color, m_maxspeed_color)
148  */
149  inline void setMaxSpeedForColor (const float s) { m_maxspeed = s; CRenderizableDisplayList::notifyChange(); }
150 
151  /**
152  * Get the max_speed with which lines are drawn.
153  */
154  float getMaxSpeedForColor() const {return m_maxspeed; }
155 
156  /**
157  * Get the vector field in three independent matrices: Matrix_x, Matrix_y and Matrix_z.
158  */
160  Matrix_x = x_vf;
161  Matrix_y = y_vf;
162  Matrix_z = z_vf;
163  }
164 
165  void getVectorField(Eigen::MatrixXf &Matrix_x, Eigen::MatrixXf &Matrix_y, Eigen::MatrixXf &Matrix_z) const {
166  Matrix_x = x_vf;
167  Matrix_y = y_vf;
168  Matrix_z = z_vf;
169  }
170 
171  /**
172  * Get the coordiantes of the points at which the vector field is plotted: Coord_x, Coord_y and Coord_z.
173  */
175  Coord_x = x_p;
176  Coord_y = y_p;
177  Coord_z = z_p;
178  }
179 
180  void getPointCoordinates(Eigen::MatrixXf &Coord_x, Eigen::MatrixXf &Coord_y, Eigen::MatrixXf &Coord_z) const {
181  Coord_x = x_p;
182  Coord_y = y_p;
183  Coord_z = z_p;
184  }
185 
186  /** Get the "x" component of the vector field as a matrix. */
187  inline const mrpt::math::CMatrixFloat & getVectorField_x() const { return x_vf; }
188  /** \overload */
189  inline mrpt::math::CMatrixFloat & getVectorField_x() { return x_vf; }
190 
191  /** Get the "y" component of the vector field as a matrix. */
192  inline const mrpt::math::CMatrixFloat & getVectorField_y() const { return y_vf; }
193  /** \overload */
194  inline mrpt::math::CMatrixFloat & getVectorField_y() { return y_vf; }
195 
196  /** Get the "z" component of the vector field as a matrix. */
197  inline const mrpt::math::CMatrixFloat & getVectorField_z() const { return z_vf; }
198  /** \overload */
199  inline mrpt::math::CMatrixFloat & getVectorField_z() { return z_vf; }
200 
201  /**
202  * Set the vector field with Matrix_x, Matrix_y and Matrix_z.
203  */
205  ASSERT_((Matrix_x.getRowCount() == Matrix_y.getRowCount())&&(Matrix_x.getRowCount() == Matrix_z.getRowCount()))
206  ASSERT_((Matrix_x.getColCount() == Matrix_y.getColCount())&&(Matrix_x.getColCount() == Matrix_z.getColCount()))
207  x_vf = Matrix_x;
208  y_vf = Matrix_y;
209  z_vf = Matrix_z;
211  }
212 
213  void setVectorField(Eigen::MatrixXf &Matrix_x,Eigen::MatrixXf &Matrix_y, Eigen::MatrixXf &Matrix_z) {
214  ASSERT_((Matrix_x.getRowCount() == Matrix_y.getRowCount())&&(Matrix_x.getRowCount() == Matrix_z.getRowCount()))
215  ASSERT_((Matrix_x.getColCount() == Matrix_y.getColCount())&&(Matrix_x.getColCount() == Matrix_z.getColCount()))
216  x_vf = Matrix_x;
217  y_vf = Matrix_y;
218  z_vf = Matrix_z;
220  }
221 
222  /**
223  * Set the coordinates of the points at which the vector field is plotted with Matrix_x, Matrix_y and Matrix_z.
224  */
226  ASSERT_((Matrix_x.getRowCount() == Matrix_y.getRowCount())&&(Matrix_x.getRowCount() == Matrix_z.getRowCount()))
227  ASSERT_((Matrix_x.getColCount() == Matrix_y.getColCount())&&(Matrix_x.getColCount() == Matrix_z.getColCount()))
228  x_p = Matrix_x;
229  y_p = Matrix_y;
230  z_p = Matrix_z;
232  }
233 
234  void setPointCoordinates(Eigen::MatrixXf &Matrix_x, Eigen::MatrixXf &Matrix_y, Eigen::MatrixXf &Matrix_z) {
235  ASSERT_((Matrix_x.getRowCount() == Matrix_y.getRowCount())&&(Matrix_x.getRowCount() == Matrix_z.getRowCount()))
236  ASSERT_((Matrix_x.getColCount() == Matrix_y.getColCount())&&(Matrix_x.getColCount() == Matrix_z.getColCount()))
237  x_p = Matrix_x;
238  y_p = Matrix_y;
239  z_p = Matrix_z;
241  }
242 
243 
244  /**
245  * Resizes the set.
246  */
247  void resize(size_t rows, size_t cols) {
248  x_vf.resize(rows,cols); y_vf.resize(rows,cols); z_vf.resize(rows,cols);
249  x_p.resize(rows,cols); y_p.resize(rows,cols); z_p.resize(rows,cols);
251  }
252 
253  /** Returns the total count of rows used to represent the vector field. */
254  inline size_t getColCount() const { return x_vf.getColCount(); }
255 
256  /** Returns the total count of columns used to represent the vector field. */
257  inline size_t getRowCount() const { return x_vf.getRowCount(); }
258 
259  /**
260  * Class factory
261  */
262  static CVectorField3DPtr Create(const mrpt::math::CMatrixFloat x_vf_ini, const mrpt::math::CMatrixFloat y_vf_ini, const mrpt::math::CMatrixFloat z_vf_ini, const mrpt::math::CMatrixFloat x_p_ini, const mrpt::math::CMatrixFloat y_p_ini, const mrpt::math::CMatrixFloat z_p_ini);
263  /** Render
264  */
265  void render_dl() const MRPT_OVERRIDE;
266 
267 
268  /** Evaluates the bounding box of this object (including possible children) in the coordinate frame of the object parent. */
269  void getBoundingBox(mrpt::math::TPoint3D &bb_min, mrpt::math::TPoint3D &bb_max) const MRPT_OVERRIDE;
270 
271  void enableAntiAliasing(bool enable=true) { m_antiAliasing = enable; CRenderizableDisplayList::notifyChange(); }
272  void enableColorFromModule(bool enable=true) { m_colorFromModule = enable; CRenderizableDisplayList::notifyChange(); }
273  void enableShowPoints(bool enable=true) { m_showPoints = enable; CRenderizableDisplayList::notifyChange(); }
274  bool isAntiAliasingEnabled() const { return m_antiAliasing; }
275  bool isColorFromModuleEnabled() const { return m_colorFromModule; }
276 
277  private:
278  /** Constructor */
279  CVectorField3D();
280  /** Constructor with a initial set of lines. */
282  /** Private, virtual destructor: only can be deleted from smart pointers. */
283  virtual ~CVectorField3D() { }
284  };
286 
287 
288  } // end namespace
289 
290 } // End of namespace
291 
292 
293 #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].
#define MRPT_OVERRIDE
C++11 "override" for virtuals:
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:3602
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:3962
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.
#define DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE(class_name, base_name, _LINKAGE_)
This declaration must be inserted in all CSerializable classes definition, before the class declarati...
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:26
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.
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:80
mrpt::math::CMatrixFloat & getVectorField_x()
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.
This class is a "CSerializable" wrapper for "CMatrixFloat".
Definition: CMatrix.h:30
class OPENGL_IMPEXP CVectorField3D
size_t getColCount() const
Returns the total count of rows used to represent the vector field.
#define DEFINE_SERIALIZABLE_POST_CUSTOM_BASE_LINKAGE(class_name, base_name, _LINKAGE_)
GLfloat GLfloat p
Definition: glext.h:5587
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.5.9 Git: 690a4699f Wed Apr 15 19:29:53 2020 +0200 at miƩ abr 15 19:30:12 CEST 2020