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