Point Cloud Library (PCL)  1.10.1-dev
mesh_indices.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2009-2012, Willow Garage, Inc.
6  * Copyright (c) 2012-, Open Perception, Inc.
7  *
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  *
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
17  * copyright notice, this list of conditions and the following
18  * disclaimer in the documentation and/or other materials provided
19  * with the distribution.
20  * * Neither the name of the copyright holder(s) nor the names of its
21  * contributors may be used to endorse or promote products derived
22  * from this software without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35  * POSSIBILITY OF SUCH DAMAGE.
36  *
37  * $Id$
38  *
39  */
40 
41 // NOTE: This file has been created with 'pcl_src/geometry/include/pcl/geometry/mesh_indices.py'
42 
43 #pragma once
44 
45 #include <iostream>
46 
47 #include <pcl/geometry/boost.h>
48 
49 ////////////////////////////////////////////////////////////////////////////////
50 // VertexIndex
51 ////////////////////////////////////////////////////////////////////////////////
52 
53 namespace pcl
54 {
55  namespace geometry
56  {
57  /** \brief Index used to access elements in the half-edge mesh. It is basically just a wrapper around an integer with a few added methods.
58  * \author Martin Saelzle
59  * \ingroup geometry
60  */
62  : boost::totally_ordered <pcl::geometry::VertexIndex // < > <= >= == !=
63  , boost::unit_steppable <pcl::geometry::VertexIndex // ++ -- (pre and post)
64  , boost::additive <pcl::geometry::VertexIndex // += + -= -
65  > > >
66  {
67  public:
68 
69  using Base = boost::totally_ordered <pcl::geometry::VertexIndex,
70  boost::unit_steppable <pcl::geometry::VertexIndex,
71  boost::additive <pcl::geometry::VertexIndex> > >;
72  using Self = pcl::geometry::VertexIndex;
73 
74  /** \brief Constructor. Initializes with an invalid index. */
76  : index_ (-1)
77  {
78  }
79 
80  /** \brief Constructor.
81  * \param[in] index The integer index.
82  */
83  explicit VertexIndex (const int index)
84  : index_ (index)
85  {
86  }
87 
88  /** \brief Returns true if the index is valid. */
89  inline bool
90  isValid () const
91  {
92  return (index_ >= 0);
93  }
94 
95  /** \brief Invalidate the index. */
96  inline void
98  {
99  index_ = -1;
100  }
101 
102  /** \brief Get the index. */
103  inline int
104  get () const
105  {
106  return (index_);
107  }
108 
109  /** \brief Set the index. */
110  inline void
111  set (const int index)
112  {
113  index_ = index;
114  }
115 
116  /** \brief Comparison operators (with boost::operators): < > <= >= */
117  inline bool
118  operator < (const Self& other) const
119  {
120  return (this->get () < other.get ());
121  }
122 
123  /** \brief Comparison operators (with boost::operators): == != */
124  inline bool
125  operator == (const Self& other) const
126  {
127  return (this->get () == other.get ());
128  }
129 
130  /** \brief Increment operators (with boost::operators): ++ (pre and post) */
131  inline Self&
133  {
134  ++index_;
135  return (*this);
136  }
137 
138  /** \brief Decrement operators (with boost::operators): \-\- (pre and post) */
139  inline Self&
141  {
142  --index_;
143  return (*this);
144  }
145 
146  /** \brief Addition operators (with boost::operators): + += */
147  inline Self&
148  operator += (const Self& other)
149  {
150  index_ += other.get ();
151  return (*this);
152  }
153 
154  /** \brief Subtraction operators (with boost::operators): - -= */
155  inline Self&
156  operator -= (const Self& other)
157  {
158  index_ -= other.get ();
159  return (*this);
160  }
161 
162  private:
163 
164  /** \brief Stored index. */
165  int index_;
166 
167  friend std::istream&
168  operator >> (std::istream& is, pcl::geometry::VertexIndex& index);
169  };
170 
171  /** \brief ostream operator. */
172  inline std::ostream&
173  operator << (std::ostream& os, const pcl::geometry::VertexIndex& index)
174  {
175  return (os << index.get ());
176  }
177 
178  /** \brief istream operator. */
179  inline std::istream&
180  operator >> (std::istream& is, pcl::geometry::VertexIndex& index)
181  {
182  return (is >> index.index_);
183  }
184 
185  } // End namespace geometry
186 } // End namespace pcl
187 
188 ////////////////////////////////////////////////////////////////////////////////
189 // HalfEdgeIndex
190 ////////////////////////////////////////////////////////////////////////////////
191 
192 namespace pcl
193 {
194  namespace geometry
195  {
196  /** \brief Index used to access elements in the half-edge mesh. It is basically just a wrapper around an integer with a few added methods.
197  * \author Martin Saelzle
198  * \ingroup geometry
199  */
201  : boost::totally_ordered <pcl::geometry::HalfEdgeIndex // < > <= >= == !=
202  , boost::unit_steppable <pcl::geometry::HalfEdgeIndex // ++ -- (pre and post)
203  , boost::additive <pcl::geometry::HalfEdgeIndex // += + -= -
204  > > >
205  {
206  public:
207 
208  using Base = boost::totally_ordered <pcl::geometry::HalfEdgeIndex,
209  boost::unit_steppable <pcl::geometry::HalfEdgeIndex,
210  boost::additive <pcl::geometry::HalfEdgeIndex> > >;
211  using Self = pcl::geometry::HalfEdgeIndex;
212 
213  /** \brief Constructor. Initializes with an invalid index. */
215  : index_ (-1)
216  {
217  }
218 
219  /** \brief Constructor.
220  * \param[in] index The integer index.
221  */
222  explicit HalfEdgeIndex (const int index)
223  : index_ (index)
224  {
225  }
226 
227  /** \brief Returns true if the index is valid. */
228  inline bool
229  isValid () const
230  {
231  return (index_ >= 0);
232  }
233 
234  /** \brief Invalidate the index. */
235  inline void
237  {
238  index_ = -1;
239  }
240 
241  /** \brief Get the index. */
242  inline int
243  get () const
244  {
245  return (index_);
246  }
247 
248  /** \brief Set the index. */
249  inline void
250  set (const int index)
251  {
252  index_ = index;
253  }
254 
255  /** \brief Comparison operators (with boost::operators): < > <= >= */
256  inline bool
257  operator < (const Self& other) const
258  {
259  return (this->get () < other.get ());
260  }
261 
262  /** \brief Comparison operators (with boost::operators): == != */
263  inline bool
264  operator == (const Self& other) const
265  {
266  return (this->get () == other.get ());
267  }
268 
269  /** \brief Increment operators (with boost::operators): ++ (pre and post) */
270  inline Self&
272  {
273  ++index_;
274  return (*this);
275  }
276 
277  /** \brief Decrement operators (with boost::operators): \-\- (pre and post) */
278  inline Self&
280  {
281  --index_;
282  return (*this);
283  }
284 
285  /** \brief Addition operators (with boost::operators): + += */
286  inline Self&
287  operator += (const Self& other)
288  {
289  index_ += other.get ();
290  return (*this);
291  }
292 
293  /** \brief Subtraction operators (with boost::operators): - -= */
294  inline Self&
295  operator -= (const Self& other)
296  {
297  index_ -= other.get ();
298  return (*this);
299  }
300 
301  private:
302 
303  /** \brief Stored index. */
304  int index_;
305 
306  friend std::istream&
307  operator >> (std::istream& is, pcl::geometry::HalfEdgeIndex& index);
308  };
309 
310  /** \brief ostream operator. */
311  inline std::ostream&
312  operator << (std::ostream& os, const pcl::geometry::HalfEdgeIndex& index)
313  {
314  return (os << index.get ());
315  }
316 
317  /** \brief istream operator. */
318  inline std::istream&
319  operator >> (std::istream& is, pcl::geometry::HalfEdgeIndex& index)
320  {
321  return (is >> index.index_);
322  }
323 
324  } // End namespace geometry
325 } // End namespace pcl
326 
327 ////////////////////////////////////////////////////////////////////////////////
328 // EdgeIndex
329 ////////////////////////////////////////////////////////////////////////////////
330 
331 namespace pcl
332 {
333  namespace geometry
334  {
335  /** \brief Index used to access elements in the half-edge mesh. It is basically just a wrapper around an integer with a few added methods.
336  * \author Martin Saelzle
337  * \ingroup geometry
338  */
339  class EdgeIndex
340  : boost::totally_ordered <pcl::geometry::EdgeIndex // < > <= >= == !=
341  , boost::unit_steppable <pcl::geometry::EdgeIndex // ++ -- (pre and post)
342  , boost::additive <pcl::geometry::EdgeIndex // += + -= -
343  > > >
344  {
345  public:
346 
347  using Base = boost::totally_ordered <pcl::geometry::EdgeIndex,
348  boost::unit_steppable <pcl::geometry::EdgeIndex,
349  boost::additive <pcl::geometry::EdgeIndex> > >;
350  using Self = pcl::geometry::EdgeIndex;
351 
352  /** \brief Constructor. Initializes with an invalid index. */
354  : index_ (-1)
355  {
356  }
357 
358  /** \brief Constructor.
359  * \param[in] index The integer index.
360  */
361  explicit EdgeIndex (const int index)
362  : index_ (index)
363  {
364  }
365 
366  /** \brief Returns true if the index is valid. */
367  inline bool
368  isValid () const
369  {
370  return (index_ >= 0);
371  }
372 
373  /** \brief Invalidate the index. */
374  inline void
376  {
377  index_ = -1;
378  }
379 
380  /** \brief Get the index. */
381  inline int
382  get () const
383  {
384  return (index_);
385  }
386 
387  /** \brief Set the index. */
388  inline void
389  set (const int index)
390  {
391  index_ = index;
392  }
393 
394  /** \brief Comparison operators (with boost::operators): < > <= >= */
395  inline bool
396  operator < (const Self& other) const
397  {
398  return (this->get () < other.get ());
399  }
400 
401  /** \brief Comparison operators (with boost::operators): == != */
402  inline bool
403  operator == (const Self& other) const
404  {
405  return (this->get () == other.get ());
406  }
407 
408  /** \brief Increment operators (with boost::operators): ++ (pre and post) */
409  inline Self&
411  {
412  ++index_;
413  return (*this);
414  }
415 
416  /** \brief Decrement operators (with boost::operators): \-\- (pre and post) */
417  inline Self&
419  {
420  --index_;
421  return (*this);
422  }
423 
424  /** \brief Addition operators (with boost::operators): + += */
425  inline Self&
426  operator += (const Self& other)
427  {
428  index_ += other.get ();
429  return (*this);
430  }
431 
432  /** \brief Subtraction operators (with boost::operators): - -= */
433  inline Self&
434  operator -= (const Self& other)
435  {
436  index_ -= other.get ();
437  return (*this);
438  }
439 
440  private:
441 
442  /** \brief Stored index. */
443  int index_;
444 
445  friend std::istream&
446  operator >> (std::istream& is, pcl::geometry::EdgeIndex& index);
447  };
448 
449  /** \brief ostream operator. */
450  inline std::ostream&
451  operator << (std::ostream& os, const pcl::geometry::EdgeIndex& index)
452  {
453  return (os << index.get ());
454  }
455 
456  /** \brief istream operator. */
457  inline std::istream&
458  operator >> (std::istream& is, pcl::geometry::EdgeIndex& index)
459  {
460  return (is >> index.index_);
461  }
462 
463  } // End namespace geometry
464 } // End namespace pcl
465 
466 ////////////////////////////////////////////////////////////////////////////////
467 // FaceIndex
468 ////////////////////////////////////////////////////////////////////////////////
469 
470 namespace pcl
471 {
472  namespace geometry
473  {
474  /** \brief Index used to access elements in the half-edge mesh. It is basically just a wrapper around an integer with a few added methods.
475  * \author Martin Saelzle
476  * \ingroup geometry
477  */
478  class FaceIndex
479  : boost::totally_ordered <pcl::geometry::FaceIndex // < > <= >= == !=
480  , boost::unit_steppable <pcl::geometry::FaceIndex // ++ -- (pre and post)
481  , boost::additive <pcl::geometry::FaceIndex // += + -= -
482  > > >
483  {
484  public:
485 
486  using Base = boost::totally_ordered <pcl::geometry::FaceIndex,
487  boost::unit_steppable <pcl::geometry::FaceIndex,
488  boost::additive <pcl::geometry::FaceIndex> > >;
489  using Self = pcl::geometry::FaceIndex;
490 
491  /** \brief Constructor. Initializes with an invalid index. */
493  : index_ (-1)
494  {
495  }
496 
497  /** \brief Constructor.
498  * \param[in] index The integer index.
499  */
500  explicit FaceIndex (const int index)
501  : index_ (index)
502  {
503  }
504 
505  /** \brief Returns true if the index is valid. */
506  inline bool
507  isValid () const
508  {
509  return (index_ >= 0);
510  }
511 
512  /** \brief Invalidate the index. */
513  inline void
515  {
516  index_ = -1;
517  }
518 
519  /** \brief Get the index. */
520  inline int
521  get () const
522  {
523  return (index_);
524  }
525 
526  /** \brief Set the index. */
527  inline void
528  set (const int index)
529  {
530  index_ = index;
531  }
532 
533  /** \brief Comparison operators (with boost::operators): < > <= >= */
534  inline bool
535  operator < (const Self& other) const
536  {
537  return (this->get () < other.get ());
538  }
539 
540  /** \brief Comparison operators (with boost::operators): == != */
541  inline bool
542  operator == (const Self& other) const
543  {
544  return (this->get () == other.get ());
545  }
546 
547  /** \brief Increment operators (with boost::operators): ++ (pre and post) */
548  inline Self&
550  {
551  ++index_;
552  return (*this);
553  }
554 
555  /** \brief Decrement operators (with boost::operators): \-\- (pre and post) */
556  inline Self&
558  {
559  --index_;
560  return (*this);
561  }
562 
563  /** \brief Addition operators (with boost::operators): + += */
564  inline Self&
565  operator += (const Self& other)
566  {
567  index_ += other.get ();
568  return (*this);
569  }
570 
571  /** \brief Subtraction operators (with boost::operators): - -= */
572  inline Self&
573  operator -= (const Self& other)
574  {
575  index_ -= other.get ();
576  return (*this);
577  }
578 
579  private:
580 
581  /** \brief Stored index. */
582  int index_;
583 
584  friend std::istream&
585  operator >> (std::istream& is, pcl::geometry::FaceIndex& index);
586  };
587 
588  /** \brief ostream operator. */
589  inline std::ostream&
590  operator << (std::ostream& os, const pcl::geometry::FaceIndex& index)
591  {
592  return (os << index.get ());
593  }
594 
595  /** \brief istream operator. */
596  inline std::istream&
597  operator >> (std::istream& is, pcl::geometry::FaceIndex& index)
598  {
599  return (is >> index.index_);
600  }
601 
602  } // End namespace geometry
603 } // End namespace pcl
604 
605 ////////////////////////////////////////////////////////////////////////////////
606 // Conversions
607 ////////////////////////////////////////////////////////////////////////////////
608 
609 namespace pcl
610 {
611  namespace geometry
612  {
613  /** \brief Convert the given half-edge index to an edge index. */
615  toEdgeIndex (const HalfEdgeIndex& index)
616  {
617  return (index.isValid () ? EdgeIndex (index.get () / 2) : EdgeIndex ());
618  }
619 
620  /** \brief Convert the given edge index to a half-edge index.
621  * \param index
622  * \param[in] get_first The first half-edge of the edge is returned if this variable is true; elsewise the second.
623  */
625  toHalfEdgeIndex (const EdgeIndex& index, const bool get_first=true)
626  {
627  return (index.isValid () ? HalfEdgeIndex (index.get () * 2 + static_cast <int> (!get_first)) : HalfEdgeIndex ());
628  }
629  } // End namespace geometry
630 } // End namespace pcl
HalfEdgeIndex(const int index)
Constructor.
Definition: mesh_indices.h:222
VertexIndex(const int index)
Constructor.
Definition: mesh_indices.h:83
friend std::istream & operator>>(std::istream &is, pcl::geometry::VertexIndex &index)
istream operator.
Definition: mesh_indices.h:180
void invalidate()
Invalidate the index.
Definition: mesh_indices.h:514
EdgeIndex(const int index)
Constructor.
Definition: mesh_indices.h:361
Self & operator++()
Increment operators (with boost::operators): ++ (pre and post)
Definition: mesh_indices.h:132
Self & operator+=(const Self &other)
Addition operators (with boost::operators): + +=.
Definition: mesh_indices.h:148
std::ostream & operator<<(std::ostream &os, const pcl::geometry::VertexIndex &index)
ostream operator.
Definition: mesh_indices.h:173
int get() const
Get the index.
Definition: mesh_indices.h:382
pcl::geometry::EdgeIndex toEdgeIndex(const HalfEdgeIndex &index)
Convert the given half-edge index to an edge index.
Definition: mesh_indices.h:615
bool isValid() const
Returns true if the index is valid.
Definition: mesh_indices.h:368
FaceIndex(const int index)
Constructor.
Definition: mesh_indices.h:500
bool operator<(const Self &other) const
Comparison operators (with boost::operators): < > <= >=.
Definition: mesh_indices.h:118
boost::totally_ordered< pcl::geometry::EdgeIndex, boost::unit_steppable< pcl::geometry::EdgeIndex, boost::additive< pcl::geometry::EdgeIndex > > > Base
Definition: mesh_indices.h:349
bool isValid() const
Returns true if the index is valid.
Definition: mesh_indices.h:90
boost::totally_ordered< pcl::geometry::FaceIndex, boost::unit_steppable< pcl::geometry::FaceIndex, boost::additive< pcl::geometry::FaceIndex > > > Base
Definition: mesh_indices.h:488
Index used to access elements in the half-edge mesh.
Definition: mesh_indices.h:339
bool operator==(const Self &other) const
Comparison operators (with boost::operators): == !=.
Definition: mesh_indices.h:125
void invalidate()
Invalidate the index.
Definition: mesh_indices.h:375
pcl::geometry::HalfEdgeIndex toHalfEdgeIndex(const EdgeIndex &index, const bool get_first=true)
Convert the given edge index to a half-edge index.
Definition: mesh_indices.h:625
Self & operator--()
Decrement operators (with boost::operators): -- (pre and post)
Definition: mesh_indices.h:140
void invalidate()
Invalidate the index.
Definition: mesh_indices.h:97
int get() const
Get the index.
Definition: mesh_indices.h:104
Index used to access elements in the half-edge mesh.
Definition: mesh_indices.h:61
boost::totally_ordered< pcl::geometry::HalfEdgeIndex, boost::unit_steppable< pcl::geometry::HalfEdgeIndex, boost::additive< pcl::geometry::HalfEdgeIndex > > > Base
Definition: mesh_indices.h:210
Index used to access elements in the half-edge mesh.
Definition: mesh_indices.h:478
VertexIndex()
Constructor.
Definition: mesh_indices.h:75
Index used to access elements in the half-edge mesh.
Definition: mesh_indices.h:200
void invalidate()
Invalidate the index.
Definition: mesh_indices.h:236
int get() const
Get the index.
Definition: mesh_indices.h:521
int get() const
Get the index.
Definition: mesh_indices.h:243
FaceIndex()
Constructor.
Definition: mesh_indices.h:492
boost::totally_ordered< pcl::geometry::VertexIndex, boost::unit_steppable< pcl::geometry::VertexIndex, boost::additive< pcl::geometry::VertexIndex > > > Base
Definition: mesh_indices.h:71
Self & operator-=(const Self &other)
Subtraction operators (with boost::operators): - -=.
Definition: mesh_indices.h:156
EdgeIndex()
Constructor.
Definition: mesh_indices.h:353
bool isValid() const
Returns true if the index is valid.
Definition: mesh_indices.h:507
bool isValid() const
Returns true if the index is valid.
Definition: mesh_indices.h:229