void ArrPolyIpelet::protected_run(int fn){ if (fn==1) { show_help(); return; } X_monotone_list output_curves; Curve_list input_curves; //Argt std::list<Segment_2> sg_list; std::list<Circle_2> cir_list; std::list<Polygon_2> pol_list; std::list<Circular_arc_2> arc_list; read_active_objects( CGAL::dispatch_or_drop_output<Polygon_2,Circle_2,Segment_2,Circular_arc_2>( std::back_inserter(pol_list), std::back_inserter(cir_list), std::back_inserter(sg_list), std::back_inserter(arc_list) ), true,true ); for (std::list<Polygon_2>::iterator it=pol_list.begin();it!=pol_list.end();++it) for(Polygon_2::Edge_const_iterator edge_it=it->edges_begin();edge_it!=it->edges_end();++edge_it) input_curves.push_back(Curve_2(edge_it->point(0),edge_it->point(1))); for (std::list<Segment_2>::iterator it=sg_list.begin();it!=sg_list.end();++it) input_curves.push_back(Curve_2(it->point(0),it->point(1))); for (std::list<Circle_2>::iterator it=cir_list.begin();it!=cir_list.end();++it) input_curves.push_back(Curve_2(it->center(),sqrt(CGAL::to_double(it->squared_radius())))); for (std::list<Circular_arc_2>::iterator it=arc_list.begin();it!=arc_list.end();++it) input_curves.push_back( Curve_2( std::get<0>(*it).center(), sqrt(CGAL::to_double(std::get<0>(*it).squared_radius())), std::get<3>(*it), Traits::Point_2(std::get<1>(*it).x(),std::get<1>(*it).y()), Traits::Point_2(std::get<2>(*it).x(),std::get<2>(*it).y()) ) ); Traits T; CGAL::compute_subcurves(input_curves.begin(),input_curves.end(),std::back_inserter(output_curves),false,T); for (X_monotone_list::iterator it=output_curves.begin();it!=output_curves.end();++it){ Point_2 S(CGAL::to_double(it->source().x()),CGAL::to_double(it->source().y())); Point_2 T(CGAL::to_double(it->target().x()),CGAL::to_double(it->target().y())); if (it->is_linear ()) draw_in_ipe(Segment_2(S,T)); if (it->is_circular()) draw_in_ipe(Circular_arc_2(it->supporting_circle(),S,T,it->supporting_circle().orientation())); } return; }
void hilbertsortIpelet::protected_run(int fn) { if (fn==1) { show_help(); return; } std::vector<Circle_2> cir_list; std::vector<Circular_arc_2> arc_list; std::vector<Polygon_2> poly_list; std::vector<Segment_2> seg_list; std::vector<Point_2> pt_list; read_active_objects( CGAL::dispatch_or_drop_output<Point_2,Circle_2,Polygon_2,Circular_arc_2,Segment_2>( std::back_inserter(pt_list),std::back_inserter(cir_list), std::back_inserter(poly_list),std::back_inserter(arc_list), std::back_inserter(seg_list) ),true,true ); if (pt_list.size()<2) { print_error_message("No point selected to define a bounding box"); return; } CGAL::Bbox_2 bbox_2=pt_list.begin()->bbox(); for (std::vector<Point_2>::iterator it=pt_list.begin();it!=pt_list.end();++it) bbox_2=bbox_2+it->bbox(); Iso_rectangle_2 bbox(bbox_2.xmin(),bbox_2.ymin(),bbox_2.xmax(),bbox_2.ymax()); draw_in_ipe(bbox); draw_in_ipe(cir_list.begin(),cir_list.end(),bbox,false); draw_in_ipe(seg_list.begin(),seg_list.end(),bbox,false); draw_in_ipe(arc_list.begin(),arc_list.end(),bbox,false); draw_in_ipe(poly_list.begin(),poly_list.end(),bbox,false); }
void MregularIpelet::protected_run(int fn) { Regular rt; std::vector<Weighted_point_2> input_wpt; if (fn==10) { show_help(false); return; } Iso_rectangle_2 bbox= read_active_objects( CGAL::dispatch_or_drop_output<Point_2,Circle_2>( wpoint_grabber(std::back_inserter(input_wpt)), wpoint_grabber(std::back_inserter(input_wpt)) ) ); if (!input_wpt.size()) { print_error_message("No circle selected"); return; } int order = 0; if(fn==0 || fn==5) order = 1; if(fn==1 || fn==6) order = 2; if(fn==2 || fn==7) order = 3; if(fn==3 || fn==8) order = input_wpt.size()-1;; if(fn==4 || fn==9){ int ret_val; boost::tie(ret_val,order)=request_value_from_user<int>("Enter order"); if (ret_val < 0){ print_error_message("Incorrect value"); return; } if(order<1 || order>=(int) input_wpt.size()){ print_error_message("Not a good order"); return; } } k_delaunay<Kernel>(rt,input_wpt,order); if(fn<5)//Draw k-th regular triangulation draw_in_ipe(rt); else{//Draw kth Power diagram double incr_len=75; bbox=Iso_rectangle_2(bbox.min()+Kernel::Vector_2(-incr_len,-incr_len), bbox.max()+Kernel::Vector_2(incr_len,incr_len)); draw_dual_in_ipe(rt,bbox); //draw Voronoi Diagram } }
void SubSelectIpelet::protected_run(int fn) { if (fn==2) { show_help(); return; } std::list<Circle_2> cir_list; std::list<Polygon_2> pol_list; Iso_rectangle_2 bbox= read_active_objects( CGAL::dispatch_or_drop_output<Polygon_2,Circle_2>( std::back_inserter(pol_list), std::back_inserter(cir_list) ) ); if (fn==0 && pol_list.size()!=2){ print_error_message("You must select exactly two polygons"); return; } std::list<double> r_offsets; for (std::list<Circle_2>::iterator it=cir_list.begin();it!=cir_list.end();++it) r_offsets.push_back(sqrt(CGAL::to_double(it->squared_radius()))); IpeMatrix tfm (1,0,0,1,-CGAL::to_double(bbox.min().x()),-CGAL::to_double(bbox.min().y())); for (std::list<Polygon_2>::iterator it=pol_list.begin();it!=pol_list.end();++it) if(!it->is_simple()){ print_error_message("Polygon(s) must be simple"); } if (fn==0){ Polygon_2 polygon1=*pol_list.begin(); Polygon_2 polygon2=*++pol_list.begin(); Polygon_with_holes_2 sum = minkowski_sum_2 (polygon1, polygon2); std::list<Point_2> LP; for (Polygon_2::iterator it=sum.outer_boundary().vertices_begin();it!= sum.outer_boundary().vertices_end();++it) LP.push_back(*it); draw_polyline_in_ipe(LP.begin(),LP.end(),true,false,false); for (Polygon_with_holes_2::Hole_const_iterator poly_it = sum.holes_begin(); poly_it != sum.holes_end(); ++poly_it){ LP.clear(); for (Polygon_2::iterator it=poly_it->vertices_begin();it!= poly_it->vertices_end();++it) LP.push_back(*it); draw_polyline_in_ipe(LP.begin(),LP.end(),true,false,false); } create_polygon_with_holes(true); transform_selected_objects_(tfm); } else{ if (r_offsets.size()==0) r_offsets.push_back(10); for (std::list<Polygon_2>::iterator it_pol=pol_list.begin();it_pol!=pol_list.end();++it_pol){ for(std::list<double>::iterator it=r_offsets.begin();it!=r_offsets.end();++it){ Offset_polygon_with_holes_2 offset=approximated_offset_2 (*it_pol, *it, 0.0001); std::list<Segment_2> LS; for( Offset_polygon_2::Curve_iterator itt=offset.outer_boundary().curves_begin(); itt!=offset.outer_boundary().curves_end();++itt){ Point_2 S=Point_2(CGAL::to_double(itt->source().x()),CGAL::to_double(itt->source().y())); Point_2 T=Point_2(CGAL::to_double(itt->target().x()),CGAL::to_double(itt->target().y())); if (itt->is_linear ()) LS.push_back(Segment_2(S,T)); if (itt->is_circular()) draw_in_ipe(Circular_arc_2(itt->supporting_circle(),S,T,itt->supporting_circle().orientation())); } draw_in_ipe(LS.begin(),LS.end()); } } } }
void pcaIpelet::protected_run(int fn) { if (fn==1) { show_help(); return; } std::list<Point_2> pt_list; std::list<Circle_2> cir_list; std::list<Polygon_2> poly_list; std::list<Kernel::Triangle_2> tri_list; std::list<Segment_2> sg_list; Iso_rectangle_2 bbox= read_active_objects( CGAL::dispatch_or_drop_output<Point_2,Polygon_2,Circle_2,Segment_2>( std::back_inserter(pt_list), std::back_inserter(poly_list), std::back_inserter(cir_list), std::back_inserter(sg_list) ) ); for (std::list<Polygon_2>::iterator it=poly_list.begin();it!=poly_list.end();++it) if (it->size()==3){ tri_list.push_back(Kernel::Triangle_2(*(it->vertices_begin()), *boost::next(it->vertices_begin()), *boost::next(it->vertices_begin(),2) )); } else{ print_error_message("This implementation is limited to triangles"); return; } int s=0; if (!pt_list.empty()) s=1; if (!cir_list.empty()) s+=2; if (!tri_list.empty()) s+=4; if (!sg_list.empty()) s+=8; if (s==0) { print_error_message("Nothing is selected"); return; } Kernel::Line_2 line; Kernel::Point_2 centroid; switch (s){ case 1://points linear_least_squares_fitting_2(pt_list.begin(),pt_list.end(),line,centroid,CGAL::Dimension_tag<0>()); break; case 2://circles linear_least_squares_fitting_2(cir_list.begin(),cir_list.end(),line,centroid,CGAL::Dimension_tag<2>()); break; case 4://triangles linear_least_squares_fitting_2(tri_list.begin(),tri_list.end(),line,centroid,CGAL::Dimension_tag<2>()); break; case 8://segments linear_least_squares_fitting_2(sg_list.begin(),sg_list.end(),line,centroid,CGAL::Dimension_tag<1>()); break; default: print_error_message("Please select a set of points or segments or triangles or circles"); return; } CGAL::Object obj_cgal = CGAL::intersection(line,bbox); Segment_2 seg; if (CGAL::assign(seg, obj_cgal)) draw_in_ipe(seg); }
void Cone_spanners_ipelet::protected_run(int fn) { std::vector<Point_2> lst; int number_of_cones; switch (fn){ case 0: case 1: case 2: case 3: case 4: case 5: case 6: { std::vector<Point_2> points_read; read_active_objects( CGAL::dispatch_or_drop_output<Point_2>(std::back_inserter(points_read)) ); if (points_read.empty()) { print_error_message("No mark selected"); return; } for(std::vector<Point_2>::iterator it = points_read.begin(); it != points_read.end(); it++) { if(std::find(points_read.begin(), it, *it) == it) { lst.push_back(*it); } } int ret_val; boost::tie(ret_val,number_of_cones)=request_value_from_user<int>("Enter the number of cones"); if (ret_val < 0) { print_error_message("Incorrect value"); return; } if(number_of_cones < 2) { print_error_message("The number of cones must be larger than 1!"); return; } break; } case 7: show_help(); return; } if(fn >= 0 && fn <= 5) { CGAL::Cones_selected cones_selected = CGAL::ALL_CONES; if(fn == 2 || fn == 3) cones_selected = CGAL::EVEN_CONES; else if(fn == 4 || fn == 5) cones_selected = CGAL::ODD_CONES; Graph g; switch (fn){ case 0: case 2: case 4: { CGAL::Construct_theta_graph_2<Kernel, Graph> theta(number_of_cones, Direction_2(1,0), cones_selected); theta(lst.begin(), lst.end(), g); break; } case 1: case 3: case 5: { CGAL::Construct_yao_graph_2<Kernel, Graph> yao(number_of_cones, Direction_2(1,0), cones_selected); yao(lst.begin(), lst.end(), g); break; } } boost::graph_traits<Graph>::edge_iterator ei, ei_end; for (boost::tie(ei, ei_end) = edges(g); ei != ei_end; ++ei) { boost::graph_traits<Graph>::edge_descriptor e = *ei; boost::graph_traits<Graph>::vertex_descriptor u = source(e, g); boost::graph_traits<Graph>::vertex_descriptor v = target(e, g); draw_in_ipe(Segment_2(g[u], g[v])); } group_selected_objects_(); } else if(fn == 6) { CGAL::Compute_cone_boundaries_2<Kernel> cones; std::vector<Direction_2> directions(number_of_cones); cones(number_of_cones, Direction_2(1,0), directions.begin()); for(std::vector<Point_2>::iterator it = lst.begin(); it != lst.end(); it++) { for(std::vector<Direction_2>::iterator dir = directions.begin(); dir != directions.end(); dir++) { draw_in_ipe(Segment_2(*it,*it + 100*dir->to_vector())); } group_selected_objects_(); get_IpePage()->deselectAll(); } } }
void ConvexpartitionIpelet::protected_run(int fn) { if (fn==4) { show_help(); return; } std::list<Polygon_2> pol_list; Iso_rectangle_2 bbox= read_active_objects( CGAL::dispatch_or_drop_output<Polygon_2>( std::back_inserter(pol_list) ) ); if (pol_list.size ()==0){ print_error_message("No polygon selected"); return; } for (std::list<Polygon_2>::iterator itp=pol_list.begin();itp!=pol_list.end();++itp){ //~ Polygon_2 polygon=*itp; //~ std::list<Polygon_2> partition_polys; CGAL::Polygon_2<Kernel,std::list<Kernel::Point_2> > polygon(itp->vertices_begin(),itp->vertices_end()); std::list<CGAL::Polygon_2<Kernel,std::list<Kernel::Point_2> > > partition_polys; if (!polygon.is_simple()){ print_error_message("Polygon must be simple"); continue; } if (polygon.orientation()!=CGAL::COUNTERCLOCKWISE) polygon.reverse_orientation(); switch(fn){ case 0: CGAL::y_monotone_partition_2(polygon.vertices_begin(), polygon.vertices_end(), std::back_inserter(partition_polys)); break; case 1: CGAL::greene_approx_convex_partition_2(polygon.vertices_begin(), polygon.vertices_end(), std::back_inserter(partition_polys)); break; case 2: CGAL::approx_convex_partition_2(polygon.vertices_begin(), polygon.vertices_end(), std::back_inserter(partition_polys)); break; case 3: CGAL::optimal_convex_partition_2(polygon.vertices_begin(), polygon.vertices_end(), std::back_inserter(partition_polys)); break; } draw_in_ipe(partition_polys.begin(),partition_polys.end()); } }