Point Cloud Library (PCL) 1.13.0
Loading...
Searching...
No Matches
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#pragma once
41
42#include <pcl/common/io.h>
43
44//outofcore classes
45#include <pcl/outofcore/octree_base_node.h>
46#include <pcl/outofcore/octree_disk_container.h>
47#include <pcl/outofcore/octree_ram_container.h>
48
49//outofcore iterators
50#include <pcl/outofcore/outofcore_iterator_base.h>
51#include <pcl/outofcore/outofcore_breadth_first_iterator.h>
52#include <pcl/outofcore/outofcore_depth_first_iterator.h>
53#include <pcl/outofcore/impl/outofcore_breadth_first_iterator.hpp>
54#include <pcl/outofcore/impl/outofcore_depth_first_iterator.hpp>
55
56//outofcore metadata
57#include <pcl/outofcore/metadata.h>
58#include <pcl/outofcore/outofcore_base_data.h>
59
60#include <pcl/filters/filter.h>
61#include <pcl/filters/random_sample.h>
62
63#include <pcl/PCLPointCloud2.h>
64
65#include <shared_mutex>
66
67namespace pcl
68{
69 namespace outofcore
70 {
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>;
152 friend class pcl::outofcore::OutofcoreIteratorBase<PointT, ContainerT>;
153
154 public:
155
156 // public typedefs
159
162
164
167
170
173
176
177 using Ptr = shared_ptr<OutofcoreOctreeBase<ContainerT, PointT> >;
178 using ConstPtr = shared_ptr<const OutofcoreOctreeBase<ContainerT, PointT> >;
179
181
182 using IndicesPtr = shared_ptr<pcl::Indices>;
183 using IndicesConstPtr = shared_ptr<const pcl::Indices>;
184
187
188 using AlignedPointTVector = std::vector<PointT, Eigen::aligned_allocator<PointT> >;
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 std::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 std::uint64_t
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 std::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 points successfully copied from the point cloud to the octree
260 */
261 std::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 std::uint64_t
283
284 std::uint64_t
286
287 std::uint64_t
289
290 /** \brief Recursively add points to the tree subsampling LODs on the way.
291 *
292 * shared read_write_mutex lock occurs
293 */
294 std::uint64_t
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 std::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 std::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 std::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 std::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 std::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, std::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 std::shared_lock < std::shared_timed_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 std::uint64_t
405 getNumPointsAtDepth (const std::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 std::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<std::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 std::uint64_t
434 getDepth () const
435 {
436 return (metadata_->getDepth ());
437 }
438
439 inline std::uint64_t
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 std::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&
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 std::size_t query_depth) const;
486
487 /** \brief Prints the coordinates of the bounding box of the node to stdout */
488 void
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, std::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, std::size_t query_depth) const;
512
513 /** \brief Gets the voxel centers of all occupied/existing leaves of the tree */
514 void
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
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
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 std::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
582
583 inline OutofcoreNodeType*
585 {
586 return (this->root_node_);
587 }
588
589 /** \brief flush empty nodes only */
590 void
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 (std::uint64_t depth, std::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 /** \brief Flush all nodes' cache */
614 void
615 flushToDisk ();
616
617 /** \brief Flush all non leaf nodes' cache */
618 void
620
621 /** \brief Flush empty nodes only */
622 void
624
625 /** \brief Pointer to the root node of the octree data structure */
627
628 /** \brief shared mutex for controlling read/write access to disk */
629 mutable std::shared_timed_mutex read_write_mutex_;
630
632
633 /** \brief defined as ".octree" to append to treepath files
634 * \note this might change
635 */
636 const static std::string TREE_EXTENSION_;
637 const static int OUTOFCORE_VERSION_;
638
639 const static std::uint64_t LOAD_COUNT_ = static_cast<std::uint64_t>(2e9);
640
641 private:
642
643 /** \brief Auxiliary function to enlarge a bounding box to a cube. */
644 void
645 enlargeToCube (Eigen::Vector3d &bb_min, Eigen::Vector3d &bb_max);
646
647 /** \brief Auxiliary function to compute the depth of the tree given the bounding box and the desired size of the leaf voxels */
648 std::uint64_t
649 calculateDepth (const Eigen::Vector3d& min_bb, const Eigen::Vector3d& max_bb, const double leaf_resolution);
650
651 double sample_percent_;
652
654
655 };
656 }
657}
shared_ptr< Filter< PointT > > Ptr
Definition filter.h:83
shared_ptr< const Filter< PointT > > ConstPtr
Definition filter.h:84
PointCloud represents the base class in PCL for storing collections of 3D points.
shared_ptr< PointCloud< PointT > > Ptr
shared_ptr< const PointCloud< PointT > > ConstPtr
shared_ptr< RandomSample< PointT > > Ptr
This code defines the octree used for point storage at Urban Robotics.
OutofcoreOctreeBaseNode< OutofcoreOctreeRamContainer< PointT >, PointT > octree_ram_node
void DeAllocEmptyNodeCache()
Flush empty nodes only.
const OutofcoreDepthFirstIterator< PointT, ContainerT > ConstIterator
OutofcoreOctreeBaseMetadata::Ptr metadata_
shared_ptr< pcl::Indices > IndicesPtr
std::uint64_t queryBoundingBoxNumPoints(const Eigen::Vector3d &min, const Eigen::Vector3d &max, const int query_depth, bool load_from_disk=true)
Queries the number of points in a bounding box.
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.
std::uint64_t getNumPointsAtDepth(const std::uint64_t &depth_index) const
Get number of points at specified LOD.
OutofcoreNodeType * getRootNode()
std::uint64_t addDataToLeaf(const AlignedPointTVector &p)
Recursively add points to the tree.
OutofcoreOctreeBase< OutofcoreOctreeRamContainer< PointT >, PointT > octree_ram
void incrementPointsInLOD(std::uint64_t depth, std::uint64_t inc)
Increment current depths (LOD for branch nodes) point count; called by addDataAtMaxDepth in Outofcore...
void queryFrustum(const double *planes, std::list< std::string > &file_names) const
std::shared_timed_mutex read_write_mutex_
shared mutex for controlling read/write access to disk
void DeAllocEmptyNodeCache(OutofcoreNodeType *current)
flush empty nodes only
const OutofcoreBreadthFirstIterator< PointT, ContainerT > BreadthFirstConstIterator
std::uint64_t addPointCloud_and_genLOD(pcl::PCLPointCloud2::Ptr &input_cloud)
Recursively add points to the tree.
const std::string & getCoordSystem() const
Get coordinate system tag from the JSON metadata file.
void convertToXYZ()
Save each .bin file as an XYZ file.
const std::vector< std::uint64_t > & getNumPointsVector() const
Get number of points at each LOD.
void getOccupiedVoxelCenters(AlignedPointTVector &voxel_centers, std::size_t query_depth) const
Returns the voxel centers of all existing voxels at query_depth.
void writeVPythonVisual(const boost::filesystem::path &filename)
Write a python script using the vpython module containing all the bounding boxes.
void buildLOD()
Generate multi-resolution LODs for the tree, which are a uniform random sampling all child leafs belo...
void queryBBIncludes(const Eigen::Vector3d &min, const Eigen::Vector3d &max, const std::uint64_t query_depth, AlignedPointTVector &dst) const
Get Points in BB, only points inside BB.
OutofcoreOctreeBaseNode< ContainerT, PointT > BranchNode
typename PointCloud::Ptr PointCloudPtr
void queryBBIntersects(const Eigen::Vector3d &min, const Eigen::Vector3d &max, const std::uint32_t query_depth, std::list< std::string > &bin_name) const
Get a list of file paths at query_depth that intersect with your bounding box specified by min and ma...
std::uint64_t getDepth() const
Get number of LODs, which is the height of the tree.
bool getBoundingBox(Eigen::Vector3d &min, Eigen::Vector3d &max) const
Get the overall bounding box of the outofcore octree; this is the same as the bounding box of the roo...
double getVoxelSideLength() const
Gets the smallest (assumed) cubic voxel side lengths.
void flushToDiskLazy()
Flush all non leaf nodes' cache.
virtual void queryBoundingBox(const Eigen::Vector3d &min, const Eigen::Vector3d &max, const int query_depth, const pcl::PCLPointCloud2::Ptr &dst_blob, double percent=1.0)
Query all points falling within the input bounding box at query_depth and return a PCLPointCloud2 obj...
std::uint64_t getTreeDepth() const
bool checkExtension(const boost::filesystem::path &path_name)
Auxiliary function to validate path_name extension is .octree.
std::uint64_t addDataToLeaf_and_genLOD(AlignedPointTVector &p)
Recursively add points to the tree subsampling LODs on the way.
OutofcoreBreadthFirstIterator< PointT, ContainerT > BreadthFirstIterator
OutofcoreOctreeBaseNode< ContainerT, PointT > OutofcoreNodeType
bool getBinDimension(double &x, double &y) const
Computes the expected voxel dimensions at the leaves.
shared_ptr< OutofcoreOctreeBase< ContainerT, PointT > > Ptr
std::vector< PointT, Eigen::aligned_allocator< PointT > > AlignedPointTVector
shared_ptr< const OutofcoreOctreeBase< ContainerT, PointT > > ConstPtr
void flushToDisk()
Flush all nodes' cache.
void printBoundingBox() const
Prints size of the bounding boxes to stdou.
OutofcoreDepthFirstIterator< PointT, ContainerT > Iterator
void buildLODRecursive(const std::vector< BranchNode * > &current_branch)
recursive portion of lod builder
static const std::string TREE_EXTENSION_
defined as ".octree" to append to treepath files
shared_ptr< const pcl::Indices > IndicesConstPtr
OutofcoreNodeType * getBranchChildPtr(const BranchNode &branch_arg, unsigned char childIdx_arg) const
void getOccupiedVoxelCenters(AlignedPointTVector &voxel_centers) const
Gets the voxel centers of all occupied/existing leaves of the tree.
const OutofcoreDepthFirstIterator< PointT, ContainerT > DepthFirstConstIterator
OutofcoreOctreeBase(const OutofcoreOctreeBase &rval)
void queryBBIncludes_subsample(const Eigen::Vector3d &min, const Eigen::Vector3d &max, std::uint64_t query_depth, const double percent, AlignedPointTVector &dst) const
Returns a random subsample of points within the given bounding box at query_depth.
void printBoundingBox(OutofcoreNodeType &node) const
Prints the coordinates of the bounding box of the node to stdout.
std::uint64_t addPointCloud(PointCloudConstPtr point_cloud)
Copies the points from the point_cloud falling within the bounding box of the octree to the out-of-co...
void init(const std::uint64_t &depth, const Eigen::Vector3d &min, const Eigen::Vector3d &max, const boost::filesystem::path &root_name, const std::string &coord_sys)
OutofcoreOctreeBase< OutofcoreOctreeDiskContainer< PointT >, PointT > octree_disk
void setSamplePercent(const double sample_percent_arg)
Sets the sampling percent for constructing LODs.
std::uint64_t addPointCloud(pcl::PCLPointCloud2::Ptr &input_cloud)
void saveToFile()
Write octree definition ".octree" (defined by octree_extension_) to disk.
OutofcoreDepthFirstIterator< PointT, ContainerT > DepthFirstIterator
OutofcoreOctreeBase & operator=(OutofcoreOctreeBase &rval)
OutofcoreOctreeBase(OutofcoreOctreeBase &rval)
OutofcoreOctreeBaseNode< OutofcoreOctreeDiskContainer< PointT >, PointT > octree_disk_node
static const std::uint64_t LOAD_COUNT_
double getSamplePercent() const
Returns the sample_percent_ used when constructing the LOD.
typename PointCloud::ConstPtr PointCloudConstPtr
void setLODFilter(const pcl::Filter< pcl::PCLPointCloud2 >::Ptr &filter_arg)
Sets the filter to use when building the levels of depth.
OutofcoreNodeType * root_node_
Pointer to the root node of the octree data structure.
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.
pcl::Filter< pcl::PCLPointCloud2 >::Ptr getLODFilter()
shared_ptr< OutofcoreOctreeBaseMetadata > Ptr
OutofcoreOctreeBaseNode Class internally representing nodes of an outofcore octree,...
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...
shared_ptr< ::pcl::PCLPointCloud2 > Ptr
A point structure representing Euclidean xyz coordinates, and the RGB color.