int main() { Arr_traits_2 arr_traits; Arr_traits_2::Construct_curve_2 construct_curve = arr_traits.construct_curve_2_object(); Arr_traits_2::Construct_x_monotone_segment_2 construct_x_monotone_segment = arr_traits.construct_x_monotone_segment_2_object(); Arr_traits_2::Construct_point_2 construct_point = arr_traits.construct_point_2_object(); Arr_traits_2::Make_x_monotone_2 make_x_monotone = arr_traits.make_x_monotone_2_object(); Arrangement_2 arr(&arr_traits); std::vector<X_monotone_curve_2> segs; Polynomial_2 x = CGAL::shift(Polynomial_2(1),1,0); Polynomial_2 y = CGAL::shift(Polynomial_2(1),1,1); // Construct x^4+y^3-1 Curve_2 cv0 = construct_curve(CGAL::ipower(x,4)+CGAL::ipower(y,3)-1); // Construct all x-monotone segments using the Make_x_mononotone functor std::vector<CGAL::Object> pre_segs; make_x_monotone(cv0,std::back_inserter(pre_segs)); // Cast all CGAL::Objects into X_monotone_segment_2 // (the vector might also contain Point_2 objects for isolated points, // but not for this instance for(size_t i = 0; i < pre_segs.size(); i++ ) { X_monotone_curve_2 curr; bool check = CGAL::assign(curr,pre_segs[i]); assert(check); segs.push_back(curr); } // Construct an ellipse with equation 2*x^2+5*y^2-7=0 Curve_2 cv1 = construct_curve(2*CGAL::ipower(x,2)+5*CGAL::ipower(y,2)-7); // Construct point on the upper arc (counting of arc numbers starts with 0! Point_2 p11 = construct_point(Algebraic_real_1(0),cv1,1); construct_x_monotone_segment(cv1,p11,Arr_traits_2::POINT_IN_INTERIOR, std::back_inserter(segs)); // Construct a vertical cusp x^2-y^3=0 Curve_2 cv2 = construct_curve(CGAL::ipower(x,2)-CGAL::ipower(y,3)); // Construct a segment containing the cusp point. // This adds to X_monotone_curve_2 objects to the vector, // because the cusp is a critical point Point_2 p21 = construct_point(Algebraic_real_1(-2),cv2,0); Point_2 p22 = construct_point(Algebraic_real_1(2),cv2,0); construct_x_monotone_segment(cv2,p21,p22,std::back_inserter(segs)); // Construct an unbounded curve, starting at x=3 Point_2 p23 = construct_point(Algebraic_real_1(3),cv2,0); construct_x_monotone_segment(cv2,p23,Arr_traits_2::MIN_ENDPOINT, std::back_inserter(segs)); // Construct another conic: y^2-x^2+1 Curve_2 cv3 = construct_curve(CGAL::ipower(y,2)-CGAL::ipower(x,2)+1); Point_2 p31 = construct_point(Algebraic_real_1(2),cv3,1); construct_x_monotone_segment(cv3,p31,Arr_traits_2::MAX_ENDPOINT, std::back_inserter(segs)); // Construct a vertical segment Point_2 v1 = construct_point(0,0); Point_2 v2 = construct_point(Algebraic_real_1(0),cv1,1); construct_x_monotone_segment(v1,v2,std::back_inserter(segs)); CGAL::insert(arr,segs.begin(),segs.end()); // Add some isolated points (must be wrapped into CGAL::Object) std::vector<CGAL::Object> isolated_points; isolated_points.push_back (CGAL::make_object(construct_point(Algebraic_real_1(2),cv3,0))); isolated_points.push_back (CGAL::make_object(construct_point(Integer(1),Integer(5)))); isolated_points.push_back (CGAL::make_object(construct_point(Algebraic_real_1(-1), Algebraic_real_1(5)))); CGAL::insert(arr,isolated_points.begin(), isolated_points.end()); // Print the arrangement size. std::cout << "The arrangement size:" << std::endl << " V = " << arr.number_of_vertices() << ", E = " << arr.number_of_edges() << ", F = " << arr.number_of_faces() << std::endl; return 0; }
// read one stroke from file stream // if successed,return the file position after reading one stroke // else return -1 // pay attention to call this function, // we should guarantee file position should stop at the beginning of stroke long read_stroke (FILE * file, PtrStroke stroke) { int i; PtrInkPoint point; if (file == NULL || stroke == NULL) { SB_INKERRPRINTF("failed:incorrect arguments\n"); return -1; } if ( !read_integer(&(stroke->iPenSize), file) ) { SB_INKPRINTF("failed getting stroke->iPenSize\n"); return -1; } //read rgb if ( !read_rgb(&stroke->gdkColor,file) ) { SB_INKERRPRINTF("failed write rgb\n"); return 0; } if ( !read_integer(&(stroke->nPoints), file) ) { SB_INKERRPRINTF("failed getting stroke->nPoints\n"); return -1; } SB_INKPRINTF("npoints=%d,ipensize=%d\n", stroke->nPoints,stroke->iPenSize); if ( stroke->nPoints == 0) { SB_INKPRINTF("returned because of stroke->nPoints=0\n"); return ftell (file);//lPos } //stroke->nPoints will be changed in iteration,so we should keep it. int nTotalPoints=stroke->nPoints; for (i = 0; i < nTotalPoints; i++) { point = construct_point (); if ( NULL==point ) { SB_INKERRPRINTF("construct point error\n"); return -1; } if ( !read_integer (&(point->x), file) ) { SB_INKERRPRINTF("failed getting (point%d->x)\n",i); return -1; } if ( !read_integer (&(point->y), file) ) { SB_INKERRPRINTF("failed getting (point%d->y)\n",i); return -1; } //SB_INKPRINTF("point(%d,%d) \n", point->x, point->y); ink_add_point(stroke, point); } return ftell (file);//current file pointer position }