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