Skip to content

Commit

Permalink
Merge pull request #919 from jpapon/supervoxel_impl_to_cpp
Browse files Browse the repository at this point in the history
Changes necessary for lccp pull request #718
  • Loading branch information
taketwo committed Sep 21, 2014
2 parents a84af0b + 80d90be commit 89ec4f9
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -767,85 +767,31 @@ pcl::SupervoxelClustering<PointT>::getMaxLabel () const

namespace pcl
{

namespace octree
{
//Explicit overloads for RGB types
template<>
void
pcl::octree::OctreePointCloudAdjacencyContainer<pcl::PointXYZRGB,pcl::SupervoxelClustering<pcl::PointXYZRGB>::VoxelData>::addPoint (const pcl::PointXYZRGB &new_point)
{
++num_points_;
//Same as before here
data_.xyz_[0] += new_point.x;
data_.xyz_[1] += new_point.y;
data_.xyz_[2] += new_point.z;
//Separate sums for r,g,b since we cant sum in uchars
data_.rgb_[0] += static_cast<float> (new_point.r);
data_.rgb_[1] += static_cast<float> (new_point.g);
data_.rgb_[2] += static_cast<float> (new_point.b);
}
pcl::octree::OctreePointCloudAdjacencyContainer<pcl::PointXYZRGB,pcl::SupervoxelClustering<pcl::PointXYZRGB>::VoxelData>::addPoint (const pcl::PointXYZRGB &new_point);

template<>
void
pcl::octree::OctreePointCloudAdjacencyContainer<pcl::PointXYZRGBA,pcl::SupervoxelClustering<pcl::PointXYZRGBA>::VoxelData>::addPoint (const pcl::PointXYZRGBA &new_point)
{
++num_points_;
//Same as before here
data_.xyz_[0] += new_point.x;
data_.xyz_[1] += new_point.y;
data_.xyz_[2] += new_point.z;
//Separate sums for r,g,b since we cant sum in uchars
data_.rgb_[0] += static_cast<float> (new_point.r);
data_.rgb_[1] += static_cast<float> (new_point.g);
data_.rgb_[2] += static_cast<float> (new_point.b);
}


pcl::octree::OctreePointCloudAdjacencyContainer<pcl::PointXYZRGBA,pcl::SupervoxelClustering<pcl::PointXYZRGBA>::VoxelData>::addPoint (const pcl::PointXYZRGBA &new_point);

//Explicit overloads for RGB types
template<> void
pcl::octree::OctreePointCloudAdjacencyContainer<pcl::PointXYZRGB,pcl::SupervoxelClustering<pcl::PointXYZRGB>::VoxelData>::computeData ()
{
data_.rgb_[0] /= (static_cast<float> (num_points_));
data_.rgb_[1] /= (static_cast<float> (num_points_));
data_.rgb_[2] /= (static_cast<float> (num_points_));
data_.xyz_[0] /= (static_cast<float> (num_points_));
data_.xyz_[1] /= (static_cast<float> (num_points_));
data_.xyz_[2] /= (static_cast<float> (num_points_));
}
pcl::octree::OctreePointCloudAdjacencyContainer<pcl::PointXYZRGB,pcl::SupervoxelClustering<pcl::PointXYZRGB>::VoxelData>::computeData ();

template<> void
pcl::octree::OctreePointCloudAdjacencyContainer<pcl::PointXYZRGBA,pcl::SupervoxelClustering<pcl::PointXYZRGBA>::VoxelData>::computeData ()
{
data_.rgb_[0] /= (static_cast<float> (num_points_));
data_.rgb_[1] /= (static_cast<float> (num_points_));
data_.rgb_[2] /= (static_cast<float> (num_points_));
data_.xyz_[0] /= (static_cast<float> (num_points_));
data_.xyz_[1] /= (static_cast<float> (num_points_));
data_.xyz_[2] /= (static_cast<float> (num_points_));
}

pcl::octree::OctreePointCloudAdjacencyContainer<pcl::PointXYZRGBA,pcl::SupervoxelClustering<pcl::PointXYZRGBA>::VoxelData>::computeData ();

//Explicit overloads for XYZ types
template<>
void
pcl::octree::OctreePointCloudAdjacencyContainer<pcl::PointXYZ,pcl::SupervoxelClustering<pcl::PointXYZ>::VoxelData>::addPoint (const pcl::PointXYZ &new_point)
{
++num_points_;
//Same as before here
data_.xyz_[0] += new_point.x;
data_.xyz_[1] += new_point.y;
data_.xyz_[2] += new_point.z;
}

pcl::octree::OctreePointCloudAdjacencyContainer<pcl::PointXYZ,pcl::SupervoxelClustering<pcl::PointXYZ>::VoxelData>::addPoint (const pcl::PointXYZ &new_point);

template<> void
pcl::octree::OctreePointCloudAdjacencyContainer<pcl::PointXYZ,pcl::SupervoxelClustering<pcl::PointXYZ>::VoxelData>::computeData ()
{
data_.xyz_[0] /= (static_cast<float> (num_points_));
data_.xyz_[1] /= (static_cast<float> (num_points_));
data_.xyz_[2] /= (static_cast<float> (num_points_));
}

pcl::octree::OctreePointCloudAdjacencyContainer<pcl::PointXYZ,pcl::SupervoxelClustering<pcl::PointXYZ>::VoxelData>::computeData ();
}
}

Expand All @@ -856,26 +802,10 @@ namespace pcl
{

template<> void
pcl::SupervoxelClustering<pcl::PointXYZRGB>::VoxelData::getPoint (pcl::PointXYZRGB &point_arg) const
{
point_arg.rgba = static_cast<uint32_t>(rgb_[0]) << 16 |
static_cast<uint32_t>(rgb_[1]) << 8 |
static_cast<uint32_t>(rgb_[2]);
point_arg.x = xyz_[0];
point_arg.y = xyz_[1];
point_arg.z = xyz_[2];
}
pcl::SupervoxelClustering<pcl::PointXYZRGB>::VoxelData::getPoint (pcl::PointXYZRGB &point_arg) const;

template<> void
pcl::SupervoxelClustering<pcl::PointXYZRGBA>::VoxelData::getPoint (pcl::PointXYZRGBA &point_arg ) const
{
point_arg.rgba = static_cast<uint32_t>(rgb_[0]) << 16 |
static_cast<uint32_t>(rgb_[1]) << 8 |
static_cast<uint32_t>(rgb_[2]);
point_arg.x = xyz_[0];
point_arg.y = xyz_[1];
point_arg.z = xyz_[2];
}
pcl::SupervoxelClustering<pcl::PointXYZRGBA>::VoxelData::getPoint (pcl::PointXYZRGBA &point_arg ) const;

template<typename PointT> void
pcl::SupervoxelClustering<PointT>::VoxelData::getPoint (PointT &point_arg ) const
Expand All @@ -896,7 +826,6 @@ namespace pcl
normal_arg.curvature = curvature_;
}
}


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ namespace pcl
* \note Usually, color isn't needed (and can be detrimental)- spatial structure is mainly used
* - J. Papon, A. Abramov, M. Schoeler, F. Woergoetter
* Voxel Cloud Connectivity Segmentation - Supervoxels from PointClouds
* In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition (CVPR) 2013
* In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition (CVPR) 2013
* \ingroup segmentation
* \author Jeremie Papon ([email protected])
*/
template <typename PointT>
Expand Down
130 changes: 115 additions & 15 deletions segmentation/src/supervoxel_clustering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,118 @@
#include <pcl/point_types.h>
#include <pcl/impl/instantiate.hpp>
#include <pcl/segmentation/impl/supervoxel_clustering.hpp>

#include <pcl/octree/impl/octree_pointcloud_adjacency.hpp>
#include <pcl/octree/impl/octree_pointcloud.hpp>
#include <pcl/octree/impl/octree_base.hpp>
#include <pcl/octree/impl/octree_iterator.hpp>

template class pcl::SupervoxelClustering<pcl::PointXYZRGBA>;
template class pcl::SupervoxelClustering<pcl::PointXYZRGB>;
template class pcl::SupervoxelClustering<pcl::PointXYZ>;
namespace pcl
{
namespace octree
{
//Explicit overloads for RGB types
template<>
void
pcl::octree::OctreePointCloudAdjacencyContainer<pcl::PointXYZRGB,pcl::SupervoxelClustering<pcl::PointXYZRGB>::VoxelData>::addPoint (const pcl::PointXYZRGB &new_point)
{
++num_points_;
//Same as before here
data_.xyz_[0] += new_point.x;
data_.xyz_[1] += new_point.y;
data_.xyz_[2] += new_point.z;
//Separate sums for r,g,b since we cant sum in uchars
data_.rgb_[0] += static_cast<float> (new_point.r);
data_.rgb_[1] += static_cast<float> (new_point.g);
data_.rgb_[2] += static_cast<float> (new_point.b);
}

template<>
void
pcl::octree::OctreePointCloudAdjacencyContainer<pcl::PointXYZRGBA,pcl::SupervoxelClustering<pcl::PointXYZRGBA>::VoxelData>::addPoint (const pcl::PointXYZRGBA &new_point)
{
++num_points_;
//Same as before here
data_.xyz_[0] += new_point.x;
data_.xyz_[1] += new_point.y;
data_.xyz_[2] += new_point.z;
//Separate sums for r,g,b since we cant sum in uchars
data_.rgb_[0] += static_cast<float> (new_point.r);
data_.rgb_[1] += static_cast<float> (new_point.g);
data_.rgb_[2] += static_cast<float> (new_point.b);
}



//Explicit overloads for RGB types
template<> void
pcl::octree::OctreePointCloudAdjacencyContainer<pcl::PointXYZRGB,pcl::SupervoxelClustering<pcl::PointXYZRGB>::VoxelData>::computeData ()
{
data_.rgb_[0] /= (static_cast<float> (num_points_));
data_.rgb_[1] /= (static_cast<float> (num_points_));
data_.rgb_[2] /= (static_cast<float> (num_points_));
data_.xyz_[0] /= (static_cast<float> (num_points_));
data_.xyz_[1] /= (static_cast<float> (num_points_));
data_.xyz_[2] /= (static_cast<float> (num_points_));
}

template<> void
pcl::octree::OctreePointCloudAdjacencyContainer<pcl::PointXYZRGBA,pcl::SupervoxelClustering<pcl::PointXYZRGBA>::VoxelData>::computeData ()
{
data_.rgb_[0] /= (static_cast<float> (num_points_));
data_.rgb_[1] /= (static_cast<float> (num_points_));
data_.rgb_[2] /= (static_cast<float> (num_points_));
data_.xyz_[0] /= (static_cast<float> (num_points_));
data_.xyz_[1] /= (static_cast<float> (num_points_));
data_.xyz_[2] /= (static_cast<float> (num_points_));
}

//Explicit overloads for XYZ types
template<>
void
pcl::octree::OctreePointCloudAdjacencyContainer<pcl::PointXYZ,pcl::SupervoxelClustering<pcl::PointXYZ>::VoxelData>::addPoint (const pcl::PointXYZ &new_point)
{
++num_points_;
//Same as before here
data_.xyz_[0] += new_point.x;
data_.xyz_[1] += new_point.y;
data_.xyz_[2] += new_point.z;
}

template<> void
pcl::octree::OctreePointCloudAdjacencyContainer<pcl::PointXYZ,pcl::SupervoxelClustering<pcl::PointXYZ>::VoxelData>::computeData ()
{
data_.xyz_[0] /= (static_cast<float> (num_points_));
data_.xyz_[1] /= (static_cast<float> (num_points_));
data_.xyz_[2] /= (static_cast<float> (num_points_));
}

}
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
namespace pcl
{
template<> void
pcl::SupervoxelClustering<pcl::PointXYZRGB>::VoxelData::getPoint (pcl::PointXYZRGB &point_arg) const
{
point_arg.rgba = static_cast<uint32_t>(rgb_[0]) << 16 |
static_cast<uint32_t>(rgb_[1]) << 8 |
static_cast<uint32_t>(rgb_[2]);
point_arg.x = xyz_[0];
point_arg.y = xyz_[1];
point_arg.z = xyz_[2];
}

template<> void
pcl::SupervoxelClustering<pcl::PointXYZRGBA>::VoxelData::getPoint (pcl::PointXYZRGBA &point_arg ) const
{
point_arg.rgba = static_cast<uint32_t>(rgb_[0]) << 16 |
static_cast<uint32_t>(rgb_[1]) << 8 |
static_cast<uint32_t>(rgb_[2]);
point_arg.x = xyz_[0];
point_arg.y = xyz_[1];
point_arg.z = xyz_[2];
}
}

typedef pcl::SupervoxelClustering<pcl::PointXYZ>::VoxelData VoxelDataT;
typedef pcl::SupervoxelClustering<pcl::PointXYZRGB>::VoxelData VoxelDataRGBT;
Expand All @@ -58,17 +161,14 @@ typedef pcl::octree::OctreePointCloudAdjacencyContainer<pcl::PointXYZ, VoxelData
typedef pcl::octree::OctreePointCloudAdjacencyContainer<pcl::PointXYZRGB, VoxelDataRGBT> AdjacencyContainerRGBT;
typedef pcl::octree::OctreePointCloudAdjacencyContainer<pcl::PointXYZRGBA, VoxelDataRGBAT> AdjacencyContainerRGBAT;

template class pcl::SupervoxelClustering<pcl::PointXYZ>;
template class pcl::SupervoxelClustering<pcl::PointXYZRGB>;
template class pcl::SupervoxelClustering<pcl::PointXYZRGBA>;

template class pcl::octree::OctreePointCloudAdjacencyContainer<pcl::PointXYZ, VoxelDataT>;
template class pcl::octree::OctreePointCloudAdjacencyContainer<pcl::PointXYZRGB, VoxelDataRGBT>;
template class pcl::octree::OctreePointCloudAdjacencyContainer<pcl::PointXYZRGBA, VoxelDataRGBAT>;

template class pcl::octree::OctreePointCloudAdjacency<pcl::PointXYZ, AdjacencyContainerT>;
template class pcl::octree::OctreePointCloudAdjacency<pcl::PointXYZRGB, AdjacencyContainerRGBT>;
template class pcl::octree::OctreePointCloudAdjacency<pcl::PointXYZRGBA, AdjacencyContainerRGBAT>;

//template class pcl::octree::OctreeBase<AdjacencyContainerRGBT, pcl::octree::OctreeContainerEmpty>;
//template class pcl::octree::OctreeBase<AdjacencyContainerRGBAT, pcl::octree::OctreeContainerEmpty>;

//template class pcl::octree::OctreeBreadthFirstIterator<pcl::octree::OctreeBase<AdjacencyContainerRGBT, pcl::octree::OctreeContainerEmpty> >;
//template class pcl::octree::OctreeBreadthFirstIterator<pcl::octree::OctreeBase<AdjacencyContainerRGBAT, pcl::octree::OctreeContainerEmpty> >;

template class pcl::octree::OctreePointCloudAdjacency<pcl::PointXYZRGBA, AdjacencyContainerRGBAT>;

0 comments on commit 89ec4f9

Please sign in to comment.