MRPT  1.9.9
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-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 #pragma once
10 
11 #include <mrpt/math/TSegment3D.h>
13 
14 namespace mrpt::opengl
15 {
16 /** A set of independent lines (or segments), one line with its own start and
17  * end positions (X,Y,Z).
18  * Optionally, the vertices can be also shown as dots.
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::CSetOfLines </td> <td> \image html
25  * preview_CSetOfLines.png </td> </tr>
26  * </table>
27  * </div>
28  *
29  * \ingroup mrpt_opengl_grp
30  */
32 {
34  protected:
35  std::vector<mrpt::math::TSegment3D> mSegments;
36  float mLineWidth{1.0};
37  bool m_antiAliasing{true};
38  /** 0: means hidden */
39  float m_verticesPointSize{.0f};
40 
41  public:
42  /**
43  * Clear the list of segments
44  */
45  inline void clear()
46  {
47  mSegments.clear();
49  }
50  /**
51  * Sets the width with which lines will be drawn.
52  */
53  inline void setLineWidth(float w)
54  {
55  mLineWidth = w;
57  }
58  /**
59  * Gets the width with which lines are drawn.
60  */
61  float getLineWidth() const { return mLineWidth; }
62  float getVerticesPointSize() const;
63  /** Enable showing vertices as dots if size_points>0 */
64  void setVerticesPointSize(const float size_points);
65  /**
66  * Appends a line to the set.
67  */
68  inline void appendLine(const mrpt::math::TSegment3D& sgm)
69  {
70  mSegments.push_back(sgm);
72  }
73  /**
74  * Appends a line to the set, given the coordinates of its bounds.
75  */
76  inline void appendLine(
77  float x0, float y0, float z0, float x1, float y1, float z1)
78  {
80  mrpt::math::TPoint3D(x0, y0, z0),
81  mrpt::math::TPoint3D(x1, y1, z1)));
83  }
84 
85  /** Appends a line whose starting point is the end point of the last line
86  * (similar to OpenGL's GL_LINE_STRIP)
87  * \exception std::exception If there is no previous segment */
88  inline void appendLineStrip(float x, float y, float z)
89  {
90  ASSERT_(!this->empty());
91  this->appendLine(this->rbegin()->point2, mrpt::math::TPoint3D(x, y, z));
92  }
93  //! \overload
94  template <class U>
95  inline void appendLineStrip(const U& point)
96  {
97  ASSERT_(!this->empty());
98  this->appendLine(this->rbegin()->point2, point);
99  }
100 
101  /**
102  * Appends any iterable collection of lines to the set. Note that this
103  * includes another CSetOfLines.
104  * \sa appendLine
105  */
106  template <class T>
107  inline void appendLines(const T& sgms)
108  {
109  mSegments.insert(mSegments.end(), sgms.begin(), sgms.end());
111  }
112  /**
113  * Appends certain amount of lines, located between two iterators, into the
114  * set.
115  * \sa appendLine
116  */
117  template <class T_it>
118  inline void appendLines(const T_it& begin, const T_it& end)
119  {
120  mSegments.reserve(mSegments.size() + (end - begin));
121  mSegments.insert(mSegments.end(), begin, end);
123  }
124  /**
125  * Resizes the set.
126  * \sa reserve
127  */
128  void resize(size_t nLines)
129  {
130  mSegments.resize(nLines);
132  }
133  /**
134  * Reserves an amount of lines to the set. This method should be used when
135  * some known amount of lines is going to be inserted, so that only a memory
136  * allocation is needed.
137  * \sa resize
138  */
139  void reserve(size_t r)
140  {
141  mSegments.reserve(r);
143  }
144  /**
145  * Inserts a line, given its bounds. Works with any pair of objects with
146  * access to x, y and z members.
147  */
148  template <class T, class U>
149  inline void appendLine(T p0, U p1)
150  {
151  appendLine(p0.x, p0.y, p0.z, p1.x, p1.y, p1.z);
153  }
154  /** Returns the total count of lines in this set. */
155  inline size_t getLineCount() const { return mSegments.size(); }
156  /** Returns the total count of lines in this set. */
157  inline size_t size() const { return mSegments.size(); }
158  /** Returns true if there are no line segments. */
159  inline bool empty() const { return mSegments.empty(); }
160  /**
161  * Sets a specific line in the set, given its index.
162  * \sa appendLine
163  */
164  void setLineByIndex(size_t index, const mrpt::math::TSegment3D& segm);
165  /**
166  * Sets a specific line in the set, given its index.
167  * \sa appendLine
168  */
169  inline void setLineByIndex(
170  size_t index, double x0, double y0, double z0, double x1, double y1,
171  double z1)
172  {
175  mrpt::math::TPoint3D(x0, y0, z0),
176  mrpt::math::TPoint3D(x1, y1, z1)));
178  }
179  /**
180  * Gets a specific line in the set, given its index.
181  * \sa getLineByIndex
182  */
183  void getLineByIndex(
184  size_t index, double& x0, double& y0, double& z0, double& x1,
185  double& y1, double& z1) const;
186 
187  /** Render */
188  void render_dl() const override;
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 mSegments.begin(); }
202  inline iterator begin()
203  {
205  return mSegments.begin();
206  }
207  /**
208  * Ending const iterator.
209  * \sa begin,rend,rbegin
210  */
211  inline const_iterator end() const { return mSegments.end(); }
212  inline iterator end()
213  {
215  return mSegments.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 mSegments.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 mSegments.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:157
std::vector< mrpt::math::TSegment3D > mSegments
Definition: CSetOfLines.h:35
void enableAntiAliasing(bool enable=true)
Definition: CSetOfLines.h:235
void notifyChange() const
Must be called to notify that the object has changed (so, the display list must be updated) ...
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:169
GLdouble GLdouble z
Definition: glext.h:3879
void appendLines(const T &sgms)
Appends any iterable collection of lines to the set.
Definition: CSetOfLines.h:107
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:88
const_iterator begin() const
Beginning const iterator.
Definition: CSetOfLines.h:201
mrpt::serialization::CArchive & operator<<(mrpt::serialization::CArchive &out, const mrpt::opengl::CLight &o)
Definition: CLight.cpp:122
size_t getLineCount() const
Returns the total count of lines in this set.
Definition: CSetOfLines.h:155
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 setLineWidth(float w)
Sets the width with which lines will be drawn.
Definition: CSetOfLines.h:53
void resize(size_t nLines)
Resizes the set.
Definition: CSetOfLines.h:128
float m_verticesPointSize
0: means hidden
Definition: CSetOfLines.h:39
std::vector< mrpt::math::TSegment3D >::const_reverse_iterator const_reverse_iterator
Definition: CSetOfLines.h:196
GLdouble s
Definition: glext.h:3682
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:4199
A renderizable object suitable for rendering with OpenGL&#39;s display lists.
#define ASSERT_(f)
Defines an assertion mechanism.
Definition: exceptions.h:120
std::vector< mrpt::math::TSegment3D >::iterator iterator
Definition: CSetOfLines.h:191
float getLineWidth() const
Gets the width with which lines are drawn.
Definition: CSetOfLines.h:61
void appendLine(const mrpt::math::TSegment3D &sgm)
Appends a line to the set.
Definition: CSetOfLines.h:68
float getVerticesPointSize() const
Definition: CSetOfLines.cpp:50
3D segment, consisting of two points.
Definition: TSegment3D.h:21
GLuint index
Definition: glext.h:4068
GLuint GLuint end
Definition: glext.h:3532
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:139
void setVerticesPointSize(const float size_points)
Enable showing vertices as dots if size_points>0.
Definition: CSetOfLines.cpp:51
void clear()
Clear the list of segments.
Definition: CSetOfLines.h:45
void render_dl() const override
Render.
Definition: CSetOfLines.cpp:60
const_reverse_iterator rbegin() const
Beginning const reverse iterator (actually, accesses the end of the set).
Definition: CSetOfLines.h:222
#define DEFINE_SERIALIZABLE(class_name)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
CSetOfLines()
Constructor.
Definition: CSetOfLines.cpp:27
std::vector< mrpt::math::TSegment3D >::reverse_iterator reverse_iterator
Definition: CSetOfLines.h:193
GLdouble GLdouble GLdouble r
Definition: glext.h:3711
const_reverse_iterator rend() const
Ending const reverse iterator (actually, refers to the starting point of the set).
Definition: CSetOfLines.h:228
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:15
std::vector< mrpt::math::TSegment3D >::const_iterator const_iterator
Definition: CSetOfLines.h:194
const auto bb_max
GLenum GLint GLint y
Definition: glext.h:3542
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:149
GLenum GLint x
Definition: glext.h:3542
Lightweight 3D point.
Definition: TPoint3D.h:90
bool empty() const
Returns true if there are no line segments.
Definition: CSetOfLines.h:159
A set of independent lines (or segments), one line with its own start and end positions (X...
Definition: CSetOfLines.h:31
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:118
~CSetOfLines() override=default
Private, virtual destructor: only can be deleted from smart pointers.
void appendLine(float x0, float y0, float z0, float x1, float y1, float z1)
Appends a line to the set, given the coordinates of its bounds.
Definition: CSetOfLines.h:76
void setLineByIndex(size_t index, const mrpt::math::TSegment3D &segm)
Sets a specific line in the set, given its index.
Definition: CSetOfLines.cpp:40
void appendLineStrip(const U &point)
Definition: CSetOfLines.h:95



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: abb8b1a1e Fri Oct 18 14:19:12 2019 +0200 at vie oct 18 14:20:13 CEST 2019