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_);
}
Exemple #2
0
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();
}
Exemple #3
0
template <typename PointT, typename NormalT> void
pcl::RegionGrowing<PointT, NormalT>::extract (std::vector <pcl::PointIndices>& clusters)
{
  clusters_.clear ();
  clusters.clear ();
  point_neighbours_.clear ();
  point_labels_.clear ();
  num_pts_in_segment_.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;
  }

  findPointNeighbours ();
  applySmoothRegionGrowingAlgorithm ();
  assembleRegions ();

  clusters.resize (clusters_.size ());
  std::vector<pcl::PointIndices>::iterator cluster_iter_input = clusters.begin ();
  for (std::vector<pcl::PointIndices>::const_iterator cluster_iter = clusters_.begin (); cluster_iter != clusters_.end (); cluster_iter++)
  {
    if ((static_cast<int> (cluster_iter->indices.size ()) >= min_pts_per_cluster_) &&
        (static_cast<int> (cluster_iter->indices.size ()) <= max_pts_per_cluster_))
    {
      *cluster_iter_input = *cluster_iter;
      cluster_iter_input++;
    }
  }

  clusters_ = std::vector<pcl::PointIndices> (clusters.begin (), cluster_iter_input);
  clusters.resize(clusters_.size());

  deinitCompute ();
}
bool RegionGrowingHSV::extract ()
{
    clusters_.clear ();
    point_neighbours_.clear ();
    point_labels_.clear ();
    num_pts_in_segment_.clear ();
    number_of_segments_ = 0;

    bool segmentation_is_possible = prepareForSegmentation ();
    if ( !segmentation_is_possible )
    {
        std::cout<<"segment is impossible"<<std::endl;
        return false;
    }
    std::cout<<"find point neighbours"<<std::endl;
    findPointNeighbours ();

//    std::vector<int> init_seed;
//    std::cout<<"calculate seed queue"<<std::endl;
//    computeInitalSeed(init_seed);
//    clusters_.clear();
//    std::vector<int> pa;
//    std::vector<int> pas;
//    for(int i=0;i<num_pts;i++ )
//    {
//        if( i<2000 )
//            pa.push_back(init_seed[i]);
//    }
//    clusters_.push_back(pa);
//    clusters_.push_back(pas);

    std::cout<<"apply region growing algorithm"<<std::endl;
    applySmoothRegionGrowingAlgorithm ();

    std::cout<<"apply region merging algorithm"<<std::endl;
    regionMerge();

    std::cout<<"end extract..."<<std::endl;
    return true;
}
Exemple #5
0
template <typename PointT, typename NormalT> void
pcl::RegionGrowing<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 ())
    {
      point_neighbours_.clear ();
      point_labels_.clear ();
      num_pts_in_segment_.clear ();
      number_of_segments_ = 0;

      segmentation_is_possible = prepareForSegmentation ();
      if ( !segmentation_is_possible )
      {
        deinitCompute ();
        return;
      }

      findPointNeighbours ();
      applySmoothRegionGrowingAlgorithm ();
      assembleRegions ();
    }
    // 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 ();
}