Get boundary points using Basic Alpha Shapes 2d

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Get boundary points using Basic Alpha Shapes 2d

bingxin pu
Hi everyone,

I use Basic Alpha Shapes to get boundary points from some 2d points. As shown in attachments, boundary points like a  rectangle is what I want to get. But I failed. Through seeing demo about Alpha_shapes_2, I think that I maybe set a wrong Alpha. I hope that you can give me some suggestions so that I can get correct result.

The wrong boundary points is result of the following code.

  1. typedef CGAL::Exact_predicates_inexact_constructions_kernel  K;  
  2.   
  3. typedef K::FT                                                FT;  
  4. typedef K::Point_2                                           Point;  
  5. typedef K::Segment_2                                         Segment;   
  6.   
  7. typedef CGAL::Alpha_shape_vertex_base_2<K>                   Vb;  
  8. typedef CGAL::Alpha_shape_face_base_2<K>                     Fb;  
  9. typedef CGAL::Triangulation_data_structure_2<Vb,Fb>          Tds;   
  10. typedef CGAL::Delaunay_triangulation_2<K,Tds>                Triangulation_2;   
  11. typedef CGAL::Alpha_shape_2<Triangulation_2>                 Alpha_shape_2;    
  12.   
  13. typedef Alpha_shape_2::Alpha_shape_edges_iterator            Alpha_shape_edges_iterator;  
  14.   
  15.   
  16. template <class OutputIterator>  
  17. void alpha_edges( const Alpha_shape_2& A, OutputIterator out)  
  18. {  
  19.   Alpha_shape_edges_iterator it = A.alpha_shape_edges_begin(),  
  20.                              end = A.alpha_shape_edges_end();  
  21.     
  22.   for (; it != end; ++it)  
  23.     out++ = A.segment(*it);  
  24.     
  25. }  
  26.   
  27. bool file_input(std::list<Point> &points)             
  28. {  
  29.     std::ifstream is("J:\\General_Random_points2D.pts", std::ios::in);  
  30.   if(is.fail())  
  31.   {  
  32.     std::cerr << "unable to open file for input" << std::endl;  
  33.     return false;  
  34.   }  
  35.   Point p;  
  36.   for (int i = 0; i < 2000; i++)  
  37.   {  
  38.       is >> p;  
  39.       points.push_back(p);  
  40.   }  
  41.   CGAL::set_pretty_mode(std::cout);  
  42.   std::cout << p << std::endl;  
  43.   
  44.   return true;  
  45. }  
  46.   
  47. // Reads a list of points and returns a list of segments  
  48. // corresponding to the Alpha shape.  
  49. int main()  
  50. {  
  51.   std::list<Point> points;  
  52.   if(! file_input(points))  
  53.     return -1;  
  54.   
  55.   Alpha_shape_2 A(points.begin(), points.end(),  
  56.                   FT(10000),  
  57.                   Alpha_shape_2::GENERAL);  
  58.   std::vector<Segment> segments;  
  59.   alpha_edges(A, std::back_inserter(segments));  
  60.   
  61.   
  62.   std::ofstream of("vertix.pts");  
  63.   CGAL::set_ascii_mode(of);  
  64.   
  65.   CGAL::set_pretty_mode(std::cout);  
  66.   for (int i = 0; i < segments.size(); i++)  
  67.   {  
  68.       of << segments[i].vertex(1) << std::endl << segments[i].vertex(2) << std::endl;  
  69.   }  
  70.   std::cout << "Alpha Shape computed" << std::endl;  
  71.   std::cout << segments.size() << " alpha shape edges" << std::endl;  
  72.   std::cout << "Optimal alpha: " << *A.find_optimal_alpha(1)<<std::endl;  
  73.   system("pause");  
  74.   return 0;  
  75. }  

Thank you, in advance. I will be honored to receive your help.
bingxin





发自网易邮箱大师

boundary_points.png (31K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Get boundary points using Basic Alpha Shapes 2d

Renato
Try to tune your alpha parameter to better fit your problem:

"A.set_alpha(value);"

On Sun, Jul 29, 2018 at 12:09 PM bingxin pu <[hidden email]> wrote:
Hi everyone,

I use Basic Alpha Shapes to get boundary points from some 2d points. As shown in attachments, boundary points like a  rectangle is what I want to get. But I failed. Through seeing demo about Alpha_shapes_2, I think that I maybe set a wrong Alpha. I hope that you can give me some suggestions so that I can get correct result.

The wrong boundary points is result of the following code.

  1. typedef CGAL::Exact_predicates_inexact_constructions_kernel  K;  
  2.   
  3. typedef K::FT                                                FT;  
  4. typedef K::Point_2                                           Point;  
  5. typedef K::Segment_2                                         Segment;   
  6.   
  7. typedef CGAL::Alpha_shape_vertex_base_2<K>                   Vb;  
  8. typedef CGAL::Alpha_shape_face_base_2<K>                     Fb;  
  9. typedef CGAL::Triangulation_data_structure_2<Vb,Fb>          Tds;   
  10. typedef CGAL::Delaunay_triangulation_2<K,Tds>                Triangulation_2;   
  11. typedef CGAL::Alpha_shape_2<Triangulation_2>                 Alpha_shape_2;    
  12.   
  13. typedef Alpha_shape_2::Alpha_shape_edges_iterator            Alpha_shape_edges_iterator;  
  14.   
  15.   
  16. template <class OutputIterator>  
  17. void alpha_edges( const Alpha_shape_2& A, OutputIterator out)  
  18. {  
  19.   Alpha_shape_edges_iterator it = A.alpha_shape_edges_begin(),  
  20.                              end = A.alpha_shape_edges_end();  
  21.     
  22.   for (; it != end; ++it)  
  23.     out++ = A.segment(*it);  
  24.     
  25. }  
  26.   
  27. bool file_input(std::list<Point> &points)             
  28. {  
  29.     std::ifstream is("J:\\General_Random_points2D.pts", std::ios::in);  
  30.   if(is.fail())  
  31.   {  
  32.     std::cerr << "unable to open file for input" << std::endl;  
  33.     return false;  
  34.   }  
  35.   Point p;  
  36.   for (int i = 0; i < 2000; i++)  
  37.   {  
  38.       is >> p;  
  39.       points.push_back(p);  
  40.   }  
  41.   CGAL::set_pretty_mode(std::cout);  
  42.   std::cout << p << std::endl;  
  43.   
  44.   return true;  
  45. }  
  46.   
  47. // Reads a list of points and returns a list of segments  
  48. // corresponding to the Alpha shape.  
  49. int main()  
  50. {  
  51.   std::list<Point> points;  
  52.   if(! file_input(points))  
  53.     return -1;  
  54.   
  55.   Alpha_shape_2 A(points.begin(), points.end(),  
  56.                   FT(10000),  
  57.                   Alpha_shape_2::GENERAL);  
  58.   std::vector<Segment> segments;  
  59.   alpha_edges(A, std::back_inserter(segments));  
  60.   
  61.   
  62.   std::ofstream of("vertix.pts");  
  63.   CGAL::set_ascii_mode(of);  
  64.   
  65.   CGAL::set_pretty_mode(std::cout);  
  66.   for (int i = 0; i < segments.size(); i++)  
  67.   {  
  68.       of << segments[i].vertex(1) << std::endl << segments[i].vertex(2) << std::endl;  
  69.   }  
  70.   std::cout << "Alpha Shape computed" << std::endl;  
  71.   std::cout << segments.size() << " alpha shape edges" << std::endl;  
  72.   std::cout << "Optimal alpha: " << *A.find_optimal_alpha(1)<<std::endl;  
  73.   system("pause");  
  74.   return 0;  
  75. }  

Thank you, in advance. I will be honored to receive your help.
bingxin





发自网易邮箱大师


--
Renato Silveira
     Ph.D. in Computer Science
     NTU / UFRGS | Núcleo de Tecnologia Urbana

     Porto Alegre - RS - Brazil