Point Cloud Library (PCL)  1.11.0
octree_pointcloud_adjacency_container.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2012, Jeremie Papon
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  * Author : jpapon@gmail.com
37  * Email : jpapon@gmail.com
38  */
39 
40 #pragma once
41 
42 namespace pcl {
43 
44 namespace octree {
45 /** \brief @b Octree adjacency leaf container class- stores a list of pointers to
46  * neighbors, number of points added, and a DataT value \note This class implements a
47  * leaf node that stores pointers to neighboring leaves \note This class also has a
48  * virtual computeData function, which is called by
49  * octreePointCloudAdjacency::addPointsFromInputCloud. \note You should make explicit
50  * instantiations of it for your pointtype/datatype combo (if needed) see
51  * supervoxel_clustering.hpp for an example of this
52  */
53 template <typename PointInT, typename DataT = PointInT>
55  template <typename T, typename U, typename V>
57 
58 public:
59  using NeighborListT = std::list<OctreePointCloudAdjacencyContainer<PointInT, DataT>*>;
60  using const_iterator = typename NeighborListT::const_iterator;
61  // const iterators to neighbors
62  inline const_iterator
63  cbegin() const
64  {
65  return (neighbors_.begin());
66  }
67  inline const_iterator
68  cend() const
69  {
70  return (neighbors_.end());
71  }
72  // size of neighbors
73  inline std::size_t
74  size() const
75  {
76  return neighbors_.size();
77  }
78 
79  /** \brief Class initialization. */
81 
82  /** \brief Empty class deconstructor. */
84 
85  /** \brief Returns the number of neighbors this leaf has
86  * \returns number of neighbors
87  */
88  std::size_t
90  {
91  return neighbors_.size();
92  }
93 
94  /** \brief Gets the number of points contributing to this leaf */
95  int
97  {
98  return num_points_;
99  }
100 
101  /** \brief Returns a reference to the data member to access it without copying */
102  DataT&
104  {
105  return data_;
106  }
107 
108  /** \brief Sets the data member
109  * \param[in] data_arg New value for data
110  */
111  void
112  setData(const DataT& data_arg)
113  {
114  data_ = data_arg;
115  }
116 
117  /** \brief virtual method to get size of container
118  * \return number of points added to leaf node container.
119  */
120  std::size_t
121  getSize() const override
122  {
123  return num_points_;
124  }
125 
126 protected:
127  // iterators to neighbors
128  using iterator = typename NeighborListT::iterator;
129  inline iterator
131  {
132  return (neighbors_.begin());
133  }
134  inline iterator
135  end()
136  {
137  return (neighbors_.end());
138  }
139 
140  /** \brief deep copy function */
142  deepCopy() const
143  {
144  OctreePointCloudAdjacencyContainer* new_container =
146  new_container->setNeighbors(this->neighbors_);
147  new_container->setPointCounter(this->num_points_);
148  return new_container;
149  }
150 
151  /** \brief Add new point to container- this just counts points
152  * \note To actually store data in the leaves, need to specialize this
153  * for your point and data type as in supervoxel_clustering.hpp
154  */
155  // param[in] new_point the new point to add
156  void
157  addPoint(const PointInT& /*new_point*/)
158  {
159  using namespace pcl::common;
160  ++num_points_;
161  }
162 
163  /** \brief Function for working on data added. Base implementation does nothing
164  * */
165  void
167  {}
168 
169  /** \brief Sets the number of points contributing to this leaf */
170  void
171  setPointCounter(int points_arg)
172  {
173  num_points_ = points_arg;
174  }
175 
176  /** \brief Clear the voxel centroid */
177  void
178  reset() override
179  {
180  neighbors_.clear();
181  num_points_ = 0;
182  data_ = DataT();
183  }
184 
185  /** \brief Add new neighbor to voxel.
186  * \param[in] neighbor the new neighbor to add
187  */
188  void
190  {
191  neighbors_.push_back(neighbor);
192  }
193 
194  /** \brief Remove neighbor from neighbor set.
195  * \param[in] neighbor the neighbor to remove
196  */
197  void
199  {
200  for (iterator neighb_it = neighbors_.begin(); neighb_it != neighbors_.end();
201  ++neighb_it) {
202  if (*neighb_it == neighbor) {
203  neighbors_.erase(neighb_it);
204  return;
205  }
206  }
207  }
208 
209  /** \brief Sets the whole neighbor set
210  * \param[in] neighbor_arg the new set
211  */
212  void
213  setNeighbors(const NeighborListT& neighbor_arg)
214  {
215  neighbors_ = neighbor_arg;
216  }
217 
218 private:
219  int num_points_;
220  NeighborListT neighbors_;
221  DataT data_;
222 };
223 } // namespace octree
224 } // namespace pcl
pcl::octree::OctreePointCloudAdjacencyContainer::cbegin
const_iterator cbegin() const
Definition: octree_pointcloud_adjacency_container.h:63
pcl
Definition: convolution.h:46
pcl::octree::OctreePointCloudAdjacencyContainer::getPointCounter
int getPointCounter() const
Gets the number of points contributing to this leaf.
Definition: octree_pointcloud_adjacency_container.h:96
pcl::octree::OctreePointCloudAdjacencyContainer::deepCopy
virtual OctreePointCloudAdjacencyContainer * deepCopy() const
deep copy function
Definition: octree_pointcloud_adjacency_container.h:142
pcl::common
Definition: generate.h:50
pcl::octree::OctreePointCloudAdjacencyContainer::setData
void setData(const DataT &data_arg)
Sets the data member.
Definition: octree_pointcloud_adjacency_container.h:112
pcl::octree::OctreePointCloudAdjacencyContainer::const_iterator
typename NeighborListT::const_iterator const_iterator
Definition: octree_pointcloud_adjacency_container.h:60
pcl::octree::OctreePointCloudAdjacencyContainer::begin
iterator begin()
Definition: octree_pointcloud_adjacency_container.h:130
pcl::octree::OctreePointCloudAdjacencyContainer::reset
void reset() override
Clear the voxel centroid.
Definition: octree_pointcloud_adjacency_container.h:178
pcl::octree::OctreePointCloudAdjacencyContainer::getNumNeighbors
std::size_t getNumNeighbors() const
Returns the number of neighbors this leaf has.
Definition: octree_pointcloud_adjacency_container.h:89
pcl::octree::OctreePointCloudAdjacencyContainer::addNeighbor
void addNeighbor(OctreePointCloudAdjacencyContainer *neighbor)
Add new neighbor to voxel.
Definition: octree_pointcloud_adjacency_container.h:189
pcl::octree::OctreePointCloudAdjacencyContainer::end
iterator end()
Definition: octree_pointcloud_adjacency_container.h:135
pcl::octree::OctreePointCloudAdjacencyContainer::~OctreePointCloudAdjacencyContainer
~OctreePointCloudAdjacencyContainer()
Empty class deconstructor.
Definition: octree_pointcloud_adjacency_container.h:83
pcl::octree::OctreePointCloudAdjacencyContainer
Octree adjacency leaf container class- stores a list of pointers to neighbors, number of points added...
Definition: octree_pointcloud_adjacency_container.h:54
pcl::octree::OctreePointCloudAdjacencyContainer::setNeighbors
void setNeighbors(const NeighborListT &neighbor_arg)
Sets the whole neighbor set.
Definition: octree_pointcloud_adjacency_container.h:213
pcl::octree::OctreePointCloudAdjacencyContainer::iterator
typename NeighborListT::iterator iterator
Definition: octree_pointcloud_adjacency_container.h:128
pcl::octree::OctreePointCloudAdjacency
Octree pointcloud voxel class which maintains adjacency information for its voxels.
Definition: octree_pointcloud_adjacency.h:81
pcl::octree::OctreePointCloudAdjacencyContainer::cend
const_iterator cend() const
Definition: octree_pointcloud_adjacency_container.h:68
pcl::octree::OctreePointCloudAdjacencyContainer::getData
DataT & getData()
Returns a reference to the data member to access it without copying.
Definition: octree_pointcloud_adjacency_container.h:103
pcl::octree::OctreePointCloudAdjacencyContainer::size
std::size_t size() const
Definition: octree_pointcloud_adjacency_container.h:74
pcl::octree::OctreePointCloudAdjacencyContainer::OctreePointCloudAdjacencyContainer
OctreePointCloudAdjacencyContainer()
Class initialization.
Definition: octree_pointcloud_adjacency_container.h:80
pcl::octree::OctreePointCloudAdjacencyContainer::setPointCounter
void setPointCounter(int points_arg)
Sets the number of points contributing to this leaf.
Definition: octree_pointcloud_adjacency_container.h:171
pcl::octree::OctreePointCloudAdjacencyContainer::NeighborListT
std::list< OctreePointCloudAdjacencyContainer< PointInT, DataT > * > NeighborListT
Definition: octree_pointcloud_adjacency_container.h:59
pcl::octree::OctreePointCloudAdjacencyContainer::addPoint
void addPoint(const PointInT &)
Add new point to container- this just counts points.
Definition: octree_pointcloud_adjacency_container.h:157
pcl::octree::OctreePointCloudAdjacencyContainer::removeNeighbor
void removeNeighbor(OctreePointCloudAdjacencyContainer *neighbor)
Remove neighbor from neighbor set.
Definition: octree_pointcloud_adjacency_container.h:198
pcl::octree::OctreePointCloudAdjacencyContainer::getSize
std::size_t getSize() const override
virtual method to get size of container
Definition: octree_pointcloud_adjacency_container.h:121
pcl::octree::OctreePointCloudAdjacencyContainer::computeData
void computeData()
Function for working on data added.
Definition: octree_pointcloud_adjacency_container.h:166
pcl::octree::OctreeContainerBase
Octree container class that can serve as a base to construct own leaf node container classes.
Definition: octree_container.h:53