41 #include <pcl/pcl_base.h>
43 #include <pcl/point_cloud.h>
46 #include <pcl/segmentation/supervoxel_clustering.h>
47 #include <pcl/segmentation/lccp_segmentation.h>
48 #include <pcl/sample_consensus/sac.h>
50 #include <pcl/segmentation/extract_clusters.h>
52 #define PCL_INSTANTIATE_CPCSegmentation(T) template class PCL_EXPORTS pcl::CPCSegmentation<T>;
65 template <
typename Po
intT>
108 const std::uint32_t cutting_min_segments = 0,
109 const float cutting_min_score = 0.16,
110 const bool locally_constrained =
true,
111 const bool directed_cutting =
true,
112 const bool clean_cutting =
false)
114 max_cuts_ = max_cuts;
115 min_segment_size_for_cutting_ = cutting_min_segments;
116 min_cut_score_ = cutting_min_score;
117 use_local_constrains_ = locally_constrained;
118 use_directed_weights_ = directed_cutting;
119 use_clean_cutting_ = clean_cutting;
127 ransac_itrs_ = ransac_iterations;
136 applyCuttingPlane (std::uint32_t depth_levels_left);
141 std::uint32_t max_cuts_{20};
144 std::uint32_t min_segment_size_for_cutting_{400};
147 float min_cut_score_{0.16};
150 bool use_local_constrains_{
true};
153 bool use_directed_weights_{
true};
156 bool use_clean_cutting_{
false};
159 std::uint32_t ransac_itrs_{10000};
174 class WeightedRandomSampleConsensus :
public SampleConsensus<WeightSACPointType>
179 using Ptr = shared_ptr<WeightedRandomSampleConsensus>;
180 using ConstPtr = shared_ptr<const WeightedRandomSampleConsensus>;
186 WeightedRandomSampleConsensus (
const SampleConsensusModelPtr &model,
198 WeightedRandomSampleConsensus (
const SampleConsensusModelPtr &model,
210 computeModel (
int debug_verbosity_level = 0)
override;
216 setWeights (
const std::vector<double> &weights,
217 const bool directed_weights =
false)
219 if (weights.size () != full_cloud_pt_indices_->size ())
221 PCL_ERROR (
"[pcl::WeightedRandomSampleConsensus::setWeights] Cannot assign weights. Weight vector needs to have the same length as the input pointcloud\n");
225 model_pt_indices_->clear ();
226 for (std::size_t i = 0; i < weights.size (); ++i)
228 if (weights[i] > std::numeric_limits<double>::epsilon ())
229 model_pt_indices_->push_back (i);
231 use_directed_weights_ = directed_weights;
238 getBestScore ()
const
240 return (best_score_);
250 use_directed_weights_ =
false;
251 model_pt_indices_.reset (
new Indices);
253 point_cloud_ptr_ =
sac_model_->getInputCloud ();
257 bool use_directed_weights_;
260 std::vector<double> weights_;
278 #ifdef PCL_NO_PRECOMPILE
279 #include <pcl/segmentation/impl/cpc_segmentation.hpp>
280 #elif defined(PCL_ONLY_CORE_POINT_TYPES)
282 #include <pcl/sample_consensus/impl/sac_model_plane.hpp>
283 #include <pcl/segmentation/impl/extract_clusters.hpp>
A segmentation algorithm partitioning a supervoxel graph.
void segment()
Merge supervoxels using cuts through local convexities.
~CPCSegmentation() override
void setCutting(const std::uint32_t max_cuts=20, const std::uint32_t cutting_min_segments=0, const float cutting_min_score=0.16, const bool locally_constrained=true, const bool directed_cutting=true, const bool clean_cutting=false)
Determines if we want to use cutting planes.
void setRANSACIterations(const std::uint32_t ransac_iterations)
Set the number of iterations for the weighted RANSAC step (best cut estimations)
A simple segmentation algorithm partitioning a supervoxel graph into groups of locally convex connect...
bool supervoxels_set_
Marks if supervoxels have been set by calling setInputSupervoxels.
std::map< std::uint32_t, std::uint32_t > sv_label_to_seg_label_map_
Storing relation between original SuperVoxel Labels and new segmantion labels.
typename boost::graph_traits< SupervoxelAdjacencyList >::edge_iterator EdgeIterator
bool grouping_data_valid_
Marks if valid grouping data (sv_adjacency_list_, sv_label_to_seg_label_map_, processed_) is availabl...
std::uint32_t k_factor_
Factor used for k-convexity.
void calculateConvexConnections(SupervoxelAdjacencyList &adjacency_list_arg)
Calculates convexity of edges and saves this to the adjacency graph.
void mergeSmallSegments()
Segments smaller than min_segment_size_ are merged to the label of largest neighbor.
float concavity_tolerance_threshold_
*** Parameters *** ///
float seed_resolution_
Seed resolution of the supervoxels (used only for smoothness check)
void doGrouping()
Perform depth search on the graph and recursively group all supervoxels with convex connections.
void applyKconvexity(const unsigned int k_arg)
Connections are only convex if this is true for at least k_arg common neighbors of the two patches.
SupervoxelAdjacencyList sv_adjacency_list_
Adjacency graph with the supervoxel labels as nodes and edges between adjacent supervoxels.
typename boost::graph_traits< SupervoxelAdjacencyList >::edge_descriptor EdgeID
std::map< std::uint32_t, typename pcl::Supervoxel< PointT >::Ptr > sv_label_to_supervoxel_map_
map from the supervoxel labels to the supervoxel objects
shared_ptr< const PointCloud< PointT > > ConstPtr
SampleConsensusModelPtr sac_model_
The underlying data model used (i.e.
int max_iterations_
Maximum number of iterations before giving up.
SampleConsensus(const SampleConsensusModelPtr &model, bool random=false)
Constructor for base SAC.
shared_ptr< SampleConsensusModel< PointT > > Ptr
Defines all the PCL implemented PointT point type structures.
IndicesAllocator<> Indices
Type used for indices in PCL.
shared_ptr< Indices > IndicesPtr
A point structure representing Euclidean xyz coordinates, intensity, together with normal coordinates...