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