Esempio n. 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) {}
}
Esempio n. 2
0
int main ()
{
  // Construct an arrangement of four polylines named A--D.
  Arrangement_2    arr;

  Point_2          points1[5] = {Point_2(0,0), Point_2(2,4), Point_2(3,3),
                                 Point_2(4,4), Point_2(6,0)};
  insert (arr, Curve_2 (Polyline_2 (points1, points1 + 5), "A"));

  Point_2          points2[3] = {Point_2(1,5), Point_2(3,3), Point_2(5,5)};
  insert (arr, Curve_2 (Polyline_2 (points2, points2 + 3), "B"));

  Point_2          points3[4] = {Point_2(1,0), Point_2(2,2),
                                 Point_2(4,2), Point_2(5,0)};
  insert (arr, Curve_2 (Polyline_2 (points3, points3 + 4), "C"));

  Point_2          points4[2] = {Point_2(0,2), Point_2(6,2)};
  insert (arr, Curve_2 (Polyline_2 (points4, points4 + 2), "D"));

  // Print all edges that correspond to an overlapping polyline.
  Arrangement_2::Edge_iterator    eit;

  for (eit = arr.edges_begin(); eit != arr.edges_end(); ++eit) {
    if (eit->curve().data().length() > 1) {
      std::cout << "[" << eit->curve() << "]  "
                << "named: " << eit->curve().data() << std::endl;

      // Rename the curve associated with the edge.
      arr.modify_edge (eit, X_monotone_curve_2 (eit->curve(), "overlap"));
    }
  }
  return 0;
}
Esempio n. 3
0
int main ()
{
  // Construct an arrangement containing three RED line segments.
  Arrangement_2     arr;
  Landmarks_pl      pl (arr);

  Segment_2         s1 (Point_2(-1, -1), Point_2(1, 3));
  Segment_2         s2 (Point_2(2, 0), Point_2(3, 3));
  Segment_2         s3 (Point_2(0, 3), Point_2(2, 5));

  insert (arr, Colored_segment_2 (s1, RED), pl);
  insert (arr, Colored_segment_2 (s2, RED), pl);
  insert (arr, Colored_segment_2 (s3, RED), pl);

  // Insert three BLUE line segments.
  Segment_2         s4 (Point_2(-1, 3), Point_2(4, 1));
  Segment_2         s5 (Point_2(-1, 0), Point_2(4, 1));
  Segment_2         s6 (Point_2(-2, 1), Point_2(1, 4));

  insert (arr, Colored_segment_2 (s4, BLUE), pl);
  insert (arr, Colored_segment_2 (s5, BLUE), pl);
  insert (arr, Colored_segment_2 (s6, BLUE), pl);

  // Go over all vertices and print just the ones corresponding to intersection
  // points between RED segments and BLUE segments. Note that we skip endpoints
  // of overlapping sections.
  Arrangement_2::Vertex_const_iterator   vit;
  Segment_color                          color;

  for (vit = arr.vertices_begin(); vit != arr.vertices_end(); ++vit) {
    // Go over the incident halfedges of the current vertex and examine their
    // colors.
    bool       has_red = false;
    bool       has_blue = false;

    Arrangement_2::Halfedge_around_vertex_const_circulator  eit, first;

    eit = first = vit->incident_halfedges();
    do {
      // Get the color of the current half-edge.
      if (eit->curve().data().size() == 1) {
        color = eit->curve().data().front();

        if (color == RED)
          has_red = true;
        else if (color == BLUE)
          has_blue = true;
      }

      ++eit;
    } while (eit != first);

    // Print the vertex only if incident RED and BLUE edges were found.
    if (has_red && has_blue)
    {
      std::cout << "Red-blue intersection at (" << vit->point() << ")"
                << std::endl;
    }
  }

  // Locate the edges that correspond to a red-blue overlap.
  Arrangement_2::Edge_iterator   eit;

  for (eit = arr.edges_begin(); eit != arr.edges_end(); ++eit)
  {
    // Go over the incident edges of the current vertex and examine their
    // colors.
    bool       has_red = false;
    bool       has_blue = false;

    Traits_2::Data_container::const_iterator       dit;

    for (dit = eit->curve().data().begin(); dit != eit->curve().data().end();
         ++dit)
    {
      if (*dit == RED)
        has_red = true;
      else if (*dit == BLUE)
        has_blue = true;
    }

    // Print the edge only if it corresponds to a red-blue overlap.
    if (has_red && has_blue)
      std::cout << "Red-blue overlap at [" << eit->curve() << "]"  << std::endl;
  }
  return 0;
}
Esempio n. 4
0
void
arrangement::compute_ACScell()
{
    /*
    for (int i = 0; i < (int)convolutions.size(); ++i)
        for (Arrangement_2::Edge_iterator edge = convolutions[i].edges_begin(); edge != convolutions[i].edges_end(); ++edge)
        {
            convolution_r_all = Arrangement_2(convolutions[i]);
            insert(convolution_r_all, edge->curve());
            Arrangement_2::Edge_iterator e = convolution_r_all.edges_end();
            e->set_data(edge->data());

        }
    */


    /*
    std::cout << "edge label convo : ";
    for (Arrangement_2::Edge_iterator edge = convolution_r_all.edges_begin(); edge != convolution_r_all.edges_end(); ++edge)
        std::cout << edge->data() << " ";
    std::cout << std::endl;
    */

    for (int i = 0; i < (int)point_in_faces.size(); ++i)
    {
        // do a copy
        Arrangement_2 copy(convolutions[0]);
        Observer observer(copy);

        // add a circle
        Rat_point_2 center(point_in_faces[i][0], point_in_faces[i][1]);
        Rat_circle_2 circle(center, r1r2 * r1r2);
        Conic_curve_2 conic_arc(circle);
        insert(copy, conic_arc);

        // then add rho label for arc
        for (Arrangement_2::Edge_iterator edge = copy.edges_begin(); edge != copy.edges_end(); ++edge)
        {
            if (edge->data().compare("") == 0)
            {
                edge->set_data("rho_");
                edge->twin()->set_data("rho_");
            }
        }

        Walk_pl walk_pl(copy);

        std::vector<std::vector<double> > points;
        compute_pointInCells(copy, points);

        for (int j = 0; j < (int)points.size(); ++j)
        {
            double _x = point_in_faces[i][0] - points[j][0];
            double _y = point_in_faces[i][1] - points[j][1];
            if (r1r2 < sqrt(_x * _x + _y * _y))
            {
                Rational x_(points[j][0]);
                Rational y_(points[j][1]);
                Conic_point_2 p(x_,y_);
                Arrangement_2::Vertex_handle v = insert_point(copy, p, walk_pl);
                try
                {
                    ACScell cell(i);

                    Arrangement_2::Ccb_halfedge_circulator first_outer_ccb = v->face()->outer_ccb();
                    Arrangement_2::Ccb_halfedge_circulator outer_ccb = v->face()->outer_ccb();
                    do
                    {
                        // for retrieving ACScell Begin and End
                        insert(cell.arr, outer_ccb->curve());

                        // then continue
                        cell.addLabel(outer_ccb->data());
                        ++outer_ccb;
                    } while (outer_ccb != first_outer_ccb);

                    ACScells.push_back(cell);
                }
                catch (const std::exception exn) {}
            }
        }
    }

    // clean ACScells
    for (int i = 0; i < (int)ACScells.size(); ++i)
        ACScells[i].cleanLabels();

    // compute ACScells id
    int cpt = 0;
    int previous = 0;
    for (int i = 0; i < (int)ACScells.size(); ++i)
    {
        if (previous != ACScells[i].NCR)
        {
            cpt = 0;
            previous = ACScells[i].NCR;
        }

        ACScells[i].id = std::to_string(ACScells[i].NCR) + "." + std::to_string(cpt);
        ++cpt;
    }
}
Esempio n. 5
0
void
arrangement::compute_criticalCurves_type_II()
{
    for (int i = 0; i < (int) convolutions_o.size(); ++i)
    {
        // for all convolution arrangements
        Arrangement_2::Edge_iterator first = convolutions_o[i].edges_begin();
        Arrangement_2::Edge_iterator previous = convolutions_o[i].edges_begin();
        bool flag = true;

        Arrangement_2 copy(convolutions_o[i]);
        Walk_pl walk_pl(copy);

        for (Arrangement_2::Edge_iterator edge = convolutions_o[i].edges_begin(); edge != convolutions_o[i].edges_end(); ++edge)
        {
            if (flag)
            {
                ++edge;
                flag = false;
            }

            if (previous->data().compare(edge->data()) != 0)
            {
                // add critical curve type II in the copy
                double x = CGAL::to_double(edge->curve().source().x());
                double y = CGAL::to_double(edge->curve().source().y());
                double radius = r1r2;
                Rat_point_2 center(x, y);
                Rat_circle_2 circle(center, radius * radius);
                Conic_curve_2 conic_arc(circle);
                insert(nonCriticalRegions, conic_arc);
            }

            previous = edge;
        }
        if (previous->data().compare(first->data()) != 0)
        {
            // add critical curve type II in the copy
            double x = CGAL::to_double(first->curve().source().x());
            double y = CGAL::to_double(first->curve().source().y());
            double radius = r1r2;
            Rat_point_2 center(x, y);
            Rat_circle_2 circle(center, radius * radius);
            Conic_curve_2 conic_arc(circle);
            insert(nonCriticalRegions, conic_arc);
        }

        // keep only wanted curves and put it in the arrangement
        for (Arrangement_2::Edge_iterator e = nonCriticalRegions.edges_begin(); e != nonCriticalRegions.edges_end(); ++e)
            if ((e->data().compare("") == 0))
                keep_arc(e, copy, walk_pl);
        for (Arrangement_2::Edge_iterator edge = convolutions_o[i].edges_begin(); edge != convolutions_o[i].edges_end(); ++edge)
            insert(nonCriticalRegions, edge->curve());
    }
}
Esempio n. 6
0
void
arrangement::compute_criticalCurves_type_I()
{
    double radius_1 = ((double)manipulator_diametre)/2.0;
    double radius_2 = ((double)target_diametre)/2.0;

    for (int i = 0; i < (int) convolutions_o.size(); ++i)
    {
        Arrangement_2 copy(convolutions_o[i]);
        Walk_pl walk_pl(copy);
        // Add the critical curves of type I.
        for (Arrangement_2::Edge_iterator edge = convolutions_o[i].edges_begin(); edge != convolutions_o[i].edges_end(); ++edge)
        {
            if (CGAL::COLLINEAR == edge->curve().orientation())
            {
                // Displaced a segment.
                Nt_traits nt_traits;
                Algebraic_ft factor = nt_traits.convert(Rational(radius_1) + Rational(radius_2));
                Conic_point_2 source = edge->curve().source();
                Conic_point_2 target = edge->curve().target();
                Algebraic_ft delta_x = target.x() - source.x();
                Algebraic_ft delta_y = target.y() - source.y();
                Algebraic_ft length = nt_traits.sqrt(delta_x * delta_x + delta_y * delta_y);
                Algebraic_ft translation_x = - factor * delta_y / length;
                Algebraic_ft translation_y = factor * delta_x / length;
                Conic_point_2 point_1(source.x() + translation_x, source.y() + translation_y);
                Conic_point_2 point_2(target.x() + translation_x, target.y() + translation_y);
                Algebraic_ft a = delta_y;
                Algebraic_ft b = - delta_x;
                Algebraic_ft c = factor * length + (source.y() * target.x() - source.x() * target.y());
                X_monotone_curve_2 x_monotone_curve(a, b, c, point_1, point_2);

                insert(nonCriticalRegions, x_monotone_curve);
            }
            else
            {
                // Displaces an arc.
                Rational two(2);

                Rational r = edge->curve().r();
                Rational u = edge->curve().u();
                Rational v = edge->curve().v();

                Nt_traits nt_traits;
                Rational x_center = - u / (two * r);
                Rational y_center = - v / (two * r);
                Rat_point_2 rat_center(x_center, y_center);
                Conic_point_2 center(nt_traits.convert(x_center), nt_traits.convert(y_center));

                Rational radius = Rational(radius_1) + two * Rational(radius_2);

                Algebraic_ft coefficient = nt_traits.convert(radius / Rational(radius_2));

                Conic_point_2 source_1 = edge->curve().source();
                Algebraic_ft x_source_2 = center.x() + coefficient * (source_1.x() - center.x());
                Algebraic_ft y_source_2 = center.y() + coefficient * (source_1.y() - center.y());
                Conic_point_2 source_2(x_source_2, y_source_2);

                Conic_point_2 target_1 = edge->curve().target();
                Algebraic_ft x_target_2 = center.x() + coefficient * (target_1.x() - center.x());
                Algebraic_ft y_target_2 = center.y() + coefficient * (target_1.y() - center.y());
                Conic_point_2 target_2(x_target_2, y_target_2);

                Rat_circle_2 circle(rat_center, radius * radius);
                Conic_curve_2 conic_arc(circle, CGAL::CLOCKWISE, source_2, target_2);

                insert(nonCriticalRegions, conic_arc);
            }
        }
        // keep only wanted curves and put it in the arrangement
        for (Arrangement_2::Edge_iterator e = nonCriticalRegions.edges_begin(); e != nonCriticalRegions.edges_end(); ++e)
            if ((e->data().compare("") == 0))
                keep_arc(e, copy, walk_pl);
        for (Arrangement_2::Edge_iterator edge = convolutions_o[i].edges_begin(); edge != convolutions_o[i].edges_end(); ++edge)
            insert(nonCriticalRegions, edge->curve());
    }

}
Esempio n. 7
0
void
arrangement::compute_convolutionLabels()
{
    // initialize variables
    int compteur_wall = 0;
    int compteur_arc = 0;
    std::vector<std::string > labels;
    for (int i = 0; i < (int) env_points.size(); ++i)
        labels.push_back("none");

    double r = manipulator_diametre/2;

    // compute labels for robot convolution
    for (int i = 0; i < (int) convolutions.size(); ++i)
    {
        for (Arrangement_2::Edge_iterator edge = convolutions[i].edges_begin(); edge != convolutions[i].edges_end(); ++edge)
        {
            if (edge->curve().orientation() == CGAL::COLLINEAR) // if it is a segment
            {
                edge->set_data("w"+std::to_string(compteur_wall));
                edge->twin()->set_data("w"+std::to_string(compteur_wall++));
            }
            else // if it is an arc
            {
                std::string l = getLabel(labels, edge->curve(), compteur_arc, r);
                edge->set_data(l);
                edge->twin()->set_data(l);
            }
        }
    }

    // compute labels for object convolution (usefull just to clean critical curves 2)
    compteur_wall = 0;
    compteur_arc = 0;
    labels.clear();
    for (int i = 0; i < (int) env_points.size(); ++i)
        labels.push_back("none");

    r = target_diametre/2;

    for (int i = 0; i < (int) convolutions_o.size(); ++i)
    {
        for (Arrangement_2::Edge_iterator edge = convolutions_o[i].edges_begin(); edge != convolutions_o[i].edges_end(); ++edge)
        {
            if (edge->curve().orientation() == CGAL::COLLINEAR) // if it is a segment
            {
                edge->set_data("w"+std::to_string(compteur_wall));
                edge->twin()->set_data("w"+std::to_string(compteur_wall++));
            }
            else // if it is an arc
            {
                std::string l = getLabel(labels, edge->curve(), compteur_arc, r);
                edge->set_data(l);
                edge->twin()->set_data(l);
            }
        }
    }
}