Point Cloud Library (PCL) 1.12.0
octree_nodes.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$
37 */
38
39#pragma once
40
41#include <pcl/octree/octree_container.h>
42#include <pcl/memory.h>
43#include <pcl/pcl_macros.h>
44
45#include <cassert>
46
47namespace pcl {
48namespace octree {
49
50// enum of node types within the octree
52
53//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
54/** \brief @b Abstract octree node class
55 * \note Every octree node should implement the getNodeType () method
56 * \author Julius Kammerl (julius@kammerl.de)
57 */
59public:
61
62 virtual ~OctreeNode() {}
63 /** \brief Pure virtual method for receiving the type of octree node (branch or leaf)
64 */
65 virtual node_type_t
66 getNodeType() const = 0;
67
68 /** \brief Pure virtual method to perform a deep copy of the octree */
69 virtual OctreeNode*
70 deepCopy() const = 0;
71};
72
73//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
74/** \brief @b Abstract octree leaf class
75 * \note Octree leafs may collect data of type DataT
76 * \author Julius Kammerl (julius@kammerl.de)
77 */
78
79template <typename ContainerT>
80class OctreeLeafNode : public OctreeNode {
81public:
82 /** \brief Empty constructor. */
84
85 /** \brief Copy constructor. */
87 {
88 container_ = source.container_;
89 }
90
91 /** \brief Empty deconstructor. */
92
94
95 /** \brief Method to perform a deep copy of the octree */
97 deepCopy() const override
98 {
99 return new OctreeLeafNode<ContainerT>(*this);
100 }
101
102 /** \brief Get the type of octree node. Returns LEAVE_NODE type */
104 getNodeType() const override
105 {
106 return LEAF_NODE;
107 }
108
109 /** \brief Get const pointer to container */
110 const ContainerT*
112 {
113 return &container_;
114 }
115
116 /** \brief Get pointer to container */
117 ContainerT*
119 {
120 return &container_;
121 }
122
123 /** \brief Get const reference to container */
124 const ContainerT&
125 operator*() const
126 {
127 return container_;
128 }
129
130 /** \brief Get reference to container */
131 ContainerT&
133 {
134 return container_;
135 }
136
137 /** \brief Get const reference to container */
138 const ContainerT&
140 {
141 return container_;
142 }
143
144 /** \brief Get reference to container */
145 ContainerT&
147 {
148 return container_;
149 }
150
151 /** \brief Get const pointer to container */
152 const ContainerT*
154 {
155 return &container_;
156 }
157
158 /** \brief Get pointer to container */
159 ContainerT*
161 {
162 return &container_;
163 }
164
165protected:
166 ContainerT container_;
167
168public:
169 // Type ContainerT may have fixed-size Eigen objects inside
171};
172
173//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
174/** \brief @b Abstract octree branch class
175 * \note Octree branch classes may collect data of type DataT
176 * \author Julius Kammerl (julius@kammerl.de)
177 */
178template <typename ContainerT>
180public:
181 /** \brief Empty constructor. */
183 {
184 // reset pointer to child node vectors
185 memset(child_node_array_, 0, sizeof(child_node_array_));
186 }
187
188 /** \brief Empty constructor. */
190 {
191 memset(child_node_array_, 0, sizeof(child_node_array_));
192
193 for (unsigned char i = 0; i < 8; ++i)
194 if (source.child_node_array_[i])
196 }
197
198 /** \brief Copy operator. */
199 inline OctreeBranchNode&
201 {
202 memset(child_node_array_, 0, sizeof(child_node_array_));
203
204 for (unsigned char i = 0; i < 8; ++i)
205 if (source.child_node_array_[i])
207 return (*this);
208 }
209
210 /** \brief Octree deep copy method */
212 deepCopy() const override
213 {
214 return (new OctreeBranchNode<ContainerT>(*this));
215 }
216
217 /** \brief Empty deconstructor. */
218
220
221 /** \brief Access operator.
222 * \param child_idx_arg: index to child node
223 * \return OctreeNode pointer
224 * */
225 inline OctreeNode*&
226 operator[](unsigned char child_idx_arg)
227 {
228 assert(child_idx_arg < 8);
229 return child_node_array_[child_idx_arg];
230 }
231
232 /** \brief Get pointer to child
233 * \param child_idx_arg: index to child node
234 * \return OctreeNode pointer
235 * */
236 inline OctreeNode*
237 getChildPtr(unsigned char child_idx_arg) const
238 {
239 assert(child_idx_arg < 8);
240 return child_node_array_[child_idx_arg];
241 }
242
243 /** \brief Get pointer to child
244 * \return OctreeNode pointer
245 * */
246 inline void
247 setChildPtr(OctreeNode* child, unsigned char index)
248 {
249 assert(index < 8);
250 child_node_array_[index] = child;
251 }
252
253 /** \brief Check if branch is pointing to a particular child node
254 * \param child_idx_arg: index to child node
255 * \return "true" if pointer to child node exists; "false" otherwise
256 * */
257 inline bool
258 hasChild(unsigned char child_idx_arg) const
259 {
260 return (child_node_array_[child_idx_arg] != nullptr);
261 }
262
263 /** \brief Check if branch can be pruned
264 * \note if all children are leaf nodes AND contain identical containers, branch can
265 * be pruned
266 * \return "true" if branch can be pruned; "false" otherwise
267 **/
268 /* inline bool isPrunable () const
269 {
270 const OctreeNode* firstChild = child_node_array_[0];
271 if (!firstChild || firstChild->getNodeType()==BRANCH_NODE)
272 return false;
273
274 bool prunable = true;
275 for (unsigned char i = 1; i < 8 && prunable; ++i)
276 {
277 const OctreeNode* child = child_node_array_[i];
278 if ( (!child) ||
279 (child->getNodeType()==BRANCH_NODE) ||
280 ((*static_cast<const OctreeContainerBase*>(child)) == (*static_cast<const
281 OctreeContainerBase*>(child)) ) ) prunable = false;
282 }
283
284 return prunable;
285 }*/
286
287 /** \brief Get the type of octree node. Returns LEAVE_NODE type */
289 getNodeType() const override
290 {
291 return BRANCH_NODE;
292 }
293
294 // reset node
295 void
297 {
298 memset(child_node_array_, 0, sizeof(child_node_array_));
299 container_.reset();
300 }
301
302 /** \brief Get const pointer to container */
303 const ContainerT*
305 {
306 return &container_;
307 }
308
309 /** \brief Get pointer to container */
310 ContainerT*
312 {
313 return &container_;
314 }
315
316 /** \brief Get const reference to container */
317 const ContainerT&
318 operator*() const
319 {
320 return container_;
321 }
322
323 /** \brief Get reference to container */
324 ContainerT&
326 {
327 return container_;
328 }
329
330 /** \brief Get const reference to container */
331 const ContainerT&
333 {
334 return container_;
335 }
336
337 /** \brief Get reference to container */
338 ContainerT&
340 {
341 return container_;
342 }
343
344 /** \brief Get const pointer to container */
345 const ContainerT*
347 {
348 return &container_;
349 }
350
351 /** \brief Get pointer to container */
352 ContainerT*
354 {
355 return &container_;
356 }
357
358protected:
360
361 ContainerT container_;
362};
363} // namespace octree
364} // namespace pcl
Abstract octree branch class
Definition: octree_nodes.h:179
bool hasChild(unsigned char child_idx_arg) const
Check if branch is pointing to a particular child node.
Definition: octree_nodes.h:258
OctreeNode * getChildPtr(unsigned char child_idx_arg) const
Get pointer to child.
Definition: octree_nodes.h:237
ContainerT & getContainer()
Get reference to container.
Definition: octree_nodes.h:339
const ContainerT * getContainerPtr() const
Get const pointer to container.
Definition: octree_nodes.h:346
OctreeNode *& operator[](unsigned char child_idx_arg)
Access operator.
Definition: octree_nodes.h:226
ContainerT * operator->()
Get pointer to container.
Definition: octree_nodes.h:311
OctreeBranchNode * deepCopy() const override
Octree deep copy method.
Definition: octree_nodes.h:212
OctreeBranchNode()
Empty constructor.
Definition: octree_nodes.h:182
OctreeBranchNode(const OctreeBranchNode &source)
Empty constructor.
Definition: octree_nodes.h:189
OctreeNode * child_node_array_[8]
Definition: octree_nodes.h:359
const ContainerT & operator*() const
Get const reference to container.
Definition: octree_nodes.h:318
~OctreeBranchNode()
Empty deconstructor.
Definition: octree_nodes.h:219
node_type_t getNodeType() const override
Check if branch can be pruned.
Definition: octree_nodes.h:289
ContainerT * getContainerPtr()
Get pointer to container.
Definition: octree_nodes.h:353
void setChildPtr(OctreeNode *child, unsigned char index)
Get pointer to child.
Definition: octree_nodes.h:247
const ContainerT * operator->() const
Get const pointer to container.
Definition: octree_nodes.h:304
OctreeBranchNode & operator=(const OctreeBranchNode &source)
Copy operator.
Definition: octree_nodes.h:200
const ContainerT & getContainer() const
Get const reference to container.
Definition: octree_nodes.h:332
ContainerT & operator*()
Get reference to container.
Definition: octree_nodes.h:325
Abstract octree leaf class
Definition: octree_nodes.h:80
node_type_t getNodeType() const override
Get the type of octree node.
Definition: octree_nodes.h:104
ContainerT & operator*()
Get reference to container.
Definition: octree_nodes.h:132
const ContainerT * operator->() const
Get const pointer to container.
Definition: octree_nodes.h:111
OctreeLeafNode(const OctreeLeafNode &source)
Copy constructor.
Definition: octree_nodes.h:86
const ContainerT * getContainerPtr() const
Get const pointer to container.
Definition: octree_nodes.h:153
~OctreeLeafNode()
Empty deconstructor.
Definition: octree_nodes.h:93
const ContainerT & getContainer() const
Get const reference to container.
Definition: octree_nodes.h:139
const ContainerT & operator*() const
Get const reference to container.
Definition: octree_nodes.h:125
OctreeLeafNode< ContainerT > * deepCopy() const override
Method to perform a deep copy of the octree.
Definition: octree_nodes.h:97
OctreeLeafNode()
Empty constructor.
Definition: octree_nodes.h:83
ContainerT * getContainerPtr()
Get pointer to container.
Definition: octree_nodes.h:160
ContainerT & getContainer()
Get reference to container.
Definition: octree_nodes.h:146
ContainerT * operator->()
Get pointer to container.
Definition: octree_nodes.h:118
Abstract octree node class
Definition: octree_nodes.h:58
virtual node_type_t getNodeType() const =0
Pure virtual method for receiving the type of octree node (branch or leaf)
virtual OctreeNode * deepCopy() const =0
Pure virtual method to perform a deep copy of the octree.
#define PCL_MAKE_ALIGNED_OPERATOR_NEW
Macro to signal a class requires a custom allocator.
Definition: memory.h:63
Defines functions, macros and traits for allocating and using memory.
Defines all the PCL and non-PCL macros used.
#define PCL_EXPORTS
Definition: pcl_macros.h:323