MIRA
PointCloudIterator.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) by
3  * MetraLabs GmbH (MLAB), GERMANY
4  * and
5  * Neuroinformatics and Cognitive Robotics Labs (NICR) at TU Ilmenau, GERMANY
6  * All rights reserved.
7  *
8  * Redistribution and modification of this code is strictly prohibited.
9  *
10  * IN NO EVENT SHALL "MLAB" OR "NICR" BE LIABLE TO ANY PARTY FOR DIRECT,
11  * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
12  * THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF "MLAB" OR
13  * "NICR" HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14  *
15  * "MLAB" AND "NICR" SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
16  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
17  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
18  * ON AN "AS IS" BASIS, AND "MLAB" AND "NICR" HAVE NO OBLIGATION TO
19  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS OR MODIFICATIONS.
20  */
21 
30 #ifndef _MIRA_POINTCLOUDITERATOR_H_
31 #define _MIRA_POINTCLOUDITERATOR_H_
32 
33 #include <maps/PointCloudFormat.h>
34 
35 namespace mira { namespace maps {
36 
38 
39 class GenericPointCloud;
40 
42 
43 template<typename PointType>
44 class PointCloud;
45 
47 {
48 protected:
49  friend class GenericPointCloud;
50  GenericPointCloudConstIterator(const uint8* ptr, std::size_t step) :
51  mPtr(ptr), mStep(step) {}
52 
53 public:
55  mPtr(NULL), mStep(0) {}
56 
57 public:
58 
59  bool operator==(const GenericPointCloudConstIterator& other) const {
60  return mPtr==other.mPtr;
61  }
62 
63  bool operator!=(const GenericPointCloudConstIterator& other) const {
64  return mPtr!=other.mPtr;
65  }
66 
67 public:
68 
69  void operator++() { mPtr += mStep; }
70 
71  void operator+=(std::size_t idx) { mPtr += mStep * idx; }
72 
73 public:
74 
75  template <typename T>
76  const T& get(const PCDataField& field) const {
77  assert(PCDataFieldTypeTrait<T>::type == field.type);
78  return *reinterpret_cast<const T*>(mPtr + field.offset);
79  }
80 
81 protected:
82  const uint8* mPtr;
83  std::size_t mStep;
84 };
85 
87 
89 {
90 protected:
91  friend class GenericPointCloud;
92  GenericPointCloudIterator(uint8* ptr, std::size_t step) :
94 
95 public:
97 
98 public:
99 
100  template <typename T>
101  T& get(const PCDataField& field) {
102  return const_cast<T&>(GenericPointCloudConstIterator::get<T>(field));
103  }
104 };
105 
107 
108 template <typename PointType>
110 {
111 public:
112 
113  typedef PointType value_type;
114  typedef int difference_type;
115 
116  typedef const PointType* const_pointer;
117  typedef const PointType& const_reference;
118  typedef std::random_access_iterator_tag iterator_category;
119 
120 protected:
121  friend class PointCloud<PointType>;
122  PointCloudConstIterator(const uint8* ptr, std::size_t step) :
124 
125 public:
127 
128 public:
129 
131  return *reinterpret_cast<const PointType*>(mPtr);
132  }
133 
135  return reinterpret_cast<const PointType*>(mPtr);
136  }
137 };
138 
140 
141 template <typename PointType>
143 {
144 public:
145  typedef PointType* pointer;
146  typedef PointType& reference;
147 
148 private:
150 protected:
151  friend class PointCloud<PointType>;
152  PointCloudIterator(uint8* ptr, std::size_t step) : Base(ptr,step) {}
153 
154 public:
156 
157 public:
158 
160  return const_cast<PointType&>(Base::operator*());
161  }
162 
164  return const_cast<PointType*>(Base::operator->());
165  }
166 };
167 
169 
170 }} // namespace
171 
172 #endif /* _MIRA_POINTCLOUDITERATOR_H_ */
const_pointer operator->() const
Definition: PointCloudIterator.h:134
GenericPointCloudIterator(uint8 *ptr, std::size_t step)
Definition: PointCloudIterator.h:92
PointCloudIterator()
Definition: PointCloudIterator.h:155
GenericPointCloudConstIterator(const uint8 *ptr, std::size_t step)
Definition: PointCloudIterator.h:50
const PointType & const_reference
Definition: PointCloudIterator.h:117
bool operator!=(const GenericPointCloudConstIterator &other) const
Definition: PointCloudIterator.h:63
Definition: PointCloudFormat.h:91
PointCloudConstIterator()
Definition: PointCloudIterator.h:126
bool operator==(const GenericPointCloudConstIterator &other) const
Definition: PointCloudIterator.h:59
Definition: PointCloud.h:172
PointCloudIterator(uint8 *ptr, std::size_t step)
Definition: PointCloudIterator.h:152
GenericPointCloudConstIterator()
Definition: PointCloudIterator.h:54
PointType & reference
Definition: PointCloudIterator.h:146
std::size_t mStep
Definition: PointCloudIterator.h:83
PointType * pointer
Definition: PointCloudIterator.h:145
Definition: PointCloudIterator.h:46
Definition: PointCloud.h:42
static const PCDataField::Type type
Definition: PointCloudFormat.h:91
const_reference operator*() const
Definition: PointCloudIterator.h:130
void operator++()
Definition: PointCloudIterator.h:69
void operator+=(std::size_t idx)
Definition: PointCloudIterator.h:71
uint8_t uint8
Definition: PointCloudIterator.h:142
PointType value_type
Definition: PointCloudIterator.h:113
pointer operator->()
Definition: PointCloudIterator.h:163
Definition: PointCloudIterator.h:109
Definition: PointCloudFormat.h:45
Description.
GenericPointCloudIterator()
Definition: PointCloudIterator.h:96
int difference_type
Definition: PointCloudIterator.h:114
PropertyHint step(const T &step)
Definition: PointCloudIterator.h:88
PointCloudConstIterator(const uint8 *ptr, std::size_t step)
Definition: PointCloudIterator.h:122
reference operator*()
Definition: PointCloudIterator.h:159
const PointType * const_pointer
Definition: PointCloudIterator.h:116
std::random_access_iterator_tag iterator_category
Definition: PointCloudIterator.h:118
const uint8 * mPtr
Definition: PointCloudIterator.h:82