38#ifndef PCL_SEGMENTATION_IMPL_LCCP_SEGMENTATION_HPP_
39#define PCL_SEGMENTATION_IMPL_LCCP_SEGMENTATION_HPP_
41#include <pcl/segmentation/lccp_segmentation.h>
53template <
typename Po
intT>
56template <
typename Po
intT>
59template <
typename Po
intT>
void
72template <
typename Po
intT>
void
93 PCL_WARN (
"[pcl::LCCPSegmentation::segment] WARNING: Call function setInputSupervoxels first. Nothing has been done. \n");
97template <
typename Po
intT>
void
103 for (
auto &voxel : labeled_cloud_arg)
110 PCL_WARN (
"[pcl::LCCPSegmentation::relabelCloud] WARNING: Call function segment first. Nothing has been done. \n");
122template <
typename Po
intT>
void
127 std::uint32_t current_segLabel;
128 std::uint32_t neigh_segLabel;
133 for(std::tie(sv_itr, sv_itr_end) = boost::vertices(
sv_adjacency_list_); sv_itr != sv_itr_end; ++sv_itr)
140 for (std::tie(itr_neighbor, itr_neighbor_end) = boost::adjacent_vertices (*sv_itr,
sv_adjacency_list_); itr_neighbor != itr_neighbor_end; ++itr_neighbor)
145 if (current_segLabel != neigh_segLabel)
153template <
typename Po
intT>
void
161 std::set<std::uint32_t> filteredSegLabels;
163 bool continue_filtering =
true;
165 while (continue_filtering)
167 continue_filtering =
false;
171 for (std::tie(sv_itr, sv_itr_end) = boost::vertices (
sv_adjacency_list_); sv_itr != sv_itr_end; ++sv_itr)
175 std::uint32_t largest_neigh_seg_label = current_seg_label;
179 if (nr_neighbors == 0)
184 continue_filtering =
true;
191 largest_neigh_seg_label = *neighbors_itr;
197 if (largest_neigh_seg_label != current_seg_label)
199 if (filteredSegLabels.count (largest_neigh_seg_label) > 0)
203 filteredSegLabels.insert (current_seg_label);
215 for (
const unsigned int &filteredSegLabel : filteredSegLabels)
227template <
typename Po
intT>
void
229 const std::multimap<std::uint32_t, std::uint32_t>& label_adjaceny_arg)
238 std::map<std::uint32_t, VertexID> label_ID_map;
244 const std::uint32_t& sv_label = svlabel_itr->first;
247 label_ID_map[sv_label] = node_id;
251 for (
const auto &sv_neighbors_itr : label_adjaceny_arg)
253 const std::uint32_t& sv_label = sv_neighbors_itr.first;
254 const std::uint32_t& neighbor_label = sv_neighbors_itr.second;
256 VertexID u = label_ID_map[sv_label];
257 VertexID v = label_ID_map[neighbor_label];
268 const std::uint32_t& sv_label = svlabel_itr->first;
277template <
typename Po
intT>
void
285 const std::uint32_t& sv_label = svlabel_itr->first;
294 unsigned int segment_label = 1;
295 for (std::tie(sv_itr, sv_itr_end) = boost::vertices (
sv_adjacency_list_); sv_itr != sv_itr_end; ++sv_itr)
297 const VertexID sv_vertex_id = *sv_itr;
308template <
typename Po
intT>
void
310 const unsigned int segment_label)
323 for (std::tie(out_Edge_itr, out_Edge_itr_end) = boost::out_edges (query_point_id,
sv_adjacency_list_); out_Edge_itr != out_Edge_itr_end; ++out_Edge_itr)
338template <
typename Po
intT>
void
346 for (std::tie (edge_itr, edge_itr_end) = boost::edges (
sv_adjacency_list_), next_edge = edge_itr; edge_itr != edge_itr_end; edge_itr = next_edge)
354 unsigned int kcount = 0;
361 for (std::tie(source_neighbors_itr, source_neighbors_itr_end) = boost::out_edges (source,
sv_adjacency_list_); source_neighbors_itr != source_neighbors_itr_end; ++source_neighbors_itr)
366 for (std::tie(target_neighbors_itr, target_neighbors_itr_end) = boost::out_edges (target,
sv_adjacency_list_); target_neighbors_itr != target_neighbors_itr_end; ++target_neighbors_itr)
369 if (source_neighbor_ID == target_neighbor_ID)
377 if (src_is_convex && tar_is_convex)
395template <
typename Po
intT>
void
400 for (std::tie(edge_itr, edge_itr_end) = boost::edges (adjacency_list_arg), next_edge = edge_itr; edge_itr != edge_itr_end; edge_itr = next_edge)
404 std::uint32_t source_sv_label = adjacency_list_arg[boost::source (*edge_itr, adjacency_list_arg)];
405 std::uint32_t target_sv_label = adjacency_list_arg[boost::target (*edge_itr, adjacency_list_arg)];
407 float normal_difference;
408 bool is_convex =
connIsConvex (source_sv_label, target_sv_label, normal_difference);
409 adjacency_list_arg[*edge_itr].is_convex = is_convex;
410 adjacency_list_arg[*edge_itr].is_valid = is_convex;
411 adjacency_list_arg[*edge_itr].normal_difference = normal_difference;
415template <
typename Po
intT>
bool
417 const std::uint32_t target_label_arg,
423 const Eigen::Vector3f& source_centroid = sv_source->
centroid_.getVector3fMap ();
424 const Eigen::Vector3f& target_centroid = sv_target->
centroid_.getVector3fMap ();
426 const Eigen::Vector3f& source_normal = sv_source->
normal_.getNormalVector3fMap (). normalized ();
427 const Eigen::Vector3f& target_normal = sv_target->
normal_.getNormalVector3fMap (). normalized ();
435 bool is_convex =
true;
436 bool is_smooth =
true;
438 normal_angle =
getAngle3D (source_normal, target_normal,
true);
440 Eigen::Vector3f vec_t_to_s, vec_s_to_t;
442 vec_t_to_s = source_centroid - target_centroid;
443 vec_s_to_t = -vec_t_to_s;
445 Eigen::Vector3f ncross;
446 ncross = source_normal.cross (target_normal);
452 float dot_p_1 = vec_t_to_s.dot (source_normal);
453 float dot_p_2 = vec_s_to_t.dot (target_normal);
454 float point_dist = (std::fabs (dot_p_1) < std::fabs (dot_p_2)) ? std::fabs (dot_p_1) : std::fabs (dot_p_2);
457 if (point_dist > (expected_distance + dist_smoothing))
465 float intersection_angle =
getAngle3D (ncross, vec_t_to_s,
true);
466 float min_intersect_angle = (intersection_angle < 90.) ? intersection_angle : 180. - intersection_angle;
468 float intersect_thresh = 60. * 1. / (1. + std::exp (-0.25 * (normal_angle - 25.)));
486 return (is_convex && is_smooth);
virtual ~LCCPSegmentation()
float voxel_resolution_
Voxel resolution used to build the supervoxels (used only for smoothness check).
std::map< std::uint32_t, std::set< std::uint32_t > > seg_label_to_sv_list_map_
map Segment Label to a set of Supervoxel Labels
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 >::vertex_iterator VertexIterator
typename boost::graph_traits< SupervoxelAdjacencyList >::edge_iterator EdgeIterator
boost::adjacency_list< boost::setS, boost::setS, boost::undirectedS, std::uint32_t, EdgeProperties > SupervoxelAdjacencyList
bool grouping_data_valid_
Marks if valid grouping data (sv_adjacency_list_, sv_label_to_seg_label_map_, processed_) is availabl...
void recursiveSegmentGrowing(const VertexID &queryPointID, const unsigned int group_label)
Assigns neighbors of the query point to the same group as the query point.
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 computeSegmentAdjacency()
Compute the adjacency of the segments.
bool use_smoothness_check_
Determines if the smoothness check is used during segmentation.
bool use_sanity_check_
Determines if we use the sanity check which tries to find and invalidate singular connected patches.
void relabelCloud(pcl::PointCloud< pcl::PointXYZL > &labeled_cloud_arg)
Relabels cloud with supervoxel labels with the computed segment labels.
void mergeSmallSegments()
Segments smaller than min_segment_size_ are merged to the label of largest neighbor.
void prepareSegmentation(const std::map< std::uint32_t, typename pcl::Supervoxel< PointT >::Ptr > &supervoxel_clusters_arg, const std::multimap< std::uint32_t, std::uint32_t > &label_adjacency_arg)
Is called within setInputSupervoxels mainly to reserve required memory.
void segment()
Merge supervoxels using local convexity.
float concavity_tolerance_threshold_
*** Parameters *** ///
float smoothness_threshold_
Two supervoxels are unsmooth if their plane-to-plane distance DIST > (expected_distance + smoothness_...
typename boost::graph_traits< SupervoxelAdjacencyList >::out_edge_iterator OutEdgeIterator
float seed_resolution_
Seed resolution of the supervoxels (used only for smoothness check).
std::uint32_t min_segment_size_
Minimum segment size.
std::map< std::uint32_t, bool > processed_
Stores which supervoxel labels were already visited during recursive grouping.
typename boost::graph_traits< SupervoxelAdjacencyList >::adjacency_iterator AdjacencyIterator
bool connIsConvex(const std::uint32_t source_label_arg, const std::uint32_t target_label_arg, float &normal_angle)
Returns true if the connection between source and target is convex.
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
typename boost::graph_traits< SupervoxelAdjacencyList >::vertex_descriptor VertexID
void reset()
Reset internal memory.
std::map< std::uint32_t, typename pcl::Supervoxel< PointT >::Ptr > sv_label_to_supervoxel_map_
map from the supervoxel labels to the supervoxel objects
std::map< std::uint32_t, std::set< std::uint32_t > > seg_label_to_neighbor_set_map_
map < SegmentID, std::set< Neighboring segment labels> >
PointCloud represents the base class in PCL for storing collections of 3D points.
pcl::PointXYZRGBA centroid_
The centroid of the supervoxel - average voxel.
shared_ptr< Supervoxel< PointT > > Ptr
pcl::Normal normal_
The normal calculated for the voxels contained in the supervoxel.
Define standard C methods and C++ classes that are common to all methods.
double getAngle3D(const Eigen::Vector4f &v1, const Eigen::Vector4f &v2, const bool in_degree=false)
Compute the smallest angle between two 3D vectors in radians (default) or degree.