Point Cloud Library (PCL)  1.9.1-dev
octree_pointcloud_changedetector.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2010-2011, Willow Garage, Inc.
6  *
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * * Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  * * Redistributions in binary form must reproduce the above
16  * copyright notice, this list of conditions and the following
17  * disclaimer in the documentation and/or other materials provided
18  * with the distribution.
19  * * Neither the name of Willow Garage, Inc. nor the names of its
20  * contributors may be used to endorse or promote products derived
21  * from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  * POSSIBILITY OF SUCH DAMAGE.
35  *
36  * $Id$
37  */
38 
39 #pragma once
40 
41 #include <boost/shared_ptr.hpp>
42 
43 #include <pcl/octree/octree_pointcloud.h>
44 #include <pcl/octree/octree2buf_base.h>
45 
46 namespace pcl
47 {
48  namespace octree
49  {
50 
51  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
52  /** \brief @b Octree pointcloud change detector class
53  * \note This pointcloud octree class generate an octrees from a point cloud (zero-copy). It allows to detect new leaf nodes and serialize their point indices
54  * \note The octree pointcloud is initialized with its voxel resolution. Its bounding box is automatically adjusted or can be predefined.
55  * \note
56  * \note typename: PointT: type of point used in pointcloud
57  * \ingroup octree
58  * \author Julius Kammerl (julius@kammerl.de)
59  */
60  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
61  template<typename PointT,
62  typename LeafContainerT = OctreeContainerPointIndices,
63  typename BranchContainerT = OctreeContainerEmpty >
64 
66  LeafContainerT, BranchContainerT, Octree2BufBase<LeafContainerT, BranchContainerT> >
67 
68  {
69 
70  public:
71 
72  using Ptr = boost::shared_ptr<OctreePointCloudChangeDetector<PointT, LeafContainerT, BranchContainerT>>;
73  using ConstPtr = boost::shared_ptr<const OctreePointCloudChangeDetector<PointT, LeafContainerT, BranchContainerT>>;
74 
75  /** \brief Constructor.
76  * \param resolution_arg: octree resolution at lowest octree level
77  * */
78  OctreePointCloudChangeDetector (const double resolution_arg) :
79  OctreePointCloud<PointT, LeafContainerT, BranchContainerT,
80  Octree2BufBase<LeafContainerT, BranchContainerT> > (resolution_arg)
81  {
82  }
83 
84  /** \brief Get a indices from all leaf nodes that did not exist in previous buffer.
85  * \param indicesVector_arg: results are written to this vector of int indices
86  * \param minPointsPerLeaf_arg: minimum amount of points required within leaf node to become serialized.
87  * \return number of point indices
88  */
89  std::size_t getPointIndicesFromNewVoxels (std::vector<int> &indicesVector_arg,
90  const int minPointsPerLeaf_arg = 0)
91  {
92 
93  std::vector<OctreeContainerPointIndices*> leaf_containers;
94  this->serializeNewLeafs (leaf_containers);
95 
96  for (const auto &leaf_container : leaf_containers)
97  {
98  if (static_cast<int> (leaf_container->getSize ()) >= minPointsPerLeaf_arg)
99  leaf_container->getPointIndices(indicesVector_arg);
100  }
101 
102  return (indicesVector_arg.size ());
103  }
104  };
105  }
106 }
107 
108 #define PCL_INSTANTIATE_OctreePointCloudChangeDetector(T) template class PCL_EXPORTS pcl::octree::OctreePointCloudChangeDetector<T>;
Octree pointcloud class
This file defines compatibility wrappers for low level I/O functions.
Definition: convolution.h:45
void serializeNewLeafs(std::vector< LeafContainerT *> &leaf_container_vector_arg)
Outputs a vector of all DataT elements from leaf nodes, that do not exist in the previous octree buff...
std::size_t getPointIndicesFromNewVoxels(std::vector< int > &indicesVector_arg, const int minPointsPerLeaf_arg=0)
Get a indices from all leaf nodes that did not exist in previous buffer.
Octree double buffer class
boost::shared_ptr< const OctreePointCloud< PointInT, OctreeContainerPointIndices, OctreeContainerEmpty, Octree2BufBase< OctreeContainerPointIndices, OctreeContainerEmpty > > > ConstPtr
A point structure representing Euclidean xyz coordinates, and the RGB color.
OctreePointCloudChangeDetector(const double resolution_arg)
Constructor.
boost::shared_ptr< OctreePointCloud< PointInT, OctreeContainerPointIndices, OctreeContainerEmpty, Octree2BufBase< OctreeContainerPointIndices, OctreeContainerEmpty > > > Ptr