octree_pointcloud_voxelcentroid.h
/*
* Software License Agreement (BSD License)
*
* Point Cloud Library (PCL) - www.pointclouds.org
* Copyright (c) 2010-2011, Willow Garage, Inc.
* 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.
*
* $Id$
*/
#pragma once
#include <pcl/octree/octree_pointcloud.h>
namespace pcl
{
namespace octree
{
/** \brief @b Octree pointcloud voxel centroid leaf node class
* \note This class implements a leaf node that calculates the mean centroid of all points added this octree container.
* \author Julius Kammerl (julius@kammerl.de)
*/
template<typename PointT>
class OctreePointCloudVoxelCentroidContainer : public OctreeContainerBase
{
public:
/** \brief Class initialization. */
OctreePointCloudVoxelCentroidContainer ()
{
this->reset();
}
/** \brief Empty class deconstructor. */
~OctreePointCloudVoxelCentroidContainer ()
{
}
/** \brief deep copy function */
virtual OctreePointCloudVoxelCentroidContainer *
deepCopy () const
{
return (new OctreePointCloudVoxelCentroidContainer (*this));
}
/** \brief Equal comparison operator - set to false
*/
// param[in] OctreePointCloudVoxelCentroidContainer to compare with
bool operator==(const OctreeContainerBase&) const override
{
return ( false );
}
/** \brief Add new point to voxel.
* \param[in] new_point the new point to add
*/
void
addPoint (const PointT& new_point)
{
using namespace pcl::common;
++point_counter_;
point_sum_ += new_point;
}
/** \brief Calculate centroid of voxel.
* \param[out] centroid_arg the resultant centroid of the voxel
*/
void
getCentroid (PointT& centroid_arg) const
{
using namespace pcl::common;
if (point_counter_)
{
centroid_arg = point_sum_;
centroid_arg /= static_cast<float> (point_counter_);
}
else
{
centroid_arg *= 0.0f;
}
}
/** \brief Reset leaf container. */
void
reset () override
{
using namespace pcl::common;
point_counter_ = 0;
point_sum_ *= 0.0f;
}
private:
unsigned int point_counter_;
PointT point_sum_;
};
/** \brief @b Octree pointcloud voxel centroid class
* \note This class generate an octrees from a point cloud (zero-copy). It provides a vector of centroids for all occupied voxels.
* \note The octree pointcloud is initialized with its voxel resolution. Its bounding box is automatically adjusted or can be predefined.
* \note
* \note typename: PointT: type of point used in pointcloud
*
* \ingroup octree
* \author Julius Kammerl (julius@kammerl.de)
*/
template<typename PointT,
typename LeafContainerT = OctreePointCloudVoxelCentroidContainer<PointT> ,
typename BranchContainerT = OctreeContainerEmpty >
class OctreePointCloudVoxelCentroid : public OctreePointCloud<PointT, LeafContainerT, BranchContainerT>
{
public:
using Ptr = shared_ptr<OctreePointCloudVoxelCentroid<PointT, LeafContainerT> >;
using ConstPtr = shared_ptr<const OctreePointCloudVoxelCentroid<PointT, LeafContainerT> >;
using OctreeT = OctreePointCloud<PointT, LeafContainerT, BranchContainerT>;
using LeafNode = typename OctreeT::LeafNode;
using BranchNode = typename OctreeT::BranchNode;
/** \brief OctreePointCloudVoxelCentroids class constructor.
* \param[in] resolution_arg octree resolution at lowest octree level
*/
OctreePointCloudVoxelCentroid (const double resolution_arg) :
OctreePointCloud<PointT, LeafContainerT, BranchContainerT> (resolution_arg)
{
}
/** \brief Empty class deconstructor. */
~OctreePointCloudVoxelCentroid ()
{
}
/** \brief Add DataT object to leaf node at octree key.
* \param pointIdx_arg
*/
void
addPointIdx (const int pointIdx_arg) override
{
OctreeKey key;
assert (pointIdx_arg < static_cast<int> (this->input_->points.size ()));
const PointT& point = this->input_->points[pointIdx_arg];
// make sure bounding box is big enough
this->adoptBoundingBoxToPoint (point);
// generate key
this->genOctreeKeyforPoint (point, key);
// add point to octree at key
LeafContainerT* container = this->createLeaf(key);
container->addPoint (point);
}
/** \brief Get centroid for a single voxel addressed by a PointT point.
* \param[in] point_arg point addressing a voxel in octree
* \param[out] voxel_centroid_arg centroid is written to this PointT reference
* \return "true" if voxel is found; "false" otherwise
*/
bool
getVoxelCentroidAtPoint (const PointT& point_arg, PointT& voxel_centroid_arg) const;
/** \brief Get centroid for a single voxel addressed by a PointT point from input cloud.
* \param[in] point_idx_arg point index from input cloud addressing a voxel in octree
* \param[out] voxel_centroid_arg centroid is written to this PointT reference
* \return "true" if voxel is found; "false" otherwise
*/
inline bool
getVoxelCentroidAtPoint (const int& point_idx_arg, PointT& voxel_centroid_arg) const
{
// get centroid at point
return (this->getVoxelCentroidAtPoint (this->input_->points[point_idx_arg], voxel_centroid_arg));
}
/** \brief Get PointT vector of centroids for all occupied voxels.
* \param[out] voxel_centroid_list_arg results are written to this vector of PointT elements
* \return number of occupied voxels
*/
std::size_t
getVoxelCentroids (typename OctreePointCloud<PointT, LeafContainerT, BranchContainerT>::AlignedPointTVector &voxel_centroid_list_arg) const;
/** \brief Recursively explore the octree and output a PointT vector of centroids for all occupied voxels.
* \param[in] branch_arg: current branch node
* \param[in] key_arg: current key
* \param[out] voxel_centroid_list_arg results are written to this vector of PointT elements
*/
void
getVoxelCentroidsRecursive (const BranchNode* branch_arg,
OctreeKey& key_arg,
typename OctreePointCloud<PointT, LeafContainerT, BranchContainerT>::AlignedPointTVector &voxel_centroid_list_arg) const;
};
}
}
// Note: Don't precompile this octree type to speed up compilation. It's probably rarely used.
#include <pcl/octree/impl/octree_pointcloud_voxelcentroid.hpp>
pcl
This file defines compatibility wrappers for low level I/O functions.
Definition: convolution.h:45
pcl::octree::OctreePointCloudVoxelCentroidContainer::reset
void reset() override
Reset leaf container.
Definition: octree_pointcloud_voxelcentroid.h:116
pcl::octree::OctreePointCloudVoxelCentroid::Ptr
shared_ptr< OctreePointCloudVoxelCentroid< PointT, LeafContainerT > > Ptr
Definition: octree_pointcloud_voxelcentroid.h:144
pcl::octree::OctreePointCloudVoxelCentroid::~OctreePointCloudVoxelCentroid
~OctreePointCloudVoxelCentroid()
Empty class deconstructor.
Definition: octree_pointcloud_voxelcentroid.h:161
pcl::common
Definition: generate.h:49
pcl::octree::OctreePointCloud
Octree pointcloud class
Definition: octree_pointcloud.h:72
pcl::octree::OctreePointCloudVoxelCentroid
Octree pointcloud voxel centroid class
Definition: octree_pointcloud_voxelcentroid.h:141
pcl::octree::OctreeKey
Octree key class
Definition: octree_key.h:50
pcl::PointXYZRGB
A point structure representing Euclidean xyz coordinates, and the RGB color.
Definition: point_types.hpp:623
pcl::octree::OctreePointCloudVoxelCentroid::getVoxelCentroidAtPoint
bool getVoxelCentroidAtPoint(const int &point_idx_arg, PointT &voxel_centroid_arg) const
Get centroid for a single voxel addressed by a PointT point from input cloud.
Definition: octree_pointcloud_voxelcentroid.h:203
pcl::octree::OctreePointCloudVoxelCentroid::ConstPtr
shared_ptr< const OctreePointCloudVoxelCentroid< PointT, LeafContainerT > > ConstPtr
Definition: octree_pointcloud_voxelcentroid.h:145
pcl::octree::OctreePointCloudVoxelCentroidContainer::getCentroid
void getCentroid(PointT &centroid_arg) const
Calculate centroid of voxel.
Definition: octree_pointcloud_voxelcentroid.h:99
pcl::octree::OctreeLeafNode
Abstract octree leaf class
Definition: octree_nodes.h:96
pcl::octree::OctreeBase
Octree class.
Definition: octree_base.h:61
pcl::octree::OctreeBranchNode
Abstract octree branch class
Definition: octree_nodes.h:203
pcl::octree::OctreePointCloudVoxelCentroidContainer::operator==
bool operator==(const OctreeContainerBase &) const override
Equal comparison operator - set to false.
Definition: octree_pointcloud_voxelcentroid.h:77
pcl::octree::OctreePointCloudVoxelCentroidContainer::addPoint
void addPoint(const PointT &new_point)
Add new point to voxel.
Definition: octree_pointcloud_voxelcentroid.h:86
pcl::octree::OctreePointCloudVoxelCentroidContainer::~OctreePointCloudVoxelCentroidContainer
~OctreePointCloudVoxelCentroidContainer()
Empty class deconstructor.
Definition: octree_pointcloud_voxelcentroid.h:63
pcl::octree::OctreePointCloudVoxelCentroidContainer::deepCopy
virtual OctreePointCloudVoxelCentroidContainer * deepCopy() const
deep copy function
Definition: octree_pointcloud_voxelcentroid.h:69
pcl::octree::OctreePointCloudVoxelCentroid::addPointIdx
void addPointIdx(const int pointIdx_arg) override
Add DataT object to leaf node at octree key.
Definition: octree_pointcloud_voxelcentroid.h:169
pcl::octree::OctreePointCloudVoxelCentroid::OctreePointCloudVoxelCentroid
OctreePointCloudVoxelCentroid(const double resolution_arg)
OctreePointCloudVoxelCentroids class constructor.
Definition: octree_pointcloud_voxelcentroid.h:154
pcl::octree::OctreePointCloudVoxelCentroidContainer::OctreePointCloudVoxelCentroidContainer
OctreePointCloudVoxelCentroidContainer()
Class initialization.
Definition: octree_pointcloud_voxelcentroid.h:57
pcl::octree::OctreePointCloudVoxelCentroidContainer
Octree pointcloud voxel centroid leaf node class
Definition: octree_pointcloud_voxelcentroid.h:53
pcl::shared_ptr
boost::shared_ptr< T > shared_ptr
Alias for boost::shared_ptr.
Definition: pcl_macros.h:90
pcl::octree::OctreeContainerBase
Octree container class that can serve as a base to construct own leaf node container classes.
Definition: octree_container.h:54