/* * 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 namespace pcl { /** \brief * \author Suat Gedikli */ template class DefaultIterator : public CloudIterator::Iterator { public: DefaultIterator (PointCloud& 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& cloud_; typename PointCloud::iterator iterator_; }; /** \brief * \author Suat Gedikli */ template class IteratorIdx : public CloudIterator::Iterator { public: IteratorIdx (PointCloud& cloud, const Indices& indices) : cloud_ (cloud) , indices_ (indices) , iterator_ (indices_.begin ()) { } IteratorIdx (PointCloud& 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& cloud_; Indices indices_; Indices::iterator iterator_; }; /** \brief * \author Suat Gedikli */ template class ConstCloudIterator::DefaultConstIterator : public ConstCloudIterator::Iterator { public: DefaultConstIterator (const PointCloud& 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& cloud_; typename PointCloud::const_iterator iterator_; }; /** \brief * \author Suat Gedikli */ template class ConstCloudIterator::ConstIteratorIdx : public ConstCloudIterator::Iterator { public: ConstIteratorIdx (const PointCloud& cloud, const Indices& indices) : cloud_ (cloud) , indices_ (indices) , iterator_ (indices_.begin ()) { } ConstIteratorIdx (const PointCloud& 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& cloud_; Indices indices_; Indices::iterator iterator_; }; } // namespace pcl ////////////////////////////////////////////////////////////////////////////// template pcl::CloudIterator::CloudIterator (PointCloud& cloud) : iterator_ (new DefaultIterator (cloud)) { } ////////////////////////////////////////////////////////////////////////////// template pcl::CloudIterator::CloudIterator ( PointCloud& cloud, const Indices& indices) : iterator_ (new IteratorIdx (cloud, indices)) { } ////////////////////////////////////////////////////////////////////////////// template pcl::CloudIterator::CloudIterator ( PointCloud& cloud, const PointIndices& indices) : iterator_ (new IteratorIdx (cloud, indices)) { } ////////////////////////////////////////////////////////////////////////////// template pcl::CloudIterator::CloudIterator ( PointCloud& 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 (cloud, indices); } ////////////////////////////////////////////////////////////////////////////// template pcl::CloudIterator::~CloudIterator () { delete iterator_; } ////////////////////////////////////////////////////////////////////////////// template void pcl::CloudIterator::operator ++ () { iterator_->operator++ (); } ////////////////////////////////////////////////////////////////////////////// template void pcl::CloudIterator::operator ++ (int) { iterator_->operator++ (0); } ////////////////////////////////////////////////////////////////////////////// template PointT& pcl::CloudIterator::operator* () const { return (iterator_->operator * ()); } ////////////////////////////////////////////////////////////////////////////// template PointT* pcl::CloudIterator::operator-> () const { return (iterator_->operator-> ()); } ////////////////////////////////////////////////////////////////////////////// template unsigned pcl::CloudIterator::getCurrentPointIndex () const { return (iterator_->getCurrentPointIndex ()); } ////////////////////////////////////////////////////////////////////////////// template unsigned pcl::CloudIterator::getCurrentIndex () const { return (iterator_->getCurrentIndex ()); } ////////////////////////////////////////////////////////////////////////////// template std::size_t pcl::CloudIterator::size () const { return (iterator_->size ()); } ////////////////////////////////////////////////////////////////////////////// template void pcl::CloudIterator::reset () { iterator_->reset (); } ////////////////////////////////////////////////////////////////////////////// template bool pcl::CloudIterator::isValid () const { return (iterator_->isValid ()); } ////////////////////////////////////////////////////////////////////////////// template pcl::ConstCloudIterator::ConstCloudIterator (const PointCloud& cloud) : iterator_ (new typename pcl::ConstCloudIterator::DefaultConstIterator (cloud)) { } ////////////////////////////////////////////////////////////////////////////// template pcl::ConstCloudIterator::ConstCloudIterator ( const PointCloud& cloud, const Indices& indices) : iterator_ (new typename pcl::ConstCloudIterator::ConstIteratorIdx (cloud, indices)) { } ////////////////////////////////////////////////////////////////////////////// template pcl::ConstCloudIterator::ConstCloudIterator ( const PointCloud& cloud, const PointIndices& indices) : iterator_ (new typename pcl::ConstCloudIterator::ConstIteratorIdx (cloud, indices)) { } ////////////////////////////////////////////////////////////////////////////// template pcl::ConstCloudIterator::ConstCloudIterator ( const PointCloud& 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::ConstIteratorIdx (cloud, indices); } ////////////////////////////////////////////////////////////////////////////// template pcl::ConstCloudIterator::~ConstCloudIterator () { delete iterator_; } ////////////////////////////////////////////////////////////////////////////// template void pcl::ConstCloudIterator::operator ++ () { iterator_->operator++ (); } ////////////////////////////////////////////////////////////////////////////// template void pcl::ConstCloudIterator::operator ++ (int) { iterator_->operator++ (0); } ////////////////////////////////////////////////////////////////////////////// template const PointT& pcl::ConstCloudIterator::operator* () const { return (iterator_->operator * ()); } ////////////////////////////////////////////////////////////////////////////// template const PointT* pcl::ConstCloudIterator::operator-> () const { return (iterator_->operator-> ()); } ////////////////////////////////////////////////////////////////////////////// template unsigned pcl::ConstCloudIterator::getCurrentPointIndex () const { return (iterator_->getCurrentPointIndex ()); } ////////////////////////////////////////////////////////////////////////////// template unsigned pcl::ConstCloudIterator::getCurrentIndex () const { return (iterator_->getCurrentIndex ()); } ////////////////////////////////////////////////////////////////////////////// template std::size_t pcl::ConstCloudIterator::size () const { return (iterator_->size ()); } ////////////////////////////////////////////////////////////////////////////// template void pcl::ConstCloudIterator::reset () { iterator_->reset (); } ////////////////////////////////////////////////////////////////////////////// template bool pcl::ConstCloudIterator::isValid () const { return (iterator_->isValid ()); } #endif // PCL_POINT_CLOUD_ITERATOR_HPP_