Point Cloud Library (PCL)  1.9.1
cloud_iterator.h
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_H_
40 #define PCL_POINT_CLOUD_ITERATOR_H_
41 
42 #include <pcl/point_cloud.h>
43 #include <pcl/PointIndices.h>
44 #include <pcl/correspondence.h>
45 
46 namespace pcl
47 {
48  /** \brief Iterator class for point clouds with or without given indices
49  * \author Suat Gedikli
50  */
51  template <typename PointT>
53  {
54  public:
56 
57  CloudIterator (PointCloud<PointT>& cloud, const std::vector<int>& indices);
58 
59  CloudIterator (PointCloud<PointT>& cloud, const PointIndices& indices);
60 
61  CloudIterator (PointCloud<PointT>& cloud, const Correspondences& corrs, bool source);
62 
63  ~CloudIterator ();
64 
65  void operator ++ ();
66 
67  void operator ++ (int);
68 
69  PointT& operator* () const;
70 
71  PointT* operator-> () const;
72 
73  unsigned getCurrentPointIndex () const;
74 
75  unsigned getCurrentIndex () const;
76 
77  /** \brief Size of the range the iterator is going through. Depending on how the CloudIterator was constructed this is the size of the cloud or indices/correspondences. */
78  size_t size () const;
79 
80  void reset ();
81 
82  bool isValid () const;
83 
84  operator bool () const
85  {
86  return isValid ();
87  }
88  private:
89 
90  class Iterator
91  {
92  public:
93  virtual ~Iterator () {}
94 
95  virtual void operator ++ () = 0;
96 
97  virtual void operator ++ (int) = 0;
98 
99  virtual PointT& operator* () const = 0;
100 
101  virtual PointT* operator-> () const = 0;
102 
103  virtual unsigned getCurrentPointIndex () const = 0;
104 
105  virtual unsigned getCurrentIndex () const = 0;
106 
107  /** \brief Size of the range the iterator is going through. Depending on how the CloudIterator was constructed this is the size of the cloud or indices/correspondences. */
108  virtual size_t size () const = 0;
109 
110  virtual void reset () = 0;
111 
112  virtual bool isValid () const = 0;
113  };
114  Iterator* iterator_;
115  };
116 
117  /** \brief Iterator class for point clouds with or without given indices
118  * \author Suat Gedikli
119  */
120  template <typename PointT>
122  {
123  public:
124  ConstCloudIterator (const PointCloud<PointT>& cloud);
125 
126  ConstCloudIterator (const PointCloud<PointT>& cloud, const std::vector<int>& indices);
127 
128  ConstCloudIterator (const PointCloud<PointT>& cloud, const PointIndices& indices);
129 
130  ConstCloudIterator (const PointCloud<PointT>& cloud, const Correspondences& corrs, bool source);
131 
133 
134  void operator ++ ();
135 
136  void operator ++ (int);
137 
138  const PointT& operator* () const;
139 
140  const PointT* operator-> () const;
141 
142  unsigned getCurrentPointIndex () const;
143 
144  unsigned getCurrentIndex () const;
145 
146  /** \brief Size of the range the iterator is going through. Depending on how the ConstCloudIterator was constructed this is the size of the cloud or indices/correspondences. */
147  size_t size () const;
148 
149  void reset ();
150 
151  bool isValid () const;
152 
153  operator bool () const
154  {
155  return isValid ();
156  }
157  private:
158 
159  class Iterator
160  {
161  public:
162  virtual ~Iterator () {}
163 
164  virtual void operator ++ () = 0;
165 
166  virtual void operator ++ (int) = 0;
167 
168  virtual const PointT& operator* () const = 0;
169 
170  virtual const PointT* operator-> () const = 0;
171 
172  virtual unsigned getCurrentPointIndex () const = 0;
173 
174  virtual unsigned getCurrentIndex () const = 0;
175 
176  /** \brief Size of the range the iterator is going through. Depending on how the ConstCloudIterator was constructed this is the size of the cloud or indices/correspondences. */
177  virtual size_t size () const = 0;
178 
179  virtual void reset () = 0;
180 
181  virtual bool isValid () const = 0;
182  };
183 
184  class DefaultConstIterator;
185  class ConstIteratorIdx;
186  Iterator* iterator_;
187  };
188 
189 } // namespace pcl
190 
191 #include <pcl/impl/cloud_iterator.hpp>
192 
193 #endif // PCL_POINT_CLOUD_ITERATOR_H_
CloudIterator(PointCloud< PointT > &cloud)
unsigned getCurrentIndex() const
const PointT & operator*() const
Iterator class for point clouds with or without given indices.
Iterator class for point clouds with or without given indices.
This file defines compatibility wrappers for low level I/O functions.
Definition: convolution.h:45
const PointT * operator->() const
PointT & operator*() const
size_t size() const
Size of the range the iterator is going through.
unsigned getCurrentPointIndex() const
PointT * operator->() const
std::vector< pcl::Correspondence, Eigen::aligned_allocator< pcl::Correspondence > > Correspondences
size_t size() const
Size of the range the iterator is going through.
PointCloud represents the base class in PCL for storing collections of 3D points.
A point structure representing Euclidean xyz coordinates, and the RGB color.
ConstCloudIterator(const PointCloud< PointT > &cloud)
unsigned getCurrentIndex() const
unsigned getCurrentPointIndex() const