Point Cloud Library (PCL)  1.10.1-dev
octree_container.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2010-2011, Willow Garage, Inc.
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  * $Id: octree_nodes.h 5596 2012-04-17 15:09:31Z jkammerl $
37  */
38 
39 #pragma once
40 
41 #include <vector>
42 
43 #include <cassert>
44 #include <cstddef>
45 
46 namespace pcl {
47 namespace octree {
48 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
49 /** \brief @b Octree container class that can serve as a base to construct own leaf node
50  * container classes.
51  * \author Julius Kammerl (julius@kammerl.de)
52  */
54 public:
55  virtual ~OctreeContainerBase() = default;
56 
57  /** \brief Equal comparison operator
58  */
59  virtual bool
61  {
62  return false;
63  }
64 
65  /** \brief Inequal comparison operator
66  * \param[in] other OctreeContainerBase to compare with
67  */
68  bool
69  operator!=(const OctreeContainerBase& other) const
70  {
71  return (!operator==(other));
72  }
73 
74  /** \brief Pure abstract method to get size of container (number of indices)
75  * \return number of points/indices stored in leaf node container.
76  */
77  virtual std::size_t
78  getSize() const
79  {
80  return 0u;
81  }
82 
83  /** \brief Pure abstract reset leaf node implementation. */
84  virtual void
85  reset() = 0;
86 
87  /** \brief Empty addPointIndex implementation. This leaf node does not store any point
88  * indices.
89  */
90  void
91  addPointIndex(const int&)
92  {}
93 
94  /** \brief Empty getPointIndex implementation as this leaf node does not store any
95  * point indices.
96  */
97  void
98  getPointIndex(int&) const
99  {}
100 
101  /** \brief Empty getPointIndices implementation as this leaf node does not store any
102  * data. \
103  */
104  void
105  getPointIndices(std::vector<int>&) const
106  {}
107 };
108 
109 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
110 /** \brief @b Octree container class that does not store any information.
111  * \note Can be used for occupancy trees that are used for checking only the existence
112  * of leaf nodes in the tree
113  * \author Julius Kammerl (julius@kammerl.de)
114  */
115 
117 public:
118  /** \brief Octree deep copy method */
119  virtual OctreeContainerEmpty*
120  deepCopy() const
121  {
122  return (new OctreeContainerEmpty(*this));
123  }
124 
125  /** \brief Abstract get size of container (number of DataT objects)
126  * \return number of DataT elements in leaf node container.
127  */
128  std::size_t
129  getSize() const override
130  {
131  return 0;
132  }
133 
134  /** \brief Abstract reset leaf node implementation. */
135  void
136  reset() override
137  {}
138 
139  /** \brief Empty addPointIndex implementation. This leaf node does not store any point
140  * indices.
141  */
142  void
144  {}
145 
146  /** \brief Empty getPointIndex implementation as this leaf node does not store any
147  * point indices.
148  */
149  int
151  {
152  assert("getPointIndex: undefined point index");
153  return -1;
154  }
155 
156  /** \brief Empty getPointIndices implementation as this leaf node does not store any
157  * data.
158  */
159  void
160  getPointIndices(std::vector<int>&) const
161  {}
162 };
163 
164 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
165 /** \brief @b Octree container class that does store a single point index.
166  * \note Enables the octree to store a single DataT element within its leaf nodes.
167  * \author Julius Kammerl (julius@kammerl.de)
168  */
170 public:
171  /** \brief Empty constructor. */
173 
174  /** \brief Octree deep copy method */
176  deepCopy() const
177  {
178  return (new OctreeContainerPointIndex(*this));
179  }
180 
181  /** \brief Equal comparison operator
182  * \param[in] other OctreeContainerBase to compare with
183  */
184  bool
185  operator==(const OctreeContainerBase& other) const override
186  {
187  const OctreeContainerPointIndex* otherConDataT =
188  dynamic_cast<const OctreeContainerPointIndex*>(&other);
189 
190  return (this->data_ == otherConDataT->data_);
191  }
192 
193  /** \brief Add point index to container memory. This container stores a only a single
194  * point index.
195  * \param[in] data_arg index to be stored within leaf node.
196  */
197  void
198  addPointIndex(int data_arg)
199  {
200  data_ = data_arg;
201  }
202 
203  /** \brief Retrieve point index from container. This container stores a only a single
204  * point index
205  * \return index stored within container.
206  */
207  int
209  {
210  return data_;
211  }
212 
213  /** \brief Retrieve point indices from container. This container stores only a single
214  * point index
215  * \param[out] data_vector_arg vector of point indices to be stored within
216  * data vector
217  */
218  void
219  getPointIndices(std::vector<int>& data_vector_arg) const
220  {
221  if (data_ >= 0)
222  data_vector_arg.push_back(data_);
223  }
224 
225  /** \brief Get size of container (number of DataT objects)
226  * \return number of DataT elements in leaf node container.
227  */
228  std::size_t
229  getSize() const override
230  {
231  return data_ < 0 ? 0 : 1;
232  }
233 
234  /** \brief Reset leaf node memory to zero. */
235  void
236  reset() override
237  {
238  data_ = -1;
239  }
240 
241 protected:
242  /** \brief Point index stored in octree. */
243  int data_;
244 };
245 
246 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
247 /** \brief @b Octree container class that does store a vector of point indices.
248  * \note Enables the octree to store multiple DataT elements within its leaf nodes.
249  * \author Julius Kammerl (julius@kammerl.de)
250  */
252 public:
253  /** \brief Octree deep copy method */
255  deepCopy() const
256  {
257  return (new OctreeContainerPointIndices(*this));
258  }
259 
260  /** \brief Equal comparison operator
261  * \param[in] other OctreeContainerDataTVector to compare with
262  */
263  bool
264  operator==(const OctreeContainerBase& other) const override
265  {
266  const OctreeContainerPointIndices* otherConDataTVec =
267  dynamic_cast<const OctreeContainerPointIndices*>(&other);
268 
269  return (this->leafDataTVector_ == otherConDataTVec->leafDataTVector_);
270  }
271 
272  /** \brief Add point index to container memory. This container stores a vector of
273  * point indices.
274  * \param[in] data_arg index to be stored within leaf node.
275  */
276  void
277  addPointIndex(int data_arg)
278  {
279  leafDataTVector_.push_back(data_arg);
280  }
281 
282  /** \brief Retrieve point index from container. This container stores a vector of
283  * point indices.
284  * \return index stored within container.
285  */
286  int
288  {
289  return leafDataTVector_.back();
290  }
291 
292  /** \brief Retrieve point indices from container. This container stores a vector of
293  * point indices.
294  * \param[out] data_vector_arg vector of point indices to be stored
295  * within data vector
296  */
297  void
298  getPointIndices(std::vector<int>& data_vector_arg) const
299  {
300  data_vector_arg.insert(
301  data_vector_arg.end(), leafDataTVector_.begin(), leafDataTVector_.end());
302  }
303 
304  /** \brief Retrieve reference to point indices vector. This container stores a vector
305  * of point indices.
306  * \return reference to vector of point indices to be stored within data vector
307  */
308  std::vector<int>&
310  {
311  return leafDataTVector_;
312  }
313 
314  /** \brief Get size of container (number of indices)
315  * \return number of point indices in container.
316  */
317  std::size_t
318  getSize() const override
319  {
320  return leafDataTVector_.size();
321  }
322 
323  /** \brief Reset leaf node. Clear DataT vector.*/
324  void
325  reset() override
326  {
327  leafDataTVector_.clear();
328  }
329 
330 protected:
331  /** \brief Leaf node DataT vector. */
332  std::vector<int> leafDataTVector_;
333 };
334 
335 } // namespace octree
336 } // namespace pcl
std::size_t getSize() const override
Get size of container (number of indices)
Octree container class that can serve as a base to construct own leaf node container classes...
void getPointIndices(std::vector< int > &data_vector_arg) const
Retrieve point indices from container.
void getPointIndices(std::vector< int > &) const
Empty getPointIndices implementation as this leaf node does not store any data.
void addPointIndex(int data_arg)
Add point index to container memory.
int getPointIndex() const
Empty getPointIndex implementation as this leaf node does not store any point indices.
Octree container class that does store a single point index.
void getPointIndex(int &) const
Empty getPointIndex implementation as this leaf node does not store any point indices.
virtual ~OctreeContainerBase()=default
virtual OctreeContainerPointIndex * deepCopy() const
Octree deep copy method.
virtual OctreeContainerEmpty * deepCopy() const
Octree deep copy method.
void getPointIndices(std::vector< int > &data_vector_arg) const
Retrieve point indices from container.
std::size_t getSize() const override
Get size of container (number of DataT objects)
void addPointIndex(int data_arg)
Add point index to container memory.
OctreeContainerPointIndex()
Empty constructor.
bool operator==(const OctreeContainerBase &other) const override
Equal comparison operator.
std::size_t getSize() const override
Abstract get size of container (number of DataT objects)
void getPointIndices(std::vector< int > &) const
Empty getPointIndices implementation as this leaf node does not store any data.
virtual void reset()=0
Pure abstract reset leaf node implementation.
void reset() override
Reset leaf node.
int data_
Point index stored in octree.
int getPointIndex() const
Retrieve point index from container.
Octree container class that does store a vector of point indices.
void addPointIndex(int)
Empty addPointIndex implementation.
std::vector< int > & getPointIndicesVector()
Retrieve reference to point indices vector.
bool operator!=(const OctreeContainerBase &other) const
Inequal comparison operator.
bool operator==(const OctreeContainerBase &other) const override
Equal comparison operator.
void reset() override
Reset leaf node memory to zero.
void reset() override
Abstract reset leaf node implementation.
virtual bool operator==(const OctreeContainerBase &) const
Equal comparison operator.
void addPointIndex(const int &)
Empty addPointIndex implementation.
Octree container class that does not store any information.
std::vector< int > leafDataTVector_
Leaf node DataT vector.
virtual OctreeContainerPointIndices * deepCopy() const
Octree deep copy method.
virtual std::size_t getSize() const
Pure abstract method to get size of container (number of indices)
int getPointIndex() const
Retrieve point index from container.