Пример #1
0
void
arrangement::keep_arc(Arrangement_2::Edge_iterator &e, Arrangement_2 &copy, Walk_pl &walk_pl)
{
    e->set_data("none");
    Conic_point_2 p;
    // if it is a segment
    if (e->curve().orientation() == CGAL::COLLINEAR)
    {
        Conic_point_2 source = e->curve().source();
        Conic_point_2 target = e->curve().target();
        double x = CGAL::to_double((target.x() + source.x()) /2);
        double y = CGAL::to_double((target.y() + source.y()) /2);
        Rational x_(x);
        Rational y_(y);
        p = Conic_point_2(x_,y_);
    }
    else // if it is an arc
    {
        int n = 2;
        approximated_point_2* points = new approximated_point_2[n + 1];
        e->curve().polyline_approximation(n, points); // there is 3 points
        p = Conic_point_2(Rational(points[1].first),Rational(points[1].second));
    }

    Arrangement_2::Vertex_handle v = insert_point(copy, p, walk_pl);
    try
    {
        if (v->face()->data() != 1)
            nonCriticalRegions.remove_edge(e, false, false);
        copy.remove_isolated_vertex(v);
    }
    catch (const std::exception exn) {}
}
Пример #2
0
void
arrangement::compute_pointInCells(Arrangement_2 &arr, std::vector<std::vector<double> > &points)
{
    Walk_pl walk_pl(arr);

    int cpt = 0;
    for (Arrangement_2::Face_iterator face = arr.faces_begin(); face != arr.faces_end(); ++face)
    {
        if (face->is_unbounded())
            face->set_data(-1);
        else
        {
            // set data to each face
            face->set_data(cpt++);
            // find a point in this face
            Arrangement_2::Ccb_halfedge_circulator previous = face->outer_ccb();
            Arrangement_2::Ccb_halfedge_circulator first_edge = face->outer_ccb();
            Arrangement_2::Ccb_halfedge_circulator edge = face->outer_ccb();
            ++edge;
            do
            {
                std::vector<double> p1 = getPointMiddle(previous);
                std::vector<double> p2 = getPointMiddle(edge);
                std::vector<double> m;
                m.push_back((p1[0]+p2[0])/2);
                m.push_back((p1[1]+p2[1])/2);
                Rational x_(m[0]);
                Rational y_(m[1]);
                Conic_point_2 p(x_,y_);

                Arrangement_2::Vertex_handle v = insert_point(arr, p, walk_pl);
                try
                {
                    if (v->face()->data() == (cpt-1))
                    {
                        bool flag = false;
                        // test if it is not in holes and not in unbounded face
                        for (int i = 0; i < (int) convolutions_o.size(); ++i)
                        {
                            Walk_pl wpl(convolutions_o[i]);
                            Arrangement_2::Vertex_handle t = insert_point(convolutions_o[i], p, wpl);
                            if (t->face()->data() == 1)
                            {
                                convolutions_o[i].remove_isolated_vertex(t);
                                break;
                            }
                            else if (t->face()->data() == 2 || t->face()->data() == 0)
                            {
                                flag = true;
                                convolutions_o[i].remove_isolated_vertex(t);
                                break;
                            }
                        }

                        // then continue
                        if (!flag)
                            points.push_back(m);
                        else
                        {
                            --cpt;
                            face->set_data(-1);
                        }

                        arr.remove_isolated_vertex(v);
                        break;
                    }
                    arr.remove_isolated_vertex(v);
                }
                catch (const std::exception exn) {}
                previous = edge;

                ++edge;
            } while (edge != first_edge);
        }
    }
}