示例#1
0
template <typename PointT> std::vector<int>
pcl::RegionGrowingRGB<PointT>::getSegmentFromPoint (const PointT& point)
{
  std::vector<int> result;
  if (cloud_for_segmentation_ == 0)
    return (result);

  // first of all we need to find out if this point belongs to cloud
  bool point_was_found = false;
  int index = 0;
  for (size_t i = 0; i < cloud_for_segmentation_->points.size (); i++)
  {
    if (cloud_for_segmentation_->points[i].x != point.x) continue;
    if (cloud_for_segmentation_->points[i].y != point.y) continue;
    if (cloud_for_segmentation_->points[i].z != point.z) continue;

    point_was_found = true;
    index = static_cast<int> (i);
    break;
  }

  if (point_was_found)
  {
    if (segments_.empty ())
    {
      // if we haven't done the segmentation yet, then we need to launch the segmentation algorithm
      unsigned int number_of_segments = 0;
      number_of_segments = segmentPoints ();
      if (number_of_segments == 0)
        return (result);
    }// end if segments are empty

    // if we have already made the segmentation, then find the segment
    // to which this point belongs
    std::vector< std::vector<int> >::iterator i_segment;
    for (i_segment = segments_.begin (); i_segment != segments_.end (); i_segment++)
    {
      bool segment_was_found = false;
      result.clear ();
      result = *i_segment;
      std::vector<int>::iterator i_point;
      for (i_point = result.begin (); i_point != result.end (); i_point++)
      {
        if (*i_point == index)
        {
          segment_was_found = true;
          break;
        }
      }

      if (segment_was_found)
        break;
    }// next segment
  }// end if point was found

  return (result);
}
示例#2
0
template <typename PointT> std::vector<int>
pcl::RegionGrowing<PointT>::getSegmentFromPoint (int index)
{
  std::vector<int> result;
  if (cloud_for_segmentation_ == 0)
    return (result);

  // first of all we need to find out if this point belongs to cloud
  bool point_was_found = false;
  if (index < static_cast<int> (cloud_for_segmentation_->points.size ()) && index >= 0)
    point_was_found = true;

  if (point_was_found)
  {
    if (segments_.empty ())
    {
      segmentPoints ();
    }
    // if we have already made the segmentation, then find the segment
    // to which this point belongs
    std::vector<std::vector<int> >::iterator i_segment;
    for (i_segment = segments_.begin (); i_segment != segments_.end (); i_segment++)
    {
      bool segment_was_found = false;
      result.clear ();
      result = *i_segment;
      std::vector<int>::iterator i_point;
      for (i_point = result.begin (); i_point != result.end (); i_point++)
      {
        if (*i_point == index)
        {
          segment_was_found = true;
          break;
        }
      }
      if (segment_was_found)
      {
        break;
      }
    }// next segment
  }// end if point was found

  return (result);
}