MRPT  2.0.5
CSetOfLines.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 #pragma once
10 
11 #include <mrpt/math/TSegment3D.h>
14 
15 namespace mrpt::opengl
16 {
17 /** A set of independent lines (or segments), one line with its own start and
18  * end positions (X,Y,Z).
19  * Optionally, the vertices can be also shown as dots.
20  * \sa opengl::COpenGLScene
21  *
22  * <div align="center">
23  * <table border="0" cellspan="4" cellspacing="4" style="border-width: 1px;
24  * border-style: solid;">
25  * <tr> <td> mrpt::opengl::CSetOfLines </td> <td> \image html
26  * preview_CSetOfLines.png </td> </tr>
27  * </table>
28  * </div>
29  *
30  * \ingroup mrpt_opengl_grp
31  */
34 {
36  protected:
37  std::vector<mrpt::math::TSegment3D> m_Segments;
38 
39  public:
40  /** @name Renderizable shader API virtual methods
41  * @{ */
42  void render(const RenderContext& rc) const override;
43  void renderUpdateBuffers() const override;
44  void freeOpenGLResources() override
45  {
48  }
49 
50  virtual shader_list_t requiredShaders() const override
51  {
52  // May use up to two shaders (triangles and lines):
54  }
55  void onUpdateBuffers_Wireframe() override;
56  void onUpdateBuffers_Points() override;
57  /** @} */
58 
59  /** Clear the list of segments */
60  inline void clear()
61  {
62  m_Segments.clear();
64  }
65  float getVerticesPointSize() const;
66  /** Enable showing vertices as dots if size_points>0 */
67  void setVerticesPointSize(const float size_points);
68  /**
69  * Appends a line to the set.
70  */
71  inline void appendLine(const mrpt::math::TSegment3D& sgm)
72  {
73  m_Segments.push_back(sgm);
75  }
76  /**
77  * Appends a line to the set, given the coordinates of its bounds.
78  */
79  inline void appendLine(
80  double x0, double y0, double z0, double x1, double y1, double z1)
81  {
83  mrpt::math::TPoint3D(x0, y0, z0),
84  mrpt::math::TPoint3D(x1, y1, z1)));
86  }
87 
88  /** Appends a line whose starting point is the end point of the last line
89  * (similar to OpenGL's GL_LINE_STRIP)
90  * \exception std::exception If there is no previous segment */
91  inline void appendLineStrip(float x, float y, float z)
92  {
93  ASSERT_(!this->empty());
94  this->appendLine(this->rbegin()->point2, mrpt::math::TPoint3D(x, y, z));
95  }
96  //! \overload
97  template <class U>
98  inline void appendLineStrip(const U& point)
99  {
100  ASSERT_(!this->empty());
101  this->appendLine(this->rbegin()->point2, point);
102  }
103 
104  /**
105  * Appends any iterable collection of lines to the set. Note that this
106  * includes another CSetOfLines.
107  * \sa appendLine
108  */
109  template <class T>
110  inline void appendLines(const T& sgms)
111  {
112  m_Segments.insert(m_Segments.end(), sgms.begin(), sgms.end());
114  }
115  /**
116  * Appends certain amount of lines, located between two iterators, into the
117  * set.
118  * \sa appendLine
119  */
120  template <class T_it>
121  inline void appendLines(const T_it& begin, const T_it& end)
122  {
123  m_Segments.reserve(m_Segments.size() + (end - begin));
124  m_Segments.insert(m_Segments.end(), begin, end);
126  }
127  /**
128  * Resizes the set.
129  * \sa reserve
130  */
131  void resize(size_t nLines)
132  {
133  m_Segments.resize(nLines);
135  }
136  /**
137  * Reserves an amount of lines to the set. This method should be used when
138  * some known amount of lines is going to be inserted, so that only a memory
139  * allocation is needed.
140  * \sa resize
141  */
142  void reserve(size_t r)
143  {
144  m_Segments.reserve(r);
146  }
147  /**
148  * Inserts a line, given its bounds. Works with any pair of objects with
149  * access to x, y and z members.
150  */
151  template <class T, class U>
152  inline void appendLine(T p0, U p1)
153  {
154  appendLine(p0.x, p0.y, p0.z, p1.x, p1.y, p1.z);
156  }
157  /** Returns the total count of lines in this set. */
158  inline size_t getLineCount() const { return m_Segments.size(); }
159  /** Returns the total count of lines in this set. */
160  inline size_t size() const { return m_Segments.size(); }
161  /** Returns true if there are no line segments. */
162  inline bool empty() const { return m_Segments.empty(); }
163  /**
164  * Sets a specific line in the set, given its index.
165  * \sa appendLine
166  */
167  void setLineByIndex(size_t index, const mrpt::math::TSegment3D& segm);
168  /**
169  * Sets a specific line in the set, given its index.
170  * \sa appendLine
171  */
172  inline void setLineByIndex(
173  size_t index, double x0, double y0, double z0, double x1, double y1,
174  double z1)
175  {
177  index, mrpt::math::TSegment3D(
178  mrpt::math::TPoint3D(x0, y0, z0),
179  mrpt::math::TPoint3D(x1, y1, z1)));
181  }
182  /**
183  * Gets a specific line in the set, given its index.
184  * \sa getLineByIndex
185  */
186  void getLineByIndex(
187  size_t index, double& x0, double& y0, double& z0, double& x1,
188  double& y1, double& z1) const;
189 
190  // Iterator management
191  using iterator = std::vector<mrpt::math::TSegment3D>::iterator;
192  using reverse_iterator =
193  std::vector<mrpt::math::TSegment3D>::reverse_iterator;
194  using const_iterator = std::vector<mrpt::math::TSegment3D>::const_iterator;
195  using const_reverse_iterator =
196  std::vector<mrpt::math::TSegment3D>::const_reverse_iterator;
197  /**
198  * Beginning const iterator.
199  * \sa end,rbegin,rend
200  */
201  inline const_iterator begin() const { return m_Segments.begin(); }
202  inline iterator begin()
203  {
205  return m_Segments.begin();
206  }
207  /**
208  * Ending const iterator.
209  * \sa begin,rend,rbegin
210  */
211  inline const_iterator end() const { return m_Segments.end(); }
212  inline iterator end()
213  {
215  return m_Segments.end();
216  }
217  /**
218  * Beginning const reverse iterator (actually, accesses the end of the
219  * set).
220  * \sa rend,begin,end
221  */
222  inline const_reverse_iterator rbegin() const { return m_Segments.rbegin(); }
223  /**
224  * Ending const reverse iterator (actually, refers to the starting point of
225  * the set).
226  * \sa rbegin,end,begin
227  */
228  inline const_reverse_iterator rend() const { return m_Segments.rend(); }
229  /** Evaluates the bounding box of this object (including possible children)
230  * in the coordinate frame of the object parent. */
231  void getBoundingBox(
233  mrpt::math::TPoint3D& bb_max) const override;
234 
235  void enableAntiAliasing(bool enable = true)
236  {
237  m_antiAliasing = enable;
239  }
240  bool isAntiAliasingEnabled() const { return m_antiAliasing; }
241  /** Constructor */
242  CSetOfLines();
243  /** Constructor with a initial set of lines. */
244  CSetOfLines(
245  const std::vector<mrpt::math::TSegment3D>& sgms,
246  bool antiAliasing = true);
247  /** Private, virtual destructor: only can be deleted from smart pointers. */
248  ~CSetOfLines() override = default;
249 };
250 /** Inserts a set of segments into the list. Allows call chaining.
251  * \sa mrpt::opengl::CSetOfLines::appendLines
252  */
253 template <class T>
255 {
256  l->appendLines(s.begin(), s.end());
257  return l;
258 }
259 /** Inserts a segment into the list. Allows call chaining.
260  * \sa mrpt::opengl::CSetOfLines::appendLine(const TSegment &)
261  */
262 template <>
265 {
266  l->appendLine(s);
267  return l;
268 }
269 } // namespace mrpt::opengl
size_t size() const
Returns the total count of lines in this set.
Definition: CSetOfLines.h:160
void render(const RenderContext &rc) const override
Implements the rendering of 3D objects in each class derived from CRenderizable.
Definition: CSetOfLines.cpp:42
void enableAntiAliasing(bool enable=true)
Definition: CSetOfLines.h:235
void appendLine(double x0, double y0, double z0, double x1, double y1, double z1)
Appends a line to the set, given the coordinates of its bounds.
Definition: CSetOfLines.h:79
void setLineByIndex(size_t index, double x0, double y0, double z0, double x1, double y1, double z1)
Sets a specific line in the set, given its index.
Definition: CSetOfLines.h:172
void appendLines(const T &sgms)
Appends any iterable collection of lines to the set.
Definition: CSetOfLines.h:110
void appendLineStrip(float x, float y, float z)
Appends a line whose starting point is the end point of the last line (similar to OpenGL&#39;s GL_LINE_ST...
Definition: CSetOfLines.h:91
const_iterator begin() const
Beginning const iterator.
Definition: CSetOfLines.h:201
size_t getLineCount() const
Returns the total count of lines in this set.
Definition: CSetOfLines.h:158
void getLineByIndex(size_t index, double &x0, double &y0, double &z0, double &x1, double &y1, double &z1) const
Gets a specific line in the set, given its index.
const_iterator end() const
Ending const iterator.
Definition: CSetOfLines.h:211
void notifyChange() const
Call to enable calling renderUpdateBuffers() before the next render() rendering iteration.
void renderUpdateBuffers() const override
Called whenever m_outdatedBuffers is true: used to re-generate OpenGL vertex buffers, etc.
Definition: CSetOfLines.cpp:54
void resize(size_t nLines)
Resizes the set.
Definition: CSetOfLines.h:131
COpenGLScene::Ptr & operator<<(COpenGLScene::Ptr &s, const CRenderizable::Ptr &r)
Inserts an openGL object into a scene.
Definition: COpenGLScene.h:252
std::vector< mrpt::math::TSegment3D >::const_reverse_iterator const_reverse_iterator
Definition: CSetOfLines.h:196
void freeOpenGLResources() override
Free opengl buffers.
std::vector< shader_id_t > shader_list_t
A list of shader IDs.
Definition: Shader.h:26
Context for calls to render()
void freeOpenGLResources() override
Free opengl buffers.
Definition: CSetOfLines.h:44
#define ASSERT_(f)
Defines an assertion mechanism.
Definition: exceptions.h:120
std::vector< mrpt::math::TSegment3D >::iterator iterator
Definition: CSetOfLines.h:191
void appendLine(const mrpt::math::TSegment3D &sgm)
Appends a line to the set.
Definition: CSetOfLines.h:71
void onUpdateBuffers_Wireframe() override
Must be implemented in derived classes to update the geometric entities to be drawn in "m_*_buffer" f...
Definition: CSetOfLines.cpp:80
float getVerticesPointSize() const
Definition: CSetOfLines.cpp:73
3D segment, consisting of two points.
Definition: TSegment3D.h:20
static constexpr shader_id_t WIREFRAME
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...
void reserve(size_t r)
Reserves an amount of lines to the set.
Definition: CSetOfLines.h:142
void setVerticesPointSize(const float size_points)
Enable showing vertices as dots if size_points>0.
Definition: CSetOfLines.cpp:74
void clear()
Clear the list of segments.
Definition: CSetOfLines.h:60
Renderizable generic renderer for objects using the points shader.
std::vector< mrpt::math::TSegment3D > m_Segments
Definition: CSetOfLines.h:37
const_reverse_iterator rbegin() const
Beginning const reverse iterator (actually, accesses the end of the set).
Definition: CSetOfLines.h:222
void onUpdateBuffers_Points() override
Must be implemented in derived classes to update the geometric entities to be drawn in "m_*_buffer" f...
Definition: CSetOfLines.cpp:97
CSetOfLines()
Constructor.
Definition: CSetOfLines.cpp:25
std::vector< mrpt::math::TSegment3D >::reverse_iterator reverse_iterator
Definition: CSetOfLines.h:193
const_reverse_iterator rend() const
Ending const reverse iterator (actually, refers to the starting point of the set).
Definition: CSetOfLines.h:228
Renderizable generic renderer for objects using the wireframe shader.
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:13
std::vector< mrpt::math::TSegment3D >::const_iterator const_iterator
Definition: CSetOfLines.h:194
const auto bb_max
virtual shader_list_t requiredShaders() const override
Returns the ID of the OpenGL shader program required to render this class.
Definition: CSetOfLines.h:50
#define DEFINE_SERIALIZABLE(class_name, NS)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
bool isAntiAliasingEnabled() const
Definition: CSetOfLines.h:240
const auto bb_min
void appendLine(T p0, U p1)
Inserts a line, given its bounds.
Definition: CSetOfLines.h:152
bool empty() const
Returns true if there are no line segments.
Definition: CSetOfLines.h:162
A set of independent lines (or segments), one line with its own start and end positions (X...
Definition: CSetOfLines.h:32
void freeOpenGLResources() override
Free opengl buffers.
void appendLines(const T_it &begin, const T_it &end)
Appends certain amount of lines, located between two iterators, into the set.
Definition: CSetOfLines.h:121
static constexpr shader_id_t POINTS
~CSetOfLines() override=default
Private, virtual destructor: only can be deleted from smart pointers.
void setLineByIndex(size_t index, const mrpt::math::TSegment3D &segm)
Sets a specific line in the set, given its index.
Definition: CSetOfLines.cpp:63
void appendLineStrip(const U &point)
Definition: CSetOfLines.h:98



Page generated by Doxygen 1.8.14 for MRPT 2.0.5 Git: 40e60e732 Thu Jul 9 08:38:35 2020 +0200 at jue jul 9 08:45:11 CEST 2020