Point Cloud Library (PCL)  1.8.1
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 #ifndef PCL_OCTREE_CONTAINER_H
40 #define PCL_OCTREE_CONTAINER_H
41 
42 #include <vector>
43 #include <cstddef>
44 
45 #include <pcl/pcl_macros.h>
46 
47 namespace pcl
48 {
49  namespace octree
50  {
51  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
52  /** \brief @b Octree container class that can serve as a base to construct own leaf node container classes.
53  * \author Julius Kammerl (julius@kammerl.de)
54  */
56  {
57  public:
58  /** \brief Empty constructor. */
60  {
61  }
62 
63  /** \brief Empty constructor. */
65  {
66  }
67 
68  /** \brief Empty deconstructor. */
69  virtual
71  {
72  }
73 
74  /** \brief Equal comparison operator
75  */
76  virtual bool
78  {
79  return false;
80  }
81 
82  /** \brief Inequal comparison operator
83  * \param[in] other OctreeContainerBase to compare with
84  */
85  bool
86  operator!= (const OctreeContainerBase& other) const
87  {
88  return (!operator== (other));
89  }
90 
91  /** \brief Pure abstract method to get size of container (number of indices)
92  * \return number of points/indices stored in leaf node container.
93  */
94  virtual size_t
95  getSize () const
96  {
97  return 0u;
98  }
99 
100  /** \brief Pure abstract reset leaf node implementation. */
101  virtual void
102  reset () = 0;
103 
104  /** \brief Empty addPointIndex implementation. This leaf node does not store any point indices.
105  */
106  void
107  addPointIndex (const int&)
108  {
109  }
110 
111  /** \brief Empty getPointIndex implementation as this leaf node does not store any point indices.
112  */
113  void
114  getPointIndex (int&) const
115  {
116  }
117 
118  /** \brief Empty getPointIndices implementation as this leaf node does not store any data. \
119  */
120  void
121  getPointIndices (std::vector<int>&) const
122  {
123  }
124 
125  };
126 
127  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
128  /** \brief @b Octree container class that does not store any information.
129  * \note Can be used for occupancy trees that are used for checking only the existence of leaf nodes in the tree
130  * \author Julius Kammerl (julius@kammerl.de)
131  */
132 
134  {
135  public:
136  /** \brief Empty constructor. */
139  {
140  }
141 
142  /** \brief Empty constructor. */
145  {
146  }
147 
148  /** \brief Empty deconstructor. */
149  virtual
151  {
152  }
153 
154  /** \brief Octree deep copy method */
155  virtual OctreeContainerEmpty *
156  deepCopy () const
157  {
158  return (new OctreeContainerEmpty (*this));
159  }
160 
161  /** \brief Abstract get size of container (number of DataT objects)
162  * \return number of DataT elements in leaf node container.
163  */
164  virtual size_t
165  getSize () const
166  {
167  return 0;
168  }
169 
170  /** \brief Abstract reset leaf node implementation. */
171  virtual void
172  reset ()
173  {
174 
175  }
176 
177  /** \brief Empty addPointIndex implementation. This leaf node does not store any point indices.
178  */
179  void
181  {
182  }
183 
184  /** \brief Empty getPointIndex implementation as this leaf node does not store any point indices.
185  */
186  int
187  getPointIndex () const
188  {
189  assert("getPointIndex: undefined point index");
190  return -1;
191  }
192 
193  /** \brief Empty getPointIndices implementation as this leaf node does not store any data. \
194  */
195  void
196  getPointIndices (std::vector<int>&) const
197  {
198  }
199 
200  };
201 
202  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
203  /** \brief @b Octree container class that does store a single point index.
204  * \note Enables the octree to store a single DataT element within its leaf nodes.
205  * \author Julius Kammerl (julius@kammerl.de)
206  */
208  {
209  public:
210  /** \brief Empty constructor. */
213  {
214  reset ();
215  }
216 
217  /** \brief Empty constructor. */
219  OctreeContainerBase (), data_ (source.data_)
220  {
221  }
222 
223  /** \brief Empty deconstructor. */
224  virtual
226  {
227  }
228 
229  /** \brief Octree deep copy method */
231  deepCopy () const
232  {
233  return (new OctreeContainerPointIndex (*this));
234  }
235 
236  /** \brief Equal comparison operator
237  * \param[in] other OctreeContainerBase to compare with
238  */
239  virtual bool
240  operator== (const OctreeContainerBase& other) const
241  {
242  const OctreeContainerPointIndex* otherConDataT = dynamic_cast<const OctreeContainerPointIndex*> (&other);
243 
244  return (this->data_ == otherConDataT->data_);
245  }
246 
247  /** \brief Add point index to container memory. This container stores a only a single point index.
248  * \param[in] data_arg index to be stored within leaf node.
249  */
250  void
251  addPointIndex (int data_arg)
252  {
253  data_ = data_arg;
254  }
255 
256  /** \brief Retrieve point index from container. This container stores a only a single point index
257  * \return index stored within container.
258  */
259  int
260  getPointIndex () const
261  {
262  return data_;
263  }
264 
265  /** \brief Retrieve point indices from container. This container stores only a single point index
266  * \param[out] data_vector_arg vector of point indices to be stored within data vector
267  */
268  void
269  getPointIndices (std::vector<int>& data_vector_arg) const
270  {
271  if (data_>=0)
272  data_vector_arg.push_back (data_);
273  }
274 
275  /** \brief Get size of container (number of DataT objects)
276  * \return number of DataT elements in leaf node container.
277  */
278  size_t
279  getSize () const
280  {
281  return data_<0 ? 0 : 1;
282  }
283 
284  /** \brief Reset leaf node memory to zero. */
285  virtual void
286  reset ()
287  {
288  data_ = -1;
289  }
290  protected:
291  /** \brief Point index stored in octree. */
292  int data_;
293  };
294 
295  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
296  /** \brief @b Octree container class that does store a vector of point indices.
297  * \note Enables the octree to store multiple DataT elements within its leaf nodes.
298  * \author Julius Kammerl (julius@kammerl.de)
299  */
301  {
302  public:
303  /** \brief Empty constructor. */
306  {
307  }
308 
309  /** \brief Empty constructor. */
312  {
313  }
314 
315  /** \brief Empty deconstructor. */
316  virtual
318  {
319  }
320 
321  /** \brief Octree deep copy method */
323  deepCopy () const
324  {
325  return (new OctreeContainerPointIndices (*this));
326  }
327 
328  /** \brief Equal comparison operator
329  * \param[in] other OctreeContainerDataTVector to compare with
330  */
331  virtual bool
332  operator== (const OctreeContainerBase& other) const
333  {
334  const OctreeContainerPointIndices* otherConDataTVec = dynamic_cast<const OctreeContainerPointIndices*> (&other);
335 
336  return (this->leafDataTVector_ == otherConDataTVec->leafDataTVector_);
337  }
338 
339  /** \brief Add point index to container memory. This container stores a vector of point indices.
340  * \param[in] data_arg index to be stored within leaf node.
341  */
342  void
343  addPointIndex (int data_arg)
344  {
345  leafDataTVector_.push_back (data_arg);
346  }
347 
348  /** \brief Retrieve point index from container. This container stores a vector of point indices.
349  * \return index stored within container.
350  */
351  int
352  getPointIndex ( ) const
353  {
354  return leafDataTVector_.back ();
355  }
356 
357  /** \brief Retrieve point indices from container. This container stores a vector of point indices.
358  * \param[out] data_vector_arg vector of point indices to be stored within data vector
359  */
360  void
361  getPointIndices (std::vector<int>& data_vector_arg) const
362  {
363  data_vector_arg.insert (data_vector_arg.end (), leafDataTVector_.begin (), leafDataTVector_.end ());
364  }
365 
366  /** \brief Retrieve reference to point indices vector. This container stores a vector of point indices.
367  * \return reference to vector of point indices to be stored within data vector
368  */
369  std::vector<int>&
371  {
372  return leafDataTVector_;
373  }
374 
375  /** \brief Get size of container (number of indices)
376  * \return number of point indices in container.
377  */
378  size_t
379  getSize () const
380  {
381  return leafDataTVector_.size ();
382  }
383 
384  /** \brief Reset leaf node. Clear DataT vector.*/
385  virtual void
386  reset ()
387  {
388  leafDataTVector_.clear ();
389  }
390 
391  protected:
392  /** \brief Leaf node DataT vector. */
393  std::vector<int> leafDataTVector_;
394  };
395 
396  }
397 }
398 
399 #endif
size_t getSize() const
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.
virtual bool operator==(const OctreeContainerBase &other) const
Equal comparison operator.
virtual ~OctreeContainerPointIndex()
Empty deconstructor.
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.
virtual void reset()
Reset leaf node memory to zero.
OctreeContainerBase(const OctreeContainerBase &)
Empty constructor.
OctreeContainerEmpty(const OctreeContainerEmpty &)
Empty constructor.
void getPointIndex(int &) const
Empty getPointIndex implementation as this leaf node does not store any point indices.
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.
virtual size_t getSize() const
Pure abstract method to get size of container (number of indices)
void addPointIndex(int data_arg)
Add point index to container memory.
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.
virtual size_t getSize() const
Abstract get size of container (number of DataT objects)
int data_
Point index stored in octree.
virtual ~OctreeContainerPointIndices()
Empty deconstructor.
int getPointIndex() const
Retrieve point index from container.
virtual void reset()
Abstract reset leaf node implementation.
Octree container class that does store a vector of point indices.
void addPointIndex(int)
Empty addPointIndex implementation.
virtual ~OctreeContainerBase()
Empty deconstructor.
virtual bool operator==(const OctreeContainerBase &other) const
Equal comparison operator.
OctreeContainerPointIndex(const OctreeContainerPointIndex &source)
Empty constructor.
std::vector< int > & getPointIndicesVector()
Retrieve reference to point indices vector.
bool operator!=(const OctreeContainerBase &other) const
Inequal comparison operator.
OctreeContainerBase()
Empty constructor.
OctreeContainerEmpty()
Empty constructor.
size_t getSize() const
Get size of container (number of DataT objects)
virtual void reset()
Reset leaf node.
virtual bool operator==(const OctreeContainerBase &) const
Equal comparison operator.
virtual ~OctreeContainerEmpty()
Empty deconstructor.
void addPointIndex(const int &)
Empty addPointIndex implementation.
Octree container class that does not store any information.
std::vector< int > leafDataTVector_
Leaf node DataT vector.
OctreeContainerPointIndices(const OctreeContainerPointIndices &source)
Empty constructor.
virtual OctreeContainerPointIndices * deepCopy() const
Octree deep copy method.
int getPointIndex() const
Retrieve point index from container.