Point Cloud Library (PCL)  1.7.2
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 set 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  public:
57  typedef std::set<OctreePointCloudAdjacencyContainer*> NeighborSetT;
58  //iterators to neighbors
59  typedef typename NeighborSetT::iterator iterator;
60  typedef typename NeighborSetT::const_iterator const_iterator;
61  inline iterator begin () { return (neighbors_.begin ()); }
62  inline iterator end () { return (neighbors_.end ()); }
63  inline const_iterator begin () const { return (neighbors_.begin ()); }
64  inline const_iterator end () const { return (neighbors_.end ()); }
65  //size of neighbors
66  inline size_t size () const { return neighbors_.size (); }
67  //insert for neighbors
68  inline std::pair<iterator, bool> insert (OctreePointCloudAdjacencyContainer* neighbor) { return neighbors_.insert (neighbor); }
69 
70  /** \brief Class initialization. */
73  {
74  this->reset();
75  }
76 
77  /** \brief Empty class deconstructor. */
79  {
80  }
81 
82  /** \brief deep copy function */
84  deepCopy () const
85  {
87  new_container->setNeighbors (this->neighbors_);
88  new_container->setPointCounter (this->num_points_);
89  return new_container;
90  }
91 
92  /** \brief Add new point to container- this just counts points
93  * \note To actually store data in the leaves, need to specialize this
94  * for your point and data type as in supervoxel_clustering.hpp
95  */
96  // param[in] new_point the new point to add
97  void
98  addPoint (const PointInT& /*new_point*/)
99  {
100  using namespace pcl::common;
101  ++num_points_;
102  }
103 
104  /** \brief Function for working on data added. Base implementation does nothing
105  * */
106  void
108  {
109  }
110 
111  /** \brief Gets the number of points contributing to this leaf */
112  int
113  getPointCounter () const { return num_points_; }
114 
115  /** \brief Sets the number of points contributing to this leaf */
116  void
117  setPointCounter (int points_arg) { num_points_ = points_arg; }
118 
119  /** \brief Clear the voxel centroid */
120  virtual void
121  reset ()
122  {
123  neighbors_.clear ();
124  num_points_ = 0;
125  data_ = DataT ();
126  }
127 
128  /** \brief Add new neighbor to voxel.
129  * \param[in] neighbor the new neighbor to add
130  */
131  void
133  {
134  neighbors_.insert (neighbor);
135  }
136 
137  /** \brief Remove neighbor from neighbor set.
138  * \param[in] neighbor the neighbor to remove
139  */
140  void
142  {
143  neighbors_.erase (neighbor);
144 
145  }
146 
147  /** \brief Returns the number of neighbors this leaf has
148  * \returns number of neighbors
149  */
150  size_t
152  {
153  return neighbors_.size ();
154  }
155 
156  /** \brief Sets the whole neighbor set
157  * \param[in] neighbor_arg the new set
158  */
159  void
160  setNeighbors (const NeighborSetT &neighbor_arg)
161  {
162  neighbors_ = neighbor_arg;
163  }
164 
165  /** \brief Returns a reference to the data member to access it without copying */
166  DataT&
167  getData () { return data_; }
168 
169  /** \brief Sets the data member
170  * \param[in] data_arg New value for data
171  */
172  void
173  setData (const DataT& data_arg) { data_ = data_arg;}
174 
175  /** \brief virtual method to get size of container
176  * \return number of points added to leaf node container.
177  */
178  virtual size_t
179  getSize () const
180  {
181  return num_points_;
182  }
183 
184 
185  private:
186  int num_points_;
187  NeighborSetT neighbors_;
188  DataT data_;
189  };
190  }
191 }
192 
193 #endif
Octree container class that can serve as a base to construct own leaf node container classes...
Octree adjacency leaf container class- stores set of pointers to neighbors, number of points added...
void setData(const DataT &data_arg)
Sets the data member.
virtual ~OctreePointCloudAdjacencyContainer()
Empty class deconstructor.
virtual OctreePointCloudAdjacencyContainer * deepCopy() const
deep copy function
virtual size_t getSize() const
virtual method to get size of container
std::pair< iterator, bool > insert(OctreePointCloudAdjacencyContainer *neighbor)
int getPointCounter() const
Gets the number of points contributing to this leaf.
DataT & getData()
Returns a reference to the data member to access it without copying.
void setNeighbors(const NeighborSetT &neighbor_arg)
Sets the whole neighbor set.
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.
size_t getNumNeighbors() const
Returns the number of neighbors this leaf has.
void removeNeighbor(OctreePointCloudAdjacencyContainer *neighbor)
Remove neighbor from neighbor set.
std::set< OctreePointCloudAdjacencyContainer * > NeighborSetT