Point Cloud Library (PCL)  1.15.1-dev
octree_base_node.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 #pragma once
41 
42 #include <memory>
43 #include <mutex>
44 #include <random>
45 #include <list>
46 
47 #include <pcl/common/io.h>
48 #include <pcl/PCLPointCloud2.h>
49 #include <pcl/point_types.h> // for pcl::PointXYZ
50 
51 #include <pcl/outofcore/octree_base.h>
52 #include <pcl/outofcore/octree_disk_container.h>
53 #include <pcl/outofcore/outofcore_node_data.h>
54 
55 #include <pcl/octree/octree_nodes.h>
56 
57 namespace pcl
58 {
59  namespace outofcore
60  {
61  // Forward Declarations
62  template<typename ContainerT, typename PointT>
63  class OutofcoreOctreeBaseNode;
64 
65  template<typename ContainerT, typename PointT>
66  class OutofcoreOctreeBase;
67 
68  /** \brief Non-class function which creates a single child leaf; used with \ref queryBBIntersects_noload to avoid loading the data from disk */
69  template<typename ContainerT, typename PointT> OutofcoreOctreeBaseNode<ContainerT, PointT>*
70  makenode_norec (const boost::filesystem::path &path, OutofcoreOctreeBaseNode<ContainerT, PointT>* super);
71 
72  /** \brief Non-class method which performs a bounding box query without loading any of the point cloud data from disk */
73  template<typename ContainerT, typename PointT> void
74  queryBBIntersects_noload (const boost::filesystem::path &root_node, const Eigen::Vector3d &min, const Eigen::Vector3d &max, const std::uint32_t query_depth, std::list<std::string> &bin_name);
75 
76  /** \brief Non-class method overload */
77  template<typename ContainerT, typename PointT> void
78  queryBBIntersects_noload (OutofcoreOctreeBaseNode<ContainerT, PointT>* current, const Eigen::Vector3d&, const Eigen::Vector3d &max, const std::uint32_t query_depth, std::list<std::string> &bin_name);
79 
80  /** \class OutofcoreOctreeBaseNode
81  *
82  * \note Code was adapted from the Urban Robotics out of core octree implementation.
83  * Contact Jacob Schloss <jacob.schloss@urbanrobotics.net> with any questions.
84  * http://www.urbanrobotics.net/
85  *
86  * \brief OutofcoreOctreeBaseNode Class internally representing nodes of an
87  * outofcore octree, with accessors to its data via the \ref
88  * pcl::outofcore::OutofcoreOctreeDiskContainer class or \ref pcl::outofcore::OutofcoreOctreeRamContainer class,
89  * whichever it is templated against.
90  *
91  * \ingroup outofcore
92  * \author Jacob Schloss (jacob.schloss@urbanrobotics.net)
93  *
94  */
95  template<typename ContainerT = OutofcoreOctreeDiskContainer<pcl::PointXYZ>, typename PointT = pcl::PointXYZ>
97  {
98  friend class OutofcoreOctreeBase<ContainerT, PointT> ;
99 
100  //these methods can be rewritten with the iterators.
102  makenode_norec<ContainerT, PointT> (const boost::filesystem::path &path, OutofcoreOctreeBaseNode<ContainerT, PointT>* super);
103 
104  friend void
105  queryBBIntersects_noload<ContainerT, PointT> (const boost::filesystem::path &rootnode, const Eigen::Vector3d &min, const Eigen::Vector3d &max, const std::uint32_t query_depth, std::list<std::string> &bin_name);
106 
107  friend void
108  queryBBIntersects_noload<ContainerT, PointT> (OutofcoreOctreeBaseNode<ContainerT, PointT>* current, const Eigen::Vector3d &min, const Eigen::Vector3d &max, const std::uint32_t query_depth, std::list<std::string> &bin_name);
109 
110  public:
113 
114  using AlignedPointTVector = std::vector<PointT, Eigen::aligned_allocator<PointT> >;
115 
117 
118  const static std::string node_index_basename;
119  const static std::string node_container_basename;
120  const static std::string node_index_extension;
121  const static std::string node_container_extension;
122  const static double sample_percent_;
123 
124  /** \brief Empty constructor; sets pointers for children and for bounding boxes to 0
125  */
127 
128  /** \brief Create root node and directory */
129  OutofcoreOctreeBaseNode (const Eigen::Vector3d &bb_min, const Eigen::Vector3d &bb_max, OutofcoreOctreeBase<ContainerT, PointT> * const tree, const boost::filesystem::path &root_name);
130 
131  /** \brief Will recursively delete all children calling recFreeChildrein */
132 
133  ~OutofcoreOctreeBaseNode () override;
134 
135  //query
136  /** \brief gets the minimum and maximum corner of the bounding box represented by this node
137  * \param[out] min_bb returns the minimum corner of the bounding box indexed by 0-->X, 1-->Y, 2-->Z
138  * \param[out] max_bb returns the maximum corner of the bounding box indexed by 0-->X, 1-->Y, 2-->Z
139  */
140  virtual inline void
141  getBoundingBox (Eigen::Vector3d &min_bb, Eigen::Vector3d &max_bb) const
142  {
143  node_metadata_->getBoundingBox (min_bb, max_bb);
144  }
145 
146 
147  const boost::filesystem::path&
148  getPCDFilename () const
149  {
150  return node_metadata_->getPCDFilename ();
151  }
152 
153  const boost::filesystem::path&
155  {
156  return node_metadata_->getMetadataFilename ();
157  }
158 
159  void
160  queryFrustum (const double planes[24], std::list<std::string>& file_names);
161 
162  void
163  queryFrustum (const double planes[24], std::list<std::string>& file_names, const std::uint32_t query_depth, const bool skip_vfc_check = false);
164 
165  /** \warning This function is only available if the visualization module is available and the preprocessor symbol `PCL_VISUALIZATION_AVAILABLE` is defined.
166  */
167 #ifdef PCL_VISUALIZATION_AVAILABLE
168  void
169  queryFrustum (const double planes[24], const Eigen::Vector3d &eye, const Eigen::Matrix4d &view_projection_matrix, std::list<std::string>& file_names, const std::uint32_t query_depth, const bool skip_vfc_check = false);
170 #else
171  void
172  queryFrustum (const double planes[24], const Eigen::Vector3d &eye, const Eigen::Matrix4d &view_projection_matrix, std::list<std::string>& file_names, const std::uint32_t query_depth, const bool skip_vfc_check = false) = delete;
173 #endif
174 
175  //point extraction
176  /** \brief Recursively add points that fall into the queried bounding box up to the \b query_depth
177  *
178  * \param[in] min_bb the minimum corner of the bounding box, indexed by X,Y,Z coordinates
179  * \param[in] max_bb the maximum corner of the bounding box, indexed by X,Y,Z coordinates
180  * \param[in] query_depth the maximum depth to query in the octree for points within the bounding box
181  * \param[out] dst destion of points returned by the queries
182  */
183  virtual void
184  queryBBIncludes (const Eigen::Vector3d &min_bb, const Eigen::Vector3d &max_bb, std::size_t query_depth, AlignedPointTVector &dst);
185 
186  /** \brief Recursively add points that fall into the queried bounding box up to the \b query_depth
187  *
188  * \param[in] min_bb the minimum corner of the bounding box, indexed by X,Y,Z coordinates
189  * \param[in] max_bb the maximum corner of the bounding box, indexed by X,Y,Z coordinates
190  * \param[in] query_depth the maximum depth to query in the octree for points within the bounding box
191  * \param[out] dst_blob destion of points returned by the queries
192  */
193  virtual void
194  queryBBIncludes (const Eigen::Vector3d &min_bb, const Eigen::Vector3d &max_bb, std::size_t query_depth, const pcl::PCLPointCloud2::Ptr &dst_blob);
195 
196  /** \brief Recursively add points that fall into the queried bounding box up to the \b query_depth
197  *
198  * \param[in] min_bb the minimum corner of the bounding box, indexed by X,Y,Z coordinates
199  * \param[in] max_bb the maximum corner of the bounding box, indexed by X,Y,Z coordinates
200  * \param[in] query_depth
201  * \param percent
202  * \param[out] v std::list of points returned by the query
203  */
204  virtual void
205  queryBBIncludes_subsample (const Eigen::Vector3d &min_bb, const Eigen::Vector3d &max_bb, std::uint64_t query_depth, const double percent, AlignedPointTVector &v);
206 
207  virtual void
208  queryBBIncludes_subsample (const Eigen::Vector3d &min_bb, const Eigen::Vector3d &max_bb, std::uint64_t query_depth, const pcl::PCLPointCloud2::Ptr& dst_blob, double percent = 1.0);
209 
210  /** \brief Recursive acquires PCD paths to any node with which the queried bounding box intersects (at query_depth only).
211  */
212  virtual void
213  queryBBIntersects (const Eigen::Vector3d &min_bb, const Eigen::Vector3d &max_bb, const std::uint32_t query_depth, std::list<std::string> &file_names);
214 
215  /** \brief Write the voxel size to stdout at \c query_depth
216  * \param[in] query_depth The depth at which to print the size of the voxel/bounding boxes
217  */
218  virtual void
219  printBoundingBox (const std::size_t query_depth) const;
220 
221  /** \brief add point to this node if we are a leaf, or find the leaf below us that is supposed to take the point
222  * \param[in] p vector of points to add to the leaf
223  * \param[in] skip_bb_check whether to check if the point's coordinates fall within the bounding box
224  */
225  virtual std::uint64_t
226  addDataToLeaf (const AlignedPointTVector &p, const bool skip_bb_check = true);
227 
228  virtual std::uint64_t
229  addDataToLeaf (const std::vector<const PointT*> &p, const bool skip_bb_check = true);
230 
231  /** \brief Add a single PCLPointCloud2 object into the octree.
232  *
233  * \param[in] input_cloud
234  * \param[in] skip_bb_check (default = false)
235  */
236  virtual std::uint64_t
237  addPointCloud (const pcl::PCLPointCloud2::Ptr &input_cloud, const bool skip_bb_check = false);
238 
239  /** \brief Add a single PCLPointCloud2 into the octree and build the subsampled LOD during construction; this method of LOD construction is <b>not</b> multiresolution. Rather, there are no redundant data. */
240  virtual std::uint64_t
241  addPointCloud_and_genLOD (const pcl::PCLPointCloud2::Ptr input_cloud); //, const bool skip_bb_check);
242 
243  /** \brief Recursively add points to the leaf and children subsampling LODs
244  * on the way down.
245  *
246  * \note rng_mutex_ lock occurs
247  */
248  virtual std::uint64_t
249  addDataToLeaf_and_genLOD (const AlignedPointTVector &p, const bool skip_bb_check);
250 
251  /** \brief Write a python visual script to @b file
252  * \param[in] file output file stream to write the python visual script
253  */
254  void
255  writeVPythonVisual (std::ofstream &file);
256 
257  virtual int
258  read (pcl::PCLPointCloud2::Ptr &output_cloud);
259 
260  inline node_type_t
261  getNodeType () const override
262  {
263  if(this->getNumChildren () > 0)
264  {
265  return (pcl::octree::BRANCH_NODE);
266  }
267  return (pcl::octree::LEAF_NODE);
268  }
269 
270 
272  deepCopy () const override
273  {
274  OutofcoreOctreeBaseNode* res = nullptr;
275  PCL_THROW_EXCEPTION (PCLException, "Not implemented\n");
276  return (res);
277  }
278 
279  virtual inline std::size_t
280  getDepth () const
281  {
282  return (this->depth_);
283  }
284 
285  /** \brief Returns the total number of children on disk */
286  virtual std::size_t
287  getNumChildren () const
288  {
289  std::size_t res = this->countNumChildren ();
290  return (res);
291  }
292 
293  /** \brief Count loaded children */
294  virtual std::size_t
296  {
297  std::size_t res = this->countNumLoadedChildren ();
298  return (res);
299  }
300 
301  /** \brief Returns a pointer to the child in octant index_arg */
302  virtual OutofcoreOctreeBaseNode*
303  getChildPtr (std::size_t index_arg) const;
304 
305  /** \brief Gets the number of points available in the PCD file */
306  virtual std::uint64_t
307  getDataSize () const;
308 
309  inline virtual void
311  {
312  //clears write cache and removes PCD file from disk
313  this->payload_->clear ();
314  }
315 
316  ///////////////////////////////////////////////////////////////////////////////
317  // PROTECTED METHODS
318  ////////////////////////////////////////////////////////////////////////////////
319  protected:
320  /** \brief Load from disk
321  * If creating root, path is full name. If creating any other
322  * node, path is dir; throws exception if directory or metadata not found
323  *
324  * \param[in] directory_path pathname
325  * \param[in] super
326  * \param[in] load_all
327  * \throws PCLException if directory is missing
328  * \throws PCLException if node index is missing
329  */
330  OutofcoreOctreeBaseNode (const boost::filesystem::path &directory_path, OutofcoreOctreeBaseNode<ContainerT, PointT>* super, bool load_all);
331 
332  /** \brief Create root node and directory
333  *
334  * Initializes the root node and performs initial filesystem checks for the octree;
335  * throws OctreeException::OCT_BAD_PATH if root directory is an existing file
336  *
337  * \param bb_min triple of x,y,z minima for bounding box
338  * \param bb_max triple of x,y,z maxima for bounding box
339  * \param tree address of the tree data structure that will hold this initial root node
340  * \param rootname Root directory for location of on-disk octree storage; if directory
341  * doesn't exist, it is created; if "rootname" is an existing file,
342  *
343  * \throws PCLException if the specified path already exists
344  */
345  void init_root_node (const Eigen::Vector3d &bb_min, const Eigen::Vector3d &bb_max, OutofcoreOctreeBase<ContainerT, PointT> * const tree, const boost::filesystem::path &rootname);
346 
347  /** \brief no copy construction right now */
349 
350  /** \brief Operator= is not implemented */
353 
354  /** \brief Counts the number of child directories on disk; used to update num_children_ */
355  virtual std::size_t
356  countNumChildren () const;
357 
358  /** \brief Counts the number of loaded children by testing the \c children_ array;
359  * used to update num_loaded_children_ internally
360  */
361  virtual std::size_t
362  countNumLoadedChildren () const;
363 
364  /** \brief Save node's metadata to file
365  * \param[in] recursive if false, save only this node's metadata to file; if true, recursively
366  * save all children's metadata to files as well
367  */
368  void
369  saveIdx (bool recursive);
370 
371  /** \brief Randomly sample point data
372  */
373  void
374  randomSample (const AlignedPointTVector &p, AlignedPointTVector &insertBuff, const bool skip_bb_check);
375 
376  /** \brief Subdivide points to pass to child nodes */
377  void
378  subdividePoints (const AlignedPointTVector &p, std::vector< AlignedPointTVector > &c, const bool skip_bb_check);
379  /** \brief Subdivide a single point into a specific child node */
380  void
381  subdividePoint (const PointT &point, std::vector< AlignedPointTVector > &c);
382 
383  /** \brief Add data to the leaf when at max depth of tree. If
384  * skip_bb_check is true, adds to the node regardless of the
385  * bounding box it represents; otherwise only adds points that
386  * fall within the bounding box
387  *
388  * \param[in] p vector of points to attempt to add to the tree
389  * \param[in] skip_bb_check if @b true, doesn't check that points
390  * are in the proper bounding box; if @b false, only adds the
391  * points that fall into the bounding box to this node
392  * \return number of points successfully added
393  */
394  std::uint64_t
395  addDataAtMaxDepth (const AlignedPointTVector &p, const bool skip_bb_check = true);
396 
397  /** \brief Add data to the leaf when at max depth of tree. If
398  * \c skip_bb_check is true, adds to the node regardless of the
399  * bounding box it represents; otherwise only adds points that
400  * fall within the bounding box
401  *
402  * \param[in] input_cloud PCLPointCloud2 points to attempt to add to the tree;
403  * \warning PCLPointCloud2 inserted into the tree must have x,y,z fields, and must be of same type of any other points inserted in the tree
404  * \param[in] skip_bb_check (default true) if @b true, doesn't check that points
405  * are in the proper bounding box; if @b false, only adds the
406  * points that fall into the bounding box to this node
407  * \return number of points successfully added
408  */
409  std::uint64_t
410  addDataAtMaxDepth (const pcl::PCLPointCloud2::Ptr input_cloud, const bool skip_bb_check = true);
411 
412  /** \brief Tests whether the input bounding box intersects with the current node's bounding box
413  * \param[in] min_bb The minimum corner of the input bounding box
414  * \param[in] max_bb The maximum corner of the input bounding box
415  * \return bool True if any portion of the bounding box intersects with this node's bounding box; false otherwise
416  */
417  inline bool
418  intersectsWithBoundingBox (const Eigen::Vector3d &min_bb, const Eigen::Vector3d &max_bb) const;
419 
420  /** \brief Tests whether the input bounding box falls inclusively within this node's bounding box
421  * \param[in] min_bb The minimum corner of the input bounding box
422  * \param[in] max_bb The maximum corner of the input bounding box
423  * \return bool True if the input bounding box falls inclusively within the boundaries of this node's bounding box
424  **/
425  inline bool
426  inBoundingBox (const Eigen::Vector3d &min_bb, const Eigen::Vector3d &max_bb) const;
427 
428  /** \brief Tests whether \c point falls within the input bounding box
429  * \param[in] min_bb The minimum corner of the input bounding box
430  * \param[in] max_bb The maximum corner of the input bounding box
431  * \param[in] point The test point
432  */
433  bool
434  pointInBoundingBox (const Eigen::Vector3d &min_bb, const Eigen::Vector3d &max_bb, const Eigen::Vector3d &point);
435 
436  /** \brief Tests whether \c p falls within the input bounding box
437  * \param[in] min_bb The minimum corner of the input bounding box
438  * \param[in] max_bb The maximum corner of the input bounding box
439  * \param[in] p The point to be tested
440  **/
441  static bool
442  pointInBoundingBox (const Eigen::Vector3d &min_bb, const Eigen::Vector3d &max_bb, const PointT &p);
443 
444  /** \brief Tests whether \c x, \c y, and \c z fall within the input bounding box
445  * \param[in] min_bb The minimum corner of the input bounding box
446  * \param[in] max_bb The maximum corner of the input bounding box
447  * \param x
448  * \param y
449  * \param z
450  **/
451  static bool
452  pointInBoundingBox (const Eigen::Vector3d &min_bb, const Eigen::Vector3d &max_bb, const double x, const double y, const double z);
453 
454  /** \brief Tests if specified point is within bounds of current node's bounding box */
455  inline bool
456  pointInBoundingBox (const PointT &p) const;
457 
458  /** \brief Creates child node \c idx
459  * \param[in] idx Index (0-7) of the child node
460  */
461  void
462  createChild (const std::size_t idx);
463 
464  /** \brief Write JSON metadata for this node to file */
465  void
466  saveMetadataToFile (const boost::filesystem::path &path);
467 
468  /** \brief Method which recursively free children of this node
469  */
470  void
471  recFreeChildren ();
472 
473  /** \brief Number of points in the payload */
474  inline std::uint64_t
475  size () const
476  {
477  return (payload_->size ());
478  }
479 
480  void
482 
483  /** \brief Loads the nodes metadata from the JSON file
484  */
485  void
486  loadFromFile (const boost::filesystem::path &path, OutofcoreOctreeBaseNode* super);
487 
488  /** \brief Recursively converts data files to ascii XZY files */
489  void
491 
492  /** \brief Private constructor used for children
493  */
494  OutofcoreOctreeBaseNode (const Eigen::Vector3d &bb_min, const Eigen::Vector3d &bb_max, const char* dir, OutofcoreOctreeBaseNode<ContainerT, PointT>* super);
495 
496  /** \brief Copies points from this and all children into a single point container (std::list)
497  */
498  void
499  copyAllCurrentAndChildPointsRec (std::list<PointT> &v);
500 
501  void
502  copyAllCurrentAndChildPointsRec_sub (std::list<PointT> &v, const double percent);
503 
504  /** \brief Returns whether or not a node has unloaded children data */
505  bool
506  hasUnloadedChildren () const;
507 
508  /** \brief Load nodes child data creating new nodes for each */
509  virtual void
510  loadChildren (bool recursive);
511 
512  /** \brief Gets a vector of occupied voxel centers
513  * \param[out] voxel_centers
514  * \param[in] query_depth
515  */
516  void
517  getOccupiedVoxelCentersRecursive (AlignedPointTVector &voxel_centers, const std::size_t query_depth);
518 
519  /** \brief Gets a vector of occupied voxel centers
520  * \param[out] voxel_centers
521  * \param[in] query_depth
522  */
523  void
524  getOccupiedVoxelCentersRecursive (std::vector<Eigen::Vector3d, Eigen::aligned_allocator<Eigen::Vector3d> > &voxel_centers, const std::size_t query_depth);
525 
526  /** \brief Sorts the indices based on x,y,z fields and pushes the index into the proper octant's vector;
527  * This could be overloaded with a parallelized implementation
528  */
529  void
530  sortOctantIndices (const pcl::PCLPointCloud2::Ptr &input_cloud, std::vector< pcl::Indices > &indices, const Eigen::Vector3d &mid_xyz);
531 
532  /** \brief Enlarges the shortest two sidelengths of the
533  * bounding box to a cubic shape; operation is done in
534  * place.
535  */
536  void
537  enlargeToCube (Eigen::Vector3d &bb_min, Eigen::Vector3d &bb_max);
538 
539  /** \brief The tree we belong to */
541  /** \brief The root node of the tree we belong to */
543  /** \brief super-node */
545  /** \brief Depth in the tree, root is 0, root's children are 1, ... */
546  std::size_t depth_;
547  /** \brief The children of this node */
548  std::vector<OutofcoreOctreeBaseNode*> children_;
549 
550  /** \brief Number of children on disk. This is only changed when a new node is created */
551  std::uint64_t num_children_;
552 
553  /** \brief Number of loaded children this node has
554  *
555  * "Loaded" means child OctreeBaseNodes have been allocated,
556  * and their metadata files have been loaded into
557  * memory. num_loaded_children_ <= num_children_
558  */
559  std::uint64_t num_loaded_children_;
560 
561  /** \brief what holds the points. currently a custom class, but in theory
562  * you could use an stl container if you rewrote some of this class. I used
563  * to use deques for this... */
564  std::shared_ptr<ContainerT> payload_;
565 
566  /** \brief Random number generator mutex */
567  static std::mutex rng_mutex_;
568 
569  /** \brief Mersenne Twister: A 623-dimensionally equidistributed uniform
570  * pseudo-random number generator */
571  static std::mt19937 rng_;
572 
573  /** \brief Extension for this class to find the pcd files on disk */
574  const static std::string pcd_extension;
575 
577  };
578  }//namespace outofcore
579 }//namespace pcl
A base class for all pcl exceptions which inherits from std::runtime_error.
Definition: exceptions.h:67
Abstract octree node class
Definition: octree_nodes.h:59
This code defines the octree used for point storage at Urban Robotics.
Definition: octree_base.h:151
OutofcoreOctreeBaseNode Class internally representing nodes of an outofcore octree,...
std::size_t depth_
Depth in the tree, root is 0, root's children are 1, ...
virtual void getBoundingBox(Eigen::Vector3d &min_bb, Eigen::Vector3d &max_bb) const
gets the minimum and maximum corner of the bounding box represented by this node
bool intersectsWithBoundingBox(const Eigen::Vector3d &min_bb, const Eigen::Vector3d &max_bb) const
Tests whether the input bounding box intersects with the current node's bounding box.
static const std::string node_index_basename
virtual std::uint64_t addPointCloud_and_genLOD(const pcl::PCLPointCloud2::Ptr input_cloud)
Add a single PCLPointCloud2 into the octree and build the subsampled LOD during construction; this me...
static const std::string node_index_extension
virtual std::uint64_t getDataSize() const
Gets the number of points available in the PCD file.
~OutofcoreOctreeBaseNode() override
Will recursively delete all children calling recFreeChildrein.
const boost::filesystem::path & getPCDFilename() const
void copyAllCurrentAndChildPointsRec_sub(std::list< PointT > &v, const double percent)
void loadFromFile(const boost::filesystem::path &path, OutofcoreOctreeBaseNode *super)
Loads the nodes metadata from the JSON file.
OutofcoreOctreeBaseNode & operator=(const OutofcoreOctreeBaseNode &rval)
Operator= is not implemented.
bool hasUnloadedChildren() const
Returns whether or not a node has unloaded children data.
void randomSample(const AlignedPointTVector &p, AlignedPointTVector &insertBuff, const bool skip_bb_check)
Randomly sample point data.
virtual std::uint64_t addDataToLeaf_and_genLOD(const AlignedPointTVector &p, const bool skip_bb_check)
Recursively add points to the leaf and children subsampling LODs on the way down.
OutofcoreOctreeBase< ContainerT, PointT > * m_tree_
The tree we belong to.
static std::mutex rng_mutex_
Random number generator mutex.
virtual void queryBBIncludes_subsample(const Eigen::Vector3d &min_bb, const Eigen::Vector3d &max_bb, std::uint64_t query_depth, const double percent, AlignedPointTVector &v)
Recursively add points that fall into the queried bounding box up to the query_depth.
const boost::filesystem::path & getMetadataFilename() const
virtual std::size_t getNumChildren() const
Returns the total number of children on disk.
std::uint64_t num_children_
Number of children on disk.
virtual void queryBBIntersects(const Eigen::Vector3d &min_bb, const Eigen::Vector3d &max_bb, const std::uint32_t query_depth, std::list< std::string > &file_names)
Recursive acquires PCD paths to any node with which the queried bounding box intersects (at query_dep...
void writeVPythonVisual(std::ofstream &file)
Write a python visual script to file.
OutofcoreOctreeBaseNode()
Empty constructor; sets pointers for children and for bounding boxes to 0.
static bool pointInBoundingBox(const Eigen::Vector3d &min_bb, const Eigen::Vector3d &max_bb, const double x, const double y, const double z)
Tests whether x, y, and z fall within the input bounding box.
virtual std::size_t countNumChildren() const
Counts the number of child directories on disk; used to update num_children_.
void convertToXYZRecursive()
Recursively converts data files to ascii XZY files.
OutofcoreOctreeBaseNode * parent_
super-node
void init_root_node(const Eigen::Vector3d &bb_min, const Eigen::Vector3d &bb_max, OutofcoreOctreeBase< ContainerT, PointT > *const tree, const boost::filesystem::path &rootname)
Create root node and directory.
std::shared_ptr< ContainerT > payload_
what holds the points.
virtual int read(pcl::PCLPointCloud2::Ptr &output_cloud)
OutofcoreOctreeBaseNode * root_node_
The root node of the tree we belong to.
std::uint64_t num_loaded_children_
Number of loaded children this node has.
bool pointInBoundingBox(const Eigen::Vector3d &min_bb, const Eigen::Vector3d &max_bb, const Eigen::Vector3d &point)
Tests whether point falls within the input bounding box.
void saveIdx(bool recursive)
Save node's metadata to file.
void queryFrustum(const double planes[24], std::list< std::string > &file_names)
OutofcoreOctreeNodeMetadata::Ptr node_metadata_
void queryFrustum(const double planes[24], const Eigen::Vector3d &eye, const Eigen::Matrix4d &view_projection_matrix, std::list< std::string > &file_names, const std::uint32_t query_depth, const bool skip_vfc_check=false)=delete
std::vector< PointT, Eigen::aligned_allocator< PointT > > AlignedPointTVector
OutofcoreOctreeBaseNode * deepCopy() const override
Pure virtual method to perform a deep copy of the octree.
void sortOctantIndices(const pcl::PCLPointCloud2::Ptr &input_cloud, std::vector< pcl::Indices > &indices, const Eigen::Vector3d &mid_xyz)
Sorts the indices based on x,y,z fields and pushes the index into the proper octant's vector; This co...
void getOccupiedVoxelCentersRecursive(AlignedPointTVector &voxel_centers, const std::size_t query_depth)
Gets a vector of occupied voxel centers.
std::vector< OutofcoreOctreeBaseNode * > children_
The children of this node.
static const std::string node_container_basename
std::uint64_t size() const
Number of points in the payload.
OutofcoreOctreeBaseNode(const OutofcoreOctreeBaseNode &rval)
no copy construction right now
static const std::string pcd_extension
Extension for this class to find the pcd files on disk.
virtual std::size_t getNumLoadedChildren() const
Count loaded children.
void subdividePoints(const AlignedPointTVector &p, std::vector< AlignedPointTVector > &c, const bool skip_bb_check)
Subdivide points to pass to child nodes.
void copyAllCurrentAndChildPointsRec(std::list< PointT > &v)
Copies points from this and all children into a single point container (std::list)
static std::mt19937 rng_
Mersenne Twister: A 623-dimensionally equidistributed uniform pseudo-random number generator.
void subdividePoint(const PointT &point, std::vector< AlignedPointTVector > &c)
Subdivide a single point into a specific child node.
virtual std::size_t getDepth() const
virtual void loadChildren(bool recursive)
Load nodes child data creating new nodes for each.
virtual std::size_t countNumLoadedChildren() const
Counts the number of loaded children by testing the children_ array; used to update num_loaded_childr...
std::uint64_t addDataAtMaxDepth(const AlignedPointTVector &p, const bool skip_bb_check=true)
Add data to the leaf when at max depth of tree.
bool inBoundingBox(const Eigen::Vector3d &min_bb, const Eigen::Vector3d &max_bb) const
Tests whether the input bounding box falls inclusively within this node's bounding box.
virtual OutofcoreOctreeBaseNode * getChildPtr(std::size_t index_arg) const
Returns a pointer to the child in octant index_arg.
virtual std::uint64_t addDataToLeaf(const AlignedPointTVector &p, const bool skip_bb_check=true)
add point to this node if we are a leaf, or find the leaf below us that is supposed to take the point
void saveMetadataToFile(const boost::filesystem::path &path)
Write JSON metadata for this node to file.
static const std::string node_container_extension
void recFreeChildren()
Method which recursively free children of this node.
virtual void queryBBIncludes(const Eigen::Vector3d &min_bb, const Eigen::Vector3d &max_bb, std::size_t query_depth, AlignedPointTVector &dst)
Recursively add points that fall into the queried bounding box up to the query_depth.
void enlargeToCube(Eigen::Vector3d &bb_min, Eigen::Vector3d &bb_max)
Enlarges the shortest two sidelengths of the bounding box to a cubic shape; operation is done in plac...
void createChild(const std::size_t idx)
Creates child node idx.
virtual std::uint64_t addPointCloud(const pcl::PCLPointCloud2::Ptr &input_cloud, const bool skip_bb_check=false)
Add a single PCLPointCloud2 object into the octree.
node_type_t getNodeType() const override
Pure virtual method for retrieving the type of octree node (branch or leaf)
virtual void printBoundingBox(const std::size_t query_depth) const
Write the voxel size to stdout at query_depth.
shared_ptr< OutofcoreOctreeNodeMetadata > Ptr
Defines all the PCL implemented PointT point type structures.
OutofcoreOctreeBaseNode< ContainerT, PointT > * makenode_norec(const boost::filesystem::path &path, OutofcoreOctreeBaseNode< ContainerT, PointT > *super)
Non-class function which creates a single child leaf; used with queryBBIntersects_noload to avoid loa...
void queryBBIntersects_noload(const boost::filesystem::path &root_node, const Eigen::Vector3d &min, const Eigen::Vector3d &max, const std::uint32_t query_depth, std::list< std::string > &bin_name)
Non-class method which performs a bounding box query without loading any of the point cloud data from...
shared_ptr< ::pcl::PCLPointCloud2 > Ptr
A point structure representing Euclidean xyz coordinates, and the RGB color.