Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #ifndef PCL_OCTREE_VOXELCENTROID_H
00041 #define PCL_OCTREE_VOXELCENTROID_H
00042
00043 #include "octree_pointcloud.h"
00044
00045 #include <pcl/common/point_operators.h>
00046 #include <pcl/point_types.h>
00047 #include <pcl/register_point_struct.h>
00048
00049 namespace pcl
00050 {
00051 namespace octree
00052 {
00057 template<typename PointT>
00058 class OctreePointCloudVoxelCentroidContainer : public OctreeContainerBase
00059 {
00060 public:
00062 OctreePointCloudVoxelCentroidContainer ()
00063 {
00064 this->reset();
00065 }
00066
00068 virtual ~OctreePointCloudVoxelCentroidContainer ()
00069 {
00070 }
00071
00073 virtual OctreePointCloudVoxelCentroidContainer *
00074 deepCopy () const
00075 {
00076 return (new OctreePointCloudVoxelCentroidContainer (*this));
00077 }
00078
00082 virtual bool operator==(const OctreeContainerBase&) const
00083 {
00084 return ( false );
00085 }
00086
00090 void
00091 addPoint (const PointT& new_point)
00092 {
00093 using namespace pcl::common;
00094
00095 ++point_counter_;
00096
00097 point_sum_ += new_point;
00098 }
00099
00103 void
00104 getCentroid (PointT& centroid_arg) const
00105 {
00106 using namespace pcl::common;
00107
00108 if (point_counter_)
00109 {
00110 centroid_arg = point_sum_;
00111 centroid_arg /= static_cast<float> (point_counter_);
00112 }
00113 else
00114 {
00115 centroid_arg *= 0.0f;
00116 }
00117 }
00118
00120 virtual void
00121 reset ()
00122 {
00123 using namespace pcl::common;
00124
00125 point_counter_ = 0;
00126 point_sum_ *= 0.0f;
00127 }
00128
00129 private:
00130 unsigned int point_counter_;
00131 PointT point_sum_;
00132 };
00133
00143 template<typename PointT,
00144 typename LeafContainerT = OctreePointCloudVoxelCentroidContainer<PointT> ,
00145 typename BranchContainerT = OctreeContainerEmpty >
00146 class OctreePointCloudVoxelCentroid : public OctreePointCloud<PointT, LeafContainerT, BranchContainerT>
00147 {
00148 public:
00149 typedef boost::shared_ptr<OctreePointCloudVoxelCentroid<PointT, LeafContainerT> > Ptr;
00150 typedef boost::shared_ptr<const OctreePointCloudVoxelCentroid<PointT, LeafContainerT> > ConstPtr;
00151
00152 typedef OctreePointCloud<PointT, LeafContainerT, BranchContainerT> OctreeT;
00153 typedef typename OctreeT::LeafNode LeafNode;
00154 typedef typename OctreeT::BranchNode BranchNode;
00155
00159 OctreePointCloudVoxelCentroid (const double resolution_arg) :
00160 OctreePointCloud<PointT, LeafContainerT, BranchContainerT> (resolution_arg)
00161 {
00162 }
00163
00165 virtual
00166 ~OctreePointCloudVoxelCentroid ()
00167 {
00168 }
00169
00174 virtual void
00175 addPointIdx (const int pointIdx_arg)
00176 {
00177 OctreeKey key;
00178
00179 assert (pointIdx_arg < static_cast<int> (this->input_->points.size ()));
00180
00181 const PointT& point = this->input_->points[pointIdx_arg];
00182
00183
00184 this->adoptBoundingBoxToPoint (point);
00185
00186
00187 this->genOctreeKeyforPoint (point, key);
00188
00189
00190 LeafContainerT* container = this->createLeaf(key);
00191 container->addPoint (point);
00192
00193 }
00194
00200 bool
00201 getVoxelCentroidAtPoint (const PointT& point_arg, PointT& voxel_centroid_arg) const;
00202
00208 inline bool
00209 getVoxelCentroidAtPoint (const int& point_idx_arg, PointT& voxel_centroid_arg) const
00210 {
00211
00212 return (this->getVoxelCentroidAtPoint (this->input_->points[point_idx_arg], voxel_centroid_arg));
00213 }
00214
00219 size_t
00220 getVoxelCentroids (typename OctreePointCloud<PointT, LeafContainerT, BranchContainerT>::AlignedPointTVector &voxel_centroid_list_arg) const;
00221
00227 void
00228 getVoxelCentroidsRecursive (const BranchNode* branch_arg,
00229 OctreeKey& key_arg,
00230 typename OctreePointCloud<PointT, LeafContainerT, BranchContainerT>::AlignedPointTVector &voxel_centroid_list_arg) const;
00231
00232 };
00233 }
00234 }
00235
00236 #include <pcl/octree/impl/octree_pointcloud_voxelcentroid.hpp>
00237
00238 #endif
00239