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