Point Cloud Library (PCL) 1.12.0
Loading...
Searching...
No Matches
cloud_iterator.hpp
1/*
2 * Software License Agreement (BSD License)
3 *
4 * Point Cloud Library (PCL) - www.pointclouds.org
5 * Copyright (c) 2012-, Open Perception, Inc.
6 *
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * * Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * * Redistributions in binary form must reproduce the above
16 * copyright notice, this list of conditions and the following
17 * disclaimer in the documentation and/or other materials provided
18 * with the distribution.
19 * * Neither the name of the copyright holder(s) nor the names of its
20 * contributors may be used to endorse or promote products derived
21 * 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
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 * POSSIBILITY OF SUCH DAMAGE.
35 *
36 *
37 */
38
39#ifndef PCL_POINT_CLOUD_ITERATOR_HPP_
40#define PCL_POINT_CLOUD_ITERATOR_HPP_
41
42#include <pcl/cloud_iterator.h>
43
44namespace pcl
45{
46 /** \brief
47 * \author Suat Gedikli
48 */
49 template <class PointT>
50 class DefaultIterator : public CloudIterator<PointT>::Iterator
51 {
52 public:
54 : cloud_ (cloud)
55 , iterator_ (cloud.begin ())
56 {
57 }
58
60 {
61 }
62
64 {
65 ++iterator_;
66 }
67
68 void operator ++ (int)
69 {
70 iterator_++;
71 }
72
74 {
75 return (*iterator_);
76 }
77
79 {
80 return (&(*iterator_));
81 }
82
83 unsigned getCurrentPointIndex () const
84 {
85 return (iterator_ - cloud_.begin ());
86 }
87
88 unsigned getCurrentIndex () const
89 {
90 return (iterator_ - cloud_.begin ());
91 }
92
93 std::size_t size () const
94 {
95 return cloud_.size ();
96 }
97
98 void reset ()
99 {
100 iterator_ = cloud_.begin ();
101 }
102
103 bool isValid () const
104 {
105 return (iterator_ != cloud_.end ());
106 }
107 private:
108 PointCloud<PointT>& cloud_;
109 typename PointCloud<PointT>::iterator iterator_;
110 };
111
112 /** \brief
113 * \author Suat Gedikli
114 */
115 template <class PointT>
116 class IteratorIdx : public CloudIterator<PointT>::Iterator
117 {
118 public:
119 IteratorIdx (PointCloud<PointT>& cloud, const Indices& indices)
120 : cloud_ (cloud)
121 , indices_ (indices)
122 , iterator_ (indices_.begin ())
123 {
124 }
125
127 : cloud_ (cloud)
128 , indices_ (indices.indices)
129 , iterator_ (indices_.begin ())
130 {
131 }
132
133 virtual ~IteratorIdx () {}
134
136 {
137 ++iterator_;
138 }
139
140 void operator ++ (int)
141 {
142 iterator_++;
143 }
144
146 {
147 return (cloud_.points [*iterator_]);
148 }
149
151 {
152 return (&(cloud_.points [*iterator_]));
153 }
154
155 unsigned getCurrentPointIndex () const
156 {
157 return (*iterator_);
158 }
159
160 unsigned getCurrentIndex () const
161 {
162 return (iterator_ - indices_.begin ());
163 }
164
165 std::size_t size () const
166 {
167 return indices_.size ();
168 }
169
170 void reset ()
171 {
172 iterator_ = indices_.begin ();
173 }
174
175 bool isValid () const
176 {
177 return (iterator_ != indices_.end ());
178 }
179
180 private:
181 PointCloud<PointT>& cloud_;
182 Indices indices_;
183 Indices::iterator iterator_;
184 };
185
186 /** \brief
187 * \author Suat Gedikli
188 */
189 template <class PointT>
191 {
192 public:
194 : cloud_ (cloud)
195 , iterator_ (cloud.begin ())
196 {
197 }
198
200 {
201 }
202
203 void operator ++ () override
204 {
205 ++iterator_;
206 }
207
208 void operator ++ (int) override
209 {
210 iterator_++;
211 }
212
213 const PointT& operator* () const override
214 {
215 return (*iterator_);
216 }
217
218 const PointT* operator-> () const override
219 {
220 return (&(*iterator_));
221 }
222
223 unsigned getCurrentPointIndex () const override
224 {
225 return (unsigned (iterator_ - cloud_.begin ()));
226 }
227
228 unsigned getCurrentIndex () const override
229 {
230 return (unsigned (iterator_ - cloud_.begin ()));
231 }
232
233 std::size_t size () const override
234 {
235 return cloud_.size ();
236 }
237
238 void reset () override
239 {
240 iterator_ = cloud_.begin ();
241 }
242
243 bool isValid () const override
244 {
245 return (iterator_ != cloud_.end ());
246 }
247 private:
248 const PointCloud<PointT>& cloud_;
249 typename PointCloud<PointT>::const_iterator iterator_;
250 };
251
252 /** \brief
253 * \author Suat Gedikli
254 */
255 template <class PointT>
257 {
258 public:
260 const Indices& indices)
261 : cloud_ (cloud)
262 , indices_ (indices)
263 , iterator_ (indices_.begin ())
264 {
265 }
266
268 const PointIndices& indices)
269 : cloud_ (cloud)
270 , indices_ (indices.indices)
271 , iterator_ (indices_.begin ())
272 {
273 }
274
276
277 void operator ++ () override
278 {
279 ++iterator_;
280 }
281
282 void operator ++ (int) override
283 {
284 iterator_++;
285 }
286
287 const PointT& operator* () const override
288 {
289 return (cloud_[*iterator_]);
290 }
291
292 const PointT* operator-> () const override
293 {
294 return (&(cloud_.points [*iterator_]));
295 }
296
297 unsigned getCurrentPointIndex () const override
298 {
299 return (unsigned (*iterator_));
300 }
301
302 unsigned getCurrentIndex () const override
303 {
304 return (unsigned (iterator_ - indices_.begin ()));
305 }
306
307 std::size_t size () const override
308 {
309 return indices_.size ();
310 }
311
312 void reset () override
313 {
314 iterator_ = indices_.begin ();
315 }
316
317 bool isValid () const override
318 {
319 return (iterator_ != indices_.end ());
320 }
321
322 private:
323 const PointCloud<PointT>& cloud_;
324 Indices indices_;
325 Indices::iterator iterator_;
326 };
327} // namespace pcl
328
329//////////////////////////////////////////////////////////////////////////////
330template <class PointT>
335
336//////////////////////////////////////////////////////////////////////////////
337template <class PointT>
339 PointCloud<PointT>& cloud, const Indices& indices)
340 : iterator_ (new IteratorIdx<PointT> (cloud, indices))
341{
342}
343
344//////////////////////////////////////////////////////////////////////////////
345template <class PointT>
347 PointCloud<PointT>& cloud, const PointIndices& indices)
348 : iterator_ (new IteratorIdx<PointT> (cloud, indices))
349{
350}
351
352//////////////////////////////////////////////////////////////////////////////
353template <class PointT>
355 PointCloud<PointT>& cloud, const Correspondences& corrs, bool source)
356{
357 Indices indices;
358 indices.reserve (corrs.size ());
359 if (source)
360 {
361 for (const auto &corr : corrs)
362 indices.push_back (corr.index_query);
363 }
364 else
365 {
366 for (const auto &corr : corrs)
367 indices.push_back (corr.index_match);
368 }
369 iterator_ = new IteratorIdx<PointT> (cloud, indices);
370}
371
372//////////////////////////////////////////////////////////////////////////////
373template <class PointT>
375{
376 delete iterator_;
377}
378
379//////////////////////////////////////////////////////////////////////////////
380template <class PointT> void
382{
383 iterator_->operator++ ();
384}
385
386//////////////////////////////////////////////////////////////////////////////
387template <class PointT> void
389{
390 iterator_->operator++ (0);
391}
392
393//////////////////////////////////////////////////////////////////////////////
394template <class PointT> PointT&
396{
397 return (iterator_->operator * ());
398}
399
400//////////////////////////////////////////////////////////////////////////////
401template <class PointT> PointT*
403{
404 return (iterator_->operator-> ());
405}
406
407//////////////////////////////////////////////////////////////////////////////
408template <class PointT> unsigned
410{
411 return (iterator_->getCurrentPointIndex ());
412}
413
414//////////////////////////////////////////////////////////////////////////////
415template <class PointT> unsigned
417{
418 return (iterator_->getCurrentIndex ());
419}
420
421//////////////////////////////////////////////////////////////////////////////
422template <class PointT> std::size_t
424{
425 return (iterator_->size ());
426}
427
428//////////////////////////////////////////////////////////////////////////////
429template <class PointT> void
431{
432 iterator_->reset ();
433}
434
435//////////////////////////////////////////////////////////////////////////////
436template <class PointT> bool
438{
439 return (iterator_->isValid ());
440}
441
442
443//////////////////////////////////////////////////////////////////////////////
444template <class PointT>
449
450//////////////////////////////////////////////////////////////////////////////
451template <class PointT>
453 const PointCloud<PointT>& cloud, const Indices& indices)
454 : iterator_ (new typename pcl::ConstCloudIterator<PointT>::ConstIteratorIdx (cloud, indices))
455{
456}
457
458//////////////////////////////////////////////////////////////////////////////
459template <class PointT>
461 const PointCloud<PointT>& cloud, const PointIndices& indices)
462 : iterator_ (new typename pcl::ConstCloudIterator<PointT>::ConstIteratorIdx (cloud, indices))
463{
464}
465
466//////////////////////////////////////////////////////////////////////////////
467template <class PointT>
469 const PointCloud<PointT>& cloud, const Correspondences& corrs, bool source)
470{
471 Indices indices;
472 indices.reserve (corrs.size ());
473 if (source)
474 {
475 for (const auto &corr : corrs)
476 indices.push_back (corr.index_query);
477 }
478 else
479 {
480 for (const auto &corr : corrs)
481 indices.push_back (corr.index_match);
482 }
483 iterator_ = new typename pcl::ConstCloudIterator<PointT>::ConstIteratorIdx (cloud, indices);
484}
485
486//////////////////////////////////////////////////////////////////////////////
487template <class PointT>
492
493//////////////////////////////////////////////////////////////////////////////
494template <class PointT> void
496{
497 iterator_->operator++ ();
498}
499
500//////////////////////////////////////////////////////////////////////////////
501template <class PointT> void
503{
504 iterator_->operator++ (0);
505}
506
507//////////////////////////////////////////////////////////////////////////////
508template <class PointT> const PointT&
510{
511 return (iterator_->operator * ());
512}
513
514//////////////////////////////////////////////////////////////////////////////
515template <class PointT> const PointT*
517{
518 return (iterator_->operator-> ());
519}
520
521//////////////////////////////////////////////////////////////////////////////
522template <class PointT> unsigned
524{
525 return (iterator_->getCurrentPointIndex ());
526}
527
528//////////////////////////////////////////////////////////////////////////////
529template <class PointT> unsigned
531{
532 return (iterator_->getCurrentIndex ());
533}
534
535//////////////////////////////////////////////////////////////////////////////
536template <class PointT> std::size_t
538{
539 return (iterator_->size ());
540}
541
542//////////////////////////////////////////////////////////////////////////////
543template <class PointT> void
545{
546 iterator_->reset ();
547}
548
549//////////////////////////////////////////////////////////////////////////////
550template <class PointT> bool
552{
553 return (iterator_->isValid ());
554}
555
556#endif // PCL_POINT_CLOUD_ITERATOR_HPP_
557
Iterator class for point clouds with or without given indices.
CloudIterator(PointCloud< PointT > &cloud)
unsigned getCurrentIndex() const
unsigned getCurrentPointIndex() const
std::size_t size() const
Size of the range the iterator is going through.
PointT * operator->() const
PointT & operator*() const
unsigned getCurrentPointIndex() const override
ConstIteratorIdx(const PointCloud< PointT > &cloud, const PointIndices &indices)
ConstIteratorIdx(const PointCloud< PointT > &cloud, const Indices &indices)
DefaultConstIterator(const PointCloud< PointT > &cloud)
Iterator class for point clouds with or without given indices.
const PointT * operator->() const
unsigned getCurrentIndex() const
ConstCloudIterator(const PointCloud< PointT > &cloud)
unsigned getCurrentPointIndex() const
const PointT & operator*() const
std::size_t size() const
Size of the range the iterator is going through.
std::size_t size() const
unsigned getCurrentPointIndex() const
PointT & operator*() const
unsigned getCurrentIndex() const
DefaultIterator(PointCloud< PointT > &cloud)
PointT & operator*() const
IteratorIdx(PointCloud< PointT > &cloud, const Indices &indices)
std::size_t size() const
unsigned getCurrentIndex() const
unsigned getCurrentPointIndex() const
IteratorIdx(PointCloud< PointT > &cloud, const PointIndices &indices)
PointCloud represents the base class in PCL for storing collections of 3D points.
std::vector< PointT, Eigen::aligned_allocator< PointT > > points
The point data.
std::size_t size() const
iterator begin() noexcept
typename VectorType::const_iterator const_iterator
iterator end() noexcept
typename VectorType::iterator iterator
std::vector< pcl::Correspondence, Eigen::aligned_allocator< pcl::Correspondence > > Correspondences
IndicesAllocator<> Indices
Type used for indices in PCL.
Definition types.h:133
A point structure representing Euclidean xyz coordinates, and the RGB color.