Point Cloud Library (PCL)  1.8.0
octree_base.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2010-2012, Willow Garage, Inc.
6  * Copyright (c) 2012, Urban Robotics, Inc.
7  *
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  *
14  * * Redistributions of source code must retain the above copyright
15  * notice, this list of conditions and the following disclaimer.
16  * * Redistributions in binary form must reproduce the above
17  * copyright notice, this list of conditions and the following
18  * disclaimer in the documentation and/or other materials provided
19  * with the distribution.
20  * * Neither the name of Willow Garage, Inc. nor the names of its
21  * contributors may be used to endorse or promote products derived
22  * from this software without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35  * POSSIBILITY OF SUCH DAMAGE.
36  *
37  * $Id$
38  */
39 
40 #ifndef PCL_OUTOFCORE_OUTOFCOREOCTREEBASE_H_
41 #define PCL_OUTOFCORE_OUTOFCOREOCTREEBASE_H_
42 
43 #include <pcl/outofcore/boost.h>
44 #include <pcl/common/io.h>
45 
46 //outofcore classes
47 #include <pcl/outofcore/octree_base_node.h>
48 #include <pcl/outofcore/octree_disk_container.h>
49 #include <pcl/outofcore/octree_ram_container.h>
50 
51 //outofcore iterators
52 #include <pcl/outofcore/outofcore_iterator_base.h>
53 #include <pcl/outofcore/outofcore_breadth_first_iterator.h>
54 #include <pcl/outofcore/outofcore_depth_first_iterator.h>
55 #include <pcl/outofcore/impl/outofcore_breadth_first_iterator.hpp>
56 #include <pcl/outofcore/impl/outofcore_depth_first_iterator.hpp>
57 
58 //outofcore metadata
59 #include <pcl/outofcore/metadata.h>
60 #include <pcl/outofcore/outofcore_base_data.h>
61 
62 #include <pcl/filters/filter.h>
63 #include <pcl/filters/random_sample.h>
64 
65 #include <pcl/PCLPointCloud2.h>
66 
67 namespace pcl
68 {
69  namespace outofcore
70  {
72  {
73  std::string node_index_basename_;
75  std::string node_index_extension_;
78  };
79 
80  /** \class OutofcoreOctreeBase
81  * \brief This code defines the octree used for point storage at Urban Robotics.
82  *
83  * \note Code was adapted from the Urban Robotics out of core octree implementation.
84  * Contact Jacob Schloss <jacob.schloss@urbanrobotics.net> with any questions.
85  * http://www.urbanrobotics.net/. This code was integrated for the Urban Robotics
86  * Code Sprint (URCS) by Stephen Fox (foxstephend@gmail.com). Additional development notes can be found at
87  * http://www.pointclouds.org/blog/urcs/.
88  *
89  * The primary purpose of this class is an interface to the
90  * recursive traversal (recursion handled by \ref pcl::outofcore::OutofcoreOctreeBaseNode) of the
91  * in-memory/top-level octree structure. The metadata in each node
92  * can be loaded entirely into main memory, from which the tree can be traversed
93  * recursively in this state. This class provides an the interface
94  * for:
95  * -# Point/Region insertion methods
96  * -# Frustrum/box/region queries
97  * -# Parameterization of resolution, container type, etc...
98  *
99  * For lower-level node access, there is a Depth-First iterator
100  * for traversing the trees with direct access to the nodes. This
101  * can be used for implementing other algorithms, and other
102  * iterators can be written in a similar fashion.
103  *
104  * The format of the octree is stored on disk in a hierarchical
105  * octree structure, where .oct_idx are the JSON-based node
106  * metadata files managed by \ref pcl::outofcore::OutofcoreOctreeNodeMetadata,
107  * and .octree is the JSON-based octree metadata file managed by
108  * \ref pcl::outofcore::OutofcoreOctreeBaseMetadata. Children of each node live
109  * in up to eight subdirectories named from 0 to 7, where a
110  * metadata and optionally a pcd file will exist. The PCD files
111  * are stored in compressed binary PCD format, containing all of
112  * the fields existing in the PCLPointCloud2 objects originally
113  * inserted into the out of core object.
114  *
115  * A brief outline of the out of core octree can be seen
116  * below. The files in [brackets] exist only when the LOD are
117  * built.
118  *
119  * At this point in time, there is not support for multiple trees
120  * existing in a single directory hierarchy.
121  *
122  * \verbatim
123  tree_name/
124  tree_name.oct_idx
125  tree_name.octree
126  [tree_name-uuid.pcd]
127  0/
128  tree_name.oct_idx
129  [tree_name-uuid.pcd]
130  0/
131  ...
132  1/
133  ...
134  ...
135  0/
136  tree_name.oct_idx
137  tree_name.pcd
138  1/
139  ...
140  7/
141  \endverbatim
142  *
143  * \ingroup outofcore
144  * \author Jacob Schloss (jacob.schloss@urbanrobotics.net)
145  * \author Stephen Fox, Urban Robotics Code Sprint (foxstephend@gmail.com)
146  *
147  */
148  template<typename ContainerT = OutofcoreOctreeDiskContainer<pcl::PointXYZ>, typename PointT = pcl::PointXYZ>
150  {
151  friend class OutofcoreOctreeBaseNode<ContainerT, PointT>;
153 
154  public:
155 
156  // public typedefs
159 
162 
164 
167 
170 
173 
176 
177  typedef boost::shared_ptr<OutofcoreOctreeBase<ContainerT, PointT> > Ptr;
178  typedef boost::shared_ptr<const OutofcoreOctreeBase<ContainerT, PointT> > ConstPtr;
179 
181 
182  typedef boost::shared_ptr<std::vector<int> > IndicesPtr;
183  typedef boost::shared_ptr<const std::vector<int> > IndicesConstPtr;
184 
185  typedef boost::shared_ptr<PointCloud> PointCloudPtr;
186  typedef boost::shared_ptr<const PointCloud> PointCloudConstPtr;
187 
188  typedef std::vector<PointT, Eigen::aligned_allocator<PointT> > AlignedPointTVector;
189 
190  // Constructors
191  // -----------------------------------------------------------------------
192 
193  /** \brief Load an existing tree
194  *
195  * If load_all is set, the BB and point count for every node is loaded,
196  * otherwise only the root node is actually created, and the rest will be
197  * generated on insertion or query.
198  *
199  * \param root_node_name Path to the top-level tree/tree.oct_idx metadata file
200  * \param load_all Load entire tree metadata (does not load any points from disk)
201  * \throws PCLException for bad extension (root node metadata must be .oct_idx extension)
202  */
203  OutofcoreOctreeBase (const boost::filesystem::path &root_node_name, const bool load_all);
204 
205  /** \brief Create a new tree
206  *
207  * Create a new tree rootname with specified bounding box; will remove and overwrite existing tree with the same name
208  *
209  * Computes the depth of the tree based on desired leaf , then calls the other constructor.
210  *
211  * \param min Bounding box min
212  * \param max Bounding box max
213  * \param resolution_arg Node dimension in meters (assuming your point data is in meters)
214  * \param root_node_name must end in ".oct_idx"
215  * \param coord_sys Coordinate system which is stored in the JSON metadata
216  * \throws PCLException if root file extension does not match \ref pcl::outofcore::OutofcoreOctreeBaseNode::node_index_extension
217  */
218  OutofcoreOctreeBase (const Eigen::Vector3d& min, const Eigen::Vector3d& max, const double resolution_arg, const boost::filesystem::path &root_node_name, const std::string &coord_sys);
219 
220  /** \brief Create a new tree; will not overwrite existing tree of same name
221  *
222  * Create a new tree rootname with specified bounding box; will not overwrite an existing tree
223  *
224  * \param max_depth Specifies a fixed number of LODs to generate, which is the depth of the tree
225  * \param min Bounding box min
226  * \param max Bounding box max
227  * \note Bounding box of the tree must be set before inserting any points. The tree \b cannot be resized at this time.
228  * \param root_node_name must end in ".oct_idx"
229  * \param coord_sys Coordinate system which is stored in the JSON metadata
230  * \throws PCLException if the parent directory has existing children (detects an existing tree)
231  * \throws PCLException if file extension is not ".oct_idx"
232  */
233  OutofcoreOctreeBase (const boost::uint64_t max_depth, const Eigen::Vector3d &min, const Eigen::Vector3d &max, const boost::filesystem::path &root_node_name, const std::string &coord_sys);
234 
235  virtual
237 
238  // Point/Region INSERTION methods
239  // --------------------------------------------------------------------------------
240  /** \brief Recursively add points to the tree
241  * \note shared read_write_mutex lock occurs
242  */
243  boost::uint64_t
244  addDataToLeaf (const AlignedPointTVector &p);
245 
246  /** \brief Copies the points from the point_cloud falling within the bounding box of the octree to the
247  * out-of-core octree; this is an interface to addDataToLeaf and can be used multiple times.
248  * \param point_cloud Pointer to the point cloud data to copy to the outofcore octree; Assumes templated
249  * PointT matches for each.
250  * \return Number of points successfully copied from the point cloud to the octree.
251  */
252  boost::uint64_t
253  addPointCloud (PointCloudConstPtr point_cloud);
254 
255  /** \brief Recursively copies points from input_cloud into the leaf nodes of the out-of-core octree, and stores them to disk.
256  *
257  * \param[in] input_cloud The cloud of points to be inserted into the out-of-core octree. Note if multiple PCLPointCloud2 objects are added to the tree, this assumes that they all have exactly the same fields.
258  * \param[in] skip_bb_check (default=false) whether to skip the bounding box check on insertion. Note the bounding box check is never skipped in the current implementation.
259  * \return Number of poitns successfully copied from the point cloud to the octree
260  */
261  boost::uint64_t
262  addPointCloud (pcl::PCLPointCloud2::Ptr &input_cloud, const bool skip_bb_check = false);
263 
264  /** \brief Recursively add points to the tree.
265  *
266  * Recursively add points to the tree. 1/8 of the remaining
267  * points at each LOD are stored at each internal node of the
268  * octree until either (a) runs out of points, in which case
269  * the leaf is not at the maximum depth of the tree, or (b)
270  * a larger set of points falls in the leaf at the maximum depth.
271  * Note unlike the old implementation, multiple
272  * copies of the same point will \b not be added at multiple
273  * LODs as it walks the tree. Once the point is added to the
274  * octree, it is no longer propagated further down the tree.
275  *
276  *\param[in] input_cloud The input cloud of points which will
277  * be copied into the sorted nodes of the out-of-core octree
278  * \return The total number of points added to the out-of-core
279  * octree.
280  */
281  boost::uint64_t
282  addPointCloud_and_genLOD (pcl::PCLPointCloud2::Ptr &input_cloud);
283 
284  boost::uint64_t
285  addPointCloud (pcl::PCLPointCloud2::Ptr &input_cloud);
286 
287  boost::uint64_t
288  addPointCloud_and_genLOD (PointCloudConstPtr point_cloud);
289 
290  /** \brief Recursively add points to the tree subsampling LODs on the way.
291  *
292  * shared read_write_mutex lock occurs
293  */
294  boost::uint64_t
295  addDataToLeaf_and_genLOD (AlignedPointTVector &p);
296 
297  // Frustrum/Box/Region REQUESTS/QUERIES: DB Accessors
298  // -----------------------------------------------------------------------
299  void
300  queryFrustum (const double *planes, std::list<std::string>& file_names) const;
301 
302  void
303  queryFrustum (const double *planes, std::list<std::string>& file_names, const boost::uint32_t query_depth) const;
304 
305  void
306  queryFrustum (const double *planes, const Eigen::Vector3d &eye, const Eigen::Matrix4d &view_projection_matrix,
307  std::list<std::string>& file_names, const boost::uint32_t query_depth) const;
308 
309  //--------------------------------------------------------------------------------
310  //templated PointT methods
311  //--------------------------------------------------------------------------------
312 
313  /** \brief Get a list of file paths at query_depth that intersect with your bounding box specified by \c min and \c max.
314  * When querying with this method, you may be stuck with extra data (some outside of your query bounds) that reside in the files.
315  *
316  * \param[in] min The minimum corner of the bounding box
317  * \param[in] max The maximum corner of the bounding box
318  * \param[in] query_depth 0 is root, (this->depth) is full
319  * \param[out] bin_name List of paths to point data files (PCD currently) which satisfy the query
320  */
321  void
322  queryBBIntersects (const Eigen::Vector3d &min, const Eigen::Vector3d &max, const boost::uint32_t query_depth, std::list<std::string> &bin_name) const;
323 
324  /** \brief Get Points in BB, only points inside BB. The query
325  * processes the data at each node, filtering points that fall
326  * out of the query bounds, and returns a single, concatenated
327  * point cloud.
328  *
329  * \param[in] min The minimum corner of the bounding box for querying
330  * \param[in] max The maximum corner of the bounding box for querying
331  * \param[in] query_depth The depth from which point data will be taken
332  * \note If the LODs of the tree have not been built, you must specify the maximum depth in order to retrieve any data
333  * \param[out] dst The destination vector of points
334  */
335  void
336  queryBBIncludes (const Eigen::Vector3d &min, const Eigen::Vector3d &max, const boost::uint64_t query_depth, AlignedPointTVector &dst) const;
337 
338  /** \brief Query all points falling within the input bounding box at \c query_depth and return a PCLPointCloud2 object in \c dst_blob.
339  *
340  * \param[in] min The minimum corner of the input bounding box.
341  * \param[in] max The maximum corner of the input bounding box.
342  * \param[in] query_depth The query depth at which to search for points; only points at this depth are returned
343  * \param[out] dst_blob Storage location for the points satisfying the query.
344  **/
345  void
346  queryBBIncludes (const Eigen::Vector3d &min, const Eigen::Vector3d &max, const boost::uint64_t query_depth, const pcl::PCLPointCloud2::Ptr &dst_blob) const;
347 
348  /** \brief Returns a random subsample of points within the given bounding box at \c query_depth.
349  *
350  * \param[in] min The minimum corner of the boudning box to query.
351  * \param[out] max The maximum corner of the bounding box to query.
352  * \param[in] query_depth The depth in the tree at which to look for the points. Only returns points within the given bounding box at the specified \c query_depth.
353  * \param percent
354  * \param[out] dst The destination in which to return the points.
355  *
356  */
357  void
358  queryBBIncludes_subsample (const Eigen::Vector3d &min, const Eigen::Vector3d &max, uint64_t query_depth, const double percent, AlignedPointTVector &dst) const;
359 
360  //--------------------------------------------------------------------------------
361  //PCLPointCloud2 methods
362  //--------------------------------------------------------------------------------
363 
364  /** \brief Query all points falling within the input bounding box at \c query_depth and return a PCLPointCloud2 object in \c dst_blob.
365  * If the optional argument for filter is given, points are processed by that filter before returning.
366  * \param[in] min The minimum corner of the input bounding box.
367  * \param[in] max The maximum corner of the input bounding box.
368  * \param[in] query_depth The depth of tree at which to query; only points at this depth are returned
369  * \param[out] dst_blob The destination in which points within the bounding box are stored.
370  * \param[in] percent optional sampling percentage which is applied after each time data are read from disk
371  */
372  virtual void
373  queryBoundingBox (const Eigen::Vector3d &min, const Eigen::Vector3d &max, const int query_depth, const pcl::PCLPointCloud2::Ptr &dst_blob, double percent = 1.0);
374 
375  /** \brief Returns list of pcd files from nodes whose bounding boxes intersect with the input bounding box.
376  * \param[in] min The minimum corner of the input bounding box.
377  * \param[in] max The maximum corner of the input bounding box.
378  * \param query_depth
379  * \param[out] filenames The list of paths to the PCD files which can be loaded and processed.
380  */
381  inline virtual void
382  queryBoundingBox (const Eigen::Vector3d &min, const Eigen::Vector3d &max, const int query_depth, std::list<std::string> &filenames) const
383  {
384  boost::shared_lock < boost::shared_mutex > lock (read_write_mutex_);
385  filenames.clear ();
386  this->root_node_->queryBBIntersects (min, max, query_depth, filenames);
387  }
388 
389  // Parameterization: getters and setters
390  // --------------------------------------------------------------------------------
391 
392  /** \brief Get the overall bounding box of the outofcore
393  * octree; this is the same as the bounding box of the \c root_node_ node
394  * \param min
395  * \param max
396  */
397  bool
398  getBoundingBox (Eigen::Vector3d &min, Eigen::Vector3d &max) const;
399 
400  /** \brief Get number of points at specified LOD
401  * \param[in] depth_index the level of detail at which we want the number of points (0 is root, 1, 2,...)
402  * \return number of points in the tree at \b depth
403  */
404  inline boost::uint64_t
405  getNumPointsAtDepth (const boost::uint64_t& depth_index) const
406  {
407  return (metadata_->getLODPoints (depth_index));
408  }
409 
410  /** \brief Queries the number of points in a bounding box
411  *
412  * \param[in] min The minimum corner of the input bounding box
413  * \param[out] max The maximum corner of the input bounding box
414  * \param[in] query_depth The depth of the nodes to restrict the search to (only this depth is searched)
415  * \param[in] load_from_disk (default true) Whether to load PCD files to count exactly the number of points within the bounding box; setting this to false will return an upper bound by just reading the number of points from the PCD header, even if there may be some points in that node do not fall within the query bounding box.
416  * \return Number of points in the bounding box at depth \b query_depth
417  **/
418  boost::uint64_t
419  queryBoundingBoxNumPoints (const Eigen::Vector3d& min, const Eigen::Vector3d& max, const int query_depth, bool load_from_disk = true);
420 
421 
422  /** \brief Get number of points at each LOD
423  * \return vector of number of points in each LOD indexed by each level of depth, 0 to the depth of the tree.
424  */
425  inline const std::vector<boost::uint64_t>&
427  {
428  return (metadata_->getLODPoints ());
429  }
430 
431  /** \brief Get number of LODs, which is the height of the tree
432  */
433  inline boost::uint64_t
434  getDepth () const
435  {
436  return (metadata_->getDepth ());
437  }
438 
439  inline boost::uint64_t
440  getTreeDepth () const
441  {
442  return (this->getDepth ());
443  }
444 
445  /** \brief Computes the expected voxel dimensions at the leaves
446  */
447  bool
448  getBinDimension (double &x, double &y) const;
449 
450  /** \brief gets the side length of an (assumed) perfect cubic voxel.
451  * \note If the initial bounding box specified in constructing the octree is not square, then this method does not return a sensible value
452  * \return the side length of the cubic voxel size at the specified depth
453  */
454  double
455  getVoxelSideLength (const boost::uint64_t& depth) const;
456 
457  /** \brief Gets the smallest (assumed) cubic voxel side lengths. The smallest voxels are located at the max depth of the tree.
458  * \return The side length of a the cubic voxel located at the leaves
459  */
460  double
462  {
463  return (this->getVoxelSideLength (metadata_->getDepth ()));
464  }
465 
466  /** \brief Get coordinate system tag from the JSON metadata file
467  */
468  const std::string&
469  getCoordSystem () const
470  {
471  return (metadata_->getCoordinateSystem ());
472  }
473 
474  // Mutators
475  // -----------------------------------------------------------------------
476 
477  /** \brief Generate multi-resolution LODs for the tree, which are a uniform random sampling all child leafs below the node.
478  */
479  void
480  buildLOD ();
481 
482  /** \brief Prints size of BBox to stdout
483  */
484  void
485  printBoundingBox (const size_t query_depth) const;
486 
487  /** \brief Prints the coordinates of the bounding box of the node to stdout */
488  void
489  printBoundingBox (OutofcoreNodeType& node) const;
490 
491  /** \brief Prints size of the bounding boxes to stdou
492  */
493  inline void
495  {
496  this->printBoundingBox (metadata_->getDepth ());
497  }
498 
499  /** \brief Returns the voxel centers of all existing voxels at \c query_depth
500  \param[out] voxel_centers Vector of PointXYZ voxel centers for nodes that exist at that depth
501  \param[in] query_depth the depth of the tree at which to retrieve occupied/existing voxels
502  */
503  void
504  getOccupiedVoxelCenters(AlignedPointTVector &voxel_centers, size_t query_depth) const;
505 
506  /** \brief Returns the voxel centers of all existing voxels at \c query_depth
507  \param[out] voxel_centers Vector of PointXYZ voxel centers for nodes that exist at that depth
508  \param[in] query_depth the depth of the tree at which to retrieve occupied/existing voxels
509  */
510  void
511  getOccupiedVoxelCenters(std::vector<Eigen::Vector3d, Eigen::aligned_allocator<Eigen::Vector3d> > &voxel_centers, size_t query_depth) const;
512 
513  /** \brief Gets the voxel centers of all occupied/existing leaves of the tree */
514  void
515  getOccupiedVoxelCenters(AlignedPointTVector &voxel_centers) const
516  {
517  getOccupiedVoxelCenters(voxel_centers, metadata_->getDepth ());
518  }
519 
520  /** \brief Returns the voxel centers of all occupied/existing leaves of the tree
521  * \param[out] voxel_centers std::vector of the centers of all occupied leaves of the octree
522  */
523  void
524  getOccupiedVoxelCenters(std::vector<Eigen::Vector3d, Eigen::aligned_allocator<Eigen::Vector3d> > &voxel_centers) const
525  {
526  getOccupiedVoxelCenters(voxel_centers, metadata_->getDepth ());
527  }
528 
529  // Serializers
530  // -----------------------------------------------------------------------
531 
532  /** \brief Save each .bin file as an XYZ file */
533  void
534  convertToXYZ ();
535 
536  /** \brief Write a python script using the vpython module containing all
537  * the bounding boxes */
538  void
539  writeVPythonVisual (const boost::filesystem::path filename);
540 
541  OutofcoreNodeType*
542  getBranchChildPtr (const BranchNode& branch_arg, unsigned char childIdx_arg) const;
543 
545  getLODFilter ();
546 
548  getLODFilter () const;
549 
550  /** \brief Sets the filter to use when building the levels of depth. Recommended filters are pcl::RandomSample<pcl::PCLPointCloud2> or pcl::VoxelGrid */
551  void
552  setLODFilter (const pcl::Filter<pcl::PCLPointCloud2>::Ptr& filter_arg);
553 
554  /** \brief Returns the sample_percent_ used when constructing the LOD. */
555  double
557  {
558  return (sample_percent_);
559  }
560 
561  /** \brief Sets the sampling percent for constructing LODs. Each LOD gets sample_percent^d points.
562  * \param[in] sample_percent_arg Percentage between 0 and 1. */
563  inline void
564  setSamplePercent (const double sample_percent_arg)
565  {
566  this->sample_percent_ = std::fabs (sample_percent_arg) > 1.0 ? 1.0 : std::fabs (sample_percent_arg);
567  }
568 
569  protected:
570  void
571  init (const boost::uint64_t& depth, const Eigen::Vector3d& min, const Eigen::Vector3d& max, const boost::filesystem::path& root_name, const std::string& coord_sys);
572 
574 
576 
579 
581  operator= (const OutofcoreOctreeBase &rval);
582 
583  inline OutofcoreNodeType*
585  {
586  return (this->root_node_);
587  }
588 
589  /** \brief flush empty nodes only */
590  void
591  DeAllocEmptyNodeCache (OutofcoreNodeType* current);
592 
593  /** \brief Write octree definition ".octree" (defined by octree_extension_) to disk */
594  void
595  saveToFile ();
596 
597  /** \brief recursive portion of lod builder */
598  void
599  buildLODRecursive (const std::vector<BranchNode*>& current_branch);
600 
601  /** \brief Increment current depths (LOD for branch nodes) point count; called by addDataAtMaxDepth in OutofcoreOctreeBaseNode
602  */
603  inline void
604  incrementPointsInLOD (boost::uint64_t depth, boost::uint64_t inc);
605 
606  /** \brief Auxiliary function to validate path_name extension is .octree
607  *
608  * \return 0 if bad; 1 if extension is .oct_idx
609  */
610  bool
611  checkExtension (const boost::filesystem::path& path_name);
612 
613 
614  /** \brief DEPRECATED - Flush all nodes' cache
615  * \deprecated this was moved to the octree_node class
616  */
617  void
618  flushToDisk ();
619 
620  /** \brief DEPRECATED - Flush all non leaf nodes' cache
621  * \deprecated
622  */
623  void
624  flushToDiskLazy ();
625 
626  /** \brief DEPRECATED - Flush empty nodes only
627  * \deprecated
628  */
629  void
630  DeAllocEmptyNodeCache ();
631 
632  /** \brief Pointer to the root node of the octree data structure */
633  OutofcoreNodeType* root_node_;
634 
635  /** \brief shared mutex for controlling read/write access to disk */
636  mutable boost::shared_mutex read_write_mutex_;
637 
638  boost::shared_ptr<OutofcoreOctreeBaseMetadata> metadata_;
639 
640  /** \brief defined as ".octree" to append to treepath files
641  * \note this might change
642  */
643  const static std::string TREE_EXTENSION_;
644  const static int OUTOFCORE_VERSION_;
645 
646  const static uint64_t LOAD_COUNT_ = static_cast<uint64_t>(2e9);
647 
648  private:
649 
650  /** \brief Auxiliary function to enlarge a bounding box to a cube. */
651  void
652  enlargeToCube (Eigen::Vector3d &bb_min, Eigen::Vector3d &bb_max);
653 
654  /** \brief Auxiliary function to compute the depth of the tree given the bounding box and the desired size of the leaf voxels */
655  boost::uint64_t
656  calculateDepth (const Eigen::Vector3d& min_bb, const Eigen::Vector3d& max_bb, const double leaf_resolution);
657 
658  double sample_percent_;
659 
661 
662  };
663  }
664 }
665 
666 
667 #endif // PCL_OUTOFCORE_OUTOFCOREOCTREEBASE_H_
boost::shared_ptr< const OutofcoreOctreeBase< ContainerT, PointT > > ConstPtr
Definition: octree_base.h:178
virtual void queryBoundingBox(const Eigen::Vector3d &min, const Eigen::Vector3d &max, const int query_depth, std::list< std::string > &filenames) const
Returns list of pcd files from nodes whose bounding boxes intersect with the input bounding box...
Definition: octree_base.h:382
void getOccupiedVoxelCenters(std::vector< Eigen::Vector3d, Eigen::aligned_allocator< Eigen::Vector3d > > &voxel_centers) const
Returns the voxel centers of all occupied/existing leaves of the tree.
Definition: octree_base.h:524
void printBoundingBox() const
Prints size of the bounding boxes to stdou.
Definition: octree_base.h:494
OutofcoreOctreeBaseNode< ContainerT, PointT > BranchNode
Definition: octree_base.h:165
OutofcoreOctreeBaseNode< OutofcoreOctreeRamContainer< PointT >, PointT > octree_ram_node
Definition: octree_base.h:161
boost::shared_ptr< PointCloud > PointCloudPtr
Definition: octree_base.h:185
boost::shared_ptr< OutofcoreOctreeBaseMetadata > metadata_
Definition: octree_base.h:638
OutofcoreBreadthFirstIterator< PointT, ContainerT > BreadthFirstIterator
Definition: octree_base.h:171
boost::uint64_t getTreeDepth() const
Definition: octree_base.h:440
boost::shared_ptr< ::pcl::PCLPointCloud2 > Ptr
void setSamplePercent(const double sample_percent_arg)
Sets the sampling percent for constructing LODs.
Definition: octree_base.h:564
OutofcoreIteratorBase & operator=(const OutofcoreIteratorBase &src)
OutofcoreOctreeBaseNode< ContainerT, PointT > LeafNode
Definition: octree_base.h:166
const OutofcoreDepthFirstIterator< PointT, ContainerT > ConstIterator
Definition: octree_base.h:169
Filter represents the base filter class.
Definition: filter.h:84
boost::shared_ptr< const std::vector< int > > IndicesConstPtr
Definition: octree_base.h:183
boost::shared_ptr< std::vector< int > > IndicesPtr
Definition: octree_base.h:182
boost::shared_ptr< OutofcoreOctreeBase< ContainerT, PointT > > Ptr
Definition: octree_base.h:177
std::vector< PointT, Eigen::aligned_allocator< PointT > > AlignedPointTVector
Definition: octree_base.h:188
OutofcoreOctreeBase< OutofcoreOctreeDiskContainer< PointT >, PointT > octree_disk
Definition: octree_base.h:157
void getOccupiedVoxelCenters(AlignedPointTVector &voxel_centers) const
Gets the voxel centers of all occupied/existing leaves of the tree.
Definition: octree_base.h:515
const OutofcoreBreadthFirstIterator< PointT, ContainerT > BreadthFirstConstIterator
Definition: octree_base.h:172
static const std::string TREE_EXTENSION_
defined as ".octree" to append to treepath files
Definition: octree_base.h:643
PointCloud represents the base class in PCL for storing collections of 3D points. ...
OutofcoreOctreeBaseNode Class internally representing nodes of an outofcore octree, with accessors to its data via the pcl::outofcore::OutofcoreOctreeDiskContainer class or pcl::outofcore::OutofcoreOctreeRamContainer class, whichever it is templated against.
pcl::PointCloud< PointT > PointCloud
Definition: octree_base.h:180
double getSamplePercent() const
Returns the sample_percent_ used when constructing the LOD.
Definition: octree_base.h:556
const std::vector< boost::uint64_t > & getNumPointsVector() const
Get number of points at each LOD.
Definition: octree_base.h:426
boost::shared_ptr< const PointCloud > PointCloudConstPtr
Definition: octree_base.h:186
double getVoxelSideLength() const
Gets the smallest (assumed) cubic voxel side lengths.
Definition: octree_base.h:461
Abstract octree iterator class.
OutofcoreNodeType * root_node_
Pointer to the root node of the octree data structure.
Definition: octree_base.h:633
boost::uint64_t getNumPointsAtDepth(const boost::uint64_t &depth_index) const
Get number of points at specified LOD.
Definition: octree_base.h:405
const OutofcoreDepthFirstIterator< PointT, ContainerT > DepthFirstConstIterator
Definition: octree_base.h:175
OutofcoreDepthFirstIterator< PointT, ContainerT > DepthFirstIterator
Definition: octree_base.h:174
OutofcoreOctreeBase< OutofcoreOctreeRamContainer< PointT >, PointT > octree_ram
Definition: octree_base.h:160
A point structure representing Euclidean xyz coordinates, and the RGB color.
OutofcoreOctreeBaseNode< OutofcoreOctreeDiskContainer< PointT >, PointT > octree_disk_node
Definition: octree_base.h:158
OutofcoreNodeType * getRootNode()
Definition: octree_base.h:584
This code defines the octree used for point storage at Urban Robotics.
Definition: octree_base.h:149
RandomSample applies a random sampling with uniform probability.
Definition: random_sample.h:56
OutofcoreDepthFirstIterator< PointT, ContainerT > Iterator
Definition: octree_base.h:168
boost::shared_mutex read_write_mutex_
shared mutex for controlling read/write access to disk
Definition: octree_base.h:636
OutofcoreOctreeBaseNode< ContainerT, PointT > OutofcoreNodeType
Definition: octree_base.h:163
boost::uint64_t getDepth() const
Get number of LODs, which is the height of the tree.
Definition: octree_base.h:434
const std::string & getCoordSystem() const
Get coordinate system tag from the JSON metadata file.
Definition: octree_base.h:469