cloud_iterator.hpp
/*
* Software License Agreement (BSD License)
*
* Point Cloud Library (PCL) - www.pointclouds.org
* Copyright (c) 2012-, Open Perception, Inc.
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of the copyright holder(s) nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*
*/
#ifndef PCL_POINT_CLOUD_ITERATOR_HPP_
#define PCL_POINT_CLOUD_ITERATOR_HPP_
#include <pcl/cloud_iterator.h>
namespace pcl
{
/** \brief
* \author Suat Gedikli
*/
template <class PointT>
class DefaultIterator : public CloudIterator<PointT>::Iterator
{
public:
DefaultIterator (PointCloud<PointT>& cloud)
: cloud_ (cloud)
, iterator_ (cloud.begin ())
{
}
~DefaultIterator ()
{
}
void operator ++ ()
{
++iterator_;
}
void operator ++ (int)
{
iterator_++;
}
PointT& operator* () const
{
return (*iterator_);
}
PointT* operator-> ()
{
return (&(*iterator_));
}
unsigned getCurrentPointIndex () const
{
return (iterator_ - cloud_.begin ());
}
unsigned getCurrentIndex () const
{
return (iterator_ - cloud_.begin ());
}
std::size_t size () const
{
return cloud_.size ();
}
void reset ()
{
iterator_ = cloud_.begin ();
}
bool isValid () const
{
return (iterator_ != cloud_.end ());
}
private:
PointCloud<PointT>& cloud_;
typename PointCloud<PointT>::iterator iterator_;
};
/** \brief
* \author Suat Gedikli
*/
template <class PointT>
class IteratorIdx : public CloudIterator<PointT>::Iterator
{
public:
IteratorIdx (PointCloud<PointT>& cloud, const Indices& indices)
: cloud_ (cloud)
, indices_ (indices)
, iterator_ (indices_.begin ())
{
}
IteratorIdx (PointCloud<PointT>& cloud, const PointIndices& indices)
: cloud_ (cloud)
, indices_ (indices.indices)
, iterator_ (indices_.begin ())
{
}
virtual ~IteratorIdx () {}
void operator ++ ()
{
++iterator_;
}
void operator ++ (int)
{
iterator_++;
}
PointT& operator* () const
{
return (cloud_.points [*iterator_]);
}
PointT* operator-> ()
{
return (&(cloud_.points [*iterator_]));
}
unsigned getCurrentPointIndex () const
{
return (*iterator_);
}
unsigned getCurrentIndex () const
{
return (iterator_ - indices_.begin ());
}
std::size_t size () const
{
return indices_.size ();
}
void reset ()
{
iterator_ = indices_.begin ();
}
bool isValid () const
{
return (iterator_ != indices_.end ());
}
private:
PointCloud<PointT>& cloud_;
Indices indices_;
Indices::iterator iterator_;
};
/** \brief
* \author Suat Gedikli
*/
template <class PointT>
class ConstCloudIterator<PointT>::DefaultConstIterator : public ConstCloudIterator<PointT>::Iterator
{
public:
DefaultConstIterator (const PointCloud<PointT>& cloud)
: cloud_ (cloud)
, iterator_ (cloud.begin ())
{
}
~DefaultConstIterator ()
{
}
void operator ++ () override
{
++iterator_;
}
void operator ++ (int) override
{
iterator_++;
}
const PointT& operator* () const override
{
return (*iterator_);
}
const PointT* operator-> () const override
{
return (&(*iterator_));
}
unsigned getCurrentPointIndex () const override
{
return (unsigned (iterator_ - cloud_.begin ()));
}
unsigned getCurrentIndex () const override
{
return (unsigned (iterator_ - cloud_.begin ()));
}
std::size_t size () const override
{
return cloud_.size ();
}
void reset () override
{
iterator_ = cloud_.begin ();
}
bool isValid () const override
{
return (iterator_ != cloud_.end ());
}
private:
const PointCloud<PointT>& cloud_;
typename PointCloud<PointT>::const_iterator iterator_;
};
/** \brief
* \author Suat Gedikli
*/
template <class PointT>
class ConstCloudIterator<PointT>::ConstIteratorIdx : public ConstCloudIterator<PointT>::Iterator
{
public:
ConstIteratorIdx (const PointCloud<PointT>& cloud,
const Indices& indices)
: cloud_ (cloud)
, indices_ (indices)
, iterator_ (indices_.begin ())
{
}
ConstIteratorIdx (const PointCloud<PointT>& cloud,
const PointIndices& indices)
: cloud_ (cloud)
, indices_ (indices.indices)
, iterator_ (indices_.begin ())
{
}
~ConstIteratorIdx () {}
void operator ++ () override
{
++iterator_;
}
void operator ++ (int) override
{
iterator_++;
}
const PointT& operator* () const override
{
return (cloud_[*iterator_]);
}
const PointT* operator-> () const override
{
return (&(cloud_.points [*iterator_]));
}
unsigned getCurrentPointIndex () const override
{
return (unsigned (*iterator_));
}
unsigned getCurrentIndex () const override
{
return (unsigned (iterator_ - indices_.begin ()));
}
std::size_t size () const override
{
return indices_.size ();
}
void reset () override
{
iterator_ = indices_.begin ();
}
bool isValid () const override
{
return (iterator_ != indices_.end ());
}
private:
const PointCloud<PointT>& cloud_;
Indices indices_;
Indices::iterator iterator_;
};
} // namespace pcl
//////////////////////////////////////////////////////////////////////////////
template <class PointT>
pcl::CloudIterator<PointT>::CloudIterator (PointCloud<PointT>& cloud)
: iterator_ (new DefaultIterator<PointT> (cloud))
{
}
//////////////////////////////////////////////////////////////////////////////
template <class PointT>
pcl::CloudIterator<PointT>::CloudIterator (
PointCloud<PointT>& cloud, const Indices& indices)
: iterator_ (new IteratorIdx<PointT> (cloud, indices))
{
}
//////////////////////////////////////////////////////////////////////////////
template <class PointT>
pcl::CloudIterator<PointT>::CloudIterator (
PointCloud<PointT>& cloud, const PointIndices& indices)
: iterator_ (new IteratorIdx<PointT> (cloud, indices))
{
}
//////////////////////////////////////////////////////////////////////////////
template <class PointT>
pcl::CloudIterator<PointT>::CloudIterator (
PointCloud<PointT>& cloud, const Correspondences& corrs, bool source)
{
Indices indices;
indices.reserve (corrs.size ());
if (source)
{
for (const auto &corr : corrs)
indices.push_back (corr.index_query);
}
else
{
for (const auto &corr : corrs)
indices.push_back (corr.index_match);
}
iterator_ = new IteratorIdx<PointT> (cloud, indices);
}
//////////////////////////////////////////////////////////////////////////////
template <class PointT>
pcl::CloudIterator<PointT>::~CloudIterator ()
{
delete iterator_;
}
//////////////////////////////////////////////////////////////////////////////
template <class PointT> void
pcl::CloudIterator<PointT>::operator ++ ()
{
iterator_->operator++ ();
}
//////////////////////////////////////////////////////////////////////////////
template <class PointT> void
pcl::CloudIterator<PointT>::operator ++ (int)
{
iterator_->operator++ (0);
}
//////////////////////////////////////////////////////////////////////////////
template <class PointT> PointT&
pcl::CloudIterator<PointT>::operator* () const
{
return (iterator_->operator * ());
}
//////////////////////////////////////////////////////////////////////////////
template <class PointT> PointT*
pcl::CloudIterator<PointT>::operator-> () const
{
return (iterator_->operator-> ());
}
//////////////////////////////////////////////////////////////////////////////
template <class PointT> unsigned
pcl::CloudIterator<PointT>::getCurrentPointIndex () const
{
return (iterator_->getCurrentPointIndex ());
}
//////////////////////////////////////////////////////////////////////////////
template <class PointT> unsigned
pcl::CloudIterator<PointT>::getCurrentIndex () const
{
return (iterator_->getCurrentIndex ());
}
//////////////////////////////////////////////////////////////////////////////
template <class PointT> std::size_t
pcl::CloudIterator<PointT>::size () const
{
return (iterator_->size ());
}
//////////////////////////////////////////////////////////////////////////////
template <class PointT> void
pcl::CloudIterator<PointT>::reset ()
{
iterator_->reset ();
}
//////////////////////////////////////////////////////////////////////////////
template <class PointT> bool
pcl::CloudIterator<PointT>::isValid () const
{
return (iterator_->isValid ());
}
//////////////////////////////////////////////////////////////////////////////
template <class PointT>
pcl::ConstCloudIterator<PointT>::ConstCloudIterator (const PointCloud<PointT>& cloud)
: iterator_ (new typename pcl::ConstCloudIterator<PointT>::DefaultConstIterator (cloud))
{
}
//////////////////////////////////////////////////////////////////////////////
template <class PointT>
pcl::ConstCloudIterator<PointT>::ConstCloudIterator (
const PointCloud<PointT>& cloud, const Indices& indices)
: iterator_ (new typename pcl::ConstCloudIterator<PointT>::ConstIteratorIdx (cloud, indices))
{
}
//////////////////////////////////////////////////////////////////////////////
template <class PointT>
pcl::ConstCloudIterator<PointT>::ConstCloudIterator (
const PointCloud<PointT>& cloud, const PointIndices& indices)
: iterator_ (new typename pcl::ConstCloudIterator<PointT>::ConstIteratorIdx (cloud, indices))
{
}
//////////////////////////////////////////////////////////////////////////////
template <class PointT>
pcl::ConstCloudIterator<PointT>::ConstCloudIterator (
const PointCloud<PointT>& cloud, const Correspondences& corrs, bool source)
{
Indices indices;
indices.reserve (corrs.size ());
if (source)
{
for (const auto &corr : corrs)
indices.push_back (corr.index_query);
}
else
{
for (const auto &corr : corrs)
indices.push_back (corr.index_match);
}
iterator_ = new typename pcl::ConstCloudIterator<PointT>::ConstIteratorIdx (cloud, indices);
}
//////////////////////////////////////////////////////////////////////////////
template <class PointT>
pcl::ConstCloudIterator<PointT>::~ConstCloudIterator ()
{
delete iterator_;
}
//////////////////////////////////////////////////////////////////////////////
template <class PointT> void
pcl::ConstCloudIterator<PointT>::operator ++ ()
{
iterator_->operator++ ();
}
//////////////////////////////////////////////////////////////////////////////
template <class PointT> void
pcl::ConstCloudIterator<PointT>::operator ++ (int)
{
iterator_->operator++ (0);
}
//////////////////////////////////////////////////////////////////////////////
template <class PointT> const PointT&
pcl::ConstCloudIterator<PointT>::operator* () const
{
return (iterator_->operator * ());
}
//////////////////////////////////////////////////////////////////////////////
template <class PointT> const PointT*
pcl::ConstCloudIterator<PointT>::operator-> () const
{
return (iterator_->operator-> ());
}
//////////////////////////////////////////////////////////////////////////////
template <class PointT> unsigned
pcl::ConstCloudIterator<PointT>::getCurrentPointIndex () const
{
return (iterator_->getCurrentPointIndex ());
}
//////////////////////////////////////////////////////////////////////////////
template <class PointT> unsigned
pcl::ConstCloudIterator<PointT>::getCurrentIndex () const
{
return (iterator_->getCurrentIndex ());
}
//////////////////////////////////////////////////////////////////////////////
template <class PointT> std::size_t
pcl::ConstCloudIterator<PointT>::size () const
{
return (iterator_->size ());
}
//////////////////////////////////////////////////////////////////////////////
template <class PointT> void
pcl::ConstCloudIterator<PointT>::reset ()
{
iterator_->reset ();
}
//////////////////////////////////////////////////////////////////////////////
template <class PointT> bool
pcl::ConstCloudIterator<PointT>::isValid () const
{
return (iterator_->isValid ());
}
#endif // PCL_POINT_CLOUD_ITERATOR_HPP_
pcl::CloudIterator
Iterator class for point clouds with or without given indices.
Definition: cloud_iterator.h:52
pcl::CloudIterator::CloudIterator
CloudIterator(PointCloud< PointT > &cloud)
Definition: cloud_iterator.hpp:331
pcl::CloudIterator::reset
void reset()
Definition: cloud_iterator.hpp:430
pcl::CloudIterator::getCurrentIndex
unsigned getCurrentIndex() const
Definition: cloud_iterator.hpp:416
pcl::CloudIterator::operator++
void operator++()
Definition: cloud_iterator.hpp:381
pcl::CloudIterator::getCurrentPointIndex
unsigned getCurrentPointIndex() const
Definition: cloud_iterator.hpp:409
pcl::CloudIterator::~CloudIterator
~CloudIterator()
Definition: cloud_iterator.hpp:374
pcl::CloudIterator::isValid
bool isValid() const
Definition: cloud_iterator.hpp:437
pcl::CloudIterator::size
std::size_t size() const
Size of the range the iterator is going through.
Definition: cloud_iterator.hpp:423
pcl::CloudIterator::operator->
PointT * operator->() const
Definition: cloud_iterator.hpp:402
pcl::CloudIterator::operator*
PointT & operator*() const
Definition: cloud_iterator.hpp:395
pcl::ConstCloudIterator::ConstIteratorIdx
Definition: cloud_iterator.hpp:257
pcl::ConstCloudIterator::ConstIteratorIdx::getCurrentPointIndex
unsigned getCurrentPointIndex() const override
Definition: cloud_iterator.hpp:297
pcl::ConstCloudIterator::ConstIteratorIdx::ConstIteratorIdx
ConstIteratorIdx(const PointCloud< PointT > &cloud, const PointIndices &indices)
Definition: cloud_iterator.hpp:267
pcl::ConstCloudIterator::ConstIteratorIdx::isValid
bool isValid() const override
Definition: cloud_iterator.hpp:317
pcl::ConstCloudIterator::ConstIteratorIdx::reset
void reset() override
Definition: cloud_iterator.hpp:312
pcl::ConstCloudIterator::ConstIteratorIdx::~ConstIteratorIdx
~ConstIteratorIdx()
Definition: cloud_iterator.hpp:275
pcl::ConstCloudIterator::ConstIteratorIdx::size
std::size_t size() const override
Definition: cloud_iterator.hpp:307
pcl::ConstCloudIterator::ConstIteratorIdx::ConstIteratorIdx
ConstIteratorIdx(const PointCloud< PointT > &cloud, const Indices &indices)
Definition: cloud_iterator.hpp:259
pcl::ConstCloudIterator::ConstIteratorIdx::getCurrentIndex
unsigned getCurrentIndex() const override
Definition: cloud_iterator.hpp:302
pcl::ConstCloudIterator::DefaultConstIterator
Definition: cloud_iterator.hpp:191
pcl::ConstCloudIterator::DefaultConstIterator::DefaultConstIterator
DefaultConstIterator(const PointCloud< PointT > &cloud)
Definition: cloud_iterator.hpp:193
pcl::ConstCloudIterator::DefaultConstIterator::isValid
bool isValid() const override
Definition: cloud_iterator.hpp:243
pcl::ConstCloudIterator::DefaultConstIterator::~DefaultConstIterator
~DefaultConstIterator()
Definition: cloud_iterator.hpp:199
pcl::ConstCloudIterator::DefaultConstIterator::size
std::size_t size() const override
Definition: cloud_iterator.hpp:233
pcl::ConstCloudIterator::DefaultConstIterator::getCurrentPointIndex
unsigned getCurrentPointIndex() const override
Definition: cloud_iterator.hpp:223
pcl::ConstCloudIterator::DefaultConstIterator::reset
void reset() override
Definition: cloud_iterator.hpp:238
pcl::ConstCloudIterator::DefaultConstIterator::getCurrentIndex
unsigned getCurrentIndex() const override
Definition: cloud_iterator.hpp:228
pcl::ConstCloudIterator
Iterator class for point clouds with or without given indices.
Definition: cloud_iterator.h:121
pcl::ConstCloudIterator::~ConstCloudIterator
~ConstCloudIterator()
Definition: cloud_iterator.hpp:488
pcl::ConstCloudIterator::operator->
const PointT * operator->() const
Definition: cloud_iterator.hpp:516
pcl::ConstCloudIterator::getCurrentIndex
unsigned getCurrentIndex() const
Definition: cloud_iterator.hpp:530
pcl::ConstCloudIterator::ConstCloudIterator
ConstCloudIterator(const PointCloud< PointT > &cloud)
Definition: cloud_iterator.hpp:445
pcl::ConstCloudIterator::isValid
bool isValid() const
Definition: cloud_iterator.hpp:551
pcl::ConstCloudIterator::getCurrentPointIndex
unsigned getCurrentPointIndex() const
Definition: cloud_iterator.hpp:523
pcl::ConstCloudIterator::operator++
void operator++()
Definition: cloud_iterator.hpp:495
pcl::ConstCloudIterator::operator*
const PointT & operator*() const
Definition: cloud_iterator.hpp:509
pcl::ConstCloudIterator::reset
void reset()
Definition: cloud_iterator.hpp:544
pcl::ConstCloudIterator::size
std::size_t size() const
Size of the range the iterator is going through.
Definition: cloud_iterator.hpp:537
pcl::DefaultIterator
Definition: cloud_iterator.hpp:51
pcl::DefaultIterator::size
std::size_t size() const
Definition: cloud_iterator.hpp:93
pcl::DefaultIterator::getCurrentPointIndex
unsigned getCurrentPointIndex() const
Definition: cloud_iterator.hpp:83
pcl::DefaultIterator::operator*
PointT & operator*() const
Definition: cloud_iterator.hpp:73
pcl::DefaultIterator::operator++
void operator++()
Definition: cloud_iterator.hpp:63
pcl::DefaultIterator::getCurrentIndex
unsigned getCurrentIndex() const
Definition: cloud_iterator.hpp:88
pcl::DefaultIterator::reset
void reset()
Definition: cloud_iterator.hpp:98
pcl::DefaultIterator::DefaultIterator
DefaultIterator(PointCloud< PointT > &cloud)
Definition: cloud_iterator.hpp:53
pcl::DefaultIterator::isValid
bool isValid() const
Definition: cloud_iterator.hpp:103
pcl::DefaultIterator::operator->
PointT * operator->()
Definition: cloud_iterator.hpp:78
pcl::DefaultIterator::~DefaultIterator
~DefaultIterator()
Definition: cloud_iterator.hpp:59
pcl::IteratorIdx
Definition: cloud_iterator.hpp:117
pcl::IteratorIdx::IteratorIdx
IteratorIdx(PointCloud< PointT > &cloud, const Indices &indices)
Definition: cloud_iterator.hpp:119
pcl::IteratorIdx::operator++
void operator++()
Definition: cloud_iterator.hpp:135
pcl::IteratorIdx::size
std::size_t size() const
Definition: cloud_iterator.hpp:165
pcl::IteratorIdx::getCurrentIndex
unsigned getCurrentIndex() const
Definition: cloud_iterator.hpp:160
pcl::IteratorIdx::operator*
PointT & operator*() const
Definition: cloud_iterator.hpp:145
pcl::IteratorIdx::operator->
PointT * operator->()
Definition: cloud_iterator.hpp:150
pcl::IteratorIdx::getCurrentPointIndex
unsigned getCurrentPointIndex() const
Definition: cloud_iterator.hpp:155
pcl::IteratorIdx::IteratorIdx
IteratorIdx(PointCloud< PointT > &cloud, const PointIndices &indices)
Definition: cloud_iterator.hpp:126
pcl::IteratorIdx::isValid
bool isValid() const
Definition: cloud_iterator.hpp:175
pcl::IteratorIdx::~IteratorIdx
virtual ~IteratorIdx()
Definition: cloud_iterator.hpp:133
pcl::IteratorIdx::reset
void reset()
Definition: cloud_iterator.hpp:170
pcl::PointCloud
PointCloud represents the base class in PCL for storing collections of 3D points.
Definition: point_cloud.h:173
pcl::PointCloud::iterator
typename VectorType::iterator iterator
Definition: point_cloud.h:425
pcl::PointCloud::const_iterator
typename VectorType::const_iterator const_iterator
Definition: point_cloud.h:426
pcl
Definition: convolution.h:46
pcl::Correspondences
std::vector< pcl::Correspondence, Eigen::aligned_allocator< pcl::Correspondence > > Correspondences
Definition: correspondence.h:89
pcl::Indices
IndicesAllocator<> Indices
Type used for indices in PCL.
Definition: types.h:133
pcl::PointIndices
Definition: PointIndices.h:12
pcl::PointXYZRGB
A point structure representing Euclidean xyz coordinates, and the RGB color.
Definition: point_types.hpp:675