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