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