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



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019