void arrangement::compute_neighbours() { neighbours.resize(nonCriticalRegions.number_of_faces() - 1); // minus unbounded face for (Arrangement_2::Face_iterator face = nonCriticalRegions.faces_begin(); face != nonCriticalRegions.faces_end(); ++face) { if (!face->is_unbounded() && face->data() != -1) { Arrangement_2::Ccb_halfedge_circulator first_outer_ccb = face->outer_ccb(); Arrangement_2::Ccb_halfedge_circulator outer_ccb = face->outer_ccb(); int id_face = face->data(); std::vector<int> voisins; do { Arrangement_2::Face_handle adjacent_face = outer_ccb->twin()->face(); if (!adjacent_face->is_unbounded()) voisins.push_back(adjacent_face->data()); ++outer_ccb; } while (outer_ccb != first_outer_ccb); neighbours[id_face] = voisins; } } // clean neighbours for (int i = 0; i < (int) neighbours.size(); ++i) for (int j = 0; j < (int) neighbours[i].size(); ++j) for (int k = 0; k < j; ++k) if (neighbours[i][j] == neighbours[i][k]) { neighbours[i].erase(neighbours[i].begin() + j); --j; break; } // print results print_neighbours(); }
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 }
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); } } }