Skip to content

Commit a17d63e

Browse files
Proof of concept
1 parent 9dae1ea commit a17d63e

File tree

3 files changed

+71
-53
lines changed

3 files changed

+71
-53
lines changed

octree/include/pcl/octree/impl/octree_iterator.hpp

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -275,13 +275,13 @@ namespace pcl
275275
//////////////////////////////////////////////////////////////////////////////////////////////
276276
template<typename OctreeT>
277277
OctreeFixedDepthIterator<OctreeT>::OctreeFixedDepthIterator () :
278-
OctreeBreadthFirstIterator<OctreeT> (0u), fixed_depth_ (0u)
278+
OctreeBreadthFirstIterator<OctreeT> (0u)
279279
{}
280280

281281
//////////////////////////////////////////////////////////////////////////////////////////////
282282
template<typename OctreeT>
283283
OctreeFixedDepthIterator<OctreeT>::OctreeFixedDepthIterator (OctreeT* octree_arg, unsigned int fixed_depth_arg) :
284-
OctreeBreadthFirstIterator<OctreeT> (octree_arg, fixed_depth_arg), fixed_depth_ (fixed_depth_arg)
284+
OctreeBreadthFirstIterator<OctreeT> (octree_arg, fixed_depth_arg)
285285
{
286286
this->reset (fixed_depth_arg);
287287
}
@@ -290,37 +290,38 @@ namespace pcl
290290
template<typename OctreeT>
291291
void OctreeFixedDepthIterator<OctreeT>::reset (unsigned int fixed_depth_arg)
292292
{
293-
// Set the desired depth to walk through
294-
fixed_depth_ = fixed_depth_arg;
295-
296293
if (!this->octree_)
297294
{
298295
return;
299296
}
300297

298+
// if (this->octree_->getTreeDepth () < fixed_depth_arg)
299+
// {
300+
// PCL_WARN ("[pcl::octree::FixedDepthIterator] The requested fixed depth "
301+
// "was bigger than the octree's depth.\n");
302+
// PCL_WARN ("[pcl::octree::FixedDepthIterator] fixed_depth = %d (instead "
303+
// "of %d)\n", this->octree_->getTreeDepth (), fixed_depth_arg);
304+
// }
305+
306+
// // By default for the parent class OctreeBreadthFirstIterator, if the
307+
// // depth argument is equal to 0, the iterator would run over every node.
308+
// // For the OctreeFixedDepthIterator, whatever the depth ask, set the
309+
// // max_octree_depth_ accordingly
310+
// this->max_octree_depth_ = std::min (fixed_depth_arg, this->octree_->getTreeDepth ());
311+
this->max_octree_depth_ = fixed_depth_arg;
312+
301313
// If I'm nowhere, reset
302314
// If I'm somewhere and I can't guarantee I'm before the first node, reset
303-
if ((!this->current_state_) || (fixed_depth_ <= this->getCurrentOctreeDepth ()))
315+
if ((!this->current_state_) || (fixed_depth_arg <= this->getCurrentOctreeDepth ()))
304316
OctreeBreadthFirstIterator<OctreeT>::reset ();
305317

306-
if (this->octree_->getTreeDepth () < fixed_depth_)
307-
{
308-
PCL_WARN ("[pcl::octree::FixedDepthIterator] The requested fixed depth was bigger than the octree's depth.\n");
309-
PCL_WARN ("[pcl::octree::FixedDepthIterator] fixed_depth = %d (instead of %d)\n", this->octree_->getTreeDepth (), fixed_depth_);
310-
}
311-
312-
// By default for the parent class OctreeBreadthFirstIterator, if the
313-
// depth argument is equal to 0, the iterator would run over every node.
314-
// For the OctreeFixedDepthIterator, whatever the depth ask, set the
315-
// max_octree_depth_ accordingly
316-
this->max_octree_depth_ = std::min (fixed_depth_, this->octree_->getTreeDepth ());
317318

318319
// Restore previous state in case breath first iterator had child nodes already set up
319320
if (FIFO_.size ())
320321
this->current_state_ = &FIFO_.front ();
321322

322323
// Iterate all the way to the desired level
323-
while (this->current_state_ && (this->getCurrentOctreeDepth () != fixed_depth_))
324+
while (this->current_state_ && (this->getCurrentOctreeDepth () != fixed_depth_arg))
324325
OctreeBreadthFirstIterator<OctreeT>::operator++ ();
325326
}
326327
}

octree/include/pcl/octree/octree_iterator.h

Lines changed: 43 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -86,22 +86,36 @@ namespace pcl
8686

8787
/** \brief Empty constructor.
8888
*/
89+
OctreeIteratorBase () :
90+
octree_ (0), current_state_(0), max_octree_depth_(0)
91+
{}
92+
8993
explicit
90-
OctreeIteratorBase (unsigned int max_depth_arg = 0) :
94+
OctreeIteratorBase (unsigned int max_depth_arg) :
9195
octree_ (0), current_state_(0), max_octree_depth_(max_depth_arg)
92-
{
93-
this->reset ();
94-
}
96+
{}
9597

9698
/** \brief Constructor.
9799
* \param[in] octree_arg Octree to be iterated. Initially the iterator is set to its root node.
98100
* \param[in] max_depth_arg Depth limitation during traversal
99101
*/
100102
explicit
101-
OctreeIteratorBase (OctreeT* octree_arg, unsigned int max_depth_arg = 0) :
102-
octree_ (octree_arg), current_state_(0), max_octree_depth_(max_depth_arg)
103+
OctreeIteratorBase (OctreeT* octree_arg) :
104+
octree_ (octree_arg),
105+
current_state_(0),
106+
max_octree_depth_(octree_arg? octree_->getTreeDepth() : 0)
107+
{}
108+
109+
/** \brief Constructor.
110+
* \param[in] octree_arg Octree to be iterated. Initially the iterator is set to its root node.
111+
* \param[in] max_depth_arg Depth limitation during traversal
112+
*/
113+
OctreeIteratorBase (OctreeT* octree_arg, unsigned int max_depth_arg) :
114+
octree_ (octree_arg),
115+
current_state_(0),
116+
// max_octree_depth_(octree_? std::min (max_depth_arg, octree_->getTreeDepth ()) : 0)
117+
max_octree_depth_(max_depth_arg)
103118
{
104-
this->reset ();
105119
}
106120

107121
/** \brief Constructor.
@@ -156,10 +170,10 @@ namespace pcl
156170
inline void reset ()
157171
{
158172
current_state_ = 0;
159-
if (octree_ && (!max_octree_depth_))
160-
{
161-
max_octree_depth_ = octree_->getTreeDepth();
162-
}
173+
// if (octree_ && (!max_octree_depth_))
174+
// {
175+
// max_octree_depth_ = octree_->getTreeDepth();
176+
// }
163177
}
164178

165179
/** \brief Get octree key for the current iterator octree node
@@ -578,6 +592,10 @@ namespace pcl
578592
template<typename OctreeT>
579593
class OctreeFixedDepthIterator : public OctreeBreadthFirstIterator<OctreeT>
580594
{
595+
protected:
596+
597+
using OctreeIteratorBase<OctreeT>::max_octree_depth_;
598+
581599
public:
582600

583601
// public typedefs
@@ -608,30 +626,29 @@ namespace pcl
608626
IteratorState* current_state,
609627
const std::deque<IteratorState>& fifo = std::deque<IteratorState> ())
610628
: OctreeBreadthFirstIterator<OctreeT> (octree_arg, fixed_depth_arg, current_state, fifo)
611-
, fixed_depth_ (fixed_depth_arg)
612629
{}
613630

614631
/** \brief Copy Constructor.
615632
* \param[in] other Another OctreeFixedDepthIterator to copy from
616633
*/
617-
OctreeFixedDepthIterator (const OctreeFixedDepthIterator& other)
618-
: OctreeBreadthFirstIterator<OctreeT> (other)
619-
{
620-
this->fixed_depth_ = other.fixed_depth_;
621-
}
634+
// OctreeFixedDepthIterator (const OctreeFixedDepthIterator& other)
635+
// : OctreeBreadthFirstIterator<OctreeT> (other)
636+
// {
637+
// this->fixed_depth_ = other.fixed_depth_;
638+
// }
622639

623640
/** \brief Copy assignment.
624641
* \param[in] src the iterator to copy into this
625642
* \return pointer to the current octree node
626643
*/
627-
inline OctreeFixedDepthIterator&
628-
operator = (const OctreeFixedDepthIterator& src)
629-
{
630-
OctreeBreadthFirstIterator<OctreeT>::operator= (src);
631-
this->fixed_depth_ = src.fixed_depth_;
644+
// inline OctreeFixedDepthIterator&
645+
// operator = (const OctreeFixedDepthIterator& src)
646+
// {
647+
// OctreeBreadthFirstIterator<OctreeT>::operator= (src);
648+
// this->fixed_depth_ = src.fixed_depth_;
632649

633-
return (*this);
634-
}
650+
// return (*this);
651+
// }
635652

636653
/** \brief Reset the iterator to the first node at the depth given as parameter
637654
* \param[in] fixed_depth_arg Depth level during traversal
@@ -644,14 +661,14 @@ namespace pcl
644661
void
645662
reset ()
646663
{
647-
this->reset (fixed_depth_);
664+
this->reset (max_octree_depth_);
648665
}
649666

650667
protected:
651668
using OctreeBreadthFirstIterator<OctreeT>::FIFO_;
652669

653670
/** \brief Given level of the node to be iterated */
654-
unsigned int fixed_depth_;
671+
// unsigned int fixed_depth_;
655672
};
656673

657674
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

test/octree/test_octree_iterator.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -690,11 +690,11 @@ TEST_F (OctreeBaseIteratorsForLoopTest, FixedDepthIterator)
690690
}
691691

692692
// Check the node_count, branch_count and leaf_count values
693-
ASSERT_EQ (leaf_count, 64);
694-
ASSERT_EQ (branch_count, 9);
695-
ASSERT_EQ (branch_count + leaf_count, node_count);
696-
ASSERT_EQ (oct_a_.getLeafCount (), leaf_count);
697-
ASSERT_EQ (oct_a_.getBranchCount (), branch_count);
693+
EXPECT_EQ (leaf_count, 64);
694+
EXPECT_EQ (branch_count, 9);
695+
EXPECT_EQ (branch_count + leaf_count, node_count);
696+
EXPECT_EQ (oct_a_.getLeafCount (), leaf_count);
697+
EXPECT_EQ (oct_a_.getBranchCount (), branch_count);
698698

699699
// Iterate over the octree oct_a_ with a depth max of 1.
700700
// As oct_a_ has a depth level of 2, we should only iterate
@@ -719,10 +719,10 @@ TEST_F (OctreeBaseIteratorsForLoopTest, FixedDepthIterator)
719719
}
720720

721721
// Check the node_count, branch_count and leaf_count values
722-
ASSERT_EQ (leaf_count, 0);
723-
ASSERT_EQ (branch_count, 8);
724-
ASSERT_EQ (branch_count + leaf_count, node_count);
725-
ASSERT_EQ ((oct_a_.getBranchCount () - 1), branch_count);
722+
EXPECT_EQ (leaf_count, 0);
723+
EXPECT_EQ (branch_count, 8);
724+
EXPECT_EQ (branch_count + leaf_count, node_count);
725+
EXPECT_EQ ((oct_a_.getBranchCount () - 1), branch_count);
726726
}
727727

728728
////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)