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-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
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::img::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::img::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.cols() - 1);
141  xMax = center_x + 0.5 * cellsize_x * (xcomp.cols() - 1);
142  yMin = center_y - 0.5 * cellsize_y * (xcomp.rows() - 1);
143  yMax = center_y + 0.5 * cellsize_y * (xcomp.rows() - 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.rows() == Matrix_y.rows()) &&
210  (Matrix_x.cols() == Matrix_y.cols()));
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 cols() const { return xcomp.cols(); }
233  /** Returns the total count of columns used to represent the vector field.
234  */
235  inline size_t rows() const { return xcomp.rows(); }
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
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:200
mrpt::opengl::CVectorField2D::getLineWidth
float getLineWidth() const
Get the width with which lines are drawn.
Definition: CVectorField2D.h:129
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:151
mrpt::opengl::CVectorField2D::CVectorField2D
CVectorField2D()
Constructor.
Definition: CVectorField2D.cpp:26
G
const double G
Definition: vision_stereo_rectify/test.cpp:31
mrpt::opengl::CVectorField2D::adjustVectorFieldToGrid
void adjustVectorFieldToGrid()
Adjust the vector field in the scene (vectors magnitude) according to the grid size.
Definition: CVectorField2D.cpp:245
mrpt::opengl::CVectorField2D::getBoundingBox
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...
Definition: CVectorField2D.cpp:193
mrpt::opengl::CVectorField2D::setPointSize
void setPointSize(const float p)
Set the size with which points will be drawn.
Definition: CVectorField2D.h:107
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:187
mrpt::opengl::CRenderizableDisplayList
A renderizable object suitable for rendering with OpenGL's display lists.
Definition: CRenderizableDisplayList.h:39
mrpt::opengl::CVectorField2D::isAntiAliasingEnabled
bool isAntiAliasingEnabled() const
Definition: CVectorField2D.h:258
mrpt::opengl::CVectorField2D::m_pointSize
float m_pointSize
By default is 1.0.
Definition: CVectorField2D.h:50
mrpt::opengl::CVectorField2D::m_field_color
mrpt::img::TColor m_field_color
Definition: CVectorField2D.h:55
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:57
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:136
mrpt::opengl::CVectorField2D::resize
void resize(size_t rows, size_t cols)
Resizes the set.
Definition: CVectorField2D.h:224
mrpt::opengl::CVectorField2D::clear
void clear()
Clear the matrices.
Definition: CVectorField2D.h:61
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:165
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CKalmanFilterCapable.h:30
w
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:4178
mrpt::opengl::CVectorField2D::Create
static Ptr Create(Args &&... args)
Definition: CVectorField2D.h:38
R
const float R
Definition: CKinematicChain.cpp:138
ASSERT_
#define ASSERT_(f)
Defines an assertion mechanism.
Definition: exceptions.h:113
p
GLfloat GLfloat p
Definition: glext.h:6305
mrpt::opengl::CVectorField2D::getPointColor
mrpt::img::TColorf getPointColor() const
Get the point color in the range [0,1].
Definition: CVectorField2D.h:81
mrpt::opengl::CVectorField2D::m_antiAliasing
bool m_antiAliasing
By default is true.
Definition: CVectorField2D.h:52
mrpt::opengl::CVectorField2D::setLineWidth
void setLineWidth(const float w)
Set the width with which lines will be drawn.
Definition: CVectorField2D.h:120
mrpt::opengl::CVectorField2D::cols
size_t cols() const
Returns the total count of rows used to represent the vector field.
Definition: CVectorField2D.h:232
lightweight_geom_data.h
mrpt::opengl::CVectorField2D::getPointSize
float getPointSize() const
Get the size with which points are drawn.
Definition: CVectorField2D.h:116
mrpt::math::CMatrixTemplateNumeric
A matrix of dynamic size.
Definition: CMatrixTemplateNumeric.h:37
mrpt::opengl::CVectorField2D::Ptr
std::shared_ptr< CVectorField2D > Ptr
Definition: CVectorField2D.h:38
mrpt::opengl::CVectorField2D::getVectorFieldColor
mrpt::img::TColorf getVectorFieldColor() const
Get the arrow color in the range [0,1].
Definition: CVectorField2D.h:99
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:195
mrpt::opengl::CVectorField2D::xMax
float xMax
Definition: CVectorField2D.h:46
mrpt::math::CMatrix
This class is a "CSerializable" wrapper for "CMatrixFloat".
Definition: CMatrix.h:24
mrpt::opengl::CVectorField2D::render_dl
void render_dl() const override
Render.
Definition: CVectorField2D.cpp:60
mrpt::opengl::CVectorField2D::getVectorField
void getVectorField(mrpt::math::CMatrixFloat &Matrix_x, mrpt::math::CMatrixFloat &Matrix_y) const
Get the vector field.
Definition: CVectorField2D.h:177
mrpt::img::TColorf
A RGB color - floats in the range [0,1].
Definition: TColor.h:79
mrpt::opengl::CVectorField2D::yMin
float yMin
Definition: CVectorField2D.h:46
mrpt::opengl::CVectorField2D::xMin
float xMin
Grid bounds.
Definition: CVectorField2D.h:46
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:89
mrpt::img::TColor
A RGB color - 8bit.
Definition: TColor.h:22
mrpt::opengl::CVectorField2D::enableAntiAliasing
void enableAntiAliasing(bool enable=true)
Definition: CVectorField2D.h:253
mrpt::opengl::CVectorField2D::setVectorField
void setVectorField(mrpt::math::CMatrixFloat &Matrix_x, mrpt::math::CMatrixFloat &Matrix_y)
Set the vector field.
Definition: CVectorField2D.h:205
mrpt::opengl::CVectorField2D::~CVectorField2D
virtual ~CVectorField2D()
Private, virtual destructor: only can be deleted from smart pointers.
Definition: CVectorField2D.h:266
mrpt::opengl::CVectorField2D::rows
size_t rows() const
Returns the total count of columns used to represent the vector field.
Definition: CVectorField2D.h:235
mrpt::opengl::CVectorField2D::m_LineWidth
float m_LineWidth
By default is 1.0.
Definition: CVectorField2D.h:48
mrpt::math::TPoint3D
Lightweight 3D point.
Definition: lightweight_geom_data.h:378
mrpt::opengl::CVectorField2D::m_point_color
mrpt::img::TColor m_point_color
Definition: CVectorField2D.h:54
DEFINE_SERIALIZABLE
#define DEFINE_SERIALIZABLE(class_name)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
Definition: CSerializable.h:102
mrpt::opengl::CVectorField2D::yMax
float yMax
Definition: CVectorField2D.h:46
mrpt::opengl::CVectorField2D::xcomp
mrpt::math::CMatrix xcomp
X component of the vector field.
Definition: CVectorField2D.h:41
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:192
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:71
mrpt::opengl::CVectorField2D::ycomp
mrpt::math::CMatrix ycomp
Y component of the vector field.
Definition: CVectorField2D.h:43



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST