MRPT  1.9.9
CVectorField2D.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-2019, 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>
14 
15 namespace mrpt::opengl
16 {
17 /** A 2D vector field representation, consisting of points and arrows drawn on a
18  * plane (invisible grid).
19  * \sa opengl::COpenGLScene
20  *
21  * <div align="center">
22  * <table border="0" cellspan="4" cellspacing="4" style="border-width: 1px;
23  * border-style: solid;">
24  * <tr> <td> mrpt::opengl::CVectorField2D </td> <td> \image html
25  * preview_CVectorField2D.png </td> </tr>
26  * </table>
27  * </div>
28  *
29  * \ingroup mrpt_opengl_grp
30  */
31 
33 {
35  protected:
36  /** X component of the vector field */
38  /** Y component of the vector field */
40 
41  /** Grid bounds */
42  float xMin{-1.0}, xMax{1.0}, yMin{-1.0}, yMax{1.0};
43  /** By default is 1.0 */
44  float m_LineWidth{1.0};
45  /** By default is 1.0 */
46  float m_pointSize{1.0};
47  /** By default is true */
48  bool m_antiAliasing{true};
49 
52 
53  public:
54  /**
55  * Clear the matrices
56  */
57  inline void clear()
58  {
59  xcomp.resize(0, 0);
60  ycomp.resize(0, 0);
62  }
63 
64  /**
65  * Set the point color in the range [0,1]
66  */
67  inline void setPointColor(
68  const float R, const float G, const float B, const float A = 1)
69  {
70  m_point_color = mrpt::img::TColor(R * 255, G * 255, B * 255, A * 255);
72  }
73 
74  /**
75  * Get the point color in the range [0,1]
76  */
78  {
80  }
81 
82  /**
83  * Set the arrow color in the range [0,1]
84  */
85  inline void setVectorFieldColor(
86  const float R, const float G, const float B, const float A = 1)
87  {
88  m_field_color = mrpt::img::TColor(R * 255, G * 255, B * 255, A * 255);
90  }
91 
92  /**
93  * Get the arrow color in the range [0,1]
94  */
96  {
98  }
99 
100  /**
101  * Set the size with which points will be drawn. By default 1.0
102  */
103  inline void setPointSize(const float p)
104  {
105  m_pointSize = p;
107  }
108 
109  /**
110  * Get the size with which points are drawn. By default 1.0
111  */
112  inline float getPointSize() const { return m_pointSize; }
113  /**
114  * Set the width with which lines will be drawn.
115  */
116  inline void setLineWidth(const float w)
117  {
118  m_LineWidth = w;
120  }
121 
122  /**
123  * Get the width with which lines are drawn.
124  */
125  float getLineWidth() const { return m_LineWidth; }
126  /**
127  * Set the coordinates of the grid on where the vector field will be drawn
128  * by setting its center and the cell size.
129  * The number of cells is marked by the content of xcomp and ycomp.
130  * \sa xcomp, ycomp
131  */
133  const float center_x, const float center_y, const float cellsize_x,
134  const float cellsize_y)
135  {
136  xMin = center_x - 0.5 * cellsize_x * (xcomp.cols() - 1);
137  xMax = center_x + 0.5 * cellsize_x * (xcomp.cols() - 1);
138  yMin = center_y - 0.5 * cellsize_y * (xcomp.rows() - 1);
139  yMax = center_y + 0.5 * cellsize_y * (xcomp.rows() - 1);
141  }
142 
143  /**
144  * Set the coordinates of the grid on where the vector field will be drawn
145  * using x-y max and min values.
146  */
148  const float xmin, const float xmax, const float ymin, const float ymax)
149  {
150  xMin = xmin;
151  xMax = xmax;
152  yMin = ymin;
153  yMax = ymax;
155  }
156 
157  /**
158  * Get the coordinates of the grid on where the vector field is drawn using
159  * the max and min values.
160  */
161  void getGridLimits(float& xmin, float& xmax, float& ymin, float& ymax) const
162  {
163  xmin = xMin;
164  xmax = xMax;
165  ymin = yMin;
166  ymax = yMax;
167  }
168 
169  /**
170  * Get the vector field. Matrix_x stores the "x" component and Matrix_y
171  * stores the "y" component.
172  */
174  mrpt::math::CMatrixFloat& Matrix_x,
175  mrpt::math::CMatrixFloat& Matrix_y) const
176  {
177  Matrix_x = xcomp;
178  Matrix_y = ycomp;
179  }
180 
181  /** Get the "x" component of the vector field, as a matrix where each entry
182  * represents a point in the 2D grid. */
184  {
185  return xcomp;
186  }
187  /** \overload */
189  /** Get the "y" component of the vector field, as a matrix where each entry
190  * represents a point in the 2D grid. */
192  {
193  return ycomp;
194  }
195  /** \overload */
197  /**
198  * Set the vector field. Matrix_x contains the "x" component and Matrix_y
199  * contains the "y" component.
200  */
203  {
204  ASSERT_(
205  (Matrix_x.rows() == Matrix_y.rows()) &&
206  (Matrix_x.cols() == Matrix_y.cols()));
207  xcomp = Matrix_x;
208  ycomp = Matrix_y;
210  }
211 
212  /**
213  * Adjust the vector field in the scene (vectors magnitude) according to
214  * the grid size.
215  */
217 
218  /** Resizes the set.
219  */
220  void resize(size_t rows, size_t cols)
221  {
222  xcomp.resize(rows, cols);
223  ycomp.resize(rows, cols);
225  }
226 
227  /** Returns the total count of rows used to represent the vector field. */
228  inline size_t cols() const { return xcomp.cols(); }
229  /** Returns the total count of columns used to represent the vector field.
230  */
231  inline size_t rows() const { return xcomp.rows(); }
232  /** Render
233  */
234  void render_dl() const override;
235 
236  /** Evaluates the bounding box of this object (including possible children)
237  * in the coordinate frame of the object parent. */
238  void getBoundingBox(
240  mrpt::math::TPoint3D& bb_max) const override;
241 
242  void enableAntiAliasing(bool enable = true)
243  {
244  m_antiAliasing = enable;
246  }
247  bool isAntiAliasingEnabled() const { return m_antiAliasing; }
248  /** Constructor */
249  CVectorField2D();
250  /** Constructor with a initial set of lines. */
253  float xmin = -1, float xmax = 1, float ymin = -1, float ymax = 1);
254  /** Private, virtual destructor: only can be deleted from smart pointers. */
255  ~CVectorField2D() override = default;
256 };
257 
258 } // namespace mrpt::opengl
mrpt::img::TColorf getVectorFieldColor() const
Get the arrow color in the range [0,1].
void notifyChange() const
Must be called to notify that the object has changed (so, the display list must be updated) ...
void resize(size_t row, size_t col)
void enableAntiAliasing(bool enable=true)
const double G
void getVectorField(mrpt::math::CMatrixFloat &Matrix_x, mrpt::math::CMatrixFloat &Matrix_y) const
Get the vector field.
mrpt::math::CMatrixF ycomp
Y component of the vector field.
mrpt::img::TColor m_point_color
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:4199
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:120
void setPointSize(const float p)
Set the size with which points will be drawn.
mrpt::math::CMatrixF xcomp
X component of the vector field.
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.
size_type rows() const
Number of rows in the matrix.
size_type cols() const
Number of columns in the matrix.
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.
This class is a "CSerializable" wrapper for "CMatrixFloat".
Definition: CMatrixF.h:22
#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.
~CVectorField2D() override=default
Private, virtual destructor: only can be deleted from smart pointers.
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
const auto bb_max
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.
const auto bb_min
void render_dl() const override
Render.
A RGB color - 8bit.
Definition: TColor.h:20
mrpt::img::TColor m_field_color
Lightweight 3D point.
Definition: TPoint3D.h:90
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...
This template class provides the basic functionality for a general 2D any-size, resizable container o...
GLfloat GLfloat p
Definition: glext.h:6398
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: 8fe78517f Sun Jul 14 19:43:28 2019 +0200 at lun oct 28 02:10:00 CET 2019