Loading...
Searching...
No Matches
octree_nodes.h
/*
* Software License Agreement (BSD License)
*
* Point Cloud Library (PCL) - www.pointclouds.org
* Copyright (c) 2010-2011, Willow Garage, Inc.
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of Willow Garage, Inc. nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* $Id$
*/
#pragma once
#include <pcl/octree/octree_container.h>
#include <pcl/memory.h>
#include <pcl/pcl_macros.h>
#include <array>
#include <cassert>
namespace pcl {
namespace octree {
// enum of node types within the octree
enum node_type_t { BRANCH_NODE, LEAF_NODE };
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/** \brief @b Abstract octree node class
* \note Every octree node should implement the getNodeType () method
* \author Julius Kammerl (julius@kammerl.de)
*/
class PCL_EXPORTS OctreeNode {
public:
OctreeNode() = default;
virtual ~OctreeNode() = default;
/** \brief Pure virtual method for retrieving the type of octree node (branch or leaf)
*/
virtual node_type_t
getNodeType() const = 0;
/** \brief Pure virtual method to perform a deep copy of the octree */
virtual OctreeNode*
deepCopy() const = 0;
};
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/** \brief @b Abstract octree leaf class
* \note Octree leaves may collect data of type ContainerT
* \author Julius Kammerl (julius@kammerl.de)
*/
template <typename ContainerT>
class OctreeLeafNode : public OctreeNode {
public:
/** \brief Empty constructor. */
OctreeLeafNode() : OctreeNode() {}
/** \brief Copy constructor. */
OctreeLeafNode(const OctreeLeafNode& source)
: OctreeNode(), container_(source.container_)
{}
/** \brief Empty deconstructor. */
~OctreeLeafNode() override = default;
/** \brief Method to perform a deep copy of the octree */
OctreeLeafNode<ContainerT>*
deepCopy() const override
{
return new OctreeLeafNode<ContainerT>(*this);
}
/** \brief Get the type of octree node. Returns LEAVE_NODE type */
node_type_t
getNodeType() const override
{
return LEAF_NODE;
}
/** \brief Get const pointer to container */
const ContainerT*
operator->() const
{
return &container_;
}
/** \brief Get pointer to container */
ContainerT*
operator->()
{
return &container_;
}
/** \brief Get const reference to container */
const ContainerT&
operator*() const
{
return container_;
}
/** \brief Get reference to container */
ContainerT&
operator*()
{
return container_;
}
/** \brief Get const reference to container */
const ContainerT&
getContainer() const
{
return container_;
}
/** \brief Get reference to container */
ContainerT&
getContainer()
{
return container_;
}
/** \brief Get const pointer to container */
const ContainerT*
getContainerPtr() const
{
return &container_;
}
/** \brief Get pointer to container */
ContainerT*
getContainerPtr()
{
return &container_;
}
protected:
ContainerT container_;
public:
// Type ContainerT may have fixed-size Eigen objects inside
PCL_MAKE_ALIGNED_OPERATOR_NEW
};
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/** \brief @b Abstract octree branch class
* \note Octree branch classes may collect data of type DataT
* \author Julius Kammerl (julius@kammerl.de)
*/
template <typename ContainerT>
class OctreeBranchNode : public OctreeNode {
public:
/** \brief Empty constructor. */
OctreeBranchNode() : OctreeNode() {}
/** \brief Copy constructor. */
OctreeBranchNode(const OctreeBranchNode& source) : OctreeNode()
{
for (unsigned char i = 0; i < 8; ++i)
if (source.child_node_array_[i]) {
child_node_array_[i] = source.child_node_array_[i]->deepCopy();
}
}
/** \brief Copy operator. */
inline OctreeBranchNode&
operator=(const OctreeBranchNode& source)
{
child_node_array_ = {};
for (unsigned char i = 0; i < 8; ++i) {
if (source.child_node_array_[i]) {
child_node_array_[i] = source.child_node_array_[i]->deepCopy();
}
}
return (*this);
}
/** \brief Octree deep copy method */
OctreeBranchNode*
deepCopy() const override
{
return (new OctreeBranchNode<ContainerT>(*this));
}
/** \brief Empty deconstructor. */
~OctreeBranchNode() override = default;
/** \brief Access operator.
* \param child_idx_arg: index to child node, must be less than 8
* \return OctreeNode pointer
* */
inline OctreeNode*&
operator[](unsigned char child_idx_arg)
{
assert(child_idx_arg < 8);
return child_node_array_[child_idx_arg];
}
/** \brief Get pointer to child
* \param child_idx_arg: index to child node, must be less than 8
* \return OctreeNode pointer
* */
inline OctreeNode*
getChildPtr(unsigned char child_idx_arg) const
{
assert(child_idx_arg < 8);
return child_node_array_[child_idx_arg];
}
/** \brief Get pointer to child
* \param index: index to child node, must be less than 8
* \return OctreeNode pointer
* */
inline void
setChildPtr(OctreeNode* child, unsigned char index)
{
assert(index < 8);
child_node_array_[index] = child;
}
/** \brief Check if branch is pointing to a particular child node
* \param child_idx_arg: index to child node, must be less than 8
* \return "true" if pointer to child node exists; "false" otherwise
* */
inline bool
hasChild(unsigned char child_idx_arg) const
{
return (child_node_array_[child_idx_arg] != nullptr);
}
/** \brief Check if branch can be pruned
* \note if all children are leaf nodes AND contain identical containers, branch can
* be pruned
* \return "true" if branch can be pruned; "false" otherwise
**/
/* inline bool isPrunable () const
{
const OctreeNode* firstChild = child_node_array_[0];
if (!firstChild || firstChild->getNodeType()==BRANCH_NODE)
return false;
bool prunable = true;
for (unsigned char i = 1; i < 8 && prunable; ++i)
{
const OctreeNode* child = child_node_array_[i];
if ( (!child) ||
(child->getNodeType()==BRANCH_NODE) ||
((*static_cast<const OctreeContainerBase*>(child)) == (*static_cast<const
OctreeContainerBase*>(child)) ) ) prunable = false;
}
return prunable;
}*/
/** \brief Get the type of octree node. Returns LEAVE_NODE type */
node_type_t
getNodeType() const override
{
return BRANCH_NODE;
}
// reset node
void
reset()
{
child_node_array_ = {};
container_.reset();
}
/** \brief Get const pointer to container */
const ContainerT*
operator->() const
{
return &container_;
}
/** \brief Get pointer to container */
ContainerT*
operator->()
{
return &container_;
}
/** \brief Get const reference to container */
const ContainerT&
operator*() const
{
return container_;
}
/** \brief Get reference to container */
ContainerT&
operator*()
{
return container_;
}
/** \brief Get const reference to container */
const ContainerT&
getContainer() const
{
return container_;
}
/** \brief Get reference to container */
ContainerT&
getContainer()
{
return container_;
}
/** \brief Get const pointer to container */
const ContainerT*
getContainerPtr() const
{
return &container_;
}
/** \brief Get pointer to container */
ContainerT*
getContainerPtr()
{
return &container_;
}
protected:
std::array<OctreeNode*, 8> child_node_array_{};
ContainerT container_;
};
} // namespace octree
} // namespace pcl
pcl::octree::OctreeBranchNode
Abstract octree branch class
Definition octree_nodes.h:179
pcl::octree::OctreeBranchNode::hasChild
bool hasChild(unsigned char child_idx_arg) const
Check if branch is pointing to a particular child node.
Definition octree_nodes.h:256
pcl::octree::OctreeBranchNode::getChildPtr
OctreeNode * getChildPtr(unsigned char child_idx_arg) const
Get pointer to child.
Definition octree_nodes.h:234
pcl::octree::OctreeBranchNode::~OctreeBranchNode
~OctreeBranchNode() override=default
Empty deconstructor.
pcl::octree::OctreeBranchNode::getContainer
ContainerT & getContainer()
Get reference to container.
Definition octree_nodes.h:337
pcl::octree::OctreeBranchNode::getContainerPtr
const ContainerT * getContainerPtr() const
Get const pointer to container.
Definition octree_nodes.h:344
pcl::octree::OctreeBranchNode::operator[]
OctreeNode *& operator[](unsigned char child_idx_arg)
Access operator.
Definition octree_nodes.h:223
pcl::octree::OctreeBranchNode::operator->
ContainerT * operator->()
Get pointer to container.
Definition octree_nodes.h:309
pcl::octree::OctreeBranchNode::deepCopy
OctreeBranchNode * deepCopy() const override
Octree deep copy method.
Definition octree_nodes.h:209
pcl::octree::OctreeBranchNode::OctreeBranchNode
OctreeBranchNode()
Empty constructor.
Definition octree_nodes.h:182
pcl::octree::OctreeBranchNode::OctreeBranchNode
OctreeBranchNode(const OctreeBranchNode &source)
Copy constructor.
Definition octree_nodes.h:185
pcl::octree::OctreeBranchNode::operator*
const ContainerT & operator*() const
Get const reference to container.
Definition octree_nodes.h:316
pcl::octree::OctreeBranchNode::getNodeType
node_type_t getNodeType() const override
Check if branch can be pruned.
Definition octree_nodes.h:287
pcl::octree::OctreeBranchNode::getContainerPtr
ContainerT * getContainerPtr()
Get pointer to container.
Definition octree_nodes.h:351
pcl::octree::OctreeBranchNode::setChildPtr
void setChildPtr(OctreeNode *child, unsigned char index)
Get pointer to child.
Definition octree_nodes.h:245
pcl::octree::OctreeBranchNode::operator->
const ContainerT * operator->() const
Get const pointer to container.
Definition octree_nodes.h:302
pcl::octree::OctreeBranchNode::operator=
OctreeBranchNode & operator=(const OctreeBranchNode &source)
Copy operator.
Definition octree_nodes.h:195
pcl::octree::OctreeBranchNode::getContainer
const ContainerT & getContainer() const
Get const reference to container.
Definition octree_nodes.h:330
pcl::octree::OctreeBranchNode::operator*
ContainerT & operator*()
Get reference to container.
Definition octree_nodes.h:323
pcl::octree::OctreeBranchNode::reset
void reset()
Definition octree_nodes.h:294
pcl::octree::OctreeBranchNode< BranchContainerT >::container_
BranchContainerT container_
Definition octree_nodes.h:359
pcl::octree::OctreeBranchNode::child_node_array_
std::array< OctreeNode *, 8 > child_node_array_
Definition octree_nodes.h:357
pcl::octree::OctreeLeafNode::getNodeType
node_type_t getNodeType() const override
Get the type of octree node.
Definition octree_nodes.h:104
pcl::octree::OctreeLeafNode::operator*
ContainerT & operator*()
Get reference to container.
Definition octree_nodes.h:132
pcl::octree::OctreeLeafNode::operator->
const ContainerT * operator->() const
Get const pointer to container.
Definition octree_nodes.h:111
pcl::octree::OctreeLeafNode::OctreeLeafNode
OctreeLeafNode(const OctreeLeafNode &source)
Copy constructor.
Definition octree_nodes.h:87
pcl::octree::OctreeLeafNode::~OctreeLeafNode
~OctreeLeafNode() override=default
Empty deconstructor.
pcl::octree::OctreeLeafNode::getContainerPtr
const ContainerT * getContainerPtr() const
Get const pointer to container.
Definition octree_nodes.h:153
pcl::octree::OctreeLeafNode::getContainer
const ContainerT & getContainer() const
Get const reference to container.
Definition octree_nodes.h:139
pcl::octree::OctreeLeafNode< LeafContainerT >::container_
LeafContainerT container_
Definition octree_nodes.h:166
pcl::octree::OctreeLeafNode::operator*
const ContainerT & operator*() const
Get const reference to container.
Definition octree_nodes.h:125
pcl::octree::OctreeLeafNode::deepCopy
OctreeLeafNode< ContainerT > * deepCopy() const override
Method to perform a deep copy of the octree.
Definition octree_nodes.h:97
pcl::octree::OctreeLeafNode::OctreeLeafNode
OctreeLeafNode()
Empty constructor.
Definition octree_nodes.h:84
pcl::octree::OctreeLeafNode::getContainerPtr
ContainerT * getContainerPtr()
Get pointer to container.
Definition octree_nodes.h:160
pcl::octree::OctreeLeafNode::getContainer
ContainerT & getContainer()
Get reference to container.
Definition octree_nodes.h:146
pcl::octree::OctreeLeafNode::operator->
ContainerT * operator->()
Get pointer to container.
Definition octree_nodes.h:118
pcl::octree::OctreeNode
Abstract octree node class
Definition octree_nodes.h:59
pcl::octree::OctreeNode::getNodeType
virtual node_type_t getNodeType() const =0
Pure virtual method for retrieving the type of octree node (branch or leaf).
pcl::octree::OctreeNode::~OctreeNode
virtual ~OctreeNode()=default
pcl::octree::OctreeNode::deepCopy
virtual OctreeNode * deepCopy() const =0
Pure virtual method to perform a deep copy of the octree.
pcl::octree::OctreeNode::OctreeNode
OctreeNode()=default
PCL_MAKE_ALIGNED_OPERATOR_NEW
#define PCL_MAKE_ALIGNED_OPERATOR_NEW
Macro to signal a class requires a custom allocator.
Definition memory.h:86
memory.h
Defines functions, macros and traits for allocating and using memory.
pcl::octree
Definition color_coding.h:47
pcl::octree::node_type_t
node_type_t
Definition octree_nodes.h:52
pcl::octree::BRANCH_NODE
@ BRANCH_NODE
Definition octree_nodes.h:52
pcl::octree::LEAF_NODE
@ LEAF_NODE
Definition octree_nodes.h:52
pcl
Definition convolution.h:46
pcl_macros.h
Defines all the PCL and non-PCL macros used.