Main MRPT website > C++ reference for MRPT 1.5.6
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  // This must be added to any CSerializable derived class:
21  DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE( CSetOfLines, CRenderizableDisplayList, OPENGL_IMPEXP )
22 
23  /** A set of independent lines (or segments), one line with its own start and end positions (X,Y,Z).
24  * Optionally, the vertices can be also shown as dots.
25  * \sa opengl::COpenGLScene
26  *
27  * <div align="center">
28  * <table border="0" cellspan="4" cellspacing="4" style="border-width: 1px; border-style: solid;">
29  * <tr> <td> mrpt::opengl::CSetOfLines </td> <td> \image html 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  float m_verticesPointSize; //!< 0: means hidden
43  public:
44  /**
45  * Clear the list of segments
46  */
47  inline void clear() {
48  mSegments.clear();
50  }
51  /**
52  * Sets the width with which lines will be drawn.
53  */
54  inline void setLineWidth(float w) {
55  mLineWidth=w;
57  }
58  /**
59  * Gets the width with which lines are drawn.
60  */
61  float getLineWidth() const {
62  return mLineWidth;
63  }
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  mSegments.push_back(sgm);
73  }
74  /**
75  * Appends a line to the set, given the coordinates of its bounds.
76  */
77  inline void appendLine(float x0,float y0,float z0,float x1,float y1,float z1) {
78  appendLine(mrpt::math::TSegment3D(mrpt::math::TPoint3D(x0,y0,z0),mrpt::math::TPoint3D(x1,y1,z1)));
80  }
81 
82  /** Appends a line whose starting point is the end point of the last line (similar to OpenGL's GL_LINE_STRIP)
83  * \exception std::exception If there is no previous segment */
84  inline void appendLineStrip(float x,float y,float z) {
85  ASSERT_(!this->empty())
86  this->appendLine(this->rbegin()->point2, mrpt::math::TPoint3D(x,y,z));
87  }
88  //! \overload
89  template<class U>
90  inline void appendLineStrip(const U &point) {
91  ASSERT_(!this->empty())
92  this->appendLine(this->rbegin()->point2,point);
93  }
94 
95  /**
96  * Appends any iterable collection of lines to the set. Note that this includes another CSetOfLines.
97  * \sa appendLine
98  */
99  template<class T> inline void appendLines(const T &sgms) {
100  mSegments.insert(mSegments.end(),sgms.begin(),sgms.end());
102  }
103  /**
104  * Appends certain amount of lines, located between two iterators, into the set.
105  * \sa appendLine
106  */
107  template<class T_it> inline void appendLines(const T_it &begin,const T_it &end) {
108  mSegments.reserve(mSegments.size()+(end-begin));
109  mSegments.insert(mSegments.end(),begin,end);
111  }
112  /**
113  * Resizes the set.
114  * \sa reserve
115  */
116  void resize(size_t nLines) {
117  mSegments.resize(nLines);
119  }
120  /**
121  * Reserves an amount of lines to the set. This method should be used when some known amount of lines is going to be inserted, so that only a memory allocation is needed.
122  * \sa resize
123  */
124  void reserve(size_t r) {
125  mSegments.reserve(r);
127  }
128  /**
129  * Inserts a line, given its bounds. Works with any pair of objects with access to x, y and z members.
130  */
131  template<class T,class U> inline void appendLine(T p0,U p1) {
132  appendLine(p0.x,p0.y,p0.z,p1.x,p1.y,p1.z);
134  }
135  /** Returns the total count of lines in this set. */
136  inline size_t getLineCount() const { return mSegments.size(); }
137  /** Returns the total count of lines in this set. */
138  inline size_t size() const { return mSegments.size(); }
139  /** Returns true if there are no line segments. */
140  inline bool empty() const { return mSegments.empty(); }
141  /**
142  * Sets a specific line in the set, given its index.
143  * \sa appendLine
144  */
145  void setLineByIndex(size_t index,const mrpt::math::TSegment3D &segm);
146  /**
147  * Sets a specific line in the set, given its index.
148  * \sa appendLine
149  */
150  inline void setLineByIndex(size_t index,double x0,double y0,double z0,double x1,double y1,double z1) {
151  setLineByIndex(index,mrpt::math::TSegment3D(mrpt::math::TPoint3D(x0,y0,z0),mrpt::math::TPoint3D(x1,y1,z1)));
153  }
154  /**
155  * Gets a specific line in the set, given its index.
156  * \sa getLineByIndex
157  */
158  void getLineByIndex(size_t index,double &x0,double &y0,double &z0,double &x1,double &y1,double &z1) const;
159 
160  /** Class factory */
161  static CSetOfLinesPtr Create(const std::vector<mrpt::math::TSegment3D> &sgms, const bool antiAliasing = true);
162 
163  /** Render */
164  void render_dl() const MRPT_OVERRIDE;
165 
166  //Iterator management
167  typedef std::vector<mrpt::math::TSegment3D>::iterator iterator; //!< Iterator to the set.
168  typedef std::vector<mrpt::math::TSegment3D>::reverse_iterator reverse_iterator; //!< Iterator to the set.
169 
170  /**
171  * Const iterator to the set.
172  */
173  typedef std::vector<mrpt::math::TSegment3D>::const_iterator const_iterator;
174  /**
175  * Const reverse iterator to the set.
176  */
178  /**
179  * Beginning const iterator.
180  * \sa end,rbegin,rend
181  */
182  inline const_iterator begin() const {
183  return mSegments.begin();
184  }
185  inline iterator begin() { CRenderizableDisplayList::notifyChange(); return mSegments.begin(); }
186  /**
187  * Ending const iterator.
188  * \sa begin,rend,rbegin
189  */
190  inline const_iterator end() const {
191  return mSegments.end();
192  }
193  inline iterator end() { CRenderizableDisplayList::notifyChange(); return mSegments.end(); }
194  /**
195  * Beginning const reverse iterator (actually, accesses the end of the set).
196  * \sa rend,begin,end
197  */
199  return mSegments.rbegin();
200  }
201  /**
202  * Ending const reverse iterator (actually, refers to the starting point of the set).
203  * \sa rbegin,end,begin
204  */
205  inline const_reverse_iterator rend() const {
206  return mSegments.rend();
207  }
208 
209  /** Evaluates the bounding box of this object (including possible children) in the coordinate frame of the object parent. */
210  void getBoundingBox(mrpt::math::TPoint3D &bb_min, mrpt::math::TPoint3D &bb_max) const MRPT_OVERRIDE;
211 
212  void enableAntiAliasing(bool enable=true) { m_antiAliasing =enable; CRenderizableDisplayList::notifyChange(); }
213  bool isAntiAliasingEnabled() const { return m_antiAliasing; }
214 
215  private:
216  /** Constructor */
217  CSetOfLines();
218  /** Constructor with a initial set of lines. */
219  CSetOfLines(const std::vector<mrpt::math::TSegment3D> &sgms,bool antiAliasing=true);
220  /** Private, virtual destructor: only can be deleted from smart pointers. */
221  virtual ~CSetOfLines() { }
222  };
223  DEFINE_SERIALIZABLE_POST_CUSTOM_BASE_LINKAGE( CSetOfLines, CRenderizableDisplayList, OPENGL_IMPEXP )
224  /** Inserts a set of segments into the list. Allows call chaining.
225  * \sa mrpt::opengl::CSetOfLines::appendLines
226  */
227  template<class T> inline CSetOfLinesPtr &operator<<(CSetOfLinesPtr &l,const T &s) {
228  l->appendLines(s.begin(),s.end());
229  return l;
230  }
231  /** Inserts a segment into the list. Allows call chaining.
232  * \sa mrpt::opengl::CSetOfLines::appendLine(const TSegment &)
233  */
234  template<> inline CSetOfLinesPtr &operator<<(CSetOfLinesPtr &l,const mrpt::math::TSegment3D &s) {
235  l->appendLine(s);
236  return l;
237  }
238  } // end namespace
239 
240 } // End of namespace
241 
242 
243 #endif
size_t size() const
Returns the total count of lines in this set.
Definition: CSetOfLines.h:138
std::vector< mrpt::math::TSegment3D > mSegments
Definition: CSetOfLines.h:39
void enableAntiAliasing(bool enable=true)
Definition: CSetOfLines.h:212
EIGEN_STRONG_INLINE bool empty() const
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:150
GLdouble GLdouble z
Definition: glext.h:3734
void appendLines(const T &sgms)
Appends any iterable collection of lines to the set.
Definition: CSetOfLines.h:99
OPENGL_IMPEXP 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:84
size_t getLineCount() const
Returns the total count of lines in this set.
Definition: CSetOfLines.h:136
#define MRPT_OVERRIDE
C++11 "override" for virtuals:
const_iterator end() const
Ending const iterator.
Definition: CSetOfLines.h:190
void setLineWidth(float w)
Sets the width with which lines will be drawn.
Definition: CSetOfLines.h:54
void resize(size_t nLines)
Resizes the set.
Definition: CSetOfLines.h:116
EIGEN_STRONG_INLINE iterator begin()
Definition: eigen_plugins.h:26
EIGEN_STRONG_INLINE void notifyChange() const
Must be called to notify that the object has changed (so, the display list must be updated) ...
STL namespace.
float m_verticesPointSize
0: means hidden
Definition: CSetOfLines.h:42
GLdouble s
Definition: glext.h:3602
struct BASE_IMPEXP TSegment3D
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:3962
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:61
#define DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE(class_name, base_name, _LINKAGE_)
This declaration must be inserted in all CSerializable classes definition, before the class declarati...
void appendLine(const mrpt::math::TSegment3D &sgm)
Appends a line to the set.
Definition: CSetOfLines.h:70
3D segment, consisting of two points.
GLuint index
Definition: glext.h:3891
GLuint GLuint end
Definition: glext.h:3512
void reserve(size_t r)
Reserves an amount of lines to the set.
Definition: CSetOfLines.h:124
void clear()
Clear the list of segments.
Definition: CSetOfLines.h:47
virtual ~CSetOfLines()
Private, virtual destructor: only can be deleted from smart pointers.
Definition: CSetOfLines.h:221
const_reverse_iterator rbegin() const
Beginning const reverse iterator (actually, accesses the end of the set).
Definition: CSetOfLines.h:198
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...
GLdouble GLdouble GLdouble r
Definition: glext.h:3618
const_reverse_iterator rend() const
Ending const reverse iterator (actually, refers to the starting point of the set).
Definition: CSetOfLines.h:205
std::vector< mrpt::math::TSegment3D >::const_reverse_iterator const_reverse_iterator
Const reverse iterator to the set.
Definition: CSetOfLines.h:177
#define ASSERT_(f)
GLenum GLint GLint y
Definition: glext.h:3516
bool isAntiAliasingEnabled() const
Definition: CSetOfLines.h:213
void appendLine(T p0, U p1)
Inserts a line, given its bounds.
Definition: CSetOfLines.h:131
GLenum GLint x
Definition: glext.h:3516
Lightweight 3D point.
bool empty() const
Returns true if there are no line segments.
Definition: CSetOfLines.h:140
std::vector< mrpt::math::TSegment3D >::reverse_iterator reverse_iterator
Iterator to the set.
Definition: CSetOfLines.h:168
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:107
#define DEFINE_SERIALIZABLE_POST_CUSTOM_BASE_LINKAGE(class_name, base_name, _LINKAGE_)
std::vector< mrpt::math::TSegment3D >::iterator iterator
Iterator to the set.
Definition: CSetOfLines.h:167
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:77
std::vector< mrpt::math::TSegment3D >::const_iterator const_iterator
Const iterator to the set.
Definition: CSetOfLines.h:173
void appendLineStrip(const U &point)
Definition: CSetOfLines.h:90



Page generated by Doxygen 1.8.14 for MRPT 1.5.6 Git: 4c65e8431 Tue Apr 24 08:18:17 2018 +0200 at lun oct 28 01:35:26 CET 2019