MRPT  1.9.9
CSetOfLines.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 #pragma once
10 
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;
38  /** 0: means hidden */
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  /** Class factory */
188  static CSetOfLines::Ptr Create(
189  const std::vector<mrpt::math::TSegment3D>& sgms,
190  const bool antiAliasing = true);
191 
192  /** Render */
193  void render_dl() const override;
194 
195  // Iterator management
197  using reverse_iterator =
198  std::vector<mrpt::math::TSegment3D>::reverse_iterator;
200  using const_reverse_iterator =
201  std::vector<mrpt::math::TSegment3D>::const_reverse_iterator;
202  /**
203  * Beginning const iterator.
204  * \sa end,rbegin,rend
205  */
206  inline const_iterator begin() const { return mSegments.begin(); }
207  inline iterator begin()
208  {
210  return mSegments.begin();
211  }
212  /**
213  * Ending const iterator.
214  * \sa begin,rend,rbegin
215  */
216  inline const_iterator end() const { return mSegments.end(); }
217  inline iterator end()
218  {
220  return mSegments.end();
221  }
222  /**
223  * Beginning const reverse iterator (actually, accesses the end of the
224  * set).
225  * \sa rend,begin,end
226  */
227  inline const_reverse_iterator rbegin() const { return mSegments.rbegin(); }
228  /**
229  * Ending const reverse iterator (actually, refers to the starting point of
230  * the set).
231  * \sa rbegin,end,begin
232  */
233  inline const_reverse_iterator rend() const { return mSegments.rend(); }
234  /** Evaluates the bounding box of this object (including possible children)
235  * in the coordinate frame of the object parent. */
236  void getBoundingBox(
237  mrpt::math::TPoint3D& bb_min,
238  mrpt::math::TPoint3D& bb_max) const override;
239 
240  void enableAntiAliasing(bool enable = true)
241  {
242  m_antiAliasing = enable;
244  }
245  bool isAntiAliasingEnabled() const { return m_antiAliasing; }
246  /** Constructor */
247  CSetOfLines();
248  /** Constructor with a initial set of lines. */
249  CSetOfLines(
250  const std::vector<mrpt::math::TSegment3D>& sgms,
251  bool antiAliasing = true);
252  /** Private, virtual destructor: only can be deleted from smart pointers. */
253  virtual ~CSetOfLines() {}
254 };
255 /** Inserts a set of segments into the list. Allows call chaining.
256  * \sa mrpt::opengl::CSetOfLines::appendLines
257  */
258 template <class T>
260 {
261  l->appendLines(s.begin(), s.end());
262  return l;
263 }
264 /** Inserts a segment into the list. Allows call chaining.
265  * \sa mrpt::opengl::CSetOfLines::appendLine(const TSegment &)
266  */
267 template <>
270 {
271  l->appendLine(s);
272  return l;
273 }
274 } // namespace mrpt
275 
276 
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:240
Scalar * iterator
Definition: eigen_plugins.h:26
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:3872
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:206
mrpt::serialization::CArchive & operator<<(mrpt::serialization::CArchive &out, const mrpt::opengl::CLight &o)
Definition: CLight.cpp:128
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:216
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
EIGEN_STRONG_INLINE void notifyChange() const
Must be called to notify that the object has changed (so, the display list must be updated) ...
float m_verticesPointSize
0: means hidden
Definition: CSetOfLines.h:39
std::vector< mrpt::math::TSegment3D >::const_reverse_iterator const_reverse_iterator
Definition: CSetOfLines.h:201
GLdouble s
Definition: glext.h:3676
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:4178
A renderizable object suitable for rendering with OpenGL&#39;s display lists.
#define ASSERT_(f)
Defines an assertion mechanism.
Definition: exceptions.h:113
std::vector< mrpt::math::TSegment3D >::iterator iterator
Definition: CSetOfLines.h:196
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:56
3D segment, consisting of two points.
GLuint index
Definition: glext.h:4054
GLuint GLuint end
Definition: glext.h:3528
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:57
void clear()
Clear the list of segments.
Definition: CSetOfLines.h:45
virtual ~CSetOfLines()
Private, virtual destructor: only can be deleted from smart pointers.
Definition: CSetOfLines.h:253
void render_dl() const override
Render.
Definition: CSetOfLines.cpp:66
const_reverse_iterator rbegin() const
Beginning const reverse iterator (actually, accesses the end of the set).
Definition: CSetOfLines.h:227
#define DEFINE_SERIALIZABLE(class_name)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
CSetOfLines()
Constructor.
Definition: CSetOfLines.cpp:26
std::vector< mrpt::math::TSegment3D >::reverse_iterator reverse_iterator
Definition: CSetOfLines.h:198
GLdouble GLdouble GLdouble r
Definition: glext.h:3705
const_reverse_iterator rend() const
Ending const reverse iterator (actually, refers to the starting point of the set).
Definition: CSetOfLines.h:233
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:15
std::vector< mrpt::math::TSegment3D >::const_iterator const_iterator
Definition: CSetOfLines.h:199
GLenum GLint GLint y
Definition: glext.h:3538
bool isAntiAliasingEnabled() const
Definition: CSetOfLines.h:245
void appendLine(T p0, U p1)
Inserts a line, given its bounds.
Definition: CSetOfLines.h:149
GLenum GLint x
Definition: glext.h:3538
Lightweight 3D point.
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
const Scalar * const_iterator
Definition: eigen_plugins.h:27
static Ptr Create(Args &&... args)
Definition: CSetOfLines.h:33
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:46
void appendLineStrip(const U &point)
Definition: CSetOfLines.h:95



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 7d5e6d718 Fri Aug 24 01:51:28 2018 +0200 at lun nov 2 08:35:50 CET 2020