MRPT  2.0.4
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-2020, 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/core/bits_math.h>
13 #include <mrpt/math/CMatrixF.h>
17 
18 namespace mrpt::opengl
19 {
20 /** A 2D vector field representation, consisting of points and arrows drawn on a
21  * plane (invisible grid).
22  * \sa opengl::COpenGLScene
23  *
24  * <div align="center">
25  * <table border="0" cellspan="4" cellspacing="4" style="border-width: 1px;
26  * border-style: solid;">
27  * <tr> <td> mrpt::opengl::CVectorField2D </td> <td> \image html
28  * preview_CVectorField2D.png </td> </tr>
29  * </table>
30  * </div>
31  *
32  * \ingroup mrpt_opengl_grp
33  */
34 
38 {
40  protected:
41  /** X component of the vector field */
43  /** Y component of the vector field */
45 
46  /** Grid bounds */
47  float xMin{-1.0f}, xMax{1.0f}, yMin{-1.0f}, yMax{1.0f};
48 
51 
52  public:
53  /** @name Renderizable shader API virtual methods
54  * @{ */
55  void render(const RenderContext& rc) const override;
56  void renderUpdateBuffers() const override;
57  void freeOpenGLResources() override
58  {
62  }
63 
64  virtual shader_list_t requiredShaders() const override
65  {
68  }
69  void onUpdateBuffers_Wireframe() override;
70  void onUpdateBuffers_Triangles() override;
71  void onUpdateBuffers_Points() override;
72  /** @} */
73 
74  /**
75  * Clear the matrices
76  */
77  inline void clear()
78  {
79  xcomp.resize(0, 0);
80  ycomp.resize(0, 0);
82  }
83 
84  /**
85  * Set the point color in the range [0,1]
86  */
87  inline void setPointColor(
88  const float R, const float G, const float B, const float A = 1)
89  {
92  }
93 
94  /**
95  * Get the point color in the range [0,1]
96  */
98  {
100  }
101 
102  /**
103  * Set the arrow color in the range [0,1]
104  */
105  inline void setVectorFieldColor(
106  const float R, const float G, const float B, const float A = 1)
107  {
110  }
111 
112  /**
113  * Get the arrow color in the range [0,1]
114  */
116  {
118  }
119 
120  /**
121  * Set the coordinates of the grid on where the vector field will be drawn
122  * by setting its center and the cell size.
123  * The number of cells is marked by the content of xcomp and ycomp.
124  * \sa xcomp, ycomp
125  */
127  const float center_x, const float center_y, const float cellsize_x,
128  const float cellsize_y)
129  {
130  xMin = center_x - 0.5f * cellsize_x * (xcomp.cols() - 1);
131  xMax = center_x + 0.5f * cellsize_x * (xcomp.cols() - 1);
132  yMin = center_y - 0.5f * cellsize_y * (xcomp.rows() - 1);
133  yMax = center_y + 0.5f * cellsize_y * (xcomp.rows() - 1);
135  }
136 
137  /**
138  * Set the coordinates of the grid on where the vector field will be drawn
139  * using x-y max and min values.
140  */
142  const float xmin, const float xmax, const float ymin, const float ymax)
143  {
144  xMin = xmin;
145  xMax = xmax;
146  yMin = ymin;
147  yMax = ymax;
149  }
150 
151  /**
152  * Get the coordinates of the grid on where the vector field is drawn using
153  * the max and min values.
154  */
155  void getGridLimits(float& xmin, float& xmax, float& ymin, float& ymax) const
156  {
157  xmin = xMin;
158  xmax = xMax;
159  ymin = yMin;
160  ymax = yMax;
161  }
162 
163  /**
164  * Get the vector field. Matrix_x stores the "x" component and Matrix_y
165  * stores the "y" component.
166  */
168  mrpt::math::CMatrixFloat& Matrix_x,
169  mrpt::math::CMatrixFloat& Matrix_y) const
170  {
171  Matrix_x = xcomp;
172  Matrix_y = ycomp;
173  }
174 
175  /** Get the "x" component of the vector field, as a matrix where each entry
176  * represents a point in the 2D grid. */
178  {
179  return xcomp;
180  }
181  /** \overload */
183  /** Get the "y" component of the vector field, as a matrix where each entry
184  * represents a point in the 2D grid. */
186  {
187  return ycomp;
188  }
189  /** \overload */
191  /**
192  * Set the vector field. Matrix_x contains the "x" component and Matrix_y
193  * contains the "y" component.
194  */
197  {
198  ASSERT_(
199  (Matrix_x.rows() == Matrix_y.rows()) &&
200  (Matrix_x.cols() == Matrix_y.cols()));
201  xcomp = Matrix_x;
202  ycomp = Matrix_y;
204  }
205 
206  /**
207  * Adjust the vector field in the scene (vectors magnitude) according to
208  * the grid size.
209  */
211 
212  /** Resizes the set.
213  */
214  void resize(size_t rows, size_t cols)
215  {
216  xcomp.resize(rows, cols);
217  ycomp.resize(rows, cols);
219  }
220 
221  /** Returns the total count of rows used to represent the vector field. */
222  inline size_t cols() const { return xcomp.cols(); }
223  /** Returns the total count of columns used to represent the vector field.
224  */
225  inline size_t rows() const { return xcomp.rows(); }
226 
227  void getBoundingBox(
229  mrpt::math::TPoint3D& bb_max) const override;
230 
231  void enableAntiAliasing(bool enable = true)
232  {
233  m_antiAliasing = enable;
235  }
236  bool isAntiAliasingEnabled() const { return m_antiAliasing; }
237  /** Constructor */
238  CVectorField2D();
239  /** Constructor with a initial set of lines. */
242  float xmin = -1, float xmax = 1, float ymin = -1, float ymax = 1);
243  /** Private, virtual destructor: only can be deleted from smart pointers. */
244  ~CVectorField2D() override = default;
245 };
246 
247 } // namespace mrpt::opengl
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:190
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:141
mrpt::opengl::CVectorField2D::CVectorField2D
CVectorField2D()
Constructor.
Definition: CVectorField2D.cpp:23
mrpt::opengl::CRenderizable::notifyChange
void notifyChange() const
Call to enable calling renderUpdateBuffers() before the next render() rendering iteration.
Definition: CRenderizable.h:315
mrpt::math::TPoint3D_< double >
G
const double G
Definition: vision_stereo_rectify/test.cpp:32
DEFINE_SERIALIZABLE
#define DEFINE_SERIALIZABLE(class_name, NS)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
Definition: CSerializable.h:152
mrpt::opengl::CVectorField2D::adjustVectorFieldToGrid
void adjustVectorFieldToGrid()
Adjust the vector field in the scene (vectors magnitude) according to the grid size.
Definition: CVectorField2D.cpp:241
mrpt::opengl::CVectorField2D::freeOpenGLResources
void freeOpenGLResources() override
Free opengl buffers.
Definition: CVectorField2D.h:57
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:189
mrpt::opengl::CRenderizableShaderWireFrame::m_antiAliasing
bool m_antiAliasing
Definition: CRenderizableShaderWireFrame.h:78
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:177
mrpt::opengl::CVectorField2D::isAntiAliasingEnabled
bool isAntiAliasingEnabled() const
Definition: CVectorField2D.h:236
mrpt::opengl::CRenderizableShaderWireFrame
Renderizable generic renderer for objects using the wireframe shader.
Definition: CRenderizableShaderWireFrame.h:24
mrpt::opengl::CVectorField2D::m_field_color
mrpt::img::TColor m_field_color
Definition: CVectorField2D.h:50
mrpt::f2u8
uint8_t f2u8(const float f)
converts a float [0,1] into an uint8_t [0,255] (without checking for out of bounds)
Definition: core/include/mrpt/core/bits_math.h:193
mrpt::opengl::CVectorField2D
A 2D vector field representation, consisting of points and arrows drawn on a plane (invisible grid).
Definition: CVectorField2D.h:35
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:126
mrpt::opengl::CVectorField2D::resize
void resize(size_t rows, size_t cols)
Resizes the set.
Definition: CVectorField2D.h:214
mrpt::opengl::CVectorField2D::clear
void clear()
Clear the matrices.
Definition: CVectorField2D.h:77
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:155
R
const float R
Definition: CKinematicChain.cpp:137
ASSERT_
#define ASSERT_(f)
Defines an assertion mechanism.
Definition: exceptions.h:120
mrpt::opengl::CVectorField2D::getPointColor
mrpt::img::TColorf getPointColor() const
Get the point color in the range [0,1].
Definition: CVectorField2D.h:97
mrpt::opengl::CRenderizableShaderTriangles::freeOpenGLResources
void freeOpenGLResources() override
Free opengl buffers.
Definition: CRenderizableShaderTriangles.h:45
mrpt::opengl::CVectorField2D::cols
size_t cols() const
Returns the total count of rows used to represent the vector field.
Definition: CVectorField2D.h:222
mrpt::opengl::CRenderizableShaderWireFrame::freeOpenGLResources
void freeOpenGLResources() override
Free opengl buffers.
Definition: CRenderizableShaderWireFrame.h:57
mrpt::math::CMatrixF
This class is a "CSerializable" wrapper for "CMatrixFloat".
Definition: CMatrixF.h:22
CRenderizableShaderTriangles.h
bb_max
const auto bb_max
Definition: CPose3DPDFGrid_unittest.cpp:25
mrpt::opengl::CVectorField2D::getVectorFieldColor
mrpt::img::TColorf getVectorFieldColor() const
Get the arrow color in the range [0,1].
Definition: CVectorField2D.h:115
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:185
mrpt::opengl::DefaultShaderID::WIREFRAME
static constexpr shader_id_t WIREFRAME
Definition: DefaultShaders.h:25
bb_min
const auto bb_min
Definition: CPose3DPDFGrid_unittest.cpp:23
mrpt::opengl::CVectorField2D::ycomp
mrpt::math::CMatrixF ycomp
Y component of the vector field.
Definition: CVectorField2D.h:44
mrpt::opengl::CVectorField2D::xMax
float xMax
Definition: CVectorField2D.h:47
mrpt::opengl::DefaultShaderID::TRIANGLES
static constexpr shader_id_t TRIANGLES
Definition: DefaultShaders.h:27
mrpt::opengl::CVectorField2D::getVectorField
void getVectorField(mrpt::math::CMatrixFloat &Matrix_x, mrpt::math::CMatrixFloat &Matrix_y) const
Get the vector field.
Definition: CVectorField2D.h:167
CRenderizableShaderWireFrame.h
mrpt::img::TColorf
An RGBA color - floats in the range [0,1].
Definition: TColor.h:88
mrpt::opengl::CVectorField2D::yMin
float yMin
Definition: CVectorField2D.h:47
mrpt::opengl::CVectorField2D::xMin
float xMin
Grid bounds.
Definition: CVectorField2D.h:47
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:105
mrpt::opengl::CVectorField2D::requiredShaders
virtual shader_list_t requiredShaders() const override
Returns the ID of the OpenGL shader program required to render this class.
Definition: CVectorField2D.h:64
mrpt::opengl::CVectorField2D::onUpdateBuffers_Wireframe
void onUpdateBuffers_Wireframe() override
Must be implemented in derived classes to update the geometric entities to be drawn in "m_*_buffer" f...
Definition: CVectorField2D.cpp:63
mrpt::img::TColor
A RGB color - 8bit.
Definition: TColor.h:25
mrpt::opengl::CVectorField2D::enableAntiAliasing
void enableAntiAliasing(bool enable=true)
Definition: CVectorField2D.h:231
mrpt::opengl::CVectorField2D::setVectorField
void setVectorField(mrpt::math::CMatrixFloat &Matrix_x, mrpt::math::CMatrixFloat &Matrix_y)
Set the vector field.
Definition: CVectorField2D.h:195
A
Definition: is_defined_unittest.cpp:13
mrpt::opengl::CRenderizable::RenderContext
Context for calls to render()
Definition: CRenderizable.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:225
mrpt::opengl::CRenderizableShaderPoints::freeOpenGLResources
void freeOpenGLResources() override
Free opengl buffers.
Definition: CRenderizableShaderPoints.h:86
mrpt::opengl::CVectorField2D::xcomp
mrpt::math::CMatrixF xcomp
X component of the vector field.
Definition: CVectorField2D.h:42
bits_math.h
mrpt::math::CMatrixDynamic::resize
void resize(size_t row, size_t col)
Definition: CMatrixDynamic.h:356
mrpt::opengl::CVectorField2D::m_point_color
mrpt::img::TColor m_point_color
Definition: CVectorField2D.h:49
mrpt::opengl::CVectorField2D::yMax
float yMax
Definition: CVectorField2D.h:47
mrpt::opengl::CVectorField2D::renderUpdateBuffers
void renderUpdateBuffers() const override
Called whenever m_outdatedBuffers is true: used to re-generate OpenGL vertex buffers,...
Definition: CVectorField2D.cpp:56
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:182
CRenderizableShaderPoints.h
mrpt::opengl::CRenderizableShaderPoints
Renderizable generic renderer for objects using the points shader.
Definition: CRenderizableShaderPoints.h:38
mrpt::opengl::shader_list_t
std::vector< shader_id_t > shader_list_t
A list of shader IDs.
Definition: Shader.h:26
mrpt::opengl::CRenderizableShaderTriangles
Renderizable generic renderer for objects using the triangles shader.
Definition: CRenderizableShaderTriangles.h:25
mrpt::math::CMatrixDynamic::cols
size_type cols() const
Number of columns in the matrix.
Definition: CMatrixDynamic.h:340
CMatrixF.h
mrpt::opengl::CVectorField2D::render
void render(const RenderContext &rc) const override
Implements the rendering of 3D objects in each class derived from CRenderizable.
Definition: CVectorField2D.cpp:41
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:87
mrpt::opengl
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:13
mrpt::opengl::DefaultShaderID::POINTS
static constexpr shader_id_t POINTS
Definition: DefaultShaders.h:24
mrpt::opengl::CVectorField2D::~CVectorField2D
~CVectorField2D() override=default
Private, virtual destructor: only can be deleted from smart pointers.
mrpt::math::CMatrixDynamic
This template class provides the basic functionality for a general 2D any-size, resizable container o...
Definition: CMatrixDynamic.h:39
mrpt::math::CMatrixDynamic::rows
size_type rows() const
Number of rows in the matrix.
Definition: CMatrixDynamic.h:337
mrpt::opengl::CVectorField2D::onUpdateBuffers_Triangles
void onUpdateBuffers_Triangles() override
Must be implemented in derived classes to update the geometric entities to be drawn in "m_*_buffer" f...
Definition: CVectorField2D.cpp:85
mrpt::opengl::CVectorField2D::onUpdateBuffers_Points
void onUpdateBuffers_Points() override
Must be implemented in derived classes to update the geometric entities to be drawn in "m_*_buffer" f...
Definition: CVectorField2D.cpp:128



Page generated by Doxygen 1.8.17 for MRPT 2.0.4 at Sat Jun 27 14:00:59 UTC 2020