template <typename PointT> unsigned int pcl::RegionGrowingRGB<PointT>::segmentPoints () { number_of_segments_ = 0; segments_.clear (); point_labels_.clear (); num_pts_in_segment_.clear (); point_neighbours_.clear (); point_distances_.clear (); segment_labels_.clear (); segment_neighbours_.clear (); segment_distances_.clear (); bool segmentation_is_possible = prepareForSegmentation (); if ( !segmentation_is_possible ) return (number_of_segments_); findPointNeighbours (); number_of_segments_ = applySmoothRegionGrowingAlgorithm (); RegionGrowing<PointT>::assembleRegions (); findSegmentNeighbours (); number_of_segments_ = applyRegionMergingAlgorithm (); return (number_of_segments_); }
template <typename PointT, typename NormalT> void pcl::RegionGrowingHSV<PointT, NormalT>::extract(std::vector <pcl::PointIndices>& clusters) { clusters_.clear(); clusters.clear(); point_neighbours_.clear(); point_labels_.clear(); num_pts_in_segment_.clear(); point_distances_.clear(); segment_neighbours_.clear(); segment_distances_.clear(); segment_labels_.clear(); number_of_segments_ = 0; bool segmentation_is_possible = initCompute(); if (!segmentation_is_possible) { deinitCompute(); return; } segmentation_is_possible = prepareForSegmentation(); if (!segmentation_is_possible) { deinitCompute(); return; } std::cout<< "Start find point neighbours"<<std::endl; findPointNeighbours(); std::cout<< "Start region growing"<<std::endl; applySmoothRegionGrowingAlgorithm(); std::cout<< "assemble regions"<<std::endl; RegionGrowing<PointT, NormalT>::assembleRegions(); std::cout<< "Start find region neighbours"<<std::endl; findSegmentNeighbours(); std::cout<< "Start merging region"<<std::endl; applyRegionMergingAlgorithm(); std::vector<pcl::PointIndices>::iterator cluster_iter = clusters_.begin(); std::cout << "Num of clusters is: " << clusters_.size() <<std::endl; while (cluster_iter != clusters_.end()) { if (cluster_iter->indices.size() < min_pts_per_cluster_ || cluster_iter->indices.size() > max_pts_per_cluster_) { cluster_iter = clusters_.erase(cluster_iter); } else cluster_iter++; } clusters.reserve(clusters_.size()); std::copy(clusters_.begin(), clusters_.end(), std::back_inserter(clusters)); findSegmentNeighbours(); deinitCompute(); }
template <typename PointT, typename NormalT> void pcl::RegionGrowingHSV<PointT, NormalT>::getSegmentFromPoint(int index, pcl::PointIndices& cluster) { cluster.indices.clear(); bool segmentation_is_possible = initCompute(); if (!segmentation_is_possible) { deinitCompute(); return; } // first of all we need to find out if this point belongs to cloud bool point_was_found = false; int number_of_points = static_cast <int> (indices_->size()); for (size_t point = 0; point < number_of_points; point++) if ((*indices_)[point] == index) { point_was_found = true; break; } if (point_was_found) { if (clusters_.empty()) { clusters_.clear(); point_neighbours_.clear(); point_labels_.clear(); num_pts_in_segment_.clear(); point_distances_.clear(); segment_neighbours_.clear(); segment_distances_.clear(); segment_labels_.clear(); number_of_segments_ = 0; segmentation_is_possible = prepareForSegmentation(); if (!segmentation_is_possible) { deinitCompute(); return; } findPointNeighbours(); applySmoothRegionGrowingAlgorithm(); RegionGrowing<PointT, NormalT>::assembleRegions(); findSegmentNeighbours(); applyRegionMergingAlgorithm(); } // if we have already made the segmentation, then find the segment // to which this point belongs std::vector <pcl::PointIndices>::iterator i_segment; for (i_segment = clusters_.begin(); i_segment != clusters_.end(); i_segment++) { bool segment_was_found = false; for (size_t i_point = 0; i_point < i_segment->indices.size(); i_point++) { if (i_segment->indices[i_point] == index) { segment_was_found = true; cluster.indices.clear(); cluster.indices.reserve(i_segment->indices.size()); std::copy(i_segment->indices.begin(), i_segment->indices.end(), std::back_inserter(cluster.indices)); break; } } if (segment_was_found) { break; } }// next segment }// end if point was found deinitCompute(); }