octree_base_node.h
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Point Cloud Library (PCL) - www.pointclouds.org
00005  *  Copyright (c) 2010-2012, Willow Garage, Inc.
00006  *  Copyright (c) 2012, Urban Robotics, Inc.
00007  *
00008  *  All rights reserved.
00009  *
00010  *  Redistribution and use in source and binary forms, with or without
00011  *  modification, are permitted provided that the following conditions
00012  *  are met:
00013  *
00014  *   * Redistributions of source code must retain the above copyright
00015  *     notice, this list of conditions and the following disclaimer.
00016  *   * Redistributions in binary form must reproduce the above
00017  *     copyright notice, this list of conditions and the following
00018  *     disclaimer in the documentation and/or other materials provided
00019  *     with the distribution.
00020  *   * Neither the name of Willow Garage, Inc. nor the names of its
00021  *     contributors may be used to endorse or promote products derived
00022  *     from this software without specific prior written permission.
00023  *
00024  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00025  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00026  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00027  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00028  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00029  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00030  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00031  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00032  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00033  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00034  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00035  *  POSSIBILITY OF SUCH DAMAGE.
00036  *
00037  *  $Id$
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     // Forward Declarations
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       //these methods can be rewritten with the iterators. 
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         //query
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         //point extraction
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); //, const bool skip_bb_check);
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           //clears write cache and removes PCD file from disk
00304           this->payload_->clear ();
00305         }
00306 
00308       // PROTECTED METHODS
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   }//namespace outofcore
00571 }//namespace pcl
00572 
00573 #endif //PCL_OUTOFCORE_OCTREE_BASE_NODE_H_


pcl
Author(s): Open Perception
autogenerated on Wed Aug 26 2015 15:26:15