Example #1
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);
        }
    }
}
Example #2
0
GeometryPtr 
Overlay::process(const Polyline2DPtr& p1, const Polyline2DPtr& p2)
{
	if (!p1 || !p2 || p1->getPointListSize() < 2 || p2->getPointListSize() < 2) return GeometryPtr();
#ifdef WITH_CGAL

  // Construct the first arrangement, containing a polyline 1.
  Arrangement_2          arr1;

  for (Point2Array::const_iterator it1 = p1->getPointList()->begin()+1; it1 != p1->getPointList()->end(); ++it1)
	insert_non_intersecting_curve(arr1,toSegment(*(it1-1),*it1));

  // to be a closed face, first and last point should be exactly the same.
  // However we should not duplicate the same point twice at the end.
  Vector2& fp1 = p1->getPointList()->getAt(0);
  Vector2& lp1 = *(p1->getPointList()->end()-1);
  if (fp1.x() != lp1.x() || fp1.y() != lp1.y())
	insert_non_intersecting_curve(arr1,toSegment(lp1,fp1));

  // std::cerr << arr1.number_of_vertices() << " " << arr1.number_of_edges() << " " << arr1.number_of_faces() << std::endl;

  // Mark just the bounded face.
  Arrangement_2::Face_iterator   fit;

  CGAL_assertion (arr1.number_of_faces() == 2);
  for (fit = arr1.faces_begin(); fit != arr1.faces_end(); ++fit)
    fit->set_data (fit != arr1.unbounded_face());

  // Construct the second arrangement.
  Arrangement_2          arr2;

  for (Point2Array::const_iterator it2 = p2->getPointList()->begin()+1; it2 != p2->getPointList()->end(); ++it2)
	 	insert(arr2,toSegment(*(it2-1),*it2));

  // to be a closed face, first and last point should be exactly the same.
  // However we should not duplicate the same point twice at the end.
  Vector2& fp2 = p2->getPointList()->getAt(0);
  Vector2& lp2 = *(p2->getPointList()->end()-1);
  if (fp2.x() != lp2.x() || fp2.y() != lp2.y())
	insert(arr2,toSegment(lp2,fp2)); 

  // std::cerr << arr2.number_of_vertices() << " " << arr2.number_of_edges() << " " << arr2.number_of_faces() << std::endl;

  CGAL_assertion (arr2.number_of_faces() == 2);
  for (fit = arr2.faces_begin(); fit != arr2.faces_end(); ++fit)
    fit->set_data (fit != arr2.unbounded_face());

  // Compute the overlay of the two arrangements.
  Arrangement_2          overlay_arr;
  Overlay_traits         overlay_traits;

  overlay (arr1, arr2, overlay_arr, overlay_traits);

  // std::cerr << overlay_arr.number_of_vertices() << " " << overlay_arr.number_of_edges() << " " << overlay_arr.number_of_faces() << std::endl;

  // conversion between cgal structures and plantgl ones.
  GeometryArrayPtr geomarray(new GeometryArray(0));
  for (Arrangement_2::Face_iterator face = overlay_arr.faces_begin(); face != overlay_arr.faces_end(); ++face)
  {
    if (face->is_fictitious () || face->is_unbounded())
		continue;
    if (! face->data())
      continue;
   
    Arrangement_2::Ccb_halfedge_circulator curr = face->outer_ccb();
	Point2ArrayPtr pointSet( new Point2Array(1,toVec2(curr->source()->point())));
    do
    {
	  pointSet->push_back(toVec2(curr->target()->point()));
      ++curr;
    } while (curr != face->outer_ccb());
	if (pointSet->size() == 1){
		geomarray->push_back(GeometryPtr(new PointSet2D(pointSet)));
	}
	else if(pointSet->size() > 1){
		geomarray->push_back(GeometryPtr(new Polyline2D(pointSet)));
	}
  }
  if (geomarray->empty())return GeometryPtr();
  else if (geomarray->size() == 1) return geomarray->getAt(0);
  else return GeometryPtr(new Group(geomarray));

#else
#ifdef _MSC_VER
#pragma message("CGAL not included. Overlay routine will not work.")
#else
#warning "CGAL not included. Overlay routine will not work."
#endif
	pglError("CGAL not included. Overlay routine will not work.");
	return GeometryPtr();
#endif

}
Example #3
0
void
arrangement::compute_admissible_configuration()
{
    // transform environment into polygons
    std::list<Rat_point_2> pts;
    for (int i=0;i<(int)frontier.size();++i)
        pts.push_back(Rat_point_2(frontier[i].x(), frontier[i].y()));
    env.insert(env.vertices_circulator(), pts.begin(), pts.end());

    // compute inset
    inset_of_polygon(env, manipulator_diametre, inset);
    inset_of_polygon(env, target_diametre, inset_o);

    // transform and compute offset of obstacles
    std::vector<std::list<Rat_point_2> > pts2;
    pts2.resize((int)obstacles.size());
    obs.resize((int)obstacles.size());
    for(int k = 0; k < (int)obstacles.size()-1; ++k)
    {
        for (int i=0;i<(int)obstacles[k].size();++i)
            pts2[k].push_back(Rat_point_2(obstacles[k][i].x(),obstacles[k][i].y()));
        obs[k].insert(obs[k].vertices_circulator(), pts2[k].begin(), pts2[k].end());
        offset_of_polygon(obs[k],manipulator_diametre, offsets);
        offset_of_polygon(obs[k],target_diametre, offsets_o);
    }

    // compute admissible configuration
    for (Op2_it pgn=inset.begin(); pgn != inset.end(); ++pgn)
        admissible_configuration(pgn, offsets, admissible);
    for (Op2_it pgn=inset_o.begin(); pgn != inset_o.end(); ++pgn)
        admissible_configuration(pgn, offsets_o, admissible_o);

    // add all curves of admissible_R space in arrangement
    for (int i = 0; i < (int) admissible.size(); ++i)
    {
        Arrangement_2 arr;
        for (X_curve_2_it curve = admissible[i].outer_boundary().curves_begin(); curve != admissible[i].outer_boundary().curves_end(); ++curve)
            insert(arr, *curve);
        if (admissible[i].has_holes())
            for(Op2_it hol = admissible[i].holes_begin(); hol != admissible[i].holes_end(); ++hol)
                for (X_curve_2_it curve = hol->curves_begin(); curve != hol->curves_end(); ++curve)
                    insert(arr, *curve);
        convolutions.push_back(arr);
    }
    for (int i = 0; i < (int) convolutions.size(); ++i)
    {
        int cpt = 0;
        for (Arrangement_2::Face_iterator face = convolutions[i].faces_begin(); face != convolutions[i].faces_end(); ++face)
            face->set_data(cpt++);
    }

    // add all curves of admissible_R space in arrangement
    for (int i = 0; i < (int) admissible_o.size(); ++i)
    {
        Arrangement_2 arr;
        for (X_curve_2_it curve = admissible_o[i].outer_boundary().curves_begin(); curve != admissible_o[i].outer_boundary().curves_end(); ++curve)
        {
            insert(arr, *curve);
            insert(nonCriticalRegions, *curve);
        }
        if (admissible_o[i].has_holes())
            for(Op2_it hol = admissible_o[i].holes_begin(); hol != admissible_o[i].holes_end(); ++hol)
                for (X_curve_2_it curve = hol->curves_begin(); curve != hol->curves_end(); ++curve)
                {
                    insert(arr, *curve);
                    insert(nonCriticalRegions, *curve);
                }
        convolutions_o.push_back(arr);
    }
    for (int i = 0; i < (int) convolutions_o.size(); ++i)
    {
        int cpt = 0;
        for (Arrangement_2::Face_iterator face = convolutions_o[i].faces_begin(); face != convolutions_o[i].faces_end(); ++face)
            face->set_data(cpt++);
    }

    // save environment vertices
    for (int i = 0; i < (int)frontier.size(); ++i)
        env_points.push_back(frontier[i]);
    for (int i = 0; i < (int) obstacles.size(); ++i)
        for (int j = 0; j < (int) obstacles[i].size(); ++j)
            env_points.push_back(obstacles[i][j]);
}