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