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_OUTOFCORE_OCTREE_BASE_NODE_H_
00041 #define PCL_OUTOFCORE_OCTREE_BASE_NODE_H_
00042
00043 #include <pcl/common/io.h>
00044 #include <pcl/PCLPointCloud2.h>
00045
00046 #include <pcl/outofcore/boost.h>
00047 #include <pcl/outofcore/octree_base.h>
00048 #include <pcl/outofcore/octree_disk_container.h>
00049 #include <pcl/outofcore/outofcore_node_data.h>
00050
00051 #include <pcl/octree/octree_nodes.h>
00052
00053 namespace pcl
00054 {
00055 namespace outofcore
00056 {
00057
00058 template<typename ContainerT, typename PointT>
00059 class OutofcoreOctreeBaseNode;
00060
00061 template<typename ContainerT, typename PointT>
00062 class OutofcoreOctreeBase;
00063
00065 template<typename ContainerT, typename PointT> OutofcoreOctreeBaseNode<ContainerT, PointT>*
00066 makenode_norec (const boost::filesystem::path &path, OutofcoreOctreeBaseNode<ContainerT, PointT>* super);
00067
00069 template<typename ContainerT, typename PointT> void
00070 queryBBIntersects_noload (const boost::filesystem::path &root_node, const Eigen::Vector3d &min, const Eigen::Vector3d &max, const boost::uint32_t query_depth, std::list<std::string> &bin_name);
00071
00073 template<typename ContainerT, typename PointT> void
00074 queryBBIntersects_noload (OutofcoreOctreeBaseNode<ContainerT, PointT>* current, const Eigen::Vector3d&, const Eigen::Vector3d &max, const boost::uint32_t query_depth, std::list<std::string> &bin_name);
00075
00091 template<typename ContainerT = OutofcoreOctreeDiskContainer<pcl::PointXYZ>, typename PointT = pcl::PointXYZ>
00092 class OutofcoreOctreeBaseNode : public pcl::octree::OctreeNode
00093 {
00094 friend class OutofcoreOctreeBase<ContainerT, PointT> ;
00095
00096
00097 friend OutofcoreOctreeBaseNode<ContainerT, PointT>*
00098 makenode_norec<ContainerT, PointT> (const boost::filesystem::path &path, OutofcoreOctreeBaseNode<ContainerT, PointT>* super);
00099
00100 friend void
00101 queryBBIntersects_noload<ContainerT, PointT> (const boost::filesystem::path &rootnode, const Eigen::Vector3d &min, const Eigen::Vector3d &max, const boost::uint32_t query_depth, std::list<std::string> &bin_name);
00102
00103 friend void
00104 queryBBIntersects_noload<ContainerT, PointT> (OutofcoreOctreeBaseNode<ContainerT, PointT>* current, const Eigen::Vector3d &min, const Eigen::Vector3d &max, const boost::uint32_t query_depth, std::list<std::string> &bin_name);
00105
00106 public:
00107 typedef OutofcoreOctreeBase<OutofcoreOctreeDiskContainer < PointT > , PointT > octree_disk;
00108 typedef OutofcoreOctreeBaseNode<OutofcoreOctreeDiskContainer < PointT > , PointT > octree_disk_node;
00109
00110 typedef std::vector<PointT, Eigen::aligned_allocator<PointT> > AlignedPointTVector;
00111
00112 typedef pcl::octree::node_type_t node_type_t;
00113
00114 const static std::string node_index_basename;
00115 const static std::string node_container_basename;
00116 const static std::string node_index_extension;
00117 const static std::string node_container_extension;
00118 const static double sample_percent_;
00119
00122 OutofcoreOctreeBaseNode ();
00123
00125 OutofcoreOctreeBaseNode (const Eigen::Vector3d &bb_min, const Eigen::Vector3d &bb_max, OutofcoreOctreeBase<ContainerT, PointT> * const tree, const boost::filesystem::path &root_name);
00126
00128 virtual
00129 ~OutofcoreOctreeBaseNode ();
00130
00131
00136 virtual inline void
00137 getBoundingBox (Eigen::Vector3d &min_bb, Eigen::Vector3d &max_bb) const
00138 {
00139 node_metadata_->getBoundingBox (min_bb, max_bb);
00140 }
00141
00142
00143 const boost::filesystem::path&
00144 getPCDFilename () const
00145 {
00146 return node_metadata_->getPCDFilename ();
00147 }
00148
00149 const boost::filesystem::path&
00150 getMetadataFilename () const
00151 {
00152 return node_metadata_->getMetadataFilename ();
00153 }
00154
00155 void
00156 queryFrustum (const double planes[24], std::list<std::string>& file_names);
00157
00158 void
00159 queryFrustum (const double planes[24], std::list<std::string>& file_names, const boost::uint32_t query_depth, const bool skip_vfc_check = false);
00160
00161 void
00162 queryFrustum (const double planes[24], const Eigen::Vector3d &eye, const Eigen::Matrix4d &view_projection_matrix, std::list<std::string>& file_names, const boost::uint32_t query_depth, const bool skip_vfc_check = false);
00163
00164
00172 virtual void
00173 queryBBIncludes (const Eigen::Vector3d &min_bb, const Eigen::Vector3d &max_bb, size_t query_depth, AlignedPointTVector &dst);
00174
00182 virtual void
00183 queryBBIncludes (const Eigen::Vector3d &min_bb, const Eigen::Vector3d &max_bb, size_t query_depth, const pcl::PCLPointCloud2::Ptr &dst_blob);
00184
00192 virtual void
00193 queryBBIncludes_subsample (const Eigen::Vector3d &min_bb, const Eigen::Vector3d &max_bb, boost::uint64_t query_depth, const double percent, AlignedPointTVector &v);
00194
00195 virtual void
00196 queryBBIncludes_subsample (const Eigen::Vector3d &min_bb, const Eigen::Vector3d &max_bb, boost::uint64_t query_depth, const pcl::PCLPointCloud2::Ptr& dst_blob, double percent = 1.0);
00197
00200 virtual void
00201 queryBBIntersects (const Eigen::Vector3d &min_bb, const Eigen::Vector3d &max_bb, const boost::uint32_t query_depth, std::list<std::string> &file_names);
00202
00206 virtual void
00207 printBoundingBox (const size_t query_depth) const;
00208
00213 virtual boost::uint64_t
00214 addDataToLeaf (const AlignedPointTVector &p, const bool skip_bb_check = true);
00215
00216 virtual boost::uint64_t
00217 addDataToLeaf (const std::vector<const PointT*> &p, const bool skip_bb_check = true);
00218
00224 virtual boost::uint64_t
00225 addPointCloud (const pcl::PCLPointCloud2::Ptr &input_cloud, const bool skip_bb_check = false);
00226
00228 virtual boost::uint64_t
00229 addPointCloud_and_genLOD (const pcl::PCLPointCloud2::Ptr input_cloud);
00230
00236 virtual boost::uint64_t
00237 addDataToLeaf_and_genLOD (const AlignedPointTVector &p, const bool skip_bb_check);
00238
00242 void
00243 writeVPythonVisual (std::ofstream &file);
00244
00245 virtual int
00246 read (pcl::PCLPointCloud2::Ptr &output_cloud);
00247
00248 virtual inline node_type_t
00249 getNodeType () const
00250 {
00251 if(this->getNumChildren () > 0)
00252 {
00253 return (pcl::octree::BRANCH_NODE);
00254 }
00255 else
00256 {
00257 return (pcl::octree::LEAF_NODE);
00258 }
00259 }
00260
00261 virtual
00262 OutofcoreOctreeBaseNode*
00263 deepCopy () const
00264 {
00265 OutofcoreOctreeBaseNode* res = NULL;
00266 PCL_THROW_EXCEPTION (PCLException, "Not implemented\n");
00267 return (res);
00268 }
00269
00270 virtual inline size_t
00271 getDepth () const
00272 {
00273 return (this->depth_);
00274 }
00275
00277 virtual size_t
00278 getNumChildren () const
00279 {
00280 size_t res = this->countNumChildren ();
00281 return (res);
00282 }
00283
00285 virtual size_t
00286 getNumLoadedChildren () const
00287 {
00288 size_t res = this->countNumLoadedChildren ();
00289 return (res);
00290 }
00291
00293 virtual OutofcoreOctreeBaseNode*
00294 getChildPtr (size_t index_arg) const;
00295
00297 virtual boost::uint64_t
00298 getDataSize () const;
00299
00300 inline virtual void
00301 clearData ()
00302 {
00303
00304 this->payload_->clear ();
00305 }
00306
00308
00310 protected:
00321 OutofcoreOctreeBaseNode (const boost::filesystem::path &directory_path, OutofcoreOctreeBaseNode<ContainerT, PointT>* super, bool load_all);
00322
00336 void init_root_node (const Eigen::Vector3d &bb_min, const Eigen::Vector3d &bb_max, OutofcoreOctreeBase<ContainerT, PointT> * const tree, const boost::filesystem::path &rootname);
00337
00339 OutofcoreOctreeBaseNode (const OutofcoreOctreeBaseNode &rval);
00340
00342 OutofcoreOctreeBaseNode&
00343 operator= (const OutofcoreOctreeBaseNode &rval);
00344
00346 virtual size_t
00347 countNumChildren () const;
00348
00352 virtual size_t
00353 countNumLoadedChildren () const;
00354
00359 void
00360 saveIdx (bool recursive);
00361
00364 void
00365 randomSample (const AlignedPointTVector &p, AlignedPointTVector &insertBuff, const bool skip_bb_check);
00366
00368 void
00369 subdividePoints (const AlignedPointTVector &p, std::vector< AlignedPointTVector > &c, const bool skip_bb_check);
00371 void
00372 subdividePoint (const PointT &point, std::vector< AlignedPointTVector > &c);
00373
00385 boost::uint64_t
00386 addDataAtMaxDepth (const AlignedPointTVector &p, const bool skip_bb_check = true);
00387
00400 boost::uint64_t
00401 addDataAtMaxDepth (const pcl::PCLPointCloud2::Ptr input_cloud, const bool skip_bb_check = true);
00402
00408 inline bool
00409 intersectsWithBoundingBox (const Eigen::Vector3d &min_bb, const Eigen::Vector3d &max_bb) const;
00410
00416 inline bool
00417 inBoundingBox (const Eigen::Vector3d &min_bb, const Eigen::Vector3d &max_bb) const;
00418
00424 bool
00425 pointInBoundingBox (const Eigen::Vector3d &min_bb, const Eigen::Vector3d &max_bb, const Eigen::Vector3d &point);
00426
00432 static bool
00433 pointInBoundingBox (const Eigen::Vector3d &min_bb, const Eigen::Vector3d &max_bb, const PointT &p);
00434
00439 static bool
00440 pointInBoundingBox (const Eigen::Vector3d &min_bb, const Eigen::Vector3d &max_bb, const double x, const double y, const double z);
00441
00443 inline bool
00444 pointInBoundingBox (const PointT &p) const;
00445
00449 void
00450 createChild (const std::size_t idx);
00451
00453 void
00454 saveMetadataToFile (const boost::filesystem::path &path);
00455
00458 void
00459 recFreeChildren ();
00460
00462 inline boost::uint64_t
00463 size () const
00464 {
00465 return (payload_->size ());
00466 }
00467
00468 void
00469 flushToDiskRecursive ();
00470
00473 void
00474 loadFromFile (const boost::filesystem::path &path, OutofcoreOctreeBaseNode* super);
00475
00479 void
00480 convertToXYZRecursive ();
00481
00484 OutofcoreOctreeBaseNode (const Eigen::Vector3d &bb_min, const Eigen::Vector3d &bb_max, const char* dir, OutofcoreOctreeBaseNode<ContainerT, PointT>* super);
00485
00488 void
00489 copyAllCurrentAndChildPointsRec (std::list<PointT> &v);
00490
00491 void
00492 copyAllCurrentAndChildPointsRec_sub (std::list<PointT> &v, const double percent);
00493
00495 bool
00496 hasUnloadedChildren () const;
00497
00499 virtual void
00500 loadChildren (bool recursive);
00501
00506 void
00507 getOccupiedVoxelCentersRecursive (AlignedPointTVector &voxel_centers, const size_t query_depth);
00508
00513 void
00514 getOccupiedVoxelCentersRecursive (std::vector<Eigen::Vector3d, Eigen::aligned_allocator<Eigen::Vector3d> > &voxel_centers, const size_t query_depth);
00515
00519 void
00520 sortOctantIndices (const pcl::PCLPointCloud2::Ptr &input_cloud, std::vector< std::vector<int> > &indices, const Eigen::Vector3d &mid_xyz);
00521
00526 void
00527 enlargeToCube (Eigen::Vector3d &bb_min, Eigen::Vector3d &bb_max);
00528
00530 OutofcoreOctreeBase<ContainerT, PointT>* m_tree_;
00532 OutofcoreOctreeBaseNode* root_node_;
00534 OutofcoreOctreeBaseNode* parent_;
00536 size_t depth_;
00538 std::vector<OutofcoreOctreeBaseNode*> children_;
00539
00541 uint64_t num_children_;
00542
00549 uint64_t num_loaded_children_;
00550
00554 boost::shared_ptr<ContainerT> payload_;
00555
00557 static boost::mutex rng_mutex_;
00558
00561 static boost::mt19937 rand_gen_;
00562
00564 const static boost::uint32_t rngseed = 0xAABBCCDD;
00566 const static std::string pcd_extension;
00567
00568 OutofcoreOctreeNodeMetadata::Ptr node_metadata_;
00569 };
00570 }
00571 }
00572
00573 #endif //PCL_OUTOFCORE_OCTREE_BASE_NODE_H_