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