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