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



Page generated by Doxygen 1.8.11 for MRPT 1.3.2 SVN:Unversioned directory at Sun May 1 08:45:24 UTC 2016