Main MRPT website > C++ reference
MRPT logo
CSetOfLines.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | The Mobile Robot Programming Toolkit (MRPT) |
3  | |
4  | http://www.mrpt.org/ |
5  | |
6  | Copyright (c) 2005-2013, Individual contributors, see AUTHORS file |
7  | Copyright (c) 2005-2013, MAPIR group, University of Malaga |
8  | Copyright (c) 2012-2013, University of Almeria |
9  | All rights reserved. |
10  | |
11  | Redistribution and use in source and binary forms, with or without |
12  | modification, are permitted provided that the following conditions are |
13  | met: |
14  | * Redistributions of source code must retain the above copyright |
15  | notice, this list of conditions and the following disclaimer. |
16  | * Redistributions in binary form must reproduce the above copyright |
17  | notice, this list of conditions and the following disclaimer in the |
18  | documentation and/or other materials provided with the distribution. |
19  | * Neither the name of the copyright holders nor the |
20  | names of its contributors may be used to endorse or promote products |
21  | derived from this software without specific prior written permission.|
22  | |
23  | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
24  | 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
25  | TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR|
26  | PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE |
27  | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL|
28  | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR|
29  | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
30  | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
31  | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
32  | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
33  | POSSIBILITY OF SUCH DAMAGE. |
34  +---------------------------------------------------------------------------+ */
35 
36 #ifndef opengl_CSetOfLines_H
37 #define opengl_CSetOfLines_H
38 
42 
43 namespace mrpt
44 {
45  namespace opengl
46  {
50 
51  // This must be added to any CSerializable derived class:
53 
54  /** A set of independent lines (or segments), one line with its own start and end positions (X,Y,Z).
55  * \sa opengl::COpenGLScene
56  *
57  * <div align="center">
58  * <table border="0" cellspan="4" cellspacing="4" style="border-width: 1px; border-style: solid;">
59  * <tr> <td> mrpt::opengl::CSetOfLines </td> <td> \image html preview_CSetOfLines.png </td> </tr>
60  * </table>
61  * </div>
62  *
63  * \ingroup mrpt_opengl_grp
64  */
66  {
68  protected:
69  std::vector<TSegment3D> mSegments;
70  float mLineWidth;
72  public:
73  /**
74  * Clear the list of segments
75  */
76  inline void clear() {
77  mSegments.clear();
79  }
80  /**
81  * Sets the width with which lines will be drawn.
82  */
83  inline void setLineWidth(float w) {
84  mLineWidth=w;
86  }
87  /**
88  * Gets the width with which lines are drawn.
89  */
90  float getLineWidth() const {
91  return mLineWidth;
92  }
93  /**
94  * Appends a line to the set.
95  */
96  inline void appendLine(const mrpt::math::TSegment3D &sgm) {
97  mSegments.push_back(sgm);
99  }
100  /**
101  * Appends a line to the set, given the coordinates of its bounds.
102  */
103  inline void appendLine(float x0,float y0,float z0,float x1,float y1,float z1) {
104  appendLine(TSegment3D(TPoint3D(x0,y0,z0),TPoint3D(x1,y1,z1)));
106  }
107 
108  /** Appends a line whose starting point is the end point of the last line (similar to OpenGL's GL_LINE_STRIP)
109  * \exception std::exception If there is no previous segment */
110  inline void appendLineStrip(float x,float y,float z) {
111  ASSERT_(!this->empty())
112  this->appendLine(this->rbegin()->point2, TPoint3D(x,y,z));
113  }
114  //! \overload
115  template<class U>
116  inline void appendLineStrip(const U &point) {
117  ASSERT_(!this->empty())
118  this->appendLine(this->rbegin()->point2,point);
119  }
120 
121  /**
122  * Appends any iterable collection of lines to the set. Note that this includes another CSetOfLines.
123  * \sa appendLine
124  */
125  template<class T> inline void appendLines(const T &sgms) {
126  mSegments.insert(mSegments.end(),sgms.begin(),sgms.end());
128  }
129  /**
130  * Appends certain amount of lines, located between two iterators, into the set.
131  * \sa appendLine
132  */
133  template<class T_it> inline void appendLines(const T_it &begin,const T_it &end) {
134  mSegments.reserve(mSegments.size()+(end-begin));
135  mSegments.insert(mSegments.end(),begin,end);
137  }
138  /**
139  * Resizes the set.
140  * \sa reserve
141  */
142  void resize(size_t nLines) {
143  mSegments.resize(nLines);
145  }
146  /**
147  * 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.
148  * \sa resize
149  */
150  void reserve(size_t r) {
151  mSegments.reserve(r);
153  }
154  /**
155  * Inserts a line, given its bounds. Works with any pair of objects with access to x, y and z members.
156  */
157  template<class T,class U> inline void appendLine(T p0,U p1) {
158  appendLine(p0.x,p0.y,p0.z,p1.x,p1.y,p1.z);
160  }
161  /** Returns the total count of lines in this set. */
162  inline size_t getLineCount() const { return mSegments.size(); }
163  /** Returns the total count of lines in this set. */
164  inline size_t size() const { return mSegments.size(); }
165  /** Returns true if there are no line segments. */
166  inline bool empty() const { return mSegments.empty(); }
167  /**
168  * Sets a specific line in the set, given its index.
169  * \sa appendLine
170  */
171  void setLineByIndex(size_t index,const TSegment3D &segm);
172  /**
173  * Sets a specific line in the set, given its index.
174  * \sa appendLine
175  */
176  inline void setLineByIndex(size_t index,double x0,double y0,double z0,double x1,double y1,double z1) {
177  setLineByIndex(index,TSegment3D(TPoint3D(x0,y0,z0),TPoint3D(x1,y1,z1)));
179  }
180  /**
181  * Gets a specific line in the set, given its index.
182  * \sa getLineByIndex
183  */
184  inline void getLineByIndex(size_t index,double &x0,double &y0,double &z0,double &x1,double &y1,double &z1) const {
185  ASSERT_(index<mSegments.size())
186  x0 = mSegments[index].point1.x;
187  y0 = mSegments[index].point1.y;
188  z0 = mSegments[index].point1.z;
189  x1 = mSegments[index].point2.x;
190  y1 = mSegments[index].point2.y;
191  z1 = mSegments[index].point2.z;
192  }
193  /**
194  * Class factory
195  */
196  inline static CSetOfLinesPtr Create(const std::vector<TSegment3D> &sgms, const bool antiAliasing = true) {
197  return CSetOfLinesPtr(new CSetOfLines(sgms,antiAliasing));
198  }
199  /** Render
200  */
201  void render_dl() const;
202 
203  //Iterator management
204  typedef std::vector<TSegment3D>::iterator iterator; //!< Iterator to the set.
205  typedef std::vector<TSegment3D>::reverse_iterator reverse_iterator; //!< Iterator to the set.
206 
207  /**
208  * Const iterator to the set.
209  */
211  /**
212  * Const reverse iterator to the set.
213  */
214  typedef std::vector<TSegment3D>::const_reverse_iterator const_reverse_iterator;
215  /**
216  * Beginning const iterator.
217  * \sa end,rbegin,rend
218  */
219  inline const_iterator begin() const {
220  return mSegments.begin();
221  }
222  inline iterator begin() { CRenderizableDisplayList::notifyChange(); return mSegments.begin(); }
223  /**
224  * Ending const iterator.
225  * \sa begin,rend,rbegin
226  */
227  inline const_iterator end() const {
228  return mSegments.end();
229  }
230  inline iterator end() { CRenderizableDisplayList::notifyChange(); return mSegments.end(); }
231  /**
232  * Beginning const reverse iterator (actually, accesses the end of the set).
233  * \sa rend,begin,end
234  */
236  return mSegments.rbegin();
237  }
238  /**
239  * Ending const reverse iterator (actually, refers to the starting point of the set).
240  * \sa rbegin,end,begin
241  */
242  inline const_reverse_iterator rend() const {
243  return mSegments.rend();
244  }
245 
246  /** Evaluates the bounding box of this object (including possible children) in the coordinate frame of the object parent. */
247  virtual void getBoundingBox(mrpt::math::TPoint3D &bb_min, mrpt::math::TPoint3D &bb_max) const;
248 
249  void enableAntiAliasing(bool enable=true) { m_antiAliasing =enable; CRenderizableDisplayList::notifyChange(); }
250  bool isAntiAliasingEnabled() const { return m_antiAliasing; }
251 
252  private:
253  /** Constructor */
254  CSetOfLines();
255  /** Constructor with a initial set of lines. */
256  CSetOfLines(const std::vector<TSegment3D> &sgms,bool antiAliasing=true);
257  /** Private, virtual destructor: only can be deleted from smart pointers. */
258  virtual ~CSetOfLines() { }
259  };
260  /** Inserts a set of segments into the list. Allows call chaining.
261  * \sa mrpt::opengl::CSetOfLines::appendLines
262  */
263  template<class T> inline CSetOfLinesPtr &operator<<(CSetOfLinesPtr &l,const T &s) {
264  l->appendLines(s.begin(),s.end());
265  return l;
266  }
267  /** Inserts a segment into the list. Allows call chaining.
268  * \sa mrpt::opengl::CSetOfLines::appendLine(const TSegment &)
269  */
271  l->appendLine(s);
272  return l;
273  }
274  } // end namespace
275 
276 } // End of namespace
277 
278 
279 #endif
size_t size() const
Returns the total count of lines in this set.
Definition: CSetOfLines.h:164
void enableAntiAliasing(bool enable=true)
Definition: CSetOfLines.h:249
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:176
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:125
EIGEN_STRONG_INLINE iterator end()
Definition: eigen_plugins.h:53
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:110
std::vector< TSegment3D >::const_iterator const_iterator
Const iterator to the set.
Definition: CSetOfLines.h:210
const_iterator begin() const
Beginning const iterator.
Definition: CSetOfLines.h:219
size_t getLineCount() const
Returns the total count of lines in this set.
Definition: CSetOfLines.h:162
const_iterator end() const
Ending const iterator.
Definition: CSetOfLines.h:227
void setLineWidth(float w)
Sets the width with which lines will be drawn.
Definition: CSetOfLines.h:83
Scalar * iterator
Definition: eigen_plugins.h:49
void resize(size_t nLines)
Resizes the set.
Definition: CSetOfLines.h:142
EIGEN_STRONG_INLINE iterator begin()
Definition: eigen_plugins.h:52
std::vector< TSegment3D >::iterator iterator
Iterator to the set.
Definition: CSetOfLines.h:204
EIGEN_STRONG_INLINE void notifyChange() const
Must be called to notify that the object has changed (so, the display list must be updated) ...
const Scalar * const_iterator
Definition: eigen_plugins.h:50
struct BASE_IMPEXP TSegment3D
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:90
#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:96
3D segment, consisting of two points.
class OPENGL_IMPEXP CSetOfLines
Definition: CSetOfLines.h:49
void reserve(size_t r)
Reserves an amount of lines to the set.
Definition: CSetOfLines.h:150
void clear()
Clear the list of segments.
Definition: CSetOfLines.h:76
virtual ~CSetOfLines()
Private, virtual destructor: only can be deleted from smart pointers.
Definition: CSetOfLines.h:258
std::vector< TSegment3D >::reverse_iterator reverse_iterator
Iterator to the set.
Definition: CSetOfLines.h:205
static CSetOfLinesPtr Create(const std::vector< TSegment3D > &sgms, const bool antiAliasing=true)
Class factory.
Definition: CSetOfLines.h:196
const_reverse_iterator rbegin() const
Beginning const reverse iterator (actually, accesses the end of the set).
Definition: CSetOfLines.h:235
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_reverse_iterator rend() const
Ending const reverse iterator (actually, refers to the starting point of the set).
Definition: CSetOfLines.h:242
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:184
#define ASSERT_(f)
bool isAntiAliasingEnabled() const
Definition: CSetOfLines.h:250
std::vector< TSegment3D >::const_reverse_iterator const_reverse_iterator
Const reverse iterator to the set.
Definition: CSetOfLines.h:214
void appendLine(T p0, U p1)
Inserts a line, given its bounds.
Definition: CSetOfLines.h:157
Lightweight 3D point.
bool empty() const
Returns true if there are no line segments.
Definition: CSetOfLines.h:166
std::vector< TSegment3D > mSegments
Definition: CSetOfLines.h:69
A set of independent lines (or segments), one line with its own start and end positions (X...
Definition: CSetOfLines.h:65
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:133
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:103
void appendLineStrip(const U &point)
Definition: CSetOfLines.h:116



Page generated by Doxygen 1.8.14 for MRPT 1.0.2 SVN: at lun oct 28 00:52:41 CET 2019 Hosted on:
SourceForge.net Logo