Main MRPT website > C++ reference for 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
15 {
16 namespace opengl
17 {
18 /** A set of independent lines (or segments), one line with its own start and
19  * end positions (X,Y,Z).
20  * Optionally, the vertices can be also shown as dots.
21  * \sa opengl::COpenGLScene
22  *
23  * <div align="center">
24  * <table border="0" cellspan="4" cellspacing="4" style="border-width: 1px;
25  * border-style: solid;">
26  * <tr> <td> mrpt::opengl::CSetOfLines </td> <td> \image html
27  * preview_CSetOfLines.png </td> </tr>
28  * </table>
29  * </div>
30  *
31  * \ingroup mrpt_opengl_grp
32  */
34 {
36  protected:
37  std::vector<mrpt::math::TSegment3D> mSegments;
38  float mLineWidth;
40  /** 0: means hidden */
42 
43  public:
44  /**
45  * Clear the list of segments
46  */
47  inline void clear()
48  {
49  mSegments.clear();
51  }
52  /**
53  * Sets the width with which lines will be drawn.
54  */
55  inline void setLineWidth(float w)
56  {
57  mLineWidth = w;
59  }
60  /**
61  * Gets the width with which lines are drawn.
62  */
63  float getLineWidth() const { return mLineWidth; }
64  float getVerticesPointSize() const;
65  /** Enable showing vertices as dots if size_points>0 */
66  void setVerticesPointSize(const float size_points);
67  /**
68  * Appends a line to the set.
69  */
70  inline void appendLine(const mrpt::math::TSegment3D& sgm)
71  {
72  mSegments.push_back(sgm);
74  }
75  /**
76  * Appends a line to the set, given the coordinates of its bounds.
77  */
78  inline void appendLine(
79  float x0, float y0, float z0, float x1, float y1, float z1)
80  {
82  mrpt::math::TPoint3D(x0, y0, z0),
83  mrpt::math::TPoint3D(x1, y1, z1)));
85  }
86 
87  /** Appends a line whose starting point is the end point of the last line
88  * (similar to OpenGL's GL_LINE_STRIP)
89  * \exception std::exception If there is no previous segment */
90  inline void appendLineStrip(float x, float y, float z)
91  {
92  ASSERT_(!this->empty());
93  this->appendLine(this->rbegin()->point2, mrpt::math::TPoint3D(x, y, z));
94  }
95  //! \overload
96  template <class U>
97  inline void appendLineStrip(const U& point)
98  {
99  ASSERT_(!this->empty());
100  this->appendLine(this->rbegin()->point2, point);
101  }
102 
103  /**
104  * Appends any iterable collection of lines to the set. Note that this
105  * includes another CSetOfLines.
106  * \sa appendLine
107  */
108  template <class T>
109  inline void appendLines(const T& sgms)
110  {
111  mSegments.insert(mSegments.end(), sgms.begin(), sgms.end());
113  }
114  /**
115  * Appends certain amount of lines, located between two iterators, into the
116  * set.
117  * \sa appendLine
118  */
119  template <class T_it>
120  inline void appendLines(const T_it& begin, const T_it& end)
121  {
122  mSegments.reserve(mSegments.size() + (end - begin));
123  mSegments.insert(mSegments.end(), begin, end);
125  }
126  /**
127  * Resizes the set.
128  * \sa reserve
129  */
130  void resize(size_t nLines)
131  {
132  mSegments.resize(nLines);
134  }
135  /**
136  * Reserves an amount of lines to the set. This method should be used when
137  * some known amount of lines is going to be inserted, so that only a memory
138  * allocation is needed.
139  * \sa resize
140  */
141  void reserve(size_t r)
142  {
143  mSegments.reserve(r);
145  }
146  /**
147  * Inserts a line, given its bounds. Works with any pair of objects with
148  * access to x, y and z members.
149  */
150  template <class T, class U>
151  inline void appendLine(T p0, U p1)
152  {
153  appendLine(p0.x, p0.y, p0.z, p1.x, p1.y, p1.z);
155  }
156  /** Returns the total count of lines in this set. */
157  inline size_t getLineCount() const { return mSegments.size(); }
158  /** Returns the total count of lines in this set. */
159  inline size_t size() const { return mSegments.size(); }
160  /** Returns true if there are no line segments. */
161  inline bool empty() const { return mSegments.empty(); }
162  /**
163  * Sets a specific line in the set, given its index.
164  * \sa appendLine
165  */
166  void setLineByIndex(size_t index, const mrpt::math::TSegment3D& segm);
167  /**
168  * Sets a specific line in the set, given its index.
169  * \sa appendLine
170  */
171  inline void setLineByIndex(
172  size_t index, double x0, double y0, double z0, double x1, double y1,
173  double z1)
174  {
177  mrpt::math::TPoint3D(x0, y0, z0),
178  mrpt::math::TPoint3D(x1, y1, z1)));
180  }
181  /**
182  * Gets a specific line in the set, given its index.
183  * \sa getLineByIndex
184  */
185  void getLineByIndex(
186  size_t index, double& x0, double& y0, double& z0, double& x1,
187  double& y1, double& z1) const;
188 
189  /** Class factory */
190  static CSetOfLines::Ptr Create(
191  const std::vector<mrpt::math::TSegment3D>& sgms,
192  const bool antiAliasing = true);
193 
194  /** Render */
195  void render_dl() const override;
196 
197  // Iterator management
199  using reverse_iterator =
200  std::vector<mrpt::math::TSegment3D>::reverse_iterator;
202  using const_reverse_iterator =
203  std::vector<mrpt::math::TSegment3D>::const_reverse_iterator;
204  /**
205  * Beginning const iterator.
206  * \sa end,rbegin,rend
207  */
208  inline const_iterator begin() const { return mSegments.begin(); }
209  inline iterator begin()
210  {
212  return mSegments.begin();
213  }
214  /**
215  * Ending const iterator.
216  * \sa begin,rend,rbegin
217  */
218  inline const_iterator end() const { return mSegments.end(); }
219  inline iterator end()
220  {
222  return mSegments.end();
223  }
224  /**
225  * Beginning const reverse iterator (actually, accesses the end of the
226  * set).
227  * \sa rend,begin,end
228  */
229  inline const_reverse_iterator rbegin() const { return mSegments.rbegin(); }
230  /**
231  * Ending const reverse iterator (actually, refers to the starting point of
232  * the set).
233  * \sa rbegin,end,begin
234  */
235  inline const_reverse_iterator rend() const { return mSegments.rend(); }
236  /** Evaluates the bounding box of this object (including possible children)
237  * in the coordinate frame of the object parent. */
238  void getBoundingBox(
239  mrpt::math::TPoint3D& bb_min,
240  mrpt::math::TPoint3D& bb_max) const override;
241 
242  void enableAntiAliasing(bool enable = true)
243  {
244  m_antiAliasing = enable;
246  }
247  bool isAntiAliasingEnabled() const { return m_antiAliasing; }
248  /** Constructor */
249  CSetOfLines();
250  /** Constructor with a initial set of lines. */
251  CSetOfLines(
252  const std::vector<mrpt::math::TSegment3D>& sgms,
253  bool antiAliasing = true);
254  /** Private, virtual destructor: only can be deleted from smart pointers. */
255  virtual ~CSetOfLines() {}
256 };
257 /** Inserts a set of segments into the list. Allows call chaining.
258  * \sa mrpt::opengl::CSetOfLines::appendLines
259  */
260 template <class T>
262 {
263  l->appendLines(s.begin(), s.end());
264  return l;
265 }
266 /** Inserts a segment into the list. Allows call chaining.
267  * \sa mrpt::opengl::CSetOfLines::appendLine(const TSegment &)
268  */
269 template <>
272 {
273  l->appendLine(s);
274  return l;
275 }
276 } // namespace opengl
277 } // namespace mrpt
mrpt::opengl::CSetOfLines::clear
void clear()
Clear the list of segments.
Definition: CSetOfLines.h:47
mrpt::opengl::CSetOfLines::Ptr
std::shared_ptr< CSetOfLines > Ptr
Definition: CSetOfLines.h:35
mrpt::opengl::CSetOfLines::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: CSetOfLines.cpp:186
mrpt::opengl::CSetOfLines::m_antiAliasing
bool m_antiAliasing
Definition: CSetOfLines.h:39
const_iterator
const Scalar * const_iterator
Definition: eigen_plugins.h:27
s
GLdouble s
Definition: glext.h:3676
mrpt::opengl::CSetOfLines::render_dl
void render_dl() const override
Render.
Definition: CSetOfLines.cpp:66
mrpt::opengl::CSetOfLines::empty
bool empty() const
Returns true if there are no line segments.
Definition: CSetOfLines.h:161
mrpt::opengl::CSetOfLines::const_iterator
std::vector< mrpt::math::TSegment3D >::const_iterator const_iterator
Definition: CSetOfLines.h:201
mrpt::opengl::CSetOfLines::enableAntiAliasing
void enableAntiAliasing(bool enable=true)
Definition: CSetOfLines.h:242
mrpt::opengl::CSetOfLines::const_reverse_iterator
std::vector< mrpt::math::TSegment3D >::const_reverse_iterator const_reverse_iterator
Definition: CSetOfLines.h:203
mrpt::opengl::CSetOfLines::CSetOfLines
CSetOfLines()
Constructor.
Definition: CSetOfLines.cpp:26
CRenderizableDisplayList.h
mrpt::opengl::CSetOfLines
A set of independent lines (or segments), one line with its own start and end positions (X,...
Definition: CSetOfLines.h:33
mrpt::opengl::CSetOfLines::begin
iterator begin()
Definition: CSetOfLines.h:209
end
GLuint GLuint end
Definition: glext.h:3528
mrpt::opengl::CRenderizableDisplayList
A renderizable object suitable for rendering with OpenGL's display lists.
Definition: CRenderizableDisplayList.h:39
mrpt::opengl::CRenderizableDisplayList::notifyChange
EIGEN_STRONG_INLINE void notifyChange() const
Must be called to notify that the object has changed (so, the display list must be updated)
Definition: CRenderizableDisplayList.h:57
mrpt::opengl::CSetOfLines::mLineWidth
float mLineWidth
Definition: CSetOfLines.h:38
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CKalmanFilterCapable.h:30
w
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:4178
ASSERT_
#define ASSERT_(f)
Defines an assertion mechanism.
Definition: exceptions.h:113
mrpt::opengl::CSetOfLines::getVerticesPointSize
float getVerticesPointSize() const
Definition: CSetOfLines.cpp:56
mrpt::opengl::CSetOfLines::Create
static Ptr Create(Args &&... args)
Definition: CSetOfLines.h:35
mrpt::opengl::CSetOfLines::reserve
void reserve(size_t r)
Reserves an amount of lines to the set.
Definition: CSetOfLines.h:141
lightweight_geom_data.h
r
GLdouble GLdouble GLdouble r
Definition: glext.h:3705
mrpt::opengl::CSetOfLines::getLineCount
size_t getLineCount() const
Returns the total count of lines in this set.
Definition: CSetOfLines.h:157
mrpt::opengl::CSetOfLines::appendLine
void appendLine(const mrpt::math::TSegment3D &sgm)
Appends a line to the set.
Definition: CSetOfLines.h:70
mrpt::opengl::CSetOfLines::appendLineStrip
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's GL_LINE_ST...
Definition: CSetOfLines.h:90
mrpt::opengl::CSetOfLines::size
size_t size() const
Returns the total count of lines in this set.
Definition: CSetOfLines.h:159
mrpt::opengl::CSetOfLines::m_verticesPointSize
float m_verticesPointSize
0: means hidden
Definition: CSetOfLines.h:41
mrpt::opengl::CSetOfLines::end
iterator end()
Definition: CSetOfLines.h:219
mrpt::opengl::CSetOfLines::appendLine
void appendLine(T p0, U p1)
Inserts a line, given its bounds.
Definition: CSetOfLines.h:151
mrpt::opengl::CSetOfLines::setLineByIndex
void setLineByIndex(size_t index, const mrpt::math::TSegment3D &segm)
Sets a specific line in the set, given its index.
Definition: CSetOfLines.cpp:46
index
GLuint index
Definition: glext.h:4054
mrpt::opengl::CSetOfLines::setLineByIndex
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:171
mrpt::opengl::CSetOfLines::mSegments
std::vector< mrpt::math::TSegment3D > mSegments
Definition: CSetOfLines.h:37
mrpt::opengl::CSetOfLines::resize
void resize(size_t nLines)
Resizes the set.
Definition: CSetOfLines.h:130
mrpt::opengl::CSetOfLines::rend
const_reverse_iterator rend() const
Ending const reverse iterator (actually, refers to the starting point of the set).
Definition: CSetOfLines.h:235
mrpt::math::TSegment3D
3D segment, consisting of two points.
Definition: lightweight_geom_data.h:1044
mrpt::opengl::CSetOfLines::setLineWidth
void setLineWidth(float w)
Sets the width with which lines will be drawn.
Definition: CSetOfLines.h:55
mrpt::opengl::CSetOfLines::isAntiAliasingEnabled
bool isAntiAliasingEnabled() const
Definition: CSetOfLines.h:247
mrpt::opengl::CSetOfLines::rbegin
const_reverse_iterator rbegin() const
Beginning const reverse iterator (actually, accesses the end of the set).
Definition: CSetOfLines.h:229
mrpt::opengl::operator<<
mrpt::serialization::CArchive & operator<<(mrpt::serialization::CArchive &out, const mrpt::opengl::CLight &o)
Definition: CLight.cpp:130
mrpt::math::TPoint3D
Lightweight 3D point.
Definition: lightweight_geom_data.h:378
mrpt::opengl::CSetOfLines::appendLine
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:78
mrpt::opengl::CSetOfLines::appendLineStrip
void appendLineStrip(const U &point)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: CSetOfLines.h:97
mrpt::opengl::CSetOfLines::appendLines
void appendLines(const T &sgms)
Appends any iterable collection of lines to the set.
Definition: CSetOfLines.h:109
DEFINE_SERIALIZABLE
#define DEFINE_SERIALIZABLE(class_name)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
Definition: CSerializable.h:102
mrpt::opengl::CSetOfLines::appendLines
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:120
mrpt::opengl::CSetOfLines::getLineWidth
float getLineWidth() const
Gets the width with which lines are drawn.
Definition: CSetOfLines.h:63
z
GLdouble GLdouble z
Definition: glext.h:3872
mrpt::opengl::CSetOfLines::getLineByIndex
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.
Definition: CSetOfLines.cpp:216
mrpt::opengl::CSetOfLines::iterator
std::vector< mrpt::math::TSegment3D >::iterator iterator
Definition: CSetOfLines.h:198
iterator
Scalar * iterator
Definition: eigen_plugins.h:26
mrpt::opengl::CSetOfLines::end
const_iterator end() const
Ending const iterator.
Definition: CSetOfLines.h:218
mrpt::opengl::CSetOfLines::reverse_iterator
std::vector< mrpt::math::TSegment3D >::reverse_iterator reverse_iterator
Definition: CSetOfLines.h:200
mrpt::opengl::CSetOfLines::~CSetOfLines
virtual ~CSetOfLines()
Private, virtual destructor: only can be deleted from smart pointers.
Definition: CSetOfLines.h:255
y
GLenum GLint GLint y
Definition: glext.h:3538
x
GLenum GLint x
Definition: glext.h:3538
mrpt::opengl::CSetOfLines::setVerticesPointSize
void setVerticesPointSize(const float size_points)
Enable showing vertices as dots if size_points>0.
Definition: CSetOfLines.cpp:57
mrpt::opengl::CSetOfLines::begin
const_iterator begin() const
Beginning const iterator.
Definition: CSetOfLines.h:208



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST