|
Point Cloud Library (PCL)
1.4.0
|
00001 /* 00002 * Software License Agreement (BSD License) 00003 * 00004 * Point Cloud Library (PCL) - www.pointclouds.org 00005 * Copyright (c) 2010-2011, Willow Garage, Inc. 00006 * 00007 * All rights reserved. 00008 * 00009 * Redistribution and use in source and binary forms, with or without 00010 * modification, are permitted provided that the following conditions 00011 * are met: 00012 * 00013 * * Redistributions of source code must retain the above copyright 00014 * notice, this list of conditions and the following disclaimer. 00015 * * Redistributions in binary form must reproduce the above 00016 * copyright notice, this list of conditions and the following 00017 * disclaimer in the documentation and/or other materials provided 00018 * with the distribution. 00019 * * Neither the name of Willow Garage, Inc. nor the names of its 00020 * contributors may be used to endorse or promote products derived 00021 * from this software without specific prior written permission. 00022 * 00023 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00024 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00025 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00026 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00027 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00028 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00029 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00030 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00031 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00032 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00033 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00034 * POSSIBILITY OF SUCH DAMAGE. 00035 * 00036 * $Id: octree_pointcloud.h 3749 2011-12-31 22:58:01Z rusu $ 00037 */ 00038 00039 #ifndef OCTREE_POINTCLOUD_H 00040 #define OCTREE_POINTCLOUD_H 00041 00042 #include "octree_base.h" 00043 #include "octree2buf_base.h" 00044 #include "octree_lowmemory_base.h" 00045 00046 #include <pcl/point_cloud.h> 00047 #include <pcl/point_types.h> 00048 00049 #include "octree_nodes.h" 00050 00051 #include <queue> 00052 #include <vector> 00053 #include <algorithm> 00054 #include <iostream> 00055 00056 namespace pcl 00057 { 00058 namespace octree 00059 { 00060 00062 00074 00075 template<typename PointT, typename LeafT = OctreeLeafDataTVector<int> , typename OctreeT = OctreeBase<int, LeafT> > 00076 class OctreePointCloud : public OctreeT 00077 { 00078 public: 00082 OctreePointCloud (const double resolution_arg); 00083 00085 virtual 00086 ~OctreePointCloud (); 00087 00088 // public typedefs 00089 typedef boost::shared_ptr<std::vector<int> > IndicesPtr; 00090 typedef boost::shared_ptr<const std::vector<int> > IndicesConstPtr; 00091 00092 typedef pcl::PointCloud<PointT> PointCloud; 00093 typedef boost::shared_ptr<PointCloud> PointCloudPtr; 00094 typedef boost::shared_ptr<const PointCloud> PointCloudConstPtr; 00095 00096 // public typedefs for single/double buffering 00097 typedef OctreePointCloud<PointT, LeafT, OctreeBase<int, LeafT> > SingleBuffer; 00098 typedef OctreePointCloud<PointT, LeafT, Octree2BufBase<int, LeafT> > DoubleBuffer; 00099 typedef OctreePointCloud<PointT, LeafT, OctreeLowMemBase<int, LeafT> > LowMem; 00100 00101 // Boost shared pointers 00102 typedef boost::shared_ptr<OctreePointCloud<PointT, LeafT, OctreeT> > Ptr; 00103 typedef boost::shared_ptr<const OctreePointCloud<PointT, LeafT, OctreeT> > ConstPtr; 00104 00105 // Eigen aligned allocator 00106 typedef std::vector<PointT, Eigen::aligned_allocator<PointT> > AlignedPointTVector; 00107 00112 inline void 00113 setInputCloud (const PointCloudConstPtr &cloud_arg, const IndicesConstPtr &indices_arg = IndicesConstPtr ()) 00114 { 00115 assert (this->leafCount_==0); 00116 00117 if ((input_ != cloud_arg) && (this->leafCount_ == 0)) 00118 { 00119 input_ = cloud_arg; 00120 indices_ = indices_arg; 00121 } 00122 } 00123 00127 inline IndicesConstPtr const 00128 getIndices () 00129 { 00130 return (indices_); 00131 } 00132 00136 inline PointCloudConstPtr 00137 getInputCloud () 00138 { 00139 return (input_); 00140 } 00141 00145 inline void 00146 setEpsilon (double eps) 00147 { 00148 epsilon_ = eps; 00149 } 00150 00152 inline double 00153 getEpsilon () 00154 { 00155 return (epsilon_); 00156 } 00157 00161 inline void 00162 setResolution (double resolution_arg) 00163 { 00164 // octree needs to be empty to change its resolution 00165 assert( this->leafCount_ == 0 ); 00166 00167 resolution_ = resolution_arg; 00168 } 00169 00173 inline double 00174 getResolution () 00175 { 00176 return (resolution_); 00177 } 00178 00180 void 00181 addPointsFromInputCloud (); 00182 00187 void 00188 addPointFromCloud (const int pointIdx_arg, IndicesPtr indices_arg); 00189 00194 void 00195 addPointToCloud (const PointT& point_arg, PointCloudPtr cloud_arg); 00196 00202 void 00203 addPointToCloud (const PointT& point_arg, PointCloudPtr cloud_arg, IndicesPtr indices_arg); 00204 00209 bool 00210 isVoxelOccupiedAtPoint (const PointT& point_arg) const; 00211 00213 void 00214 deleteTree () 00215 { 00216 // reset bounding box 00217 minX_ = minY_ = maxY_ = minZ_ = maxZ_ = 0; 00218 maxKeys_ = 1; 00219 this->boundingBoxDefined_ = false; 00220 00221 OctreeT::deleteTree (); 00222 } 00223 00230 bool 00231 isVoxelOccupiedAtPoint (const double pointX_arg, const double pointY_arg, const double pointZ_arg) const; 00232 00237 bool 00238 isVoxelOccupiedAtPoint (const int& pointIdx_arg) const; 00239 00244 int 00245 getOccupiedVoxelCenters (AlignedPointTVector &voxelCenterList_arg) const; 00246 00247 00258 int 00259 getApproxIntersectedVoxelCentersBySegment (const Eigen::Vector3f& origin, 00260 const Eigen::Vector3f& end, 00261 AlignedPointTVector &voxel_center_list, 00262 float precision = 0.2); 00263 00267 void 00268 deleteVoxelAtPoint (const PointT& point_arg); 00269 00273 void 00274 deleteVoxelAtPoint (const int& pointIdx_arg); 00275 00277 // Bounding box methods 00279 00280 00282 void 00283 defineBoundingBox (); 00284 00294 void 00295 defineBoundingBox (const double minX_arg, const double minY_arg, const double minZ_arg, const double maxX_arg, 00296 const double maxY_arg, const double maxZ_arg); 00297 00305 void 00306 defineBoundingBox (const double maxX_arg, const double maxY_arg, const double maxZ_arg); 00307 00313 void 00314 defineBoundingBox (const double cubeLen_arg); 00315 00325 void 00326 getBoundingBox (double& minX_arg, double& minY_arg, double& minZ_arg, double& maxX_arg, double& maxY_arg, 00327 double& maxZ_arg) const ; 00328 00333 double 00334 getVoxelSquaredDiameter (unsigned int treeDepth_arg) const ; 00335 00339 inline double 00340 getVoxelSquaredDiameter () const 00341 { 00342 return getVoxelSquaredDiameter (this->octreeDepth_); 00343 } 00344 00349 double 00350 getVoxelSquaredSideLen (unsigned int treeDepth_arg) const ; 00351 00355 inline double 00356 getVoxelSquaredSideLen () const 00357 { 00358 return getVoxelSquaredSideLen (this->octreeDepth_); 00359 } 00360 00361 typedef typename OctreeT::OctreeLeaf OctreeLeaf; 00362 00363 protected: 00364 00368 void 00369 addPointIdx (const int pointIdx_arg); 00370 00375 const PointT& 00376 getPointByIndex (const unsigned int index_arg) const; 00377 00382 LeafT* 00383 findLeafAtPoint (const PointT& point_arg) const ; 00384 00386 // Protected octree methods based on octree keys 00388 00389 typedef typename OctreeT::OctreeKey OctreeKey; 00390 typedef typename OctreeT::OctreeBranch OctreeBranch; 00391 00393 void 00394 getKeyBitSize (); 00395 00399 void 00400 adoptBoundingBoxToPoint (const PointT& pointIdx_arg); 00401 00406 void 00407 genOctreeKeyforPoint (const PointT & point_arg, OctreeKey &key_arg) const ; 00408 00415 void 00416 genOctreeKeyforPoint (const double pointX_arg, const double pointY_arg, const double pointZ_arg, 00417 OctreeKey & key_arg) const; 00418 00425 virtual bool 00426 genOctreeKeyForDataT (const int& data_arg, OctreeKey & key_arg) const; 00427 00432 void 00433 genLeafNodeCenterFromOctreeKey (const OctreeKey & key_arg, PointT& point_arg) const ; 00434 00440 void 00441 genVoxelCenterFromOctreeKey (const OctreeKey & key_arg, unsigned int treeDepth_arg, PointT& point_arg) const ; 00442 00449 void 00450 genVoxelBoundsFromOctreeKey (const OctreeKey & key_arg, unsigned int treeDepth_arg, Eigen::Vector3f &min_pt, 00451 Eigen::Vector3f &max_pt) const; 00452 00459 int 00460 getOccupiedVoxelCentersRecursive (const OctreeBranch* node_arg, 00461 const OctreeKey& key_arg, 00462 std::vector<PointT, Eigen::aligned_allocator<PointT> > &voxelCenterList_arg) const; 00463 00465 // Globals 00467 00468 PointCloudConstPtr input_; 00469 00471 IndicesConstPtr indices_; 00472 00474 double epsilon_; 00475 00477 double resolution_; 00478 00479 // Octree bounding box coordinates 00480 double minX_; 00481 double maxX_; 00482 00483 double minY_; 00484 double maxY_; 00485 00486 double minZ_; 00487 double maxZ_; 00488 00490 unsigned int maxKeys_; 00491 00493 bool boundingBoxDefined_; 00494 }; 00495 } 00496 } 00497 00498 #endif 00499
1.7.6.1