43#include <boost/version.hpp>
45#include <pcl/features/normal_3d.h>
47#include <pcl/pcl_base.h>
49#include <pcl/point_cloud.h>
51#include <pcl/octree/octree_search.h>
52#include <pcl/octree/octree_pointcloud_adjacency.h>
53#include <pcl/search/search.h>
54#include <boost/ptr_container/ptr_list.hpp>
66 template <
typename Po
intT>
75 using Ptr = shared_ptr<Supervoxel<PointT> >;
76 using ConstPtr = shared_ptr<const Supervoxel<PointT> >;
97 normal_arg.normal_x =
normal_.normal_x;
98 normal_arg.normal_y =
normal_.normal_y;
99 normal_arg.normal_z =
normal_.normal_z;
125 template <
typename Po
intT>
129 class SupervoxelHelper;
130 friend class SupervoxelHelper;
139 xyz_ (0.0f, 0.0f, 0.0f),
140 rgb_ (0.0f, 0.0f, 0.0f),
141 normal_ (0.0f, 0.0f, 0.0f, 0.0f),
153 template<
typename Po
intT2 = Po
intT, traits::HasColor<Po
intT2> = true>
void
156 point_arg.rgba =
static_cast<std::uint32_t
>(
rgb_[0]) << 16 |
157 static_cast<std::uint32_t
>(
rgb_[1]) << 8 |
158 static_cast<std::uint32_t
>(
rgb_[2]);
159 point_arg.x =
xyz_[0];
160 point_arg.y =
xyz_[1];
161 point_arg.z =
xyz_[2];
164 template<
typename Po
intT2 = Po
intT, traits::HasNoColor<Po
intT2> = true>
void
165 getPoint (PointT &point_arg )
const
168 point_arg.x = xyz_[0];
169 point_arg.y = xyz_[1];
170 point_arg.z = xyz_[2];
178 getNormal (
Normal &normal_arg)
const;
206 using VoxelAdjacencyList = boost::adjacency_list<boost::setS, boost::setS, boost::undirectedS, std::uint32_t, float>;
207 using VoxelID = VoxelAdjacencyList::vertex_descriptor;
208 using EdgeID = VoxelAdjacencyList::edge_descriptor;
339 prepareForSegmentation ();
345 selectInitialSupervoxelSeeds (
Indices &seed_indices);
351 createSupervoxelHelpers (
Indices &seed_indices);
355 expandSupervoxels (
int depth);
363 reseedSupervoxels ();
373 float seed_resolution_;
381 transformFunction (PointT &p);
396 float color_importance_{0.1f};
398 float spatial_importance_{0.4f};
400 float normal_importance_{1.0f};
406 bool use_single_camera_transform_;
408 bool use_default_transform_behaviour_{
true};
414 class SupervoxelHelper
426 return leaf_data_left.
idx_ < leaf_data_right.
idx_;
429 using LeafSetT = std::set<LeafContainerT*, typename SupervoxelHelper::compareLeaves>;
430 using iterator =
typename LeafSetT::iterator;
431 using const_iterator =
typename LeafSetT::const_iterator;
439 addLeaf (LeafContainerT* leaf_arg);
442 removeLeaf (LeafContainerT* leaf_arg);
470 {
return centroid_.normal_; }
474 {
return centroid_.rgb_; }
478 {
return centroid_.xyz_;}
481 getXYZ (
float &x,
float &y,
float &z)
const
482 { x=centroid_.xyz_[0]; y=centroid_.xyz_[1]; z=centroid_.xyz_[2]; }
485 getRGB (std::uint32_t &rgba)
const
487 rgba =
static_cast<std::uint32_t
>(centroid_.rgb_[0]) << 16 |
488 static_cast<std::uint32_t
>(centroid_.rgb_[1]) << 8 |
489 static_cast<std::uint32_t
>(centroid_.rgb_[2]);
493 getNormal (pcl::Normal &normal_arg)
const
495 normal_arg.normal_x = centroid_.normal_[0];
496 normal_arg.normal_y = centroid_.normal_[1];
497 normal_arg.normal_z = centroid_.normal_[2];
498 normal_arg.
curvature = centroid_.curvature_;
502 getNeighborLabels (std::set<std::uint32_t> &neighbor_labels)
const;
506 {
return centroid_; }
509 size ()
const {
return leaves_.size (); }
513 std::uint32_t label_;
515 SupervoxelClustering* parent_;
522#if BOOST_VERSION >= 107000
525 friend void boost::checked_delete<> (
const typename pcl::SupervoxelClustering<PointT>::SupervoxelHelper *);
528 using HelperListT = boost::ptr_list<SupervoxelHelper>;
529 HelperListT supervoxel_helpers_;
539#ifdef PCL_NO_PRECOMPILE
540#include <pcl/segmentation/impl/supervoxel_clustering.hpp>
PointCloudConstPtr input_
The input point cloud dataset.
bool initCompute()
This method should get called before starting the actual computation.
PCLBase()
Empty constructor.
bool deinitCompute()
This method should get called after finishing the actual computation.
PointCloud represents the base class in PCL for storing collections of 3D points.
shared_ptr< PointCloud< PointT > > Ptr
shared_ptr< const PointCloud< PointT > > ConstPtr
VoxelData is a structure used for storing data within a pcl::octree::OctreePointCloudAdjacencyContain...
void getPoint(PointT &point_arg) const
Gets the data of in the form of a point.
SupervoxelHelper * owner_
Implements a supervoxel algorithm based on voxel structure, normals, and rgb values.
static pcl::PointCloud< pcl::PointNormal >::Ptr makeSupervoxelNormalCloud(std::map< std::uint32_t, typename Supervoxel< PointT >::Ptr > &supervoxel_clusters)
Static helper function which returns a pointcloud of normals for the input supervoxels.
VoxelAdjacencyList::edge_descriptor EdgeID
int getMaxLabel() const
Returns the current maximum (highest) label.
pcl::octree::OctreePointCloudSearch< PointT > OctreeSearchT
virtual void refineSupervoxels(int num_itr, std::map< std::uint32_t, typename Supervoxel< PointT >::Ptr > &supervoxel_clusters)
This method refines the calculated supervoxels - may only be called after extract.
std::vector< LeafContainerT * > LeafVectorT
pcl::IndicesPtr IndicesPtr
void setSpatialImportance(float val)
Set the importance of spatial distance for supervoxels.
float getVoxelResolution() const
Get the resolution of the octree voxels.
virtual void setNormalCloud(typename NormalCloudT::ConstPtr normal_cloud)
This method sets the normals to be used for supervoxels (should be same size as input cloud).
void setColorImportance(float val)
Set the importance of color for supervoxels.
pcl::PointCloud< pcl::PointXYZL >::Ptr getLabeledVoxelCloud() const
Returns labeled voxelized cloud Points that belong to the same supervoxel have the same label.
void setVoxelResolution(float resolution)
Set the resolution of the octree voxels.
pcl::PointCloud< PointT > PointCloudT
void setInputCloud(const typename pcl::PointCloud< PointT >::ConstPtr &cloud) override
This method sets the cloud to be supervoxelized.
virtual void extract(std::map< std::uint32_t, typename Supervoxel< PointT >::Ptr > &supervoxel_clusters)
This method launches the segmentation algorithm and returns the supervoxels that were obtained during...
pcl::PointCloud< Normal > NormalCloudT
boost::adjacency_list< boost::setS, boost::setS, boost::undirectedS, std::uint32_t, float > VoxelAdjacencyList
pcl::octree::OctreePointCloudAdjacency< PointT, LeafContainerT > OctreeAdjacencyT
pcl::PointCloud< PointT >::Ptr getVoxelCentroidCloud() const
Returns a deep copy of the voxel centroid cloud.
void setSeedResolution(float seed_resolution)
Set the resolution of the octree seed voxels.
void getSupervoxelAdjacency(std::multimap< std::uint32_t, std::uint32_t > &label_adjacency) const
Get a multimap which gives supervoxel adjacency.
void setUseSingleCameraTransform(bool val)
Set whether or not to use the single camera transform.
SupervoxelClustering(float voxel_resolution, float seed_resolution)
Constructor that sets default values for member variables.
pcl::octree::OctreePointCloudAdjacencyContainer< PointT, VoxelData > LeafContainerT
void getSupervoxelAdjacencyList(VoxelAdjacencyList &adjacency_list_arg) const
Gets the adjacency list (Boost Graph library) which gives connections between supervoxels.
VoxelAdjacencyList::vertex_descriptor VoxelID
pcl::search::KdTree< PointT > KdTreeT
~SupervoxelClustering() override
This destructor destroys the cloud, normals and search method used for finding neighbors.
float getSeedResolution() const
Get the resolution of the octree seed voxels.
friend class SupervoxelHelper
void setNormalImportance(float val)
Set the importance of scalar normal product for supervoxels.
pcl::PointCloud< PointXYZL >::Ptr getLabeledCloud() const
Returns labeled cloud Points that belong to the same supervoxel have the same label.
pcl::PointXYZRGBA centroid_
The centroid of the supervoxel - average voxel.
pcl::PointCloud< Normal >::Ptr normals_
A Pointcloud of the normals for the points in the supervoxel.
shared_ptr< const Supervoxel< PointT > > ConstPtr
void getCentroidPoint(PointXYZRGBA ¢roid_arg)
Gets the centroid of the supervoxel.
shared_ptr< Supervoxel< PointT > > Ptr
pcl::PointCloud< PointT >::Ptr voxels_
A Pointcloud of the voxels in the supervoxel.
pcl::Normal normal_
The normal calculated for the voxels contained in the supervoxel.
void getCentroidPointNormal(PointNormal &normal_arg)
Gets the point normal for the supervoxel.
Octree adjacency leaf container class- stores a list of pointers to neighbors, number of points added...
DataT & getData()
Returns a reference to the data member to access it without copying.
Octree pointcloud voxel class which maintains adjacency information for its voxels.
shared_ptr< OctreeAdjacencyT > Ptr
Octree pointcloud search class
search::KdTree is a wrapper class which inherits the pcl::KdTree class for performing search function...
shared_ptr< KdTree< PointT, Tree > > Ptr
Defines all the PCL implemented PointT point type structures.
Define methods for measuring time spent in code blocks.
#define PCL_MAKE_ALIGNED_OPERATOR_NEW
Macro to signal a class requires a custom allocator.
Defines functions, macros and traits for allocating and using memory.
shared_ptr< Indices > IndicesPtr
IndicesAllocator<> Indices
Type used for indices in PCL.
Defines all the PCL and non-PCL macros used.
A point structure representing normal coordinates and the surface curvature estimate.
A point structure representing Euclidean xyz coordinates, together with normal coordinates and the su...
A point structure representing Euclidean xyz coordinates, and the RGBA color.
Comparator for LeafContainerT pointers - used for sorting set of leaves.