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



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 7d5e6d718 Fri Aug 24 01:51:28 2018 +0200 at lun nov 2 08:35:50 CET 2020