Skip to content

OctreeIterators special member revision #2108

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions octree/include/pcl/octree/impl/octree_iterator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,6 @@ namespace pcl
this->reset ();
}

//////////////////////////////////////////////////////////////////////////////////////////////
template<typename OctreeT>
OctreeDepthFirstIterator<OctreeT>::~OctreeDepthFirstIterator ()
{
}

//////////////////////////////////////////////////////////////////////////////////////////////
template<typename OctreeT>
void OctreeDepthFirstIterator<OctreeT>::reset ()
Expand Down Expand Up @@ -197,12 +191,6 @@ namespace pcl
this->reset ();
}

//////////////////////////////////////////////////////////////////////////////////////////////
template<typename OctreeT>
OctreeBreadthFirstIterator<OctreeT>::~OctreeBreadthFirstIterator ()
{
}

//////////////////////////////////////////////////////////////////////////////////////////////
template<typename OctreeT>
void OctreeBreadthFirstIterator<OctreeT>::reset ()
Expand Down
103 changes: 69 additions & 34 deletions octree/include/pcl/octree/octree_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ namespace pcl
typename BranchContainerT = OctreeContainerEmpty >
class OctreeBase
{

public:

typedef OctreeBase<LeafContainerT, BranchContainerT> OctreeT;
Expand All @@ -72,6 +71,35 @@ namespace pcl
typedef BranchContainerT BranchContainer;
typedef LeafContainerT LeafContainer;

protected:

///////////////////////////////////////////////////////////////////////
// Members
///////////////////////////////////////////////////////////////////////

/** \brief Amount of leaf nodes **/
std::size_t leaf_count_;

/** \brief Amount of branch nodes **/
std::size_t branch_count_;

/** \brief Pointer to root branch node of octree **/
BranchNode* root_node_;

/** \brief Depth mask based on octree depth **/
unsigned int depth_mask_;

/** \brief Octree depth */
unsigned int octree_depth_;

/** \brief Enable dynamic_depth **/
bool dynamic_depth_enabled_;

/** \brief key range */
OctreeKey max_key_;

public:

// iterators are friends
friend class OctreeIteratorBase<OctreeT> ;
friend class OctreeDepthFirstIterator<OctreeT> ;
Expand All @@ -81,26 +109,58 @@ namespace pcl
// Octree default iterators
typedef OctreeDepthFirstIterator<OctreeT> Iterator;
typedef const OctreeDepthFirstIterator<OctreeT> ConstIterator;
Iterator begin(unsigned int max_depth_arg = 0) {return Iterator(this, max_depth_arg);};
const Iterator end() {return Iterator();};

Iterator begin (unsigned int max_depth_arg = 0u)
{
return Iterator (this, max_depth_arg? max_depth_arg : this->octree_depth_);
};

const Iterator end (unsigned int max_depth_arg = 0u)
{
return Iterator (this, max_depth_arg? max_depth_arg : this->octree_depth_ , NULL);
};

// Octree leaf node iterators
typedef OctreeLeafNodeIterator<OctreeT> LeafNodeIterator;
typedef const OctreeLeafNodeIterator<OctreeT> ConstLeafNodeIterator;
LeafNodeIterator leaf_begin(unsigned int max_depth_arg = 0) {return LeafNodeIterator(this, max_depth_arg);};
const LeafNodeIterator leaf_end() {return LeafNodeIterator();};

LeafNodeIterator leaf_begin (unsigned int max_depth_arg = 0u)
{
return LeafNodeIterator (this, max_depth_arg? max_depth_arg : this->octree_depth_);
};

const LeafNodeIterator leaf_end (unsigned int max_depth_arg = 0u)
{
return LeafNodeIterator (this, max_depth_arg? max_depth_arg : this->octree_depth_, NULL);
};

// Octree depth-first iterators
typedef OctreeDepthFirstIterator<OctreeT> DepthFirstIterator;
typedef const OctreeDepthFirstIterator<OctreeT> ConstDepthFirstIterator;
DepthFirstIterator depth_begin(unsigned int max_depth_arg = 0) {return DepthFirstIterator(this, max_depth_arg);};
const DepthFirstIterator depth_end() {return DepthFirstIterator();};

DepthFirstIterator depth_begin (unsigned int max_depth_arg = 0u)
{
return DepthFirstIterator (this, max_depth_arg? max_depth_arg : this->octree_depth_);
};

const DepthFirstIterator depth_end (unsigned int max_depth_arg = 0u)
{
return DepthFirstIterator (this, max_depth_arg? max_depth_arg : this->octree_depth_, NULL);
};

// Octree breadth-first iterators
typedef OctreeBreadthFirstIterator<OctreeT> BreadthFirstIterator;
typedef const OctreeBreadthFirstIterator<OctreeT> ConstBreadthFirstIterator;
BreadthFirstIterator breadth_begin(unsigned int max_depth_arg = 0) {return BreadthFirstIterator(this, max_depth_arg);};
const BreadthFirstIterator breadth_end() {return BreadthFirstIterator();};

BreadthFirstIterator breadth_begin (unsigned int max_depth_arg = 0u)
{
return BreadthFirstIterator (this, max_depth_arg? max_depth_arg : this->octree_depth_);
};

const BreadthFirstIterator breadth_end (unsigned int max_depth_arg = 0u)
{
return BreadthFirstIterator (this, max_depth_arg? max_depth_arg : this->octree_depth_, NULL);
};


/** \brief Empty constructor. */
Expand Down Expand Up @@ -564,31 +624,6 @@ namespace pcl
{
return (true);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Globals
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/** \brief Amount of leaf nodes **/
std::size_t leaf_count_;

/** \brief Amount of branch nodes **/
std::size_t branch_count_;

/** \brief Pointer to root branch node of octree **/
BranchNode* root_node_;

/** \brief Depth mask based on octree depth **/
unsigned int depth_mask_;

/** \brief Octree depth */
unsigned int octree_depth_;

/** \brief Enable dynamic_depth **/
bool dynamic_depth_enabled_;

/** \brief key range */
OctreeKey max_key_;
};
}
}
Expand Down
130 changes: 91 additions & 39 deletions octree/include/pcl/octree/octree_iterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,26 +103,21 @@ namespace pcl
this->reset ();
}

/** \brief Copy constructor.
* \param[in] src the iterator to copy into this
* \param[in] max_depth_arg Depth limitation during traversal
*/
OctreeIteratorBase (const OctreeIteratorBase& src, unsigned int max_depth_arg = 0) :
octree_ (src.octree_), current_state_(0), max_octree_depth_(max_depth_arg)
{
}

/** \brief Copy operator.
* \param[in] src the iterator to copy into this
*/
inline OctreeIteratorBase&
operator = (const OctreeIteratorBase& src)
{
octree_ = src.octree_;
current_state_ = src.current_state_;
max_octree_depth_ = src.max_octree_depth_;
return (*this);
}
/** \brief Constructor.
* \param[in] octree_arg Octree to be iterated. Initially the iterator is set to its root node.
* \param[in] max_depth_arg Depth limitation during traversal
* \param[in] current_state A pointer to the current iterator state
*
* \warning For advanced users only.
*/
explicit
OctreeIteratorBase (OctreeT* octree_arg,
unsigned int max_depth_arg,
IteratorState* current_state)
: octree_(octree_arg)
, current_state_ (current_state)
, max_octree_depth_ (max_depth_arg)
{}

/** \brief Empty deconstructor. */
virtual
Expand All @@ -135,19 +130,20 @@ namespace pcl
*/
bool operator==(const OctreeIteratorBase& other) const
{
return (( octree_ ==other.octree_) &&
( current_state_ == other.current_state_) &&
( max_octree_depth_ == other.max_octree_depth_) );
return (this == &other) ||
((octree_ == other.octree_) &&
(max_octree_depth_ == other.max_octree_depth_) &&
((current_state_ == other.current_state_) || // end state case
(current_state_ && other.current_state_ && // null dereference protection
(current_state_->key_ == other.current_state_->key_))));
}

/** \brief Inequal comparison operator
* \param[in] other OctreeIteratorBase to compare with
*/
bool operator!=(const OctreeIteratorBase& other) const
{
return (( octree_ !=other.octree_) &&
( current_state_ != other.current_state_) &&
( max_octree_depth_ != other.max_octree_depth_) );
return !operator== (other);
}

/** \brief Reset iterator */
Expand Down Expand Up @@ -384,11 +380,33 @@ namespace pcl
explicit
OctreeDepthFirstIterator (OctreeT* octree_arg, unsigned int max_depth_arg = 0);

/** \brief Empty deconstructor. */
virtual
~OctreeDepthFirstIterator ();
/** \brief Constructor.
* \param[in] octree_arg Octree to be iterated. Initially the iterator is set to its root node.
* \param[in] max_depth_arg Depth limitation during traversal
* \param[in] current_state A pointer to the current iterator state
*
* \warning For advanced users only.
*/
explicit
OctreeDepthFirstIterator (OctreeT* octree_arg,
unsigned int max_depth_arg,
IteratorState* current_state,
const std::vector<IteratorState>& stack = std::vector<IteratorState> ())
: OctreeIteratorBase<OctreeT> (octree_arg, max_depth_arg, current_state)
, stack_ (stack)
{}

/** \brief Copy Constructor.
* \param[in] other Another OctreeDepthFirstIterator to copy from
*/
OctreeDepthFirstIterator (const OctreeDepthFirstIterator& other)
: OctreeIteratorBase<OctreeT> (other)
, stack_ (other.stack_)
{
this->current_state_ = stack_.size ()? &stack_.back () : NULL;
}

/** \brief Copy operator.
/** \brief Copy assignment
* \param[in] src the iterator to copy into this
*/
inline OctreeDepthFirstIterator&
Expand All @@ -401,7 +419,7 @@ namespace pcl

if (stack_.size())
{
this->current_state_ = &stack_.back();
this->current_state_ = &stack_.back ();
} else
{
this->current_state_ = 0;
Expand Down Expand Up @@ -470,9 +488,31 @@ namespace pcl
explicit
OctreeBreadthFirstIterator (OctreeT* octree_arg, unsigned int max_depth_arg = 0);

/** \brief Empty deconstructor. */
virtual
~OctreeBreadthFirstIterator ();
/** \brief Constructor.
* \param[in] octree_arg Octree to be iterated. Initially the iterator is set to its root node.
* \param[in] max_depth_arg Depth limitation during traversal
* \param[in] current_state A pointer to the current iterator state
*
* \warning For advanced users only.
*/
explicit
OctreeBreadthFirstIterator (OctreeT* octree_arg,
unsigned int max_depth_arg,
IteratorState* current_state,
const std::deque<IteratorState>& fifo = std::deque<IteratorState> ())
: OctreeIteratorBase<OctreeT> (octree_arg, max_depth_arg, current_state)
, FIFO_ (fifo)
{}

/** \brief Copy Constructor.
* \param[in] other Another OctreeBreadthFirstIterator to copy from
*/
OctreeBreadthFirstIterator (const OctreeBreadthFirstIterator& other)
: OctreeIteratorBase<OctreeT> (other)
, FIFO_ (other.FIFO_)
{
this->current_state_ = FIFO_.size ()? &FIFO_.front () : NULL;
}

/** \brief Copy operator.
* \param[in] src the iterator to copy into this
Expand Down Expand Up @@ -558,11 +598,23 @@ namespace pcl
reset ();
}

/** \brief Empty deconstructor. */
virtual
~OctreeLeafNodeIterator ()
{
}
/** \brief Constructor.
* \param[in] octree_arg Octree to be iterated. Initially the iterator is set to its root node.
* \param[in] max_depth_arg Depth limitation during traversal
* \param[in] current_state A pointer to the current iterator state
*
* \warning For advanced users only.
*/
explicit
OctreeLeafNodeIterator (OctreeT* octree_arg,
unsigned int max_depth_arg,
IteratorState* current_state,
const std::vector<IteratorState>& stack = std::vector<IteratorState> ())
: OctreeDepthFirstIterator<OctreeT> (octree_arg,
max_depth_arg,
current_state,
stack)
{}

/** \brief Reset the iterator to the root node of the octree
*/
Expand Down
22 changes: 18 additions & 4 deletions octree/include/pcl/octree/octree_pointcloud_adjacency.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,29 @@ namespace pcl
typedef OctreeDepthFirstIterator<OctreeAdjacencyT> Iterator;
typedef const OctreeDepthFirstIterator<OctreeAdjacencyT> ConstIterator;

Iterator depth_begin (unsigned int max_depth_arg = 0) { return Iterator (this, max_depth_arg); }
const Iterator depth_end () { return Iterator (); }
Iterator depth_begin (unsigned int max_depth_arg = 0)
{
return Iterator (this, max_depth_arg? max_depth_arg : this->octree_depth_);
}

const Iterator depth_end (unsigned int max_depth_arg = 0)
{
return Iterator (this, max_depth_arg? max_depth_arg : this->octree_depth_, NULL);
}

// Octree leaf node iterators
typedef OctreeLeafNodeIterator<OctreeAdjacencyT> LeafNodeIterator;
typedef const OctreeLeafNodeIterator<OctreeAdjacencyT> ConstLeafNodeIterator;

LeafNodeIterator leaf_begin (unsigned int max_depth_arg = 0) { return LeafNodeIterator (this, max_depth_arg); }
const LeafNodeIterator leaf_end () { return LeafNodeIterator (); }
LeafNodeIterator leaf_begin (unsigned int max_depth_arg = 0)
{
return LeafNodeIterator (this, max_depth_arg? max_depth_arg : this->octree_depth_);
}

const LeafNodeIterator leaf_end (unsigned int max_depth_arg = 0)
{
return LeafNodeIterator (this, max_depth_arg? max_depth_arg : this->octree_depth_, NULL);
}

// BGL graph
typedef boost::adjacency_list<boost::setS, boost::setS, boost::undirectedS, PointT, float> VoxelAdjacencyList;
Expand Down
3 changes: 3 additions & 0 deletions test/octree/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@ if (build)
PCL_ADD_TEST(a_octree_test test_octree
FILES test_octree.cpp
LINK_WITH pcl_gtest pcl_common)
PCL_ADD_TEST(a_octree_iterator_test test_octree_iterator
FILES test_octree_iterator.cpp
LINK_WITH pcl_gtest pcl_common pcl_octree)
endif (build)
Loading