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

Fix: alignment issue of SupervoxelClustering #625

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
6 changes: 6 additions & 0 deletions octree/include/pcl/octree/octree_nodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@

#include <string.h>

#include <Eigen/Core>

#include <pcl/pcl_macros.h>

#include "octree_container.h"
Expand Down Expand Up @@ -190,6 +192,10 @@ namespace pcl

protected:
ContainerT container_;

public:
//Type ContainerT may have fixed-size Eigen objects inside
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
};

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pcl::SupervoxelClustering<PointT>::SupervoxelClustering (float voxel_resolution,
normal_importance_(1.0f),
label_colors_ (0)
{
adjacency_octree_ = boost::make_shared <OctreeAdjacencyT> (resolution_);
adjacency_octree_.reset (new OctreeAdjacencyT (resolution_));
if (use_single_camera_transform)
adjacency_octree_->setTransformFunction (boost::bind (&SupervoxelClustering::transformFunction, this, _1));
}
Expand Down Expand Up @@ -205,7 +205,7 @@ pcl::SupervoxelClustering<PointT>::prepareForSegmentation ()
template <typename PointT> void
pcl::SupervoxelClustering<PointT>::computeVoxelData ()
{
voxel_centroid_cloud_ = boost::make_shared<PointCloudT> ();
voxel_centroid_cloud_.reset (new PointCloudT);
voxel_centroid_cloud_->resize (adjacency_octree_->getLeafCount ());
typename LeafVectorT::iterator leaf_itr = adjacency_octree_->begin ();
typename PointCloudT::iterator cent_cloud_itr = voxel_centroid_cloud_->begin ();
Expand Down Expand Up @@ -326,7 +326,7 @@ pcl::SupervoxelClustering<PointT>::makeSupervoxels (std::map<uint32_t,typename S
for (typename HelperListT::iterator sv_itr = supervoxel_helpers_.begin (); sv_itr != supervoxel_helpers_.end (); ++sv_itr)
{
uint32_t label = sv_itr->getLabel ();
supervoxel_clusters[label] = boost::make_shared<Supervoxel<PointT> > ();
supervoxel_clusters[label].reset (new Supervoxel<PointT>);
sv_itr->getXYZ (supervoxel_clusters[label]->centroid_.x,supervoxel_clusters[label]->centroid_.y,supervoxel_clusters[label]->centroid_.z);
sv_itr->getRGB (supervoxel_clusters[label]->centroid_.rgba);
sv_itr->getNormal (supervoxel_clusters[label]->normal_);
Expand Down Expand Up @@ -386,7 +386,7 @@ pcl::SupervoxelClustering<PointT>::selectInitialSupervoxelSeeds (std::vector<Poi
distance.resize(1,0);
if (voxel_kdtree_ == 0)
{
voxel_kdtree_ = boost::make_shared< pcl::search::KdTree<PointT> >();
voxel_kdtree_.reset (new pcl::search::KdTree<PointT>);
voxel_kdtree_ ->setInputCloud (voxel_centroid_cloud_);
}

Expand Down Expand Up @@ -548,7 +548,7 @@ pcl::SupervoxelClustering<PointT>::getSupervoxelAdjacency (std::multimap<uint32_
template <typename PointT> pcl::PointCloud<pcl::PointXYZRGBA>::Ptr
pcl::SupervoxelClustering<PointT>::getColoredCloud () const
{
pcl::PointCloud<pcl::PointXYZRGBA>::Ptr colored_cloud = boost::make_shared <pcl::PointCloud<pcl::PointXYZRGBA> >();
pcl::PointCloud<pcl::PointXYZRGBA>::Ptr colored_cloud (new pcl::PointCloud<pcl::PointXYZRGBA>);
pcl::copyPointCloud (*input_,*colored_cloud);

pcl::PointCloud <pcl::PointXYZRGBA>::iterator i_colored;
Expand Down Expand Up @@ -578,7 +578,7 @@ pcl::SupervoxelClustering<PointT>::getColoredCloud () const
template <typename PointT> pcl::PointCloud<pcl::PointXYZRGBA>::Ptr
pcl::SupervoxelClustering<PointT>::getColoredVoxelCloud () const
{
pcl::PointCloud<pcl::PointXYZRGBA>::Ptr colored_cloud = boost::make_shared< pcl::PointCloud<pcl::PointXYZRGBA> > ();
pcl::PointCloud<pcl::PointXYZRGBA>::Ptr colored_cloud (new pcl::PointCloud<pcl::PointXYZRGBA>);
for (typename HelperListT::const_iterator sv_itr = supervoxel_helpers_.cbegin (); sv_itr != supervoxel_helpers_.cend (); ++sv_itr)
{
typename PointCloudT::Ptr voxels;
Expand All @@ -600,7 +600,7 @@ pcl::SupervoxelClustering<PointT>::getColoredVoxelCloud () const
template <typename PointT> typename pcl::PointCloud<PointT>::Ptr
pcl::SupervoxelClustering<PointT>::getVoxelCentroidCloud () const
{
typename PointCloudT::Ptr centroid_copy = boost::make_shared<PointCloudT> ();
typename PointCloudT::Ptr centroid_copy (new PointCloudT);
copyPointCloud (*voxel_centroid_cloud_, *centroid_copy);
return centroid_copy;
}
Expand All @@ -609,7 +609,7 @@ pcl::SupervoxelClustering<PointT>::getVoxelCentroidCloud () const
template <typename PointT> pcl::PointCloud<pcl::PointXYZL>::Ptr
pcl::SupervoxelClustering<PointT>::getLabeledVoxelCloud () const
{
pcl::PointCloud<pcl::PointXYZL>::Ptr labeled_voxel_cloud = boost::make_shared< pcl::PointCloud<pcl::PointXYZL> > ();
pcl::PointCloud<pcl::PointXYZL>::Ptr labeled_voxel_cloud (new pcl::PointCloud<pcl::PointXYZL>);
for (typename HelperListT::const_iterator sv_itr = supervoxel_helpers_.cbegin (); sv_itr != supervoxel_helpers_.cend (); ++sv_itr)
{
typename PointCloudT::Ptr voxels;
Expand All @@ -631,7 +631,7 @@ pcl::SupervoxelClustering<PointT>::getLabeledVoxelCloud () const
template <typename PointT> pcl::PointCloud<pcl::PointXYZL>::Ptr
pcl::SupervoxelClustering<PointT>::getLabeledCloud () const
{
pcl::PointCloud<pcl::PointXYZL>::Ptr labeled_cloud = boost::make_shared <pcl::PointCloud<pcl::PointXYZL> >();
pcl::PointCloud<pcl::PointXYZL>::Ptr labeled_cloud (new pcl::PointCloud<pcl::PointXYZL>);
pcl::copyPointCloud (*input_,*labeled_cloud);

pcl::PointCloud <pcl::PointXYZL>::iterator i_labeled;
Expand Down Expand Up @@ -661,7 +661,7 @@ pcl::SupervoxelClustering<PointT>::getLabeledCloud () const
template <typename PointT> pcl::PointCloud<pcl::PointNormal>::Ptr
pcl::SupervoxelClustering<PointT>::makeSupervoxelNormalCloud (std::map<uint32_t,typename Supervoxel<PointT>::Ptr > &supervoxel_clusters)
{
pcl::PointCloud<pcl::PointNormal>::Ptr normal_cloud = boost::make_shared<pcl::PointCloud<pcl::PointNormal> > ();
pcl::PointCloud<pcl::PointNormal>::Ptr normal_cloud (new pcl::PointCloud<pcl::PointNormal>);
normal_cloud->resize (supervoxel_clusters.size ());
typename std::map <uint32_t, typename pcl::Supervoxel<PointT>::Ptr>::iterator sv_itr,sv_itr_end;
sv_itr = supervoxel_clusters.begin ();
Expand Down Expand Up @@ -1037,7 +1037,7 @@ pcl::SupervoxelClustering<PointT>::SupervoxelHelper::updateCentroid ()
template <typename PointT> void
pcl::SupervoxelClustering<PointT>::SupervoxelHelper::getVoxels (typename pcl::PointCloud<PointT>::Ptr &voxels) const
{
voxels = boost::make_shared<pcl::PointCloud<PointT> > ();
voxels.reset (new pcl::PointCloud<PointT>);
voxels->clear ();
voxels->resize (leaves_.size ());
typename pcl::PointCloud<PointT>::iterator voxel_itr = voxels->begin ();
Expand All @@ -1055,7 +1055,7 @@ pcl::SupervoxelClustering<PointT>::SupervoxelHelper::getVoxels (typename pcl::Po
template <typename PointT> void
pcl::SupervoxelClustering<PointT>::SupervoxelHelper::getNormals (typename pcl::PointCloud<Normal>::Ptr &normals) const
{
normals = boost::make_shared<pcl::PointCloud<Normal> > ();
normals.reset (new pcl::PointCloud<Normal>);
normals->clear ();
normals->resize (leaves_.size ());
typename std::set<LeafContainerT*>::const_iterator leaf_itr;
Expand Down
10 changes: 7 additions & 3 deletions segmentation/include/pcl/segmentation/supervoxel_clustering.h
Original file line number Diff line number Diff line change
Expand Up @@ -477,16 +477,20 @@ namespace pcl

size_t
size () const { return leaves_.size (); }
private:
private:
//Stores leaves
std::set<LeafContainerT*> leaves_;
uint32_t label_;
VoxelData centroid_;
SupervoxelClustering* parent_;


public:
//Type VoxelData may have fixed-size Eigen objects inside
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
};

//Make boost::ptr_list can access the private class SupervoxelHelper
friend void boost::checked_delete<> (const typename pcl::SupervoxelClustering<PointT>::SupervoxelHelper *);

typedef boost::ptr_list<SupervoxelHelper> HelperListT;
HelperListT supervoxel_helpers_;

Expand Down