Point Cloud Library (PCL)  1.7.0
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 #ifndef PCL_GEOMETRY_MESH_INDICES_H
44 #define PCL_GEOMETRY_MESH_INDICES_H
45 
46 #include <iostream>
47 
48 #include <pcl/geometry/boost.h>
49 
50 ////////////////////////////////////////////////////////////////////////////////
51 // VertexIndex
52 ////////////////////////////////////////////////////////////////////////////////
53 
54 namespace pcl
55 {
56  namespace geometry
57  {
58  /** \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.
59  * \author Martin Saelzle
60  * \ingroup geometry
61  */
63  : boost::totally_ordered <pcl::geometry::VertexIndex // < > <= >= == !=
64  , boost::unit_steppable <pcl::geometry::VertexIndex // ++ -- (pre and post)
65  , boost::additive <pcl::geometry::VertexIndex // += + -= -
66  > > >
67  {
68  public:
69 
70  typedef boost::totally_ordered <pcl::geometry::VertexIndex,
71  boost::unit_steppable <pcl::geometry::VertexIndex,
72  boost::additive <pcl::geometry::VertexIndex> > > Base;
74 
75  /** \brief Constructor. Initializes with an invalid index. */
77  : index_ (-1)
78  {
79  }
80 
81  /** \brief Constructor.
82  * \param[in] index The integer index.
83  */
84  explicit VertexIndex (const int index)
85  : index_ (index)
86  {
87  }
88 
89  /** \brief Returns true if the index is valid. */
90  inline bool
91  isValid () const
92  {
93  return (index_ >= 0);
94  }
95 
96  /** \brief Invalidate the index. */
97  inline void
99  {
100  index_ = -1;
101  }
102 
103  /** \brief Get the index. */
104  inline int
105  get () const
106  {
107  return (index_);
108  }
109 
110  /** \brief Set the index. */
111  inline void
112  set (const int index)
113  {
114  index_ = index;
115  }
116 
117  /** \brief Comparison operators (with boost::operators): < > <= >= */
118  inline bool
119  operator < (const Self& other) const
120  {
121  return (this->get () < other.get ());
122  }
123 
124  /** \brief Comparison operators (with boost::operators): == != */
125  inline bool
126  operator == (const Self& other) const
127  {
128  return (this->get () == other.get ());
129  }
130 
131  /** \brief Increment operators (with boost::operators): ++ (pre and post) */
132  inline Self&
134  {
135  ++index_;
136  return (*this);
137  }
138 
139  /** \brief Decrement operators (with boost::operators): \-\- (pre and post) */
140  inline Self&
142  {
143  --index_;
144  return (*this);
145  }
146 
147  /** \brief Addition operators (with boost::operators): + += */
148  inline Self&
149  operator += (const Self& other)
150  {
151  index_ += other.get ();
152  return (*this);
153  }
154 
155  /** \brief Subtraction operators (with boost::operators): - -= */
156  inline Self&
157  operator -= (const Self& other)
158  {
159  index_ -= other.get ();
160  return (*this);
161  }
162 
163  private:
164 
165  /** \brief Stored index. */
166  int index_;
167 
168  friend std::istream&
169  operator >> (std::istream& is, pcl::geometry::VertexIndex& index);
170  };
171 
172  /** \brief ostream operator. */
173  inline std::ostream&
174  operator << (std::ostream& os, const pcl::geometry::VertexIndex& index)
175  {
176  return (os << index.get ());
177  }
178 
179  /** \brief istream operator. */
180  inline std::istream&
181  operator >> (std::istream& is, pcl::geometry::VertexIndex& index)
182  {
183  return (is >> index.index_);
184  }
185 
186  } // End namespace geometry
187 } // End namespace pcl
188 
189 ////////////////////////////////////////////////////////////////////////////////
190 // HalfEdgeIndex
191 ////////////////////////////////////////////////////////////////////////////////
192 
193 namespace pcl
194 {
195  namespace geometry
196  {
197  /** \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.
198  * \author Martin Saelzle
199  * \ingroup geometry
200  */
202  : boost::totally_ordered <pcl::geometry::HalfEdgeIndex // < > <= >= == !=
203  , boost::unit_steppable <pcl::geometry::HalfEdgeIndex // ++ -- (pre and post)
204  , boost::additive <pcl::geometry::HalfEdgeIndex // += + -= -
205  > > >
206  {
207  public:
208 
209  typedef boost::totally_ordered <pcl::geometry::HalfEdgeIndex,
210  boost::unit_steppable <pcl::geometry::HalfEdgeIndex,
211  boost::additive <pcl::geometry::HalfEdgeIndex> > > Base;
213 
214  /** \brief Constructor. Initializes with an invalid index. */
216  : index_ (-1)
217  {
218  }
219 
220  /** \brief Constructor.
221  * \param[in] index The integer index.
222  */
223  explicit HalfEdgeIndex (const int index)
224  : index_ (index)
225  {
226  }
227 
228  /** \brief Returns true if the index is valid. */
229  inline bool
230  isValid () const
231  {
232  return (index_ >= 0);
233  }
234 
235  /** \brief Invalidate the index. */
236  inline void
238  {
239  index_ = -1;
240  }
241 
242  /** \brief Get the index. */
243  inline int
244  get () const
245  {
246  return (index_);
247  }
248 
249  /** \brief Set the index. */
250  inline void
251  set (const int index)
252  {
253  index_ = index;
254  }
255 
256  /** \brief Comparison operators (with boost::operators): < > <= >= */
257  inline bool
258  operator < (const Self& other) const
259  {
260  return (this->get () < other.get ());
261  }
262 
263  /** \brief Comparison operators (with boost::operators): == != */
264  inline bool
265  operator == (const Self& other) const
266  {
267  return (this->get () == other.get ());
268  }
269 
270  /** \brief Increment operators (with boost::operators): ++ (pre and post) */
271  inline Self&
273  {
274  ++index_;
275  return (*this);
276  }
277 
278  /** \brief Decrement operators (with boost::operators): \-\- (pre and post) */
279  inline Self&
281  {
282  --index_;
283  return (*this);
284  }
285 
286  /** \brief Addition operators (with boost::operators): + += */
287  inline Self&
288  operator += (const Self& other)
289  {
290  index_ += other.get ();
291  return (*this);
292  }
293 
294  /** \brief Subtraction operators (with boost::operators): - -= */
295  inline Self&
296  operator -= (const Self& other)
297  {
298  index_ -= other.get ();
299  return (*this);
300  }
301 
302  private:
303 
304  /** \brief Stored index. */
305  int index_;
306 
307  friend std::istream&
308  operator >> (std::istream& is, pcl::geometry::HalfEdgeIndex& index);
309  };
310 
311  /** \brief ostream operator. */
312  inline std::ostream&
313  operator << (std::ostream& os, const pcl::geometry::HalfEdgeIndex& index)
314  {
315  return (os << index.get ());
316  }
317 
318  /** \brief istream operator. */
319  inline std::istream&
320  operator >> (std::istream& is, pcl::geometry::HalfEdgeIndex& index)
321  {
322  return (is >> index.index_);
323  }
324 
325  } // End namespace geometry
326 } // End namespace pcl
327 
328 ////////////////////////////////////////////////////////////////////////////////
329 // EdgeIndex
330 ////////////////////////////////////////////////////////////////////////////////
331 
332 namespace pcl
333 {
334  namespace geometry
335  {
336  /** \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.
337  * \author Martin Saelzle
338  * \ingroup geometry
339  */
340  class EdgeIndex
341  : boost::totally_ordered <pcl::geometry::EdgeIndex // < > <= >= == !=
342  , boost::unit_steppable <pcl::geometry::EdgeIndex // ++ -- (pre and post)
343  , boost::additive <pcl::geometry::EdgeIndex // += + -= -
344  > > >
345  {
346  public:
347 
348  typedef boost::totally_ordered <pcl::geometry::EdgeIndex,
349  boost::unit_steppable <pcl::geometry::EdgeIndex,
350  boost::additive <pcl::geometry::EdgeIndex> > > Base;
352 
353  /** \brief Constructor. Initializes with an invalid index. */
355  : index_ (-1)
356  {
357  }
358 
359  /** \brief Constructor.
360  * \param[in] index The integer index.
361  */
362  explicit EdgeIndex (const int index)
363  : index_ (index)
364  {
365  }
366 
367  /** \brief Returns true if the index is valid. */
368  inline bool
369  isValid () const
370  {
371  return (index_ >= 0);
372  }
373 
374  /** \brief Invalidate the index. */
375  inline void
377  {
378  index_ = -1;
379  }
380 
381  /** \brief Get the index. */
382  inline int
383  get () const
384  {
385  return (index_);
386  }
387 
388  /** \brief Set the index. */
389  inline void
390  set (const int index)
391  {
392  index_ = index;
393  }
394 
395  /** \brief Comparison operators (with boost::operators): < > <= >= */
396  inline bool
397  operator < (const Self& other) const
398  {
399  return (this->get () < other.get ());
400  }
401 
402  /** \brief Comparison operators (with boost::operators): == != */
403  inline bool
404  operator == (const Self& other) const
405  {
406  return (this->get () == other.get ());
407  }
408 
409  /** \brief Increment operators (with boost::operators): ++ (pre and post) */
410  inline Self&
412  {
413  ++index_;
414  return (*this);
415  }
416 
417  /** \brief Decrement operators (with boost::operators): \-\- (pre and post) */
418  inline Self&
420  {
421  --index_;
422  return (*this);
423  }
424 
425  /** \brief Addition operators (with boost::operators): + += */
426  inline Self&
427  operator += (const Self& other)
428  {
429  index_ += other.get ();
430  return (*this);
431  }
432 
433  /** \brief Subtraction operators (with boost::operators): - -= */
434  inline Self&
435  operator -= (const Self& other)
436  {
437  index_ -= other.get ();
438  return (*this);
439  }
440 
441  private:
442 
443  /** \brief Stored index. */
444  int index_;
445 
446  friend std::istream&
447  operator >> (std::istream& is, pcl::geometry::EdgeIndex& index);
448  };
449 
450  /** \brief ostream operator. */
451  inline std::ostream&
452  operator << (std::ostream& os, const pcl::geometry::EdgeIndex& index)
453  {
454  return (os << index.get ());
455  }
456 
457  /** \brief istream operator. */
458  inline std::istream&
459  operator >> (std::istream& is, pcl::geometry::EdgeIndex& index)
460  {
461  return (is >> index.index_);
462  }
463 
464  } // End namespace geometry
465 } // End namespace pcl
466 
467 ////////////////////////////////////////////////////////////////////////////////
468 // FaceIndex
469 ////////////////////////////////////////////////////////////////////////////////
470 
471 namespace pcl
472 {
473  namespace geometry
474  {
475  /** \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.
476  * \author Martin Saelzle
477  * \ingroup geometry
478  */
479  class FaceIndex
480  : boost::totally_ordered <pcl::geometry::FaceIndex // < > <= >= == !=
481  , boost::unit_steppable <pcl::geometry::FaceIndex // ++ -- (pre and post)
482  , boost::additive <pcl::geometry::FaceIndex // += + -= -
483  > > >
484  {
485  public:
486 
487  typedef boost::totally_ordered <pcl::geometry::FaceIndex,
488  boost::unit_steppable <pcl::geometry::FaceIndex,
489  boost::additive <pcl::geometry::FaceIndex> > > Base;
491 
492  /** \brief Constructor. Initializes with an invalid index. */
494  : index_ (-1)
495  {
496  }
497 
498  /** \brief Constructor.
499  * \param[in] index The integer index.
500  */
501  explicit FaceIndex (const int index)
502  : index_ (index)
503  {
504  }
505 
506  /** \brief Returns true if the index is valid. */
507  inline bool
508  isValid () const
509  {
510  return (index_ >= 0);
511  }
512 
513  /** \brief Invalidate the index. */
514  inline void
516  {
517  index_ = -1;
518  }
519 
520  /** \brief Get the index. */
521  inline int
522  get () const
523  {
524  return (index_);
525  }
526 
527  /** \brief Set the index. */
528  inline void
529  set (const int index)
530  {
531  index_ = index;
532  }
533 
534  /** \brief Comparison operators (with boost::operators): < > <= >= */
535  inline bool
536  operator < (const Self& other) const
537  {
538  return (this->get () < other.get ());
539  }
540 
541  /** \brief Comparison operators (with boost::operators): == != */
542  inline bool
543  operator == (const Self& other) const
544  {
545  return (this->get () == other.get ());
546  }
547 
548  /** \brief Increment operators (with boost::operators): ++ (pre and post) */
549  inline Self&
551  {
552  ++index_;
553  return (*this);
554  }
555 
556  /** \brief Decrement operators (with boost::operators): \-\- (pre and post) */
557  inline Self&
559  {
560  --index_;
561  return (*this);
562  }
563 
564  /** \brief Addition operators (with boost::operators): + += */
565  inline Self&
566  operator += (const Self& other)
567  {
568  index_ += other.get ();
569  return (*this);
570  }
571 
572  /** \brief Subtraction operators (with boost::operators): - -= */
573  inline Self&
574  operator -= (const Self& other)
575  {
576  index_ -= other.get ();
577  return (*this);
578  }
579 
580  private:
581 
582  /** \brief Stored index. */
583  int index_;
584 
585  friend std::istream&
586  operator >> (std::istream& is, pcl::geometry::FaceIndex& index);
587  };
588 
589  /** \brief ostream operator. */
590  inline std::ostream&
591  operator << (std::ostream& os, const pcl::geometry::FaceIndex& index)
592  {
593  return (os << index.get ());
594  }
595 
596  /** \brief istream operator. */
597  inline std::istream&
598  operator >> (std::istream& is, pcl::geometry::FaceIndex& index)
599  {
600  return (is >> index.index_);
601  }
602 
603  } // End namespace geometry
604 } // End namespace pcl
605 
606 ////////////////////////////////////////////////////////////////////////////////
607 // Conversions
608 ////////////////////////////////////////////////////////////////////////////////
609 
610 namespace pcl
611 {
612  namespace geometry
613  {
614  /** \brief Convert the given half-edge index to an edge index. */
616  toEdgeIndex (const HalfEdgeIndex& index)
617  {
618  return (index.isValid () ? EdgeIndex (index.get () / 2) : EdgeIndex ());
619  }
620 
621  /** \brief Convert the given edge index to a half-edge 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
631 
632 #endif // PCL_GEOMETRY_MESH_INDICES_H