Main MRPT website > C++ reference
MRPT logo
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-2014, 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  {
22 
23 
24  // This must be added to any CSerializable derived class:
25  DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE( CSetOfLines, CRenderizableDisplayList, OPENGL_IMPEXP )
26 
27  /** A set of independent lines (or segments), one line with its own start and end positions (X,Y,Z).
28  * \sa opengl::COpenGLScene
29  *
30  * <div align="center">
31  * <table border="0" cellspan="4" cellspacing="4" style="border-width: 1px; border-style: solid;">
32  * <tr> <td> mrpt::opengl::CSetOfLines </td> <td> \image html preview_CSetOfLines.png </td> </tr>
33  * </table>
34  * </div>
35  *
36  * \ingroup mrpt_opengl_grp
37  */
39  {
41  protected:
42  std::vector<TSegment3D> mSegments;
43  float mLineWidth;
44  bool m_antiAliasing;
45  public:
46  /**
47  * Clear the list of segments
48  */
49  inline void clear() {
50  mSegments.clear();
52  }
53  /**
54  * Sets the width with which lines will be drawn.
55  */
56  inline void setLineWidth(float w) {
57  mLineWidth=w;
59  }
60  /**
61  * Gets the width with which lines are drawn.
62  */
63  float getLineWidth() const {
64  return mLineWidth;
65  }
66  /**
67  * Appends a line to the set.
68  */
69  inline void appendLine(const mrpt::math::TSegment3D &sgm) {
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(float x0,float y0,float z0,float x1,float y1,float z1) {
77  appendLine(TSegment3D(TPoint3D(x0,y0,z0),TPoint3D(x1,y1,z1)));
79  }
80 
81  /** Appends a line whose starting point is the end point of the last line (similar to OpenGL's GL_LINE_STRIP)
82  * \exception std::exception If there is no previous segment */
83  inline void appendLineStrip(float x,float y,float z) {
84  ASSERT_(!this->empty())
85  this->appendLine(this->rbegin()->point2, TPoint3D(x,y,z));
86  }
87  //! \overload
88  template<class U>
89  inline void appendLineStrip(const U &point) {
90  ASSERT_(!this->empty())
91  this->appendLine(this->rbegin()->point2,point);
92  }
93 
94  /**
95  * Appends any iterable collection of lines to the set. Note that this includes another CSetOfLines.
96  * \sa appendLine
97  */
98  template<class T> inline void appendLines(const T &sgms) {
99  mSegments.insert(mSegments.end(),sgms.begin(),sgms.end());
101  }
102  /**
103  * Appends certain amount of lines, located between two iterators, into the set.
104  * \sa appendLine
105  */
106  template<class T_it> inline void appendLines(const T_it &begin,const T_it &end) {
107  mSegments.reserve(mSegments.size()+(end-begin));
108  mSegments.insert(mSegments.end(),begin,end);
110  }
111  /**
112  * Resizes the set.
113  * \sa reserve
114  */
115  void resize(size_t nLines) {
116  mSegments.resize(nLines);
118  }
119  /**
120  * 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.
121  * \sa resize
122  */
123  void reserve(size_t r) {
124  mSegments.reserve(r);
126  }
127  /**
128  * Inserts a line, given its bounds. Works with any pair of objects with access to x, y and z members.
129  */
130  template<class T,class U> inline void appendLine(T p0,U p1) {
131  appendLine(p0.x,p0.y,p0.z,p1.x,p1.y,p1.z);
133  }
134  /** Returns the total count of lines in this set. */
135  inline size_t getLineCount() const { return mSegments.size(); }
136  /** Returns the total count of lines in this set. */
137  inline size_t size() const { return mSegments.size(); }
138  /** Returns true if there are no line segments. */
139  inline bool empty() const { return mSegments.empty(); }
140  /**
141  * Sets a specific line in the set, given its index.
142  * \sa appendLine
143  */
144  void setLineByIndex(size_t index,const TSegment3D &segm);
145  /**
146  * Sets a specific line in the set, given its index.
147  * \sa appendLine
148  */
149  inline void setLineByIndex(size_t index,double x0,double y0,double z0,double x1,double y1,double z1) {
150  setLineByIndex(index,TSegment3D(TPoint3D(x0,y0,z0),TPoint3D(x1,y1,z1)));
152  }
153  /**
154  * Gets a specific line in the set, given its index.
155  * \sa getLineByIndex
156  */
157  inline void getLineByIndex(size_t index,double &x0,double &y0,double &z0,double &x1,double &y1,double &z1) const {
158  ASSERT_(index<mSegments.size())
159  x0 = mSegments[index].point1.x;
160  y0 = mSegments[index].point1.y;
161  z0 = mSegments[index].point1.z;
162  x1 = mSegments[index].point2.x;
163  y1 = mSegments[index].point2.y;
164  z1 = mSegments[index].point2.z;
165  }
166  /**
167  * Class factory
168  */
169  static CSetOfLinesPtr Create(const std::vector<TSegment3D> &sgms, const bool antiAliasing = true);
170  /** Render
171  */
172  void render_dl() const;
173 
174  //Iterator management
175  typedef std::vector<TSegment3D>::iterator iterator; //!< Iterator to the set.
176  typedef std::vector<TSegment3D>::reverse_iterator reverse_iterator; //!< Iterator to the set.
177 
178  /**
179  * Const iterator to the set.
180  */
182  /**
183  * Const reverse iterator to the set.
184  */
185  typedef std::vector<TSegment3D>::const_reverse_iterator const_reverse_iterator;
186  /**
187  * Beginning const iterator.
188  * \sa end,rbegin,rend
189  */
190  inline const_iterator begin() const {
191  return mSegments.begin();
192  }
193  inline iterator begin() { CRenderizableDisplayList::notifyChange(); return mSegments.begin(); }
194  /**
195  * Ending const iterator.
196  * \sa begin,rend,rbegin
197  */
198  inline const_iterator end() const {
199  return mSegments.end();
200  }
201  inline iterator end() { CRenderizableDisplayList::notifyChange(); return mSegments.end(); }
202  /**
203  * Beginning const reverse iterator (actually, accesses the end of the set).
204  * \sa rend,begin,end
205  */
206  inline const_reverse_iterator rbegin() const {
207  return mSegments.rbegin();
208  }
209  /**
210  * Ending const reverse iterator (actually, refers to the starting point of the set).
211  * \sa rbegin,end,begin
212  */
213  inline const_reverse_iterator rend() const {
214  return mSegments.rend();
215  }
216 
217  /** Evaluates the bounding box of this object (including possible children) in the coordinate frame of the object parent. */
218  virtual void getBoundingBox(mrpt::math::TPoint3D &bb_min, mrpt::math::TPoint3D &bb_max) const;
219 
220  void enableAntiAliasing(bool enable=true) { m_antiAliasing =enable; CRenderizableDisplayList::notifyChange(); }
221  bool isAntiAliasingEnabled() const { return m_antiAliasing; }
222 
223  private:
224  /** Constructor */
225  CSetOfLines();
226  /** Constructor with a initial set of lines. */
227  CSetOfLines(const std::vector<TSegment3D> &sgms,bool antiAliasing=true);
228  /** Private, virtual destructor: only can be deleted from smart pointers. */
229  virtual ~CSetOfLines() { }
230  };
231  DEFINE_SERIALIZABLE_POST_CUSTOM_BASE_LINKAGE( CSetOfLines, CRenderizableDisplayList, OPENGL_IMPEXP )
232  /** Inserts a set of segments into the list. Allows call chaining.
233  * \sa mrpt::opengl::CSetOfLines::appendLines
234  */
235  template<class T> inline CSetOfLinesPtr &operator<<(CSetOfLinesPtr &l,const T &s) {
236  l->appendLines(s.begin(),s.end());
237  return l;
238  }
239  /** Inserts a segment into the list. Allows call chaining.
240  * \sa mrpt::opengl::CSetOfLines::appendLine(const TSegment &)
241  */
242  template<> inline CSetOfLinesPtr &operator<<(CSetOfLinesPtr &l,const mrpt::math::TSegment3D &s) {
243  l->appendLine(s);
244  return l;
245  }
246  } // end namespace
247 
248 } // End of namespace
249 
250 
251 #endif
void enableAntiAliasing(bool enable=true)
Definition: CSetOfLines.h:220
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:149
OPENGL_IMPEXP mrpt::utils::CStream & operator<<(mrpt::utils::CStream &out, const mrpt::opengl::CLight &o)
void appendLines(const T &sgms)
Appends any iterable collection of lines to the set.
Definition: CSetOfLines.h:98
EIGEN_STRONG_INLINE iterator end()
Definition: eigen_plugins.h:27
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:83
std::vector< TSegment3D >::const_iterator const_iterator
Const iterator to the set.
Definition: CSetOfLines.h:181
void setLineWidth(float w)
Sets the width with which lines will be drawn.
Definition: CSetOfLines.h:56
size_t getLineCount() const
Returns the total count of lines in this set.
Definition: CSetOfLines.h:135
Scalar * iterator
Definition: eigen_plugins.h:23
void resize(size_t nLines)
Resizes the set.
Definition: CSetOfLines.h:115
EIGEN_STRONG_INLINE iterator begin()
Definition: eigen_plugins.h:26
std::vector< TSegment3D >::iterator iterator
Iterator to the set.
Definition: CSetOfLines.h:175
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.
const Scalar * const_iterator
Definition: eigen_plugins.h:24
struct BASE_IMPEXP TSegment3D
A renderizable object suitable for rendering with OpenGL's display lists.
#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:69
3D segment, consisting of two points.
EIGEN_STRONG_INLINE bool empty() const
float getLineWidth() const
Gets the width with which lines are drawn.
Definition: CSetOfLines.h:63
void reserve(size_t r)
Reserves an amount of lines to the set.
Definition: CSetOfLines.h:123
const_iterator begin() const
Beginning const iterator.
Definition: CSetOfLines.h:190
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.h:157
virtual ~CSetOfLines()
Private, virtual destructor: only can be deleted from smart pointers.
Definition: CSetOfLines.h:229
std::vector< TSegment3D >::reverse_iterator reverse_iterator
Iterator to the set.
Definition: CSetOfLines.h:176
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...
const_iterator end() const
Ending const iterator.
Definition: CSetOfLines.h:198
size_t size() const
Returns the total count of lines in this set.
Definition: CSetOfLines.h:137
bool empty() const
Returns true if there are no line segments.
Definition: CSetOfLines.h:139
#define ASSERT_(f)
const_reverse_iterator rbegin() const
Beginning const reverse iterator (actually, accesses the end of the set).
Definition: CSetOfLines.h:206
bool isAntiAliasingEnabled() const
Definition: CSetOfLines.h:221
std::vector< TSegment3D >::const_reverse_iterator const_reverse_iterator
Const reverse iterator to the set.
Definition: CSetOfLines.h:185
void appendLine(T p0, U p1)
Inserts a line, given its bounds.
Definition: CSetOfLines.h:130
const_reverse_iterator rend() const
Ending const reverse iterator (actually, refers to the starting point of the set).
Definition: CSetOfLines.h:213
Lightweight 3D point.
A set of independent lines (or segments), one line with its own start and end positions (X...
Definition: CSetOfLines.h:38
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:106
#define DEFINE_SERIALIZABLE_POST_CUSTOM_BASE_LINKAGE(class_name, base_name, _LINKAGE_)
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 appendLineStrip(const U &point)
Definition: CSetOfLines.h:89



Page generated by Doxygen 1.8.8 for MRPT 1.2.2 SVN:Unversioned directory at Tue Oct 14 02:14:08 UTC 2014