Circulating through points of alpha_shape_2

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Circulating through points of alpha_shape_2

orxshi
I made a test for circulating through output points of alpha_shape_2. There is a square at vertices (0 0), (10 0), (10 10), (0 10).

Obviously, `A.alpha_shape_vertices_begin()` begins with (10 0) and the incident vertex chosen by `incident_vertices` was (10, 10). Circulation was going good until I got a weird output (0.5 0.5) which should have been (10 0).

I thought that (0.5 0.5) is past-end-value although circulators have no such thing. Thats why I tried `--vccopy` to stop circulation earlier and avoid (0.5 0.5). This cheap trick works for this specific case but not in general.

I also checked edges. The same weird number (0.5 0.5) appears again. 

My ultimate goal is to make a simple polygon from points returned by alpha_shape_2. Purpose of circulating is to get ordered points.

Anyone has idea why I get this weird number?

    #include <CGAL/Exact_predicates_exact_constructions_kernel.h>
    #include <CGAL/Alpha_shape_2.h>
    #include <CGAL/Alpha_shape_vertex_base_2.h>
    #include <CGAL/Alpha_shape_face_base_2.h>
    #include <CGAL/Polygon_2.h>
    #include <CGAL/Iso_rectangle_2.h>
    #include <CGAL/Delaunay_triangulation_2.h>
    typedef CGAL::Exact_predicates_exact_constructions_kernel CGAL_kernel;
    typedef CGAL_kernel::Point_2 CGAL_Point;
    typedef CGAL::Alpha_shape_vertex_base_2<CGAL_kernel> Vb;
    typedef CGAL::Alpha_shape_face_base_2<CGAL_kernel> Fb;
    typedef CGAL::Triangulation_data_structure_2<Vb,Fb> Tds;
    typedef CGAL::Delaunay_triangulation_2<CGAL_kernel,Tds> Triangulation_2;
    typedef CGAL::Alpha_shape_2<Triangulation_2> Alpha_shape_2;
    typedef CGAL_kernel::FT FT;
    typedef CGAL::Polygon_2<CGAL_kernel> Polygon_2;
    
    int main()
    {
        std::deque<Polygon_2> pols;
    
        std::vector<CGAL_Point> ptscgal;
        ptscgal.push_back(CGAL_Point(0,0));
        ptscgal.push_back(CGAL_Point(10,0));
        ptscgal.push_back(CGAL_Point(10,10));
        ptscgal.push_back(CGAL_Point(0,10));
    
        Alpha_shape_2 A(ptscgal.begin(), ptscgal.end(), FT(10000), Alpha_shape_2::REGULARIZED);
    
        Alpha_shape_2::Alpha_shape_vertices_iterator vit = A.alpha_shape_vertices_begin(),
            vend = A.alpha_shape_vertices_end();

        Alpha_shape_2::Alpha_shape_edges_iterator it = A.alpha_shape_edges_begin(),
            end = A.alpha_shape_edges_end();
    
        Triangulation_2::Vertex_circulator vc = A.incident_vertices(*vit);
        Triangulation_2::Vertex_circulator vccopy = vc;
        // --vccopy;

        Triangulation_2::Edge_circulator ec = A.incident_edges(*vit);
        Triangulation_2::Edge_circulator eccopy = ec;     

        do
        {
            std::cout << vc->point() << std::endl;
        }
        while(++vc != vccopy);

        do
        {
            std::cout << "ec: " << *(ec->first->vertex(0)) << " " << *(ec->first->vertex(1)) << std::endl;
        }
        while(++ec != eccopy);

        return 0;
    }

Output:

    10 10
    0 10
    0 0
    0.5 0.5 // ??

    10 0 10 10
    10 0 0 10
    0.5 0.5 10 0 // ??
    10 10 10 0