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 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  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  data_ ()
180  {
181  reset ();
182  }
183 
184  /** \brief Octree deep copy method */
186  deepCopy () const
187  {
188  return (new OctreeContainerPointIndex (*this));
189  }
190 
191  /** \brief Equal comparison operator
192  * \param[in] other OctreeContainerBase to compare with
193  */
194  bool
195  operator== (const OctreeContainerBase& other) const override
196  {
197  const OctreeContainerPointIndex* otherConDataT = dynamic_cast<const OctreeContainerPointIndex*> (&other);
198 
199  return (this->data_ == otherConDataT->data_);
200  }
201 
202  /** \brief Add point index to container memory. This container stores a only a single point index.
203  * \param[in] data_arg index to be stored within leaf node.
204  */
205  void
206  addPointIndex (int data_arg)
207  {
208  data_ = data_arg;
209  }
210 
211  /** \brief Retrieve point index from container. This container stores a only a single point index
212  * \return index stored within container.
213  */
214  int
215  getPointIndex () const
216  {
217  return data_;
218  }
219 
220  /** \brief Retrieve point indices from container. This container stores only a single point index
221  * \param[out] data_vector_arg vector of point indices to be stored within data vector
222  */
223  void
224  getPointIndices (std::vector<int>& data_vector_arg) const
225  {
226  if (data_>=0)
227  data_vector_arg.push_back (data_);
228  }
229 
230  /** \brief Get size of container (number of DataT objects)
231  * \return number of DataT elements in leaf node container.
232  */
233  size_t
234  getSize () const override
235  {
236  return data_<0 ? 0 : 1;
237  }
238 
239  /** \brief Reset leaf node memory to zero. */
240  void
241  reset () override
242  {
243  data_ = -1;
244  }
245  protected:
246  /** \brief Point index stored in octree. */
247  int data_;
248  };
249 
250  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
251  /** \brief @b Octree container class that does store a vector of point indices.
252  * \note Enables the octree to store multiple DataT elements within its leaf nodes.
253  * \author Julius Kammerl (julius@kammerl.de)
254  */
256  {
257  public:
258  /** \brief Octree deep copy method */
260  deepCopy () const
261  {
262  return (new OctreeContainerPointIndices (*this));
263  }
264 
265  /** \brief Equal comparison operator
266  * \param[in] other OctreeContainerDataTVector to compare with
267  */
268  bool
269  operator== (const OctreeContainerBase& other) const override
270  {
271  const OctreeContainerPointIndices* otherConDataTVec = dynamic_cast<const OctreeContainerPointIndices*> (&other);
272 
273  return (this->leafDataTVector_ == otherConDataTVec->leafDataTVector_);
274  }
275 
276  /** \brief Add point index to container memory. This container stores a vector of point indices.
277  * \param[in] data_arg index to be stored within leaf node.
278  */
279  void
280  addPointIndex (int data_arg)
281  {
282  leafDataTVector_.push_back (data_arg);
283  }
284 
285  /** \brief Retrieve point index from container. This container stores a vector of point indices.
286  * \return index stored within container.
287  */
288  int
289  getPointIndex ( ) const
290  {
291  return leafDataTVector_.back ();
292  }
293 
294  /** \brief Retrieve point indices from container. This container stores a vector of point indices.
295  * \param[out] data_vector_arg vector of point indices to be stored within data vector
296  */
297  void
298  getPointIndices (std::vector<int>& data_vector_arg) const
299  {
300  data_vector_arg.insert (data_vector_arg.end (), leafDataTVector_.begin (), leafDataTVector_.end ());
301  }
302 
303  /** \brief Retrieve reference to point indices vector. This container stores a vector of point indices.
304  * \return reference to vector of point indices to be stored within data vector
305  */
306  std::vector<int>&
308  {
309  return leafDataTVector_;
310  }
311 
312  /** \brief Get size of container (number of indices)
313  * \return number of point indices in container.
314  */
315  size_t
316  getSize () const override
317  {
318  return leafDataTVector_.size ();
319  }
320 
321  /** \brief Reset leaf node. Clear DataT vector.*/
322  void
323  reset () override
324  {
325  leafDataTVector_.clear ();
326  }
327 
328  protected:
329  /** \brief Leaf node DataT vector. */
330  std::vector<int> leafDataTVector_;
331  };
332 
333  }
334 }
virtual OctreeContainerPointIndex * deepCopy() const
Octree deep copy method.
Octree container class that can serve as a base to construct own leaf node container classes...
void addPointIndex(int data_arg)
Add point index to container memory.
size_t getSize() const override
Abstract get size of container (number of DataT objects)
virtual size_t getSize() const
Pure abstract method to get size of container (number of 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:44
virtual OctreeContainerEmpty * deepCopy() const
Octree deep copy method.
void getPointIndex(int &) const
Empty getPointIndex implementation as this leaf node does not store any point indices.
virtual ~OctreeContainerBase()=default
void addPointIndex(int data_arg)
Add point index to container memory.
OctreeContainerPointIndex()
Empty constructor.
virtual void reset()=0
Pure abstract reset leaf node implementation.
void reset() override
Reset leaf node.
virtual bool operator==(const OctreeContainerBase &) const
Equal comparison operator.
int data_
Point index stored in octree.
int getPointIndex() const
Retrieve point index from container.
virtual OctreeContainerPointIndices * deepCopy() const
Octree deep copy method.
Octree container class that does store a vector of point indices.
void getPointIndices(std::vector< int > &) const
Empty getPointIndices implementation as this leaf node does not store any data.
void addPointIndex(int)
Empty addPointIndex implementation.
std::vector< int > & getPointIndicesVector()
Retrieve reference to point indices vector.
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 reset() override
Reset leaf node memory to zero.
void reset() override
Abstract reset leaf node implementation.
void getPointIndices(std::vector< int > &data_vector_arg) const
Retrieve point indices from container.
int getPointIndex() const
Empty getPointIndex implementation as this leaf node does not store any point indices.
void addPointIndex(const int &)
Empty addPointIndex implementation.
bool operator!=(const OctreeContainerBase &other) const
Inequal comparison operator.
Octree container class that does not store any information.
int getPointIndex() const
Retrieve point index from container.
std::vector< int > leafDataTVector_
Leaf node DataT vector.
size_t getSize() const override
Get size of container (number of indices)
size_t getSize() const override
Get size of container (number of DataT objects)