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



Page generated by Doxygen 1.9.1 for MRPT 1.9.9 Git: 63ea9d1f1 Thu Nov 23 00:06:53 2017 +0100 at mar 26 may 2026 12:19:29 CEST