Main MRPT website > C++ reference for MRPT 1.5.7
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  // This must be added to any CSerializable derived class:
22  DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE( CVectorField2D, CRenderizableDisplayList, OPENGL_IMPEXP )
23 
24  /** A 2D vector field representation, consisting of points and arrows drawn on a plane (invisible grid).
25  * \sa opengl::COpenGLScene
26  *
27  * <div align="center">
28  * <table border="0" cellspan="4" cellspacing="4" style="border-width: 1px; border-style: solid;">
29  * <tr> <td> mrpt::opengl::CVectorField2D </td> <td> \image html preview_CVectorField2D.png </td> </tr>
30  * </table>
31  * </div>
32  *
33  * \ingroup mrpt_opengl_grp
34  */
35 
37  {
39  protected:
40  mrpt::math::CMatrix xcomp; //!< X component of the vector field
41  mrpt::math::CMatrix ycomp; //!< Y component of the vector field
42 
43  float xMin,xMax,yMin,yMax; //!< Grid bounds
44  float m_LineWidth; //!< By default is 1.0
45  float m_pointSize; //!< By default is 1.0
46  bool m_antiAliasing; //!< By default is true
47 
50 
51  public:
52  /**
53  * Clear the matrices
54  */
55  inline void clear() {
56  xcomp.resize(0,0);
57  ycomp.resize(0,0);
59  }
60 
61  /**
62  * Set the point color in the range [0,1]
63  */
64  inline void setPointColor( const float R, const float G, const float B, const float A = 1)
65  {
66  m_point_color = mrpt::utils::TColor(R*255,G*255,B*255,A*255);
68  }
69 
70  /**
71  * Get the point color in the range [0,1]
72  */
73  inline mrpt::utils::TColorf getPointColor() const { return mrpt::utils::TColorf(m_point_color); }
74 
75  /**
76  * Set the arrow color in the range [0,1]
77  */
78  inline void setVectorFieldColor( const float R, const float G, const float B, const float A = 1)
79  {
80  m_field_color = mrpt::utils::TColor(R*255,G*255,B*255,A*255);
82  }
83 
84  /**
85  * Get the arrow color in the range [0,1]
86  */
87  inline mrpt::utils::TColorf getVectorFieldColor() const { return mrpt::utils::TColorf(m_field_color); }
88 
89  /**
90  * Set the size with which points will be drawn. By default 1.0
91  */
92  inline void setPointSize(const float p) { m_pointSize=p; CRenderizableDisplayList::notifyChange(); }
93 
94  /**
95  * Get the size with which points are drawn. By default 1.0
96  */
97  inline float getPointSize() const { return m_pointSize; }
98 
99  /**
100  * Set the width with which lines will be drawn.
101  */
102  inline void setLineWidth(const float w) { m_LineWidth = w; CRenderizableDisplayList::notifyChange(); }
103 
104  /**
105  * Get the width with which lines are drawn.
106  */
107  float getLineWidth() const {
108  return m_LineWidth;
109  }
110 
111  /**
112  * Set the coordinates of the grid on where the vector field will be drawn by setting its center and the cell size.
113  * The number of cells is marked by the content of xcomp and ycomp.
114  * \sa xcomp, ycomp
115  */
116  void setGridCenterAndCellSize(const float center_x, const float center_y, const float cellsize_x, const float cellsize_y)
117  {
118  xMin = center_x - 0.5*cellsize_x*(xcomp.getColCount()-1);
119  xMax = center_x + 0.5*cellsize_x*(xcomp.getColCount()-1);
120  yMin = center_y - 0.5*cellsize_y*(xcomp.getRowCount()-1);
121  yMax = center_y + 0.5*cellsize_y*(xcomp.getRowCount()-1);
123  }
124 
125  /**
126  * Set the coordinates of the grid on where the vector field will be drawn using x-y max and min values.
127  */
128  void setGridLimits(const float xmin,const float xmax, const float ymin, const float ymax)
129  {
130  xMin=xmin; xMax = xmax;
131  yMin=ymin; yMax = ymax;
133  }
134 
135  /**
136  * Get the coordinates of the grid on where the vector field is drawn using the max and min values.
137  */
138  void getGridLimits(float &xmin,float &xmax, float &ymin, float &ymax) const
139  {
140  xmin=xMin; xmax=xMax;
141  ymin=yMin; ymax=yMax;
142  }
143 
144  /**
145  * Get the vector field. Matrix_x stores the "x" component and Matrix_y stores the "y" component.
146  */
148  Matrix_x = xcomp;
149  Matrix_y = ycomp;
150  }
151 
152  /** Get the "x" component of the vector field, as a matrix where each entry represents a point in the 2D grid. */
153  inline const mrpt::math::CMatrixFloat & getVectorField_x() const { return xcomp; }
154  /** \overload */
155  inline mrpt::math::CMatrixFloat & getVectorField_x() { return xcomp; }
156 
157  /** Get the "y" component of the vector field, as a matrix where each entry represents a point in the 2D grid. */
158  inline const mrpt::math::CMatrixFloat & getVectorField_y() const { return ycomp; }
159  /** \overload */
160  inline mrpt::math::CMatrixFloat & getVectorField_y() { return ycomp; }
161 
162  /**
163  * Set the vector field. Matrix_x contains the "x" component and Matrix_y contains the "y" component.
164  */
166  ASSERT_((Matrix_x.getRowCount() == Matrix_y.getRowCount())&&(Matrix_x.getColCount() == Matrix_y.getColCount()))
167  xcomp = Matrix_x;
168  ycomp = Matrix_y;
170  }
171 
172  /**
173  * Adjust the vector field in the scene (vectors magnitude) according to the grid size.
174  */
175  void adjustVectorFieldToGrid();
176 
177  /** Resizes the set.
178  */
179  void resize(size_t rows, size_t cols) {
180  xcomp.resize(rows, cols);
181  ycomp.resize(rows, cols);
183  }
184 
185  /** Returns the total count of rows used to represent the vector field. */
186  inline size_t getColCount() const { return xcomp.getColCount(); }
187 
188  /** Returns the total count of columns used to represent the vector field. */
189  inline size_t getRowCount() const { return xcomp.getRowCount(); }
190 
191  /**
192  * Class factory
193  */
194  static CVectorField2DPtr 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);
195  /** Render
196  */
197  void render_dl() const MRPT_OVERRIDE;
198 
199 
200  /** Evaluates the bounding box of this object (including possible children) in the coordinate frame of the object parent. */
201  void getBoundingBox(mrpt::math::TPoint3D &bb_min, mrpt::math::TPoint3D &bb_max) const MRPT_OVERRIDE;
202 
203  void enableAntiAliasing(bool enable=true) { m_antiAliasing = enable; CRenderizableDisplayList::notifyChange(); }
204  bool isAntiAliasingEnabled() const { return m_antiAliasing; }
205 
206  private:
207  /** Constructor */
208  CVectorField2D();
209  /** Constructor with a initial set of lines. */
210  CVectorField2D( mrpt::math::CMatrixFloat Matrix_x, mrpt::math::CMatrixFloat Matrix_y, float xmin=-1, float xmax=1, float ymin=-1, float ymax=1);
211  /** Private, virtual destructor: only can be deleted from smart pointers. */
212  virtual ~CVectorField2D() { }
213  };
214  DEFINE_SERIALIZABLE_POST_CUSTOM_BASE_LINKAGE( CVectorField2D, CRenderizableDisplayList, OPENGL_IMPEXP )
215 
216 
217  } // end namespace
218 
219 } // End of namespace
220 
221 
222 #endif
virtual ~CVectorField2D()
Private, virtual destructor: only can be deleted from smart pointers.
#define MRPT_OVERRIDE
C++11 "override" for virtuals:
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::math::CMatrix xcomp
X component of the vector field.
mrpt::utils::TColorf getPointColor() const
Get the point color in the range [0,1].
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:3962
float getPointSize() const
Get the size with which points are drawn.
mrpt::utils::TColor m_point_color
mrpt::utils::TColorf getVectorFieldColor() const
Get the arrow color in the range [0,1].
A renderizable object suitable for rendering with OpenGL&#39;s display lists.
void setPointSize(const float p)
Set the size with which points will be drawn.
#define DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE(class_name, base_name, _LINKAGE_)
This declaration must be inserted in all CSerializable classes definition, before the class declarati...
void resize(size_t rows, size_t cols)
Resizes the set.
mrpt::utils::TColor m_field_color
A RGB color - 8bit.
Definition: TColor.h:26
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.
size_t getRowCount() const
Returns the total count of columns used to represent the vector field.
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 ...
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 ...
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
#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.
#define ASSERT_(f)
A RGB color - floats in the range [0,1].
Definition: TColor.h:80
void setVectorField(mrpt::math::CMatrixFloat &Matrix_x, mrpt::math::CMatrixFloat &Matrix_y)
Set the vector field.
float m_pointSize
By default is 1.0.
This class is a "CSerializable" wrapper for "CMatrixFloat".
Definition: CMatrix.h:30
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...
#define DEFINE_SERIALIZABLE_POST_CUSTOM_BASE_LINKAGE(class_name, base_name, _LINKAGE_)
GLfloat GLfloat p
Definition: glext.h:5587
size_t getColCount() const
Returns the total count of rows used to represent the vector field.
float m_LineWidth
By default is 1.0.
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.5.7 Git: 8277875f6 Mon Jun 11 02:47:32 2018 +0200 at lun oct 28 01:50:49 CET 2019