Main MRPT website > C++ reference for MRPT 1.4.0
CVectorField2D.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-2016, 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_CVectorField2D_H
11 #define opengl_CVectorField2D_H
12 
15 #include <mrpt/math/CMatrix.h>
16 
17 namespace mrpt
18 {
19  namespace opengl
20  {
21  // This must be added to any CSerializable derived class:
22  DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE( CVectorField2D, CRenderizableDisplayList, OPENGL_IMPEXP )
23 
24  /** A 2D vector field representation, consisting of points and arrows drawn on a plane (invisible grid).
25  * \sa opengl::COpenGLScene
26  *
27  * <div align="center">
28  * <table border="0" cellspan="4" cellspacing="4" style="border-width: 1px; border-style: solid;">
29  * <tr> <td> mrpt::opengl::CVectorField2D </td> <td> \image html preview_CVectorField2D.png </td> </tr>
30  * </table>
31  * </div>
32  *
33  * \ingroup mrpt_opengl_grp
34  */
35 
37  {
39  protected:
40  mrpt::math::CMatrix xcomp; //!< X component of the vector field
41  mrpt::math::CMatrix ycomp; //!< Y component of the vector field
42 
43  float xMin,xMax,yMin,yMax; //!< Grid bounds
44  float m_LineWidth; //!< By default is 1.0
45  float m_pointSize; //!< By default is 1.0
46  bool m_antiAliasing; //!< By default is true
47 
50 
51  public:
52  /**
53  * Clear the matrices
54  */
55  inline void clear() {
56  xcomp.resize(0,0);
57  ycomp.resize(0,0);
59  }
60 
61  /**
62  * Set the point color in the range [0,1]
63  */
64  inline void setPointColor( const float R, const float G, const float B, const float A = 1)
65  {
66  m_point_color = mrpt::utils::TColor(R*255,G*255,B*255,A*255);
68  }
69 
70  /**
71  * Get the point color in the range [0,1]
72  */
73  inline mrpt::utils::TColorf getPointColor() const { return mrpt::utils::TColorf(m_point_color); }
74 
75  /**
76  * Set the arrow color in the range [0,1]
77  */
78  inline void setVectorFieldColor( const float R, const float G, const float B, const float A = 1)
79  {
80  m_field_color = mrpt::utils::TColor(R*255,G*255,B*255,A*255);
82  }
83 
84  /**
85  * Get the arrow color in the range [0,1]
86  */
87  inline mrpt::utils::TColorf getVectorFieldColor() const { return mrpt::utils::TColorf(m_field_color); }
88 
89  /**
90  * Set the size with which points will be drawn. By default 1.0
91  */
92  inline void setPointSize(const float p) { m_pointSize=p; CRenderizableDisplayList::notifyChange(); }
93 
94  /**
95  * Get the size with which points are drawn. By default 1.0
96  */
97  inline float getPointSize() const { return m_pointSize; }
98 
99  /**
100  * Set the width with which lines will be drawn.
101  */
102  inline void setLineWidth(const float w) { m_LineWidth = w; CRenderizableDisplayList::notifyChange(); }
103 
104  /**
105  * Get the width with which lines are drawn.
106  */
107  float getLineWidth() const {
108  return m_LineWidth;
109  }
110 
111  /**
112  * Set the coordinates of the grid on where the vector field will be drawn by setting its center and the cell size.
113  * The number of cells is marked by the content of xcomp and ycomp.
114  * \sa xcomp, ycomp
115  */
116  void setGridCenterAndCellSize(const float center_x, const float center_y, const float cellsize_x, const float cellsize_y)
117  {
118  xMin = center_x - 0.5*cellsize_x*(xcomp.getColCount()-1);
119  xMax = center_x + 0.5*cellsize_x*(xcomp.getColCount()-1);
120  yMin = center_y - 0.5*cellsize_y*(xcomp.getRowCount()-1);
121  yMax = center_y + 0.5*cellsize_y*(xcomp.getRowCount()-1);
123  }
124 
125  /**
126  * Set the coordinates of the grid on where the vector field will be drawn using x-y max and min values.
127  */
128  void setGridLimits(const float xmin,const float xmax, const float ymin, const float ymax)
129  {
130  xMin=xmin; xMax = xmax;
131  yMin=ymin; yMax = ymax;
133  }
134 
135  /**
136  * Get the coordinates of the grid on where the vector field is drawn using the max and min values.
137  */
138  void getGridLimits(float &xmin,float &xmax, float &ymin, float &ymax) const
139  {
140  xmin=xMin; xmax=xMax;
141  ymin=yMin; ymax=yMax;
142  }
143 
144  /**
145  * Get the vector field. Matrix_x stores the "x" component and Matrix_y stores the "y" component.
146  */
148  Matrix_x = xcomp;
149  Matrix_y = ycomp;
150  }
151 
152  /** Get the "x" component of the vector field, as a matrix where each entry represents a point in the 2D grid. */
153  inline const mrpt::math::CMatrixFloat & getVectorField_x() const { return xcomp; }
154  /** \overload */
155  inline mrpt::math::CMatrixFloat & getVectorField_x() { return xcomp; }
156 
157  /** Get the "y" component of the vector field, as a matrix where each entry represents a point in the 2D grid. */
158  inline const mrpt::math::CMatrixFloat & getVectorField_y() const { return ycomp; }
159  /** \overload */
160  inline mrpt::math::CMatrixFloat & getVectorField_y() { return ycomp; }
161 
162  /**
163  * Set the vector field. Matrix_x contains the "x" component and Matrix_y contains the "y" component.
164  */
166  ASSERT_((Matrix_x.getRowCount() == Matrix_y.getRowCount())&&(Matrix_x.getColCount() == Matrix_y.getColCount()))
167  xcomp = Matrix_x;
168  ycomp = Matrix_y;
170  }
171 
172  /**
173  * Adjust the vector field in the scene (vectors magnitude) according to the grid size.
174  */
175  void adjustVectorFieldToGrid();
176 
177  /** Resizes the set.
178  */
179  void resize(size_t rows, size_t cols) {
180  xcomp.resize(rows, cols);
181  ycomp.resize(rows, cols);
183  }
184 
185  /** Returns the total count of rows used to represent the vector field. */
186  inline size_t getColCount() const { return xcomp.getColCount(); }
187 
188  /** Returns the total count of columns used to represent the vector field. */
189  inline size_t getRowCount() const { return xcomp.getRowCount(); }
190 
191  /**
192  * Class factory
193  */
194  static CVectorField2DPtr Create(const mrpt::math::CMatrixFloat &Matrix_x, const mrpt::math::CMatrixFloat &Matrix_y, float xmin=-1, float xmax=1, float ymin=-1, float ymax=1);
195  /** Render
196  */
197  void render_dl() const MRPT_OVERRIDE;
198 
199 
200  /** Evaluates the bounding box of this object (including possible children) in the coordinate frame of the object parent. */
201  void getBoundingBox(mrpt::math::TPoint3D &bb_min, mrpt::math::TPoint3D &bb_max) const MRPT_OVERRIDE;
202 
203  void enableAntiAliasing(bool enable=true) { m_antiAliasing = enable; CRenderizableDisplayList::notifyChange(); }
204  bool isAntiAliasingEnabled() const { return m_antiAliasing; }
205 
206  private:
207  /** Constructor */
208  CVectorField2D();
209  /** Constructor with a initial set of lines. */
210  CVectorField2D( mrpt::math::CMatrixFloat Matrix_x, mrpt::math::CMatrixFloat Matrix_y, float xmin=-1, float xmax=1, float ymin=-1, float ymax=1);
211  /** Private, virtual destructor: only can be deleted from smart pointers. */
212  virtual ~CVectorField2D() { }
213  };
214  DEFINE_SERIALIZABLE_POST_CUSTOM_BASE_LINKAGE( CVectorField2D, CRenderizableDisplayList, OPENGL_IMPEXP )
215 
216 
217  } // end namespace
218 
219 } // End of namespace
220 
221 
222 #endif
mrpt::opengl::CVectorField2D::getVectorField_y
mrpt::math::CMatrixFloat & getVectorField_y()
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: CVectorField2D.h:160
mrpt::opengl::CVectorField2D::getLineWidth
float getLineWidth() const
Get the width with which lines are drawn.
Definition: CVectorField2D.h:107
mrpt::opengl::CVectorField2D::setGridLimits
void setGridLimits(const float xmin, const float xmax, const float ymin, const float ymax)
Set the coordinates of the grid on where the vector field will be drawn using x-y max and min values.
Definition: CVectorField2D.h:128
mrpt::opengl::CVectorField2D::getColCount
size_t getColCount() const
Returns the total count of rows used to represent the vector field.
Definition: CVectorField2D.h:186
mrpt::opengl::CVectorField2D::setPointSize
void setPointSize(const float p)
Set the size with which points will be drawn.
Definition: CVectorField2D.h:92
CRenderizableDisplayList.h
mrpt::opengl::CVectorField2D::getVectorField_x
const mrpt::math::CMatrixFloat & getVectorField_x() const
Get the "x" component of the vector field, as a matrix where each entry represents a point in the 2D ...
Definition: CVectorField2D.h:153
mrpt::opengl::CRenderizableDisplayList
A renderizable object suitable for rendering with OpenGL's display lists.
Definition: CRenderizableDisplayList.h:36
mrpt::opengl::CVectorField2D::isAntiAliasingEnabled
bool isAntiAliasingEnabled() const
Definition: CVectorField2D.h:204
mrpt::opengl::CVectorField2D::m_pointSize
float m_pointSize
By default is 1.0.
Definition: CVectorField2D.h:45
CMatrix.h
mrpt::opengl::CRenderizableDisplayList::notifyChange
EIGEN_STRONG_INLINE void notifyChange() const
Must be called to notify that the object has changed (so, the display list must be updated)
Definition: CRenderizableDisplayList.h:49
mrpt::opengl::CVectorField2D
A 2D vector field representation, consisting of points and arrows drawn on a plane (invisible grid).
Definition: CVectorField2D.h:36
mrpt::opengl::CVectorField2D::setGridCenterAndCellSize
void setGridCenterAndCellSize(const float center_x, const float center_y, const float cellsize_x, const float cellsize_y)
Set the coordinates of the grid on where the vector field will be drawn by setting its center and the...
Definition: CVectorField2D.h:116
mrpt::opengl::CVectorField2D::resize
void resize(size_t rows, size_t cols)
Resizes the set.
Definition: CVectorField2D.h:179
mrpt::opengl::CVectorField2D::clear
void clear()
Clear the matrices.
Definition: CVectorField2D.h:55
mrpt::opengl::CVectorField2D::getGridLimits
void getGridLimits(float &xmin, float &xmax, float &ymin, float &ymax) const
Get the coordinates of the grid on where the vector field is drawn using the max and min values.
Definition: CVectorField2D.h:138
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CParticleFilter.h:16
mrpt::opengl::CVectorField2D::m_antiAliasing
bool m_antiAliasing
By default is true.
Definition: CVectorField2D.h:46
mrpt::opengl::CVectorField2D::setLineWidth
void setLineWidth(const float w)
Set the width with which lines will be drawn.
Definition: CVectorField2D.h:102
lightweight_geom_data.h
mrpt::opengl::CVectorField2D::getPointSize
float getPointSize() const
Get the size with which points are drawn.
Definition: CVectorField2D.h:97
mrpt::opengl::CVectorField2D::m_field_color
mrpt::utils::TColor m_field_color
Definition: CVectorField2D.h:49
mrpt::math::CMatrixTemplateNumeric
A matrix of dynamic size.
Definition: CMatrixTemplateNumeric.h:32
mrpt::opengl::CVectorField2D::getVectorField_y
const mrpt::math::CMatrixFloat & getVectorField_y() const
Get the "y" component of the vector field, as a matrix where each entry represents a point in the 2D ...
Definition: CVectorField2D.h:158
mrpt::math::CMatrix
This class is a "CSerializable" wrapper for "CMatrixFloat".
Definition: CMatrix.h:30
mrpt::opengl::CVectorField2D::getVectorFieldColor
mrpt::utils::TColorf getVectorFieldColor() const
Get the arrow color in the range [0,1].
Definition: CVectorField2D.h:87
mrpt::opengl::CVectorField2D::getVectorField
void getVectorField(mrpt::math::CMatrixFloat &Matrix_x, mrpt::math::CMatrixFloat &Matrix_y) const
Get the vector field.
Definition: CVectorField2D.h:147
mrpt::opengl::CVectorField2D::yMin
float yMin
Definition: CVectorField2D.h:43
DEFINE_SERIALIZABLE_POST_CUSTOM_BASE_LINKAGE
#define DEFINE_SERIALIZABLE_POST_CUSTOM_BASE_LINKAGE(class_name, base_name, _LINKAGE_)
Definition: CSerializable.h:174
mrpt::opengl::CVectorField2D::setVectorFieldColor
void setVectorFieldColor(const float R, const float G, const float B, const float A=1)
Set the arrow color in the range [0,1].
Definition: CVectorField2D.h:78
mrpt::opengl::CVectorField2D::setVectorField
void setVectorField(mrpt::math::CMatrixFloat &Matrix_x, mrpt::math::CMatrixFloat &Matrix_y)
Set the vector field.
Definition: CVectorField2D.h:165
mrpt::opengl::CVectorField2D::~CVectorField2D
virtual ~CVectorField2D()
Private, virtual destructor: only can be deleted from smart pointers.
Definition: CVectorField2D.h:212
mrpt::opengl::CVectorField2D::m_LineWidth
float m_LineWidth
By default is 1.0.
Definition: CVectorField2D.h:44
mrpt::opengl::CVectorField2D::getRowCount
size_t getRowCount() const
Returns the total count of columns used to represent the vector field.
Definition: CVectorField2D.h:189
mrpt::utils::TColorf
A RGB color - floats in the range [0,1].
Definition: TColor.h:52
DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE
#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...
Definition: CSerializable.h:170
mrpt::utils::TColor
A RGB color - 8bit.
Definition: TColor.h:25
DEFINE_SERIALIZABLE
#define DEFINE_SERIALIZABLE(class_name)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
Definition: CSerializable.h:147
mrpt::opengl::CVectorField2D::xcomp
mrpt::math::CMatrix xcomp
X component of the vector field.
Definition: CVectorField2D.h:40
mrpt::opengl::CVectorField2D::getVectorField_x
mrpt::math::CMatrixFloat & getVectorField_x()
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: CVectorField2D.h:155
mrpt::opengl::CVectorField2D::m_point_color
mrpt::utils::TColor m_point_color
Definition: CVectorField2D.h:48
ASSERT_
#define ASSERT_(f)
Definition: mrpt_macros.h:261
mrpt::opengl::CVectorField2D::getPointColor
mrpt::utils::TColorf getPointColor() const
Get the point color in the range [0,1].
Definition: CVectorField2D.h:73
mrpt::opengl::CVectorField2D::setPointColor
void setPointColor(const float R, const float G, const float B, const float A=1)
Set the point color in the range [0,1].
Definition: CVectorField2D.h:64
mrpt::opengl::CVectorField2D::ycomp
mrpt::math::CMatrix ycomp
Y component of the vector field.
Definition: CVectorField2D.h:41
MRPT_OVERRIDE
#define MRPT_OVERRIDE
C++11 "override" for virtuals:
Definition: mrpt_macros.h:28



Page generated by Doxygen 1.8.17 for MRPT 1.4.0 SVN: at Tue Mar 3 09:15:16 UTC 2020