Skip to content
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

Octree Iterator begin/end method and added tests #2174

Merged
merged 2 commits into from
Jan 27, 2018
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
22 changes: 0 additions & 22 deletions octree/include/pcl/octree/octree_pointcloud.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,34 +72,12 @@ namespace pcl

class OctreePointCloud : public OctreeT
{
// iterators are friends
friend class OctreeIteratorBase<OctreeT> ;
friend class OctreeDepthFirstIterator<OctreeT> ;
friend class OctreeBreadthFirstIterator<OctreeT> ;
friend class OctreeLeafNodeIterator<OctreeT> ;

public:
typedef OctreeT Base;

typedef typename OctreeT::LeafNode LeafNode;
typedef typename OctreeT::BranchNode BranchNode;

// Octree default iterators
typedef OctreeDepthFirstIterator<OctreeT> Iterator;
typedef const OctreeDepthFirstIterator<OctreeT> ConstIterator;

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

// Octree depth-first iterators
typedef OctreeDepthFirstIterator<OctreeT> DepthFirstIterator;
typedef const OctreeDepthFirstIterator<OctreeT> ConstDepthFirstIterator;

// Octree breadth-first iterators
typedef OctreeBreadthFirstIterator<OctreeT> BreadthFirstIterator;
typedef const OctreeBreadthFirstIterator<OctreeT> ConstBreadthFirstIterator;

/** \brief Octree pointcloud constructor.
* \param[in] resolution_arg octree resolution at lowest octree level
*/
Expand Down
34 changes: 0 additions & 34 deletions octree/include/pcl/octree/octree_pointcloud_adjacency.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,40 +95,6 @@ namespace pcl
typedef boost::shared_ptr<PointCloud> PointCloudPtr;
typedef boost::shared_ptr<const PointCloud> PointCloudConstPtr;

// Iterators are friends
friend class OctreeIteratorBase<OctreeAdjacencyT>;
friend class OctreeDepthFirstIterator<OctreeAdjacencyT>;
friend class OctreeBreadthFirstIterator<OctreeAdjacencyT>;
friend class OctreeLeafNodeIterator<OctreeAdjacencyT>;

// Octree default iterators
typedef OctreeDepthFirstIterator<OctreeAdjacencyT> Iterator;
typedef const OctreeDepthFirstIterator<OctreeAdjacencyT> ConstIterator;

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? 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;
typedef typename VoxelAdjacencyList::vertex_descriptor VoxelID;
Expand Down
72 changes: 56 additions & 16 deletions test/octree/test_octree_iterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -690,10 +690,50 @@ struct OctreePointCloudAdjacencyBeginEndIteratorsTest
OctreeT oct_a_, oct_b_;
};

TEST_F (OctreePointCloudAdjacencyBeginEndIteratorsTest, LeafBegin)
{
// Useful types
typedef typename OctreeT::LeafNodeIterator IteratorT;

// Default initialization
IteratorT it_a_1 = oct_a_.leaf_begin ();
IteratorT it_a_2 = oct_a_.leaf_begin ();
IteratorT it_b = oct_b_.leaf_begin ();

EXPECT_EQ (it_a_1, it_a_2);
EXPECT_NE (it_a_1, it_b);
EXPECT_NE (it_a_2, it_b);

// Different max depths are not the same iterators
IteratorT it_m = oct_a_.leaf_begin ();
IteratorT it_m_1 = oct_a_.leaf_begin (1);
IteratorT it_m_md = oct_a_.leaf_begin (oct_a_.getTreeDepth ());
IteratorT it_m_b_1 = oct_b_.leaf_begin (1);

EXPECT_NE (it_m_1, it_m_md);
EXPECT_EQ (it_m_md, it_m); // should default to tree depth
EXPECT_NE (it_m_1, it_m_b_1);
}

TEST_F (OctreePointCloudAdjacencyBeginEndIteratorsTest, LeafEnd)
{
// Useful types
typedef typename OctreeT::LeafNodeIterator IteratorT;

// Default initialization
IteratorT it_a_1 = oct_a_.leaf_end ();
IteratorT it_a_2 = oct_a_.leaf_end ();
IteratorT it_b = oct_b_.leaf_end ();

EXPECT_EQ (it_a_1, it_a_2);
EXPECT_NE (it_a_1, it_b);
EXPECT_NE (it_a_2, it_b);
}

TEST_F (OctreePointCloudAdjacencyBeginEndIteratorsTest, DepthBegin)
{
// Useful types
typedef typename OctreeT::Iterator IteratorT;
typedef typename OctreeT::DepthFirstIterator IteratorT;

// Default initialization
IteratorT it_a_1 = oct_a_.depth_begin ();
Expand All @@ -718,7 +758,7 @@ TEST_F (OctreePointCloudAdjacencyBeginEndIteratorsTest, DepthBegin)
TEST_F (OctreePointCloudAdjacencyBeginEndIteratorsTest, DepthEnd)
{
// Useful types
typedef typename OctreeT::Iterator IteratorT;
typedef typename OctreeT::DepthFirstIterator IteratorT;

// Default initialization
IteratorT it_a_1 = oct_a_.depth_end ();
Expand All @@ -730,40 +770,40 @@ TEST_F (OctreePointCloudAdjacencyBeginEndIteratorsTest, DepthEnd)
EXPECT_NE (it_a_2, it_b);
}

TEST_F (OctreePointCloudAdjacencyBeginEndIteratorsTest, LeafBegin)
TEST_F (OctreePointCloudAdjacencyBeginEndIteratorsTest, BreadthBegin)
{
// Useful types
typedef typename OctreeT::LeafNodeIterator IteratorT;
typedef typename OctreeT::BreadthFirstIterator IteratorT;

// Default initialization
IteratorT it_a_1 = oct_a_.leaf_begin ();
IteratorT it_a_2 = oct_a_.leaf_begin ();
IteratorT it_b = oct_b_.leaf_begin ();
IteratorT it_a_1 = oct_a_.breadth_begin ();
IteratorT it_a_2 = oct_a_.breadth_begin ();
IteratorT it_b = oct_b_.breadth_begin ();

EXPECT_EQ (it_a_1, it_a_2);
EXPECT_NE (it_a_1, it_b);
EXPECT_NE (it_a_2, it_b);

// Different max depths are not the same iterators
IteratorT it_m = oct_a_.leaf_begin ();
IteratorT it_m_1 = oct_a_.leaf_begin (1);
IteratorT it_m_md = oct_a_.leaf_begin (oct_a_.getTreeDepth ());
IteratorT it_m_b_1 = oct_b_.leaf_begin (1);
IteratorT it_m = oct_a_.breadth_begin ();
IteratorT it_m_1 = oct_a_.breadth_begin (1);
IteratorT it_m_md = oct_a_.breadth_begin (oct_a_.getTreeDepth ());
IteratorT it_m_b_1 = oct_b_.breadth_begin (1);

EXPECT_NE (it_m_1, it_m_md);
EXPECT_EQ (it_m_md, it_m); // should default to tree depth
EXPECT_NE (it_m_1, it_m_b_1);
}

TEST_F (OctreePointCloudAdjacencyBeginEndIteratorsTest, LeafEnd)
TEST_F (OctreePointCloudAdjacencyBeginEndIteratorsTest, BreadthEnd)
{
// Useful types
typedef typename OctreeT::LeafNodeIterator IteratorT;
typedef typename OctreeT::BreadthFirstIterator IteratorT;

// Default initialization
IteratorT it_a_1 = oct_a_.leaf_end ();
IteratorT it_a_2 = oct_a_.leaf_end ();
IteratorT it_b = oct_b_.leaf_end ();
IteratorT it_a_1 = oct_a_.breadth_end ();
IteratorT it_a_2 = oct_a_.breadth_end ();
IteratorT it_b = oct_b_.breadth_end ();

EXPECT_EQ (it_a_1, it_a_2);
EXPECT_NE (it_a_1, it_b);
Expand Down