diff --git a/Packages/Map_overlay_2/demo/Map_overlay_2/Segment_incremental_ovl_from_file.C b/Packages/Map_overlay_2/demo/Map_overlay_2/Segment_incremental_ovl_from_file.C new file mode 100644 index 00000000000..1950fb01465 --- /dev/null +++ b/Packages/Map_overlay_2/demo/Map_overlay_2/Segment_incremental_ovl_from_file.C @@ -0,0 +1,339 @@ +// demo/Map_overlay_2/Segment_bops_from_mouse.C +// +// constructs an overlay of two segment planar maps from CGAL window. +// We use the leda traits (therefore we are using leda functions). + +#include // needed for the LONGNAME flag + +#ifdef CGAL_CFG_NO_LONGNAME_PROBLEM +// Define shorter names to please linker (g++/egcs) +#define Planar_map_with_intersections Pmwx +#define Arr_leda_segment_exact_traits Alset +#define Bop_default_dcel Bdd +#define Boolean_operation Bo +#define In_place_list_iterator IPLI +#define Arr_2_vertex_base Avb +#define Arr_2_halfedge_base Ahb +#define Arr_2_face_base Afb +#define Point_2 pT +#define Segment_2 sT +#define Topological_map TpM +#define _List_iterator Lit +#define Halfedge hE +#define Forward_circulator_tag Fct +#endif + +#include + +#ifndef CGAL_USE_LEDA +int main() +{ + + std::cout << "Sorry, this demo needs LEDA for visualisation."; + std::cout << std::endl; + + return 0; +} + +#else + +#include +#include +#include + + +#include +#include +#include + + +#include +#include +#include + +#if defined(LEDA_NAMESPACE) +using namespace leda; +#endif + +typedef leda_rational NT; +typedef CGAL::Arr_leda_segment_exact_traits Traits; + +typedef Traits::Point Point; +typedef Traits::X_curve X_curve; +typedef Traits::X_curve Curve; + +typedef CGAL::Map_overlay_default_dcel Dcel; +typedef CGAL::Planar_map_2 PM; +typedef CGAL::Planar_map_with_intersections_2 Pmwx; + +typedef CGAL::Map_overlay_default_notifier MapOverlay_change_notification; +typedef CGAL::Map_overlay_incremental + MapOverlay_incremental; +typedef CGAL::Map_overlay MapOverlay; + +typedef CGAL::Pm_walk_along_line_point_location PmWalkPL; + + +//I had to add these in global namespace for the program to compile + +/* + CGAL::Window_stream& operator<<(CGAL::Window_stream& os, + const Point& p) + { + //return os << leda_point(p.xcoordD(),p.ycoordD()); + return os << p.to_point(); + } + + + CGAL::Window_stream& operator<<(CGAL::Window_stream& os, + const X_curve &c) + { + return os << c.to_segment(); + }*/ + +// global variables are used so that the redraw function for the LEDA window +// can be defined to draw information found in these variables. +//static PmWalkPL pm_walk1, pm_walk2; +static Pmwx pmwx1; +static Pmwx pmwx2; +static CGAL::Window_stream W(700, 700, "CGAL - Segment Map-Overlay Demo: Incremental Algorithm"); + +/*CGAL_BEGIN_NAMESPACE + Window_stream& operator<<(Window_stream& os, const PM &pm) + { + My_Arr_drawer< PM, + PM::Ccb_halfedge_const_circulator, + PM::Holes_const_iterator> drawer(os); + + draw_pm(pm, drawer, os); + + return os; + } + CGAL_END_NAMESPACE*/ + +// redraw function for the LEDA window. +// used automatically when window reappears. +void redraw(CGAL::Window_stream * wp) +{ wp->start_buffering(); + wp->clear(); + // draw planar map. + *wp << CGAL::BLUE; + *wp << pmwx1; + *wp << CGAL::RED; + *wp << pmwx2; + wp->flush_buffer(); + wp->stop_buffering(); +} + +void draw_and_locate_maps (const Pmwx& pmwx, + const Pmwx& pmwx1, + const Pmwx& pmwx2, + CGAL::Window_stream& W) +{ + W << CGAL::BLUE; + W << pmwx1; + W << CGAL::RED; + W << pmwx2; + + for (;;) { + double x,y; + + int b = W.read_mouse(x,y); + if (b == 4) + break; + + W.clear(); + W << CGAL::BLUE; + W << pmwx1; + W << CGAL::RED; + W << pmwx2; + + //W << pm; + + NT z(x), w(y); + Point p(z, w); + + //debug. + cout<face(); + if (lt == Pmwx::UNBOUNDED_FACE) { + std::cout << "UNBOUNDED" << endl; + } + else { + W.set_node_width(4); + + Pmwx::Face* f1 = (Pmwx::Face*) fh->get_first_face_above(); + Pmwx::Face* f2 = (Pmwx::Face*) fh->get_second_face_above(); + + if (f1 == NULL || f2 == NULL) + std::cout<<"NULL faces pointers\n"; + + leda_color fg_col; + if (f1 != NULL && !(f1->is_unbounded()) && f2 != NULL && !(f2->is_unbounded()) ){ + // debug! + cout<<"both maps lay above face"<is_unbounded())){ + cout<<"first map lays above face"<is_unbounded())){ + cout<<"second map lays above face"<outer_ccb(); + + leda_list points_list; + do { + leda_point p = leda_point(CGAL::to_double(cc->source()->point().xcoordD()), + CGAL::to_double(cc->source()->point().ycoordD()) ); + + points_list.push_back(p); + } while (++cc != fh->outer_ccb()); + W.draw_filled_polygon(points_list); + + do { + W << (*cc).curve(); + W << cc->source()->point(); + std::cout<curve()<outer_ccb()); + + for (Pmwx::Holes_const_iterator hit = fh->holes_begin(); hit != fh->holes_end(); ++hit, ++hit) { + Pmwx::Ccb_halfedge_const_circulator cc(*hit); + do{ + W << cc->curve(); + //std::cout<curve()<get_first_vertex_above() != NULL && v_iter->get_second_vertex_above() != NULL) + W.set_color(leda_violet); + else if (v_iter->get_first_vertex_above() != NULL && v_iter->get_second_vertex_above() == NULL) + W<get_second_vertex_above() != NULL && v_iter->get_first_vertex_above() == NULL) + W << CGAL::RED; + else + W << CGAL::ORANGE; + + W << v_iter->point(); + } + + if (lt == Pmwx::EDGE){ + if (e.operator->()->get_first_halfedge_above() != NULL) + std::cout<<"edge belongs to first subdivision\n"; + if (e.operator->()->get_second_halfedge_above() != NULL) + std::cout<<"edge belongs to second subdivision\n"; + } + } + } +} + +void scan_pmwx(const char* filename, Pmwx& pmwx) +{ + std::vector curves; + + std::ifstream file(filename); + int num_curves; + file >> num_curves; + while (num_curves--) { + //NT x,y; + double x,y; //(actually int) + file >> x >> y; + NT nx(x),ny(y); + Point s(nx,ny); + file >> x >> y; + NT mx(x),my(y); + Point t(mx,my); + + pmwx.insert(Curve(s,t)); + } + + W << pmwx; +} + + +int main(int argc, char* argv[]) +{ + double x0=-200,x1=200,y0=-200; + + if (argc != 3) { + std::cout << "usage: Segment_sweep_ovl_from_file filename\n"; + exit(1); + } + + W.init(x0,x1,y0); + W.set_redraw(redraw); + W.set_mode(leda_src_mode); + W.set_node_width(3); + W.open_status_window(); + W.button("Exit",4); + W.display(); + + //POINT LOCATION + W.set_status_string( "Enter a point with left button."); + + + scan_pmwx(argv[1],pmwx1); + scan_pmwx(argv[2],pmwx2); + + W << CGAL::RED; + W << pmwx1; + W << CGAL::BLUE; + W << pmwx2; + + std::cout<<"Locate Overlay Face:"< // needed for the LONGNAME flag + +#ifdef CGAL_CFG_NO_LONGNAME_PROBLEM +// Define shorter names to please linker (g++/egcs) +#define Planar_map Pm +#define Arr_leda_segment_exact_traits Alset +#define Bop_default_dcel Bdd +#define Boolean_operation Bo +#define In_place_list_iterator IPLI +#define Arr_2_vertex_base Avb +#define Arr_2_halfedge_base Ahb +#define Arr_2_face_base Afb +#define Point_2 pT +#define Segment_2 sT +#define Topological_map TpM +#define _List_iterator Lit +#define Halfedge hE +#define Forward_circulator_tag Fct +#endif + +#include + +#ifndef CGAL_USE_LEDA +int main() +{ + + std::cout << "Sorry, this demo needs LEDA for visualisation."; + std::cout << std::endl; + + return 0; +} + +#else + +#include +#include +#include + +#include + +#ifndef CGAL_MAP_OVERLAY_DEFAULT_DCEL_H +#include +#endif + +#ifndef CGAL_MAP_OVERLAY_H +#include +#endif + +#include +#include +#include + +#if defined(LEDA_NAMESPACE) +using namespace leda; +#endif + +typedef leda_rational NT; +typedef CGAL::Arr_leda_segment_exact_traits Traits; + +typedef Traits::Point_2 Point; +typedef Traits::Curve_2 Curve; +typedef Traits::X_curve X_curve; + +typedef CGAL::Map_overlay_default_dcel Dcel; +typedef CGAL::Planar_map_2 PM; + +typedef CGAL::Map_overlay_default_notifier Ovl_change_notification; +typedef CGAL::Map_overlay MapOverlay; + +typedef CGAL::Pm_walk_along_line_point_location PmWalkPL; + +//I had to add these in global namespace for the program to compile + +/* + CGAL::Window_stream& operator<<(CGAL::Window_stream& os, + const Point& p) + { + //return os << leda_point(p.xcoordD(),p.ycoordD()); + return os << p.to_point(); + } + + + CGAL::Window_stream& operator<<(CGAL::Window_stream& os, + const X_curve &c) + { + return os << c.to_segment(); + }*/ + +// global variables are used so that the redraw function for the LEDA window +// can be defined to draw information found in these variables. +static PmWalkPL pm_walk1, pm_walk2; +static PM pm1(&pm_walk1); +static PM pm2(&pm_walk2); +static CGAL::Window_stream W(700, 700, "CGAL - Segment Map-Overlay Demo: Sweep Algorithm"); + +/*CGAL_BEGIN_NAMESPACE +Window_stream& operator<<(Window_stream& os, const PM &pm) +{ + My_Arr_drawer< PM, + PM::Ccb_halfedge_const_circulator, + PM::Holes_const_iterator> drawer(os); + + draw_pm(pm, drawer, os); + + return os; +} +CGAL_END_NAMESPACE*/ + +// redraw function for the LEDA window. +// used automatically when window reappears. +void redraw(CGAL::Window_stream * wp) +{ wp->start_buffering(); + wp->clear(); + // draw planar map. + W << CGAL::BLUE; + *wp << pm1; + W << CGAL::RED; + *wp << pm2; + + wp->flush_buffer(); + wp->stop_buffering(); +} + +void draw_and_locate_maps (const MapOverlay& ovl, + const PM& pm1, + const PM& pm2, + CGAL::Window_stream& W) +{ + W << CGAL::BLUE; + W << pm1; + W << CGAL::RED; + W << pm2; + + for (;;) { + double x,y; + + int b = W.read_mouse(x,y); + if (b == 4) + break; + + W.clear(); + W << CGAL::BLUE; + W << pm1; + W << CGAL::RED; + W << pm2; + + const PM& pm = ovl.subdivision(); + + + NT z(x), w(y); + Point p(z, w); + + PM::Locate_type lt; + PM::Halfedge_const_handle e = pm.locate(p, lt); + + PM::Face_const_handle fh = e->face(); + if (lt == PM::UNBOUNDED_FACE) { + std::cout << "UNBOUNDED" << endl; + } + else { + W.set_node_width(4); + + PM::Face_const_handle f1 = ovl.change_notification()->get_first_face_above(fh); + PM::Face_const_handle f2 = ovl.change_notification()->get_second_face_above(fh); + + if (f1 == fh || f2 == fh) + std::cout<<"NULL faces pointers\n"; + + leda_color fg_col; + if (f1 != fh && !(f1->is_unbounded()) && f2 != fh && !(f2->is_unbounded()) ){ + // debug! + cout<<"both maps lay above face"<is_unbounded())){ + cout<<"first map lays above face"<is_unbounded())){ + cout<<"second map lays above face"<outer_ccb(); + + leda_list points_list; + do { + leda_point p = leda_point(CGAL::to_double(cc->source()->point().xcoordD()), + CGAL::to_double(cc->source()->point().ycoordD()) ); + + points_list.push_back(p); + } while (++cc != fh->outer_ccb()); + W.draw_filled_polygon(points_list); + + do { + W << (*cc).curve(); + W << cc->source()->point(); + std::cout<curve()<outer_ccb()); + + for (PM::Holes_const_iterator hit = fh->holes_begin(); hit != fh->holes_end(); ++hit, ++hit) { + PM::Ccb_halfedge_const_circulator cc(*hit); + do{ + W << cc->curve(); + } while (++cc != *hit); + } + + for (PM::Vertex_const_iterator v_iter = pm.vertices_begin(); v_iter != pm.vertices_end(); v_iter++){ + if (v_iter->get_first_vertex_above() != NULL && v_iter->get_second_vertex_above() != NULL) + W.set_color(leda_violet); + else if (v_iter->get_first_vertex_above() != NULL && v_iter->get_second_vertex_above() == NULL) + W<get_second_vertex_above() != NULL && v_iter->get_first_vertex_above() == NULL) + W << CGAL::RED; + else + W << CGAL::ORANGE; + + W << v_iter->point(); + } + + if (lt == PM::EDGE){ + if (e.operator->()->get_first_halfedge_above() != NULL) + std::cout<<"edge belongs to first subdivision\n"; + if (e.operator->()->get_second_halfedge_above() != NULL) + std::cout<<"edge belongs to second subdivision\n"; + } + } + } +} + +void scan_planar_map(const char* filename, PM& pm) +{ + std::vector curves; + + std::ifstream file(filename); + int num_curves; + file >> num_curves; + while (num_curves--) { + //NT x,y; + double x,y; //(actually int) + file >> x >> y; + NT nx(x),ny(y); + Point s(nx,ny); + file >> x >> y; + NT mx(x),my(y); + Point t(mx,my); + + curves.push_back(Curve(s,t)); + } + + Traits traits; + CGAL::sweep_to_construct_planar_map_2(curves.begin(), + curves.end(), + traits, pm); + W << pm; + +} + +int main(int argc, char* argv[]) +{ + double x0=-200,x1=200,y0=-200; + + if (argc != 3) { + std::cout << "usage: Segment_sweep_ovl_from_file filename\n"; + exit(1); + } + + W.init(x0,x1,y0); + W.set_redraw(redraw); + W.set_mode(leda_src_mode); + W.set_node_width(3); + W.open_status_window(); + W.button("Exit",4); + + W.display(); + + scan_planar_map(argv[1],pm1); + scan_planar_map(argv[2],pm2); + + //POINT LOCATION + W.set_status_string( "Enter a point with left button."); + + W << CGAL::RED; + W << pm1; + W << CGAL::BLUE; + W << pm2; + + //MapOverlay_sweep ovl_sweep, pm_sweep1, pm_sweep2; + MapOverlay map1(pm1); + MapOverlay map2(pm2); + MapOverlay map_overlay(map1, map2); + + //MapOverlay map_overlay(pm1, pm2); // makes problem with the pointer to the creators: the two contrsucted overlays of pm1 and pm2 are temporary variables, and hence the pointers to them are not valid. + + std::cout<<"Locate Overlay Face:"<