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 <cstddef>
#include <cassert>
#include <Eigen/Core>
#include <pcl/pcl_macros.h>
#include "octree_container.h"
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 ()
{
}
virtual
~OctreeNode ()
{
}
/** \brief Pure virtual method for receiving 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 leafs may collect data of type DataT
* \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 ()
{
}
/** \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()
{
// reset pointer to child node vectors
memset (child_node_array_, 0, sizeof(child_node_array_));
}
/** \brief Empty constructor. */
OctreeBranchNode (const OctreeBranchNode& source) :
OctreeNode()
{
memset (child_node_array_, 0, sizeof(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 ();
}
/** \brief Copy operator. */
inline OctreeBranchNode&
operator = (const OctreeBranchNode &source)
{
memset (child_node_array_, 0, sizeof(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 ()
{
}
/** \brief Access operator.
* \param child_idx_arg: index to child node
* \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
* \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
* \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
* \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()
{
memset(child_node_array_, 0, sizeof(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:
OctreeNode* child_node_array_[8];
ContainerT container_;
};
}
}
pcl_macros.h
Defines all the PCL and non-PCL macros used.
pcl::octree::OctreeLeafNode::~OctreeLeafNode
~OctreeLeafNode()
Empty deconstructor.
Definition: octree_nodes.h:115
pcl
This file defines compatibility wrappers for low level I/O functions.
Definition: convolution.h:45
pcl::octree::OctreeBranchNode::reset
void reset()
Definition: octree_nodes.h:324
pcl::octree::OctreeBranchNode::getContainerPtr
const ContainerT * getContainerPtr() const
Get const pointer to container.
Definition: octree_nodes.h:375
pcl::octree::OctreeBranchNode::OctreeBranchNode
OctreeBranchNode(const OctreeBranchNode &source)
Empty constructor.
Definition: octree_nodes.h:216
pcl::octree::OctreeLeafNode::getContainer
const ContainerT & getContainer() const
Get const reference to container.
Definition: octree_nodes.h:163
pcl::octree::OctreeLeafNode::operator->
const ContainerT * operator->() const
Get const pointer to container.
Definition: octree_nodes.h:135
pcl::octree::OctreeBranchNode::child_node_array_
OctreeNode * child_node_array_[8]
Definition: octree_nodes.h:388
pcl::octree::OctreeBranchNode::setChildPtr
void setChildPtr(OctreeNode *child, unsigned char index)
Get pointer to child.
Definition: octree_nodes.h:276
pcl::octree::OctreeNode
Abstract octree node class
Definition: octree_nodes.h:67
pcl::octree::OctreeBranchNode::operator->
const ContainerT * operator->() const
Get const pointer to container.
Definition: octree_nodes.h:333
pcl::octree::LEAF_NODE
Definition: octree_nodes.h:59
pcl::octree::OctreeBranchNode::container_
ContainerT container_
Definition: octree_nodes.h:390
pcl::octree::OctreeLeafNode
Abstract octree leaf class
Definition: octree_nodes.h:96
pcl::octree::OctreeLeafNode::getNodeType
node_type_t getNodeType() const override
Get the type of octree node.
Definition: octree_nodes.h:128
pcl::octree::OctreeNode::OctreeNode
OctreeNode()
Definition: octree_nodes.h:71
pcl::octree::OctreeBranchNode::deepCopy
OctreeBranchNode * deepCopy() const override
Octree deep copy method.
Definition: octree_nodes.h:240
pcl::octree::BRANCH_NODE
Definition: octree_nodes.h:59
pcl::octree::OctreeBranchNode::getContainer
const ContainerT & getContainer() const
Get const reference to container.
Definition: octree_nodes.h:361
pcl::octree::OctreeBranchNode::getContainerPtr
ContainerT * getContainerPtr()
Get pointer to container.
Definition: octree_nodes.h:382
pcl::octree::OctreeBranchNode
Abstract octree branch class
Definition: octree_nodes.h:203
pcl::octree::OctreeBranchNode::operator*
const ContainerT & operator*() const
Get const reference to container.
Definition: octree_nodes.h:347
pcl::octree::OctreeBranchNode::OctreeBranchNode
OctreeBranchNode()
Empty constructor.
Definition: octree_nodes.h:208
pcl::octree::OctreeBranchNode::getContainer
ContainerT & getContainer()
Get reference to container.
Definition: octree_nodes.h:368
PCL_MAKE_ALIGNED_OPERATOR_NEW
#define PCL_MAKE_ALIGNED_OPERATOR_NEW
Macro to signal a class requires a custom allocator.
Definition: pcl_macros.h:371
pcl::octree::OctreeNode::~OctreeNode
virtual ~OctreeNode()
Definition: octree_nodes.h:76
pcl::octree::node_type_t
node_type_t
Definition: octree_nodes.h:57
pcl::octree::OctreeLeafNode::deepCopy
OctreeLeafNode< ContainerT > * deepCopy() const override
Method to perform a deep copy of the octree.
Definition: octree_nodes.h:121
pcl::octree::OctreeNode::deepCopy
virtual OctreeNode * deepCopy() const =0
Pure virtual method to perform a deep copy of the octree.
pcl::octree::OctreeBranchNode::getNodeType
node_type_t getNodeType() const override
Check if branch can be pruned.
Definition: octree_nodes.h:318
pcl::octree::OctreeLeafNode::getContainerPtr
ContainerT * getContainerPtr()
Get pointer to container.
Definition: octree_nodes.h:184
pcl::octree::OctreeLeafNode::OctreeLeafNode
OctreeLeafNode()
Empty constructor.
Definition: octree_nodes.h:101
pcl::octree::OctreeBranchNode::getChildPtr
OctreeNode * getChildPtr(unsigned char child_idx_arg) const
Get pointer to child.
Definition: octree_nodes.h:267
pcl::octree::OctreeBranchNode::operator[]
OctreeNode *& operator[](unsigned char child_idx_arg)
Access operator.
Definition: octree_nodes.h:256
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:287
pcl::octree::OctreeLeafNode::getContainer
ContainerT & getContainer()
Get reference to container.
Definition: octree_nodes.h:170
pcl::octree::OctreeLeafNode::OctreeLeafNode
OctreeLeafNode(const OctreeLeafNode &source)
Copy constructor.
Definition: octree_nodes.h:107
pcl::octree::OctreeLeafNode::container_
ContainerT container_
Definition: octree_nodes.h:190
pcl::octree::OctreeBranchNode::~OctreeBranchNode
~OctreeBranchNode()
Empty deconstructor.
Definition: octree_nodes.h:247
pcl::octree::OctreeLeafNode::operator*
const ContainerT & operator*() const
Get const reference to container.
Definition: octree_nodes.h:149
pcl::octree::OctreeLeafNode::getContainerPtr
const ContainerT * getContainerPtr() const
Get const pointer to container.
Definition: octree_nodes.h:177
pcl::octree::OctreeBranchNode::operator=
OctreeBranchNode & operator=(const OctreeBranchNode &source)
Copy operator.
Definition: octree_nodes.h:228
PCL_EXPORTS
#define PCL_EXPORTS
Definition: pcl_macros.h:253