diff --git a/Packages/Planar_map/demo/Planar_map/Leda_window/README b/Packages/Planar_map/demo/Planar_map/Leda_window/README new file mode 100644 index 00000000000..89d71c23004 --- /dev/null +++ b/Packages/Planar_map/demo/Planar_map/Leda_window/README @@ -0,0 +1,72 @@ +Planar Map Package Demo Program +------------------------------- + + The directory contains a demo program (do "make demo" to compile) +and a utility program for generating input files for the demo program +(do "make helputil" to compile). + There is also a directory "input_files" which contains some input +files in the format needed for the demo program. + +The demo program: +----------------- + + The demo program can be run with a file in the format defined below, +or it can be run without arguments in which case the user builds a planar +map interactively using the mouse. + The left button starts (resp. ends) a new segment at the position of +the mouse. The middle button will start (resp. end) at the nearest existing +vertex. The right button removes the segment directly above it. +Pressing "finish" will end the interactive reading of the planar map. + +After the planar map is read (from the file or interactively) the user can use +the mouse for queries (ray shooting and point location). + +usage: + demo [filename] + + +The helputil program : +------------------- +The program handles input files for the demo program . +The Input file should be at the following format: + + + ... + + + + ... + + Where xi, yi are the coordinates of point i and si,ti +are the indices (in the the above list of points) +of the source and the target of curve i. + + The utilities given are creating a random file of (possibly +intersecting) segments, and splitting of segments in such a file into +a file of non-intersecting segments. +Do not run the demo on a randomly generated file without splitting +the segments via the 'i' parameter. The demo might crash or +disfunction. + +Usages: + +* The first parameter is always 'e' or 'f' indicates that + the input file is: + 'e' --- exact calculations (leda_rationals). + 'f' --- floating point (double). + +1. Split line segments at intersection points: + **** helputil i + +2. Convert rationals file to doubles file (and vice versa) + **** helputil c + +3. Create random (not intersected) file with segments + **** helputil r + + + + + + + diff --git a/Packages/Planar_map/demo/Planar_map/Leda_window/configuration b/Packages/Planar_map/demo/Planar_map/Leda_window/configuration new file mode 100644 index 00000000000..689afaca9bf --- /dev/null +++ b/Packages/Planar_map/demo/Planar_map/Leda_window/configuration @@ -0,0 +1,6 @@ +//#define USE_NAIVE_POINT_LOCATION //for naive strategy +//#define USE_WALK_POINT_LOCATION //for naive strategy +//#define USE_RATIONAL //for leda_rational coordinates +//#define USE_LEDA_RAT_KERNEL //for rational kernel (rat_point,etc..) +//#define CGAL_PM_DEBUG // internal debug flag +//#define CGAL_PM_TIMER // internal timing flag diff --git a/Packages/Planar_map/demo/Planar_map/Leda_window/demo.C b/Packages/Planar_map/demo/Planar_map/Leda_window/demo.C new file mode 100644 index 00000000000..2eb89022093 --- /dev/null +++ b/Packages/Planar_map/demo/Planar_map/Leda_window/demo.C @@ -0,0 +1,244 @@ +#include + +#ifndef CGAL_USE_LEDA +int main() +{ + + std::cout << "Sorry, this demo needs LEDA for visualisation."; + std::cout << std::endl; + + return 0; +} + +#else + +#include "configuration" + +#include +#include + + +#ifdef USE_NAIVE_POINT_LOCATION +#include +#endif +#ifdef USE_WALK_POINT_LOCATION +#include +#endif + +#include "draw_map.h" + +//typedef CGAL::Point_2 Point; +//typedef CGAL::Segment_2 Segment; + +typedef CGAL::Window_stream Window_stream; + +unsigned int delete_restriction=0; + +void redraw(leda_window* wp, double x0, double y0, double x1, double y1) +{ wp->flush_buffer(x0,y0,x1,y1); } + + + +#ifdef CGAL_PM_TIMER +CGAL::Timer t_total,t_construction,t_insert,t_remove,t_locate,t_vertical,t_split,t_merge; +int n_total=0,n_insert=0,n_remove=0,n_locate=0,n_vertical=0,n_split=0,n_merge=0; +#endif + +int test(Planar_map& M,char* name,int argc,char** argv) +{ + Window_stream W(400, 400); + + W.button("finish",10); + W.set_redraw(redraw); + double x0=-1.1,x1=1.1 ,y0=-1.1; + W.init(x0,x1,y0); // logical window size + + W.set_mode(leda_src_mode); + W.set_node_width(3); + W.display(leda_window::center,leda_window::center); + +#ifdef CGAL_PM_TIMER + t_construction.reset(); + t_insert.reset(); + t_remove.reset(); + t_locate.reset(); + t_vertical.reset(); + t_split.reset(); + t_merge.reset(); + n_total=0;n_insert=0;n_remove=0;n_locate=0;n_vertical=0,n_split=0,n_merge=0; +#endif + + if (argc>1) + { +#ifdef CGAL_PM_TIMER + t_construction.start(); +#endif + + if (!Init(argv[1],M)) {std::cerr << "\nBad input file";return true;} +#ifdef CGAL_PM_TIMER + t_construction.stop(); +#endif + win_border(x0,x1,y0,M); //rescale window + W.init(x0,x1,y0); + if (argc>2) + { + Planar_map::Locate_type lt; + std::ifstream in(argv[2]); + if (in.bad()) {std::cerr << "\nBad locate input file";return false;} + unsigned int i,n_pt; in >> n_pt; + // bool first=true; + Planar_map::Point* p=new Planar_map::Point[n_pt]; + + for (i=0;i> x >> y ; + p[i]=Planar_map::Point(x,y); + } + do + { +#ifdef CGAL_PM_TIMER + t_locate.start(); +#endif + for(i=0;i" << std::flush; + n_remove++; +#endif + } + } + } + else + { + W.set_redraw(redraw); + W.set_mode(leda_src_mode); + W.set_node_width(3); + W.display(leda_window::center,leda_window::center); + draw_pm(M,W); + } + } + else + { + W << CGAL::GREEN; + window_input(M,W); + CGAL::Window_stream W2(400, 400); + W2.init(x0,x1,y0); + W2.set_mode(leda_src_mode); + W2.set_node_width(3); + W2.button("quit",10); + W2.display(leda_window::max,leda_window::center); + draw_pm(M,W2); + } + +#ifdef CGAL_PM_TIMER + if (delete_restriction) + { + std::cout << "\n" << name << " " << t_construction.time() << " " << + t_insert.time()/n_insert << " " << + t_locate.time()/n_locate << " " << + t_remove.time()/n_remove << " " << + t_vertical.time()/n_vertical << " cilrv" ; + } + else if (argc>2) + { + std::cout << "\n" << name << " " << t_construction.time() << " " << + t_insert.time()/n_insert << " " << + t_locate.time()/n_locate << " " << + t_vertical.time()/n_vertical << " cilv"; + } + else // (argc>1) + { + std::cout << "\n" << name << t_construction.time() << " " << + t_insert.time()/n_insert << " " << + t_locate.time()/n_locate << " cil"; + } +#endif + return true; +} + +int main(int argc, char* argv[]) +{ +#ifdef CGAL_PM_TIMER + t_total.reset(); + t_total.start(); + t_construction.reset(); + t_insert.reset(); + t_remove.reset(); + t_locate.reset(); + t_vertical.reset(); +#endif + +#ifdef USE_NAIVE_POINT_LOCATION +#ifdef USE_DEFAULT_WITHOUT_REBUILD +#error USE one point location +#endif +#ifdef USE_WALK_POINT_LOCATION +#error USE one point location +#endif + CGAL::Pm_naive_point_location naive_pl; + Planar_map M(&naive_pl); + test(M,"naive",argc,argv); + std::cout << std::endl; +#else +#if defined(USE_WALK_POINT_LOCATION) +#ifdef USE_NAIVE_POINT_LOCATION +#error USE one point location +#endif +#ifdef USE_DEFAULT_WITHOUT_REBUILD +#error USE one point location +#endif + CGAL::Pm_walk_along_line_point_location pl; + Planar_map M(&pl); + test(M,"walk_along_line",argc,argv); + std::cout << std::endl; +#else +#if defined(USE_DEFAULT_WITHOUT_REBUILD) +#ifdef USE_NAIVE_POINT_LOCATION +#error USE one point location +#endif +#ifdef USE_WALK_POINT_LOCATION +#error USE one point location +#endif + CGAL::Pm_default_point_location pl(false); + Planar_map M(&pl); + test(M,"default_without_rebuilding",argc,argv); + std::cout << std::endl; +#else + Planar_map M; + test(M,"default",argc,argv); + std::cout << std::endl; +#endif +#endif +#endif + return 0; +} + +#endif // CGAL_USE_LEDA diff --git a/Packages/Planar_map/demo/Planar_map/Leda_window/draw_map.C b/Packages/Planar_map/demo/Planar_map/Leda_window/draw_map.C new file mode 100644 index 00000000000..47cf4925fee --- /dev/null +++ b/Packages/Planar_map/demo/Planar_map/Leda_window/draw_map.C @@ -0,0 +1,533 @@ +#include + +// if LEDA is not installed, a message will be issued in runtime. +#ifdef CGAL_USE_LEDA + +#include +#include +#include +#include "draw_map.h" +#include "read_inp.h" + +/*========================================================================= + * Start of Code + \*=========================================================================*/ + + +void MarkCcb (const Ccb_halfedge_circulator & b, std::list& l) +{ + Ccb_halfedge_circulator first = b, iter = b; + do + { + l.push_back(iter->curve()); + iter++; + } + while (iter != first); +} + + + +void draw_arrow(Pm_point p1, Pm_point p2, bool black, CGAL::Window_stream & W) +{ + if (black) + W << CGAL::BLACK; + else + W << CGAL::WHITE; + + //float + number_type ar_size=(W.xmax()-W.xmin())/20 ; + + W << Pm_curve (p1, p2); +#ifndef USE_LEDA_RAT_KERNEL + W << Pm_curve(p2, Pm_point (p2.x () - ar_size , p2.y () - ar_size)); + W << Pm_curve(p2, Pm_point (p2.x () + ar_size , p2.y () - ar_size)); +#else + W << Pm_curve(p2, Pm_point (p2.xcoord () - ar_size, p2.ycoord () - ar_size)); + W << Pm_curve(p2, Pm_point (p2.xcoord () + ar_size, p2.ycoord () - ar_size)); +#endif +} + +void Draw (CGAL::Window_stream & W , Planar_map & pm) +{ + W.set_flush( 0 ); + + Vertex_iterator vi; + for (vi = pm.vertices_begin (); vi != pm.vertices_end (); vi++) + { + W << CGAL::GREEN; + W << (*vi).point(); + } + + Halfedge_iterator ei; + for (ei = pm.halfedges_begin (); ei != pm.halfedges_end (); ei++) + { + W << CGAL::BLUE; + W << ((*ei).curve()); + } + + W.set_flush( 1 ); + W.flush(); +} + +bool VerticalRayShoot (Pm_point p, Pm_point & q, bool up , Planar_map &pm) +{ + Halfedge_handle e; + Planar_map::Locate_type lt; + number_type y_min, y_max, y_arrow_tip; + +#ifdef CGAL_PM_TIMER + t_vertical.start(); +#endif + e=pm.vertical_ray_shoot (p,lt, up); +#ifdef CGAL_PM_TIMER + t_vertical.stop(); + n_vertical++; +#endif + if (lt!=Planar_map::UNBOUNDED_FACE) + { + Pm_point p1 = e->source()->point(); + Pm_point p2 = e->target()->point(); + // make the arrow point upwards and touch the found segment: +#ifndef USE_LEDA_RAT_KERNEL + if (p1.x() == p2.x()) + { + // the found segment is vertical + y_min = std::min (p1.y(), p2.y()); + y_max = std::max (p1.y(), p2.y()); + y_arrow_tip = (p.y() < y_min) ? y_min : y_max; + q = Pm_point(p.x(), y_arrow_tip); + } + else + { + y_arrow_tip = p2.y()- + ((p2.x()-p.x())*(p2.y()-p1.y()))/(p2.x()-p1.x()); + q = Pm_point(p.x(), y_arrow_tip); + } +#else + if (p1.xcoord() == p2.xcoord()) + { + // the found segment is vertical + y_min = std::min (p1.ycoord(), p2.ycoord()); + y_max = std::max (p1.ycoord(), p2.ycoord()); + y_arrow_tip = (p.ycoord() < y_min) ? y_min : y_max; + q = Pm_point(p.xcoord(), y_arrow_tip); + } + else + { + y_arrow_tip = p2.ycoord()- + ((p2.xcoord()-p.xcoord())*(p2.ycoord()-p1.ycoord()))/ + (p2.xcoord()-p1.xcoord()); + q = Pm_point(p.xcoord(), y_arrow_tip); + } +#endif + return true; + } + else + { + return false; + } +} + +void FindFace (const Pm_point& p , Planar_map &pm, std::list& l) +{ + Planar_map::Locate_type lt; +#ifdef CGAL_PM_TIMER + t_vertical.start(); +#endif + Halfedge_handle e = pm.vertical_ray_shoot (p, lt, true); +#ifdef CGAL_PM_TIMER + t_vertical.stop(); + n_vertical++; +#endif + Face_handle f; + + if (lt!=Planar_map::UNBOUNDED_FACE) + { + f = e->face (); + } + else + { + f = pm.unbounded_face (); + } + + Ccb_halfedge_circulator ccb_circ; + + if (f->does_outer_ccb_exist ()) + { + ccb_circ = f->halfedge_on_outer_ccb()->ccb(); + MarkCcb (ccb_circ,l); + } + + Planar_map::Holes_iterator iccbit; + for (iccbit = f->holes_begin (); iccbit != f->holes_end (); ++iccbit) + { + MarkCcb (*iccbit,l); + } + +} + + + + +int draw_pm (Planar_map & pm , CGAL::Window_stream & W) +{ + + std::list l; + Pm_point pnt (20, 20); + Pm_point ar1, ar2; + int mbutton = 0; + double x, y; + + std::cerr << "Drawing the map:" << std::endl; + Draw (W,pm); + + std::cerr << "1.Left button: vertical ray shooting." << std::endl; + std::cerr << "2.Middle button: point location." << std::endl; + std::cerr << "3.Right button: exit" << std::endl; + + while (mbutton != 3) + { + int b=W.read_mouse(x,y); + if (b==10) return 0; + + mbutton = -b; + // pnt = Pm_point (x, y); +#ifndef USE_LEDA_RAT_KERNEL + pnt = Pm_point(Rep::FT(x), + Rep::FT(y)); +#else + pnt = Pm_point(leda_rational(x),leda_rational(y)); +#endif + + draw_arrow (ar1, ar2, false,W); + if (mbutton == 1) + { + ar1 = pnt; + if (VerticalRayShoot (ar1, ar2, true,pm)) + draw_arrow (ar1, ar2, true,W); + } + + if (mbutton == 2) + { + FindFace (pnt,pm,l); + } + + if (mbutton != 0) + { + Draw (W,pm); + W << CGAL::RED; + for (std::list::iterator lit=l.begin(); lit!=l.end(); ++lit) + W << *lit; + l.erase(l.begin(),l.end()); + } + } + + return 0; +} + +//------------------------------------------------------------------- +bool ReadFile(char *filename, int &num_points, Pm_point* &pnts, + int &num_curves, Pm_curve* &cvs ) +{ + int j, k; + + std::ifstream is(filename); + if (is.bad()) return false; + PM_input inp; + is >> inp; + is.close(); + + num_points = inp.get_num_pnts(); + num_curves = inp.get_num_cvs(); + pnts = new Pm_point[num_points]; + cvs = new Pm_curve[num_curves]; + + int i; + for(i = 0; i < num_points; i++) + { + inp.get(i, pnts[i]); + } + + for(i = 0; i < inp.get_num_cvs(); i++) + { + inp.get(i, k, j); + cvs[i] = Pm_curve(pnts[k], pnts[j]); + } + + return true; + +} +//---------------------------------------------------------------- + +void win_border( double &x0 , double &x1 , double &y0 ,Planar_map &pm) +{ + Vertex_iterator vit = pm.vertices_begin(); +#ifndef USE_LEDA_RAT_KERNEL + x0=x1=CGAL::to_double(( vit->point() ).x()); + y0=CGAL::to_double(( vit->point() ).y()); +#else + x0=x1=vit->point().xcoordD(); + y0=vit->point().ycoordD(); +#endif + + while (vit!=pm.vertices_end()) + { +#ifndef USE_LEDA_RAT_KERNEL + if ( ((*vit).point() ).x() < x0 ) + x0 = CGAL::to_double(( (*vit).point() ).x()) ; + if ( ( (*vit).point() ).x() > x1 ) + x1 = CGAL::to_double(( (*vit).point() ).x()) ; + if ( ( (*vit).point() ).y() < y0 ) + y0 = CGAL::to_double(( (*vit).point() ).y()) ; +#else + if ( vit->point().xcoordD() < x0 ) + x0 = vit->point().xcoordD() ; + if ( vit->point().xcoordD() > x1 ) + x1 = vit->point().xcoordD() ; + if ( vit->point().ycoordD() < y0 ) + y0 = vit->point().ycoordD() ; +#endif + vit++; + } + + x0=x0-(x1-x0)/2; + x1=x1+(x1-x0)/3; + y0=y0-(x1-x0)/4; + + if (x1<=x0) + std::cerr << "\nIf you are trying to read an input file " + << "(e.g. from input_files directory)," + << "\nmake sure to define the " + << "USE_RATIONAL flag whenever you are reading exact input " + << "\n(i.e. *.e files), otherwise avoid using this flag." + << "\nexample: demo input_files\\window.f\n"; + // CGAL_postcondition(x1>x0); +} + +//DEBUG +//bool Init (char *filename , Planar_map & pm, CGAL::Window_stream& W) +bool Init (char *filename , Planar_map & pm) +{ + int num_points, num_curves, i; + Pm_point *pnts; + Pm_curve *cvs; + +#ifdef CGAL_PM_TIMER + // ReadFile shouldn't be included in construction time. + t_construction.stop(); +#endif + if (!ReadFile (filename, num_points, pnts, num_curves, cvs )) + return false; + +#ifdef CGAL_PM_TIMER + t_construction.start(); +#endif + + for (i = 0; i < num_curves; i++) + { +#ifdef CGAL_PM_DEBUG + std::cout << "inserting curve: i\n"; + std::cout << cvs[i] << std::endl; + // W << cvs[i] ; +#endif +#ifdef CGAL_PM_TIMER + t_insert.start(); +#endif + pm.insert (cvs[i]); +#ifdef CGAL_PM_TIMER + t_insert.stop(); + n_insert++; +#endif + } + + delete[] cvs; + delete[] pnts; + + return true; +} + +/////////////////////////////////////////////////////////////////////// + +CGAL::Window_stream& operator<<(CGAL::Window_stream& os, Planar_map &M) +{ + Halfedge_iterator it = M.halfedges_begin(); + + while(it != M.halfedges_end()){ + os << (*it).curve(); + ++it; + } + + return os; +} + +//function needed for window input +Vertex_handle closest_vertex(Planar_map &M, const Pm_point& p) +{ + Vertex_handle v; + Vertex_iterator vi = M.vertices_begin(); + if (vi==M.vertices_end()) + return vi; + else v=vi; +#ifndef USE_LEDA_RAT_KERNEL + Rep::FT d = CGAL::squared_distance(p, (*vi).point()); + for (; vi!=M.vertices_end(); ++vi) + { + Rep::FT d2 = CGAL::squared_distance(p, (*vi).point()); + if(d2 < d){ + d = d2; + v = vi; + } + } + +#else + for (; vi!=M.vertices_end(); ++vi) + if(p.cmp_dist(vi->point(),v->point())<0){v = vi;} +#endif + + return v; +} + +void window_input(Planar_map & M, CGAL::Window_stream &W ) +{ + std::cerr << "1.Left button: start or end edge at mouse position." + << std::endl; + std::cerr << "2.Middle button: start or end edge at closest vertex \ +from mouse position" + << std::endl; + std::cerr << "3.Right button: remove the edge directly above the mouse \ +position" + << std::endl; + + Pm_point p; + Pm_point first_point; +// Vertex_handle last_vertex; + + bool start_flag = true; + + while(1) { + double x, y; + int b = W.get_mouse(x,y); + if (b==10) break; +#ifndef USE_LEDA_RAT_KERNEL + p = Pm_point(Rep::FT(x), Rep::FT(y)); +#else + p = Pm_point(leda_rational(x),leda_rational(y)); +#endif + + if (b == MOUSE_BUTTON(1)) + { + if (start_flag) + { + first_point=p; + start_flag=false; + } + else + { + start_flag=true; +#ifdef CGAL_PM_TIMER + t_insert.start(); +#endif +#ifdef CGAL_PM_DEBUG + Halfedge_handle e= +#endif + + M.insert(Pm_curve(first_point,p)); + +#ifdef CGAL_PM_TIMER + t_insert.stop(); + n_insert++; +#endif +#ifdef CGAL_PM_DEBUG + Traits_wrap traits=M.get_traits(); + CGAL_postcondition(traits.point_equal(e->source()->point(), + first_point)); + CGAL_postcondition(traits.point_equal(e->target()->point(),p)); +#endif + } + + W << M; + } + + else + if (b==MOUSE_BUTTON(2)) + { + if (M.number_of_vertices()==0) { //an empty map do nothing + start_flag=true; + } + else { + Vertex_handle v=closest_vertex(M,p); + + if (start_flag) { + first_point=v->point(); + start_flag=false; + } + else //insert fromfirst_point to nearest + { +#ifdef CGAL_PM_TIMER + t_insert.start(); +#endif +#ifdef CGAL_PM_DEBUG + Halfedge_handle e= +#endif + + M.insert(Pm_curve(first_point,v->point())); + +#ifdef CGAL_PM_TIMER + t_insert.stop(); + n_insert++; +#endif +#ifdef CGAL_PM_DEBUG + Traits_wrap traits=M.get_traits(); + CGAL_postcondition(traits.point_equal(e->source()->point(), + first_point)); + CGAL_postcondition(traits.point_equal(e->target()->point(), + v->point())); +#endif + start_flag=true; + } + } + + W << M; + } + + else if(b == MOUSE_BUTTON(3)) + { + start_flag=true; + Planar_map::Locate_type l; + Halfedge_handle e; +#ifdef CGAL_PM_TIMER + t_vertical.start(); +#endif + e=M.vertical_ray_shoot(p,l,true); +#ifdef CGAL_PM_TIMER + t_vertical.stop(); + n_vertical++; +#endif + if (l!=Planar_map::UNBOUNDED_FACE) + { +#ifdef CGAL_PM_TIMER + t_remove.start(); +#endif + M.remove_edge(e); +#ifdef CGAL_PM_TIMER + t_remove.stop(); + n_remove++; +#endif + W.clear(); + W << M; + +#ifdef CGAL_PM_DEBUG + std::cout << "\nremove()" << std::flush; + M.debug(); +#endif + } + } + + if (!M.is_valid()) { + std::cerr << "map is not valid - aborting" << std::endl; + exit(1); + } + } +} + +#endif diff --git a/Packages/Planar_map/demo/Planar_map/Leda_window/draw_map.h b/Packages/Planar_map/demo/Planar_map/Leda_window/draw_map.h new file mode 100644 index 00000000000..6863e568d3e --- /dev/null +++ b/Packages/Planar_map/demo/Planar_map/Leda_window/draw_map.h @@ -0,0 +1,112 @@ +#ifndef __DRAW_MAP_H +#define __DRAW_MAP_H + +#include + +// if LEDA is not installed, a message will be issued in runtime by demo.C. +#ifdef CGAL_USE_LEDA + +#include "configuration" + +#include +#include +#include +#include +#include + +#include +#ifdef USE_RATIONAL +#include +#else +#if defined (USE_LEDA_RAT_KERNEL) +#include +#endif +#endif + +#include +#include + +#include + +//#define CGAL_PM_DEBUG +#ifdef CGAL_PM_DEBUG +#include +#endif + +#ifdef CGAL_PM_TIMER +#include +#endif + +#define BUNDLE 100 +#define WIDE_PRECISION 10 + +#if defined(USE_RATIONAL) || defined(USE_LEDA_RAT_KERNEL) +#if defined(USE_RATIONAL) && defined(USE_LEDA_RAT_KERNEL) +#error only one kernel should be defined +#endif +typedef leda_rational number_type; +#else +typedef double number_type; +#endif + +#ifdef USE_LEDA_RAT_KERNEL +typedef CGAL::leda_rat_kernel_traits Rep; +#else +typedef CGAL::Cartesian Rep; +#endif + +typedef CGAL::Pm_segment_traits_2 Traits; + +typedef CGAL::Pm_default_dcel Dcel; +typedef CGAL::Planar_map_2 Planar_map; +typedef Planar_map::Traits_wrap Traits_wrap; + +typedef Planar_map::Vertex Vertex; +typedef Planar_map::Halfedge Halfedge; +typedef Planar_map::Face Face; + +typedef Planar_map::Vertex_handle Vertex_handle; +typedef Planar_map::Halfedge_handle Halfedge_handle; +typedef Planar_map::Face_handle Face_handle; + +typedef Planar_map::Vertex_iterator Vertex_iterator; +typedef Planar_map::Halfedge_iterator Halfedge_iterator; + +typedef Planar_map::Ccb_halfedge_circulator Ccb_halfedge_circulator; + +typedef Traits::Point Pm_point; +typedef Traits::X_curve Pm_curve; + + +extern int draw_pm (Planar_map & pm , CGAL::Window_stream & W); + +extern bool Init (char *filename , Planar_map & pm) ; + +extern void win_border( double &x0 , double &x1 , double &y0 , + Planar_map &pm); + +extern CGAL::Window_stream& operator<<(CGAL::Window_stream& os, + Planar_map &M); + +extern void window_input(Planar_map & M, CGAL::Window_stream &W ); + +#ifdef CGAL_PM_TIMER +extern CGAL::Timer t_total,t_construction,t_insert,t_remove,t_locate,t_vertical; +extern int n_total,n_insert,n_remove,n_locate,n_vertical; +#endif + +/* move to Eyals leda_rat ? */ +#ifdef USE_LEDA_RAT_KERNEL +inline CGAL::Window_stream& operator<<(CGAL::Window_stream& os, const Pm_point& p){ + return os << leda_point(p.xcoordD(),p.ycoordD()); + } +inline CGAL::Window_stream& operator<<(CGAL::Window_stream& os, const Pm_curve& c){ + leda_segment s(c.xcoord1D(),c.ycoord1D(),c.xcoord2D(),c.ycoord2D()); + return os << s; + } +#endif + +#endif // CGAL_USE_LEDA + +#endif // __DRAW_MAP_H + diff --git a/Packages/Planar_map/demo/Planar_map/Leda_window/helputil.C b/Packages/Planar_map/demo/Planar_map/Leda_window/helputil.C new file mode 100644 index 00000000000..e03eb165e53 --- /dev/null +++ b/Packages/Planar_map/demo/Planar_map/Leda_window/helputil.C @@ -0,0 +1,428 @@ +#include + +// if LEDA is not installed, a message will be issued in runtime. +#ifndef CGAL_USE_LEDA +int main() +{ + + std::cout << "Sorry, helputil needs LEDA.."; + std::cout << std::endl; + + return 0; +} + +#else + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include "read_inp.h" +#include "inter.h" + + +typedef PM_input< CGAL::Cartesian > pminpD; +typedef pminpD::Point pntD; + +typedef PM_input< CGAL::Cartesian > pminpR; +typedef pminpR::Point pntR; + +void print_help() +{ + std::cout << "Utilities program for CGAL Planar Map package" << std::endl; + std::cout << "---------------------------------------------" << std::endl; + std::cout << "The program handles input files for the Planar Map"; + std::cout << std::endl; + std::cout << "example program dctest." << std::endl; + std::cout << "The Input file should be at the following format:"; + std::cout << std::endl; + std::cout << " " << std::endl; + std::cout << " " << std::endl; + std::cout << " ..." << std::endl; + std::cout << " " << std::endl; + std::cout << " " << std::endl; + std::cout << " " << std::endl; + std::cout << " ..." << std::endl; + std::cout << " " << std::endl; + std::cout << " Where xi, yi are the coordinates of point i (for "; + std::cout << std::endl; + std::cout << " rational version in rational format), and si, ti "; + std::cout << std::endl; + std::cout << " are the indices (in the the above list of points) "; + std::cout << std::endl; + std::cout << " of the source and the target of curve i." << std::endl; + std::cout << "" << std::endl; + std::cout << "Usages:" << std::endl; + std::cout << "* The first parameter is always 'e' or 'f' indicates that "; + std::cout << std::endl; + std::cout << " the input file is:" << std::endl; + std::cout << " 'e' --- exact calculations (leda_rationals)." << std::endl; + std::cout << " 'f' --- floating point (double)." << std::endl; + std::cout << "" << std::endl; + std::cout << "1. Intersect Line Segments:" << std::endl; + std::cout << " **** helputil i "; + std::cout << std::endl; + std::cout << " " << std::endl; + std::cout << "2. Convert rationals file to doubles file (and vice versa)"; + std::cout << std::endl; + std::cout << " **** helputil c "; + std::cout << std::endl; + std::cout << "" << std::endl; + std::cout << "3. Create random (not intersected) file with segments"; + std::cout << std::endl; + std::cout << " **** helputil r " << std::endl; + + std::cin.get(); + exit(1); +} + +void convert(const pminpR &i1, pminpD &i2) + // convert from rationals to doubles +{ + i2.alloc(i1.get_num_pnts(), i1.get_num_cvs()); + pntD pD; + pntR pR; + int i,k, j; + + + for(i = 0; i < i1.get_num_pnts(); i++) + { + i1.get(i, pR); + pD = pntD(CGAL::to_double(pR.x()), CGAL::to_double(pR.y())); + i2.set(i, pD); + } + + for(i = 0; i < i1.get_num_cvs(); i++) + { + i1.get(i, k, j); + i2.set(i, k, j); + } +} + +void convert(const pminpD &i1, pminpR &i2) + // convert from rationals to doubles +{ + i2.alloc(i1.get_num_pnts(), i1.get_num_cvs()); + pntD pD; + pntR pR; + int i,k, j; + + for(i = 0; i < i1.get_num_pnts(); i++) + { + i1.get(i, pD); + pR = pntR(leda_rational(pD.x()), leda_rational(pD.y())); + i2.set(i, pR); + } + + for(i = 0; i < i1.get_num_cvs(); i++) + { + i1.get(i, k, j); + i2.set(i, k, j); + } +} + +void intersect(const pminpD &in, pminpD &out) +{ + pntD p; + int k, j; + Lines l(1); + int nc, np; + int intr_nc, intr_np; + + nc = in.get_num_cvs(); + np = in.get_num_pnts(); + + Lines::pmcurve *cvs = new Lines::pmcurve[nc]; + Lines::pmpoint *pnts = new Lines::pmpoint[np]; + + Lines::pmcurve *intr_cvs; + Lines::pmpoint *intr_pnts; + + int i; + for(i = 0; i < in.get_num_pnts(); i++) + { + in.get(i, p); + pnts[i].x = p.x(); + pnts[i].y = p.y(); + pnts[i].n = i; + } + + for(i = 0; i < in.get_num_cvs(); i++) + { + in.get(i, k, j); + cvs[i].s = pnts[k]; + cvs[i].t = pnts[j]; + } + + l.Intersect(pnts, np, cvs, nc, intr_pnts, intr_np, intr_cvs, intr_nc); + + out.alloc(intr_np, intr_nc); + + for(i = 0; i < intr_np; i++) + { + p = pntD(intr_pnts[i].x, intr_pnts[i].y); + out.set(i, p); + } + + for(i = 0; i < intr_nc; i++) + { + out.set(i, intr_cvs[i].s.n, intr_cvs[i].t.n); + } + + if (cvs != NULL) delete[] cvs; + if (pnts != NULL) delete[] pnts; + if (intr_cvs != NULL) delete[] intr_cvs; + if (intr_pnts != NULL) delete[] intr_pnts; + +} + +void intersect(const pminpR &in, pminpR &out) +{ + pntR p; + int k, j; + Lines l(0); + int nc, np; + int intr_nc, intr_np; + + nc = in.get_num_cvs(); + np = in.get_num_pnts(); + + Lines::pmcurve *cvs = new Lines::pmcurve[nc]; + Lines::pmpoint *pnts = new Lines::pmpoint[np]; + + Lines::pmcurve *intr_cvs; + Lines::pmpoint *intr_pnts; + + int i; + for(i = 0; i < in.get_num_pnts(); i++) + { + in.get(i, p); + pnts[i].x = p.x(); + pnts[i].y = p.y(); + pnts[i].n = i; + } + + for(i = 0; i < in.get_num_cvs(); i++) + { + in.get(i, k, j); + cvs[i].s = pnts[k]; + cvs[i].t = pnts[j]; + } + + l.Intersect(pnts, np, cvs, nc, intr_pnts, intr_np, intr_cvs, intr_nc); + + out.alloc(intr_np, intr_nc); + + for(i = 0; i < intr_np; i++) + { + p = pntR(intr_pnts[i].x, intr_pnts[i].y); + out.set(i, p); + } + + for(i = 0; i < intr_nc; i++) + { + out.set(i, intr_cvs[i].s.n, intr_cvs[i].t.n); + } + + if (cvs != NULL) delete[] cvs; + if (pnts != NULL) delete[] pnts; + if (intr_cvs != NULL) delete[] intr_cvs; + if (intr_pnts != NULL) delete[] intr_pnts; + +} + + +void random(int num, pminpD &out, int max = 200) +{ + srand( (unsigned)time( NULL ) ); + out.alloc(num*2, num); + pntD p; + int i; + + for (i =0; i < num*2; i++) + { + p = pntD(rand() % max, rand() % max); + out.set(i, p); + } + + for (i =0; i < num; i++) + { + out.set(i, i*2, i*2+1); + } +} + +void random(int num, pminpR &out, int max = 200) +{ + srand( (unsigned)time( NULL ) ); + out.alloc(num*2, num); + pntR p; + + int i; + for (i =0; i < num*2; i++) + { + p = pntR(leda_rational(rand() % max), + leda_rational(rand() % max)); + out.set(i, p); + } + + for (i =0; i < num; i++) + { + out.set(i, i*2, i*2+1); + } +} + +int main(int argc, char *argv[]) +{ + if (argc < 3) + print_help(); + + bool use_rational; + + switch (argv[1][0]) + { + case 'e': + use_rational = true; + break; + case 'f': + use_rational = false; + break; + default: + print_help(); + }; + + + switch (argv[2][0]) + { + case 'r': // generate random file argv[4] with argv[3] curves + if (argc < 5) + print_help(); + + if (use_rational) + { + std::cout << "Create random file using rationals with "; + std::cout << CGAL_CLIB_STD::atoi(argv[3]) + << "segments" << std::endl; + std::cout << "Attention: the segments might intersect."; + std::cout << std::endl; + std::cout << " Split them using the i parameter of " + "helputil before running the demo."; + std::cout << std::endl; + pminpR rnd; + random(CGAL_CLIB_STD::atoi(argv[3]), rnd); + std::ofstream f(argv[4]); + f << rnd; + f.close(); + } + else + { + std::cout << "Create random file using doubles with "; + std::cout << CGAL_CLIB_STD::atoi(argv[3]) + << " segments" << std::endl; + std::cout << "Attention: the segments might intersect."; + std::cout << std::endl; + std::cout << "Split them using the i parameter of helputil " + "before running the demo"; + std::cout << std::endl; + pminpD rnd; + random(CGAL_CLIB_STD::atoi(argv[3]), rnd); + std::ofstream f(argv[4]); + f << rnd; + f.close(); + } + break; + + case 'i': // intersect argv[3] to argv[4] + if (argc < 5) + print_help(); + std::cout << "Intersect the segments in " << argv[3] + << " and write the intersected segments in "; + std::cout << argv[4] << std::endl; + + if (use_rational) + { + pminpR inpR1; + pminpR inpR2; + + std::ifstream in(argv[3]); + in >> inpR1; + in.close(); + + intersect(inpR1, inpR2); + + std::ofstream out(argv[4]); + out << inpR2; + out.close(); + } + else + { + pminpD inpD1; + pminpD inpD2; + + std::ifstream in(argv[3]); + in >> inpD1; + in.close(); + + intersect(inpD1, inpD2); + + std::ofstream out(argv[4]); + out << inpD2; + out.close(); + } + break; + + case 'c': // convert argv[3] to argv[4] switching from rationals to doubles + if (argc < 5) + print_help(); + + std::cout << "Convert the numbers in " << argv[3] + << " and write the new file " << argv[4] << std::endl; + + if (use_rational) + { + pminpR inpR; + pminpD inpD; + + std::ifstream in(argv[3]); + in >> inpR; + in.close(); + + convert(inpR, inpD); + + std::ofstream out(argv[4]); + out << inpD; + out.close(); + } + else + { + pminpR inpR; + pminpD inpD; + + std::ifstream in(argv[3]); + in >> inpD; + in.close(); + + convert(inpD, inpR); + + std::ofstream out(argv[4]); + out << inpR; + out.close(); + } + + break; + + default: + print_help(); + break; + }; + + + return 0; +} + +#endif // CGAL_USE_LEDA diff --git a/Packages/Planar_map/demo/Planar_map/Leda_window/input_files/grid.e b/Packages/Planar_map/demo/Planar_map/Leda_window/input_files/grid.e new file mode 100644 index 00000000000..71b6e547357 --- /dev/null +++ b/Packages/Planar_map/demo/Planar_map/Leda_window/input_files/grid.e @@ -0,0 +1,64 @@ +24 +10/1 10/1 +50/1 10/1 +90/1 10/1 +130/1 10/1 +170/1 10/1 +210/1 10/1 +10/1 50/1 +50/1 50/1 +90/1 50/1 +130/1 50/1 +170/1 50/1 +210/1 50/1 +10/1 90/1 +50/1 90/1 +90/1 90/1 +130/1 90/1 +170/1 90/1 +210/1 90/1 +10/1 130/1 +50/1 130/1 +90/1 130/1 +130/1 130/1 +170/1 130/1 +210/1 130/1 +38 +20 21 +1 7 +13 14 +3 9 +4 10 +6 12 +21 22 +11 17 +3 4 +12 18 +16 22 +0 6 +22 23 +9 15 +9 10 +15 21 +1 2 +19 20 +2 3 +8 14 +10 16 +7 8 +7 13 +16 17 +14 15 +2 8 +13 19 +14 20 +6 7 +10 11 +17 23 +18 19 +0 1 +5 11 +12 13 +8 9 +4 5 +15 16 diff --git a/Packages/Planar_map/demo/Planar_map/Leda_window/input_files/grid.f b/Packages/Planar_map/demo/Planar_map/Leda_window/input_files/grid.f new file mode 100644 index 00000000000..00bb288d883 --- /dev/null +++ b/Packages/Planar_map/demo/Planar_map/Leda_window/input_files/grid.f @@ -0,0 +1,64 @@ +24 +10 10 +50 10 +90 10 +130 10 +170 10 +210 10 +10 50 +50 50 +90 50 +130 50 +170 50 +210 50 +10 90 +50 90 +90 90 +130 90 +170 90 +210 90 +10 130 +50 130 +90 130 +130 130 +170 130 +210 130 +38 +20 21 +1 7 +13 14 +3 9 +4 10 +6 12 +21 22 +11 17 +3 4 +12 18 +16 22 +0 6 +22 23 +9 15 +9 10 +15 21 +1 2 +19 20 +2 3 +8 14 +10 16 +7 8 +7 13 +16 17 +14 15 +2 8 +13 19 +14 20 +6 7 +10 11 +17 23 +18 19 +0 1 +5 11 +12 13 +8 9 +4 5 +15 16 diff --git a/Packages/Planar_map/demo/Planar_map/Leda_window/input_files/md.e b/Packages/Planar_map/demo/Planar_map/Leda_window/input_files/md.e new file mode 100644 index 00000000000..5ed35a90ed8 --- /dev/null +++ b/Packages/Planar_map/demo/Planar_map/Leda_window/input_files/md.e @@ -0,0 +1,41 @@ +14 +120/1 10/1 +20/1 63/1 +87/1 63/1 +155/1 63/1 +220/1 63/1 +53/1 120/1 +187/1 120/1 +20/1 180/1 +87/1 180/1 +155/1 180/1 +220/1 180/1 +120/1 240/1 +100/1 120/1 +140/1 120/1 +25 +12 13 +9 10 +3 4 +5 8 +9 11 +6 9 +4 6 +0 2 +5 2 +8 11 +1 5 +5 7 +1 2 +6 10 +2 3 +3 6 +0 3 +8 9 +7 8 +5 12 +9 13 +8 12 +2 12 +3 13 +13 6 diff --git a/Packages/Planar_map/demo/Planar_map/Leda_window/input_files/md.f b/Packages/Planar_map/demo/Planar_map/Leda_window/input_files/md.f new file mode 100644 index 00000000000..fe78f9ca0e0 --- /dev/null +++ b/Packages/Planar_map/demo/Planar_map/Leda_window/input_files/md.f @@ -0,0 +1,41 @@ +14 +120 10 +20 63 +87 63 +155 63 +220 63 +53 120 +187 120 +20 180 +87 180 +155 180 +220 180 +120 240 +100 120 +140 120 +25 +12 13 +9 10 +3 4 +5 8 +9 11 +6 9 +4 6 +0 2 +5 2 +8 11 +1 5 +5 7 +1 2 +6 10 +2 3 +3 6 +0 3 +8 9 +7 8 +5 12 +9 13 +8 12 +2 12 +3 13 +13 6 diff --git a/Packages/Planar_map/demo/Planar_map/Leda_window/input_files/mess.e b/Packages/Planar_map/demo/Planar_map/Leda_window/input_files/mess.e new file mode 100644 index 00000000000..fe32b3b60f7 --- /dev/null +++ b/Packages/Planar_map/demo/Planar_map/Leda_window/input_files/mess.e @@ -0,0 +1,116 @@ +41 +10/1 100/1 +200/1 140/1 +200/1 180/1 +80/1 250/1 +80/1 15/1 +200/1 60/1 +10/1 60/1 +10/1 220/1 +160/1 2314762247538213/17592186044416 +160/1 7154143929938477/35184372088832 +160/1 250/1 +160/1 45/1 +160/1 5/1 +598918937007725/8796093022208 7897413790315053/70368744177664 +10/1 180/1 +4716605815996285/35184372088832 4963853435538925/140737488355328 +180/1 105/2 +200/1 100/1 +5840528361127517/70368744177664 2029575319572185/17592186044416 +1212805305902039/8796093022208 2582891791915575/70368744177664 +160/1 5518387287156589/35184372088832 +4624246839263101/35184372088832 220/1 +160/1 220/1 +200/1 220/1 +10/1 140/1 +160/1 3018449689314853/17592186044416 +686879867229805/17592186044416 642620565969961/4398046511104 +1032063186481709/17592186044416 1321568996121641/8796093022208 +4808542580264403/35184372088832 5864073742929363/35184372088832 +160/1 2407353441127183/35184372088832 +405783562323755/2199023255552 8902631300892983/140737488355328 +3295709578249267/35184372088832 2898675049850051/35184372088832 +7609324151651697/70368744177664 2791528081527931/35184372088832 +3368819185012651/70368744177664 7597924415094915/70368744177664 +2609160444117097/70368744177664 6635723317832791/70368744177664 +4741973748272333/35184372088832 958985245653205/4398046511104 +2086964548886279/35184372088832 8617778624461799/70368744177664 +1218422490906021/17592186044416 1188017915765457/8796093022208 +7374785127307543/70368744177664 6336107278873133/35184372088832 +1508485972843561/17592186044416 1371724318534271/8796093022208 +4796192865661223/35184372088832 220/1 +73 +0 33 +2 9 +4 15 +6 0 +0 24 +8 1 +9 35 +10 22 +9 25 +11 16 +8 29 +11 12 +13 18 +14 7 +14 26 +15 19 +13 31 +15 12 +5 12 +16 5 +17 30 +16 12 +18 8 +7 27 +19 11 +18 32 +19 12 +20 8 +1 20 +20 28 +21 3 +22 9 +23 22 +22 40 +21 7 +24 14 +25 20 +2 25 +26 36 +27 37 +28 38 +25 28 +28 39 +27 26 +26 24 +5 17 +17 1 +29 11 +30 16 +5 30 +30 29 +31 15 +32 19 +29 32 +32 31 +31 34 +33 13 +34 0 +6 34 +34 33 +35 21 +36 13 +33 36 +37 18 +36 37 +38 7 +39 27 +37 39 +39 38 +38 35 +40 21 +35 40 +40 10 diff --git a/Packages/Planar_map/demo/Planar_map/Leda_window/input_files/mess.f b/Packages/Planar_map/demo/Planar_map/Leda_window/input_files/mess.f new file mode 100644 index 00000000000..3c12e3b17a7 --- /dev/null +++ b/Packages/Planar_map/demo/Planar_map/Leda_window/input_files/mess.f @@ -0,0 +1,116 @@ +41 +10 100 +200 140 +200 180 +80 250 +80 15 +200 60 +10 60 +10 220 +160 131.579 +160 203.333 +160 250 +160 45 +160 5 +68.0892 112.229 +10 180 +134.054 35.2703 +180 52.5 +200 100 +82.9989 115.368 +137.88 36.7051 +160 156.842 +131.429 220 +160 220 +200 220 +10 140 +160 171.579 +39.0446 146.115 +58.666 150.245 +136.667 166.667 +160 68.4211 +184.529 63.257 +93.6697 82.3853 +108.135 79.34 +47.8738 107.973 +37.0784 94.2993 +134.775 218.048 +59.3151 122.466 +69.2593 135.062 +104.802 180.083 +85.7475 155.947 +136.316 220 +73 +0 33 +2 9 +4 15 +6 0 +0 24 +8 1 +9 35 +10 22 +9 25 +11 16 +8 29 +11 12 +13 18 +14 7 +14 26 +15 19 +13 31 +15 12 +5 12 +16 5 +17 30 +16 12 +18 8 +7 27 +19 11 +18 32 +19 12 +20 8 +1 20 +20 28 +21 3 +22 9 +23 22 +22 40 +21 7 +24 14 +25 20 +2 25 +26 36 +27 37 +28 38 +25 28 +28 39 +27 26 +26 24 +5 17 +17 1 +29 11 +30 16 +5 30 +30 29 +31 15 +32 19 +29 32 +32 31 +31 34 +33 13 +34 0 +6 34 +34 33 +35 21 +36 13 +33 36 +37 18 +36 37 +38 7 +39 27 +37 39 +39 38 +38 35 +40 21 +35 40 +40 10 diff --git a/Packages/Planar_map/demo/Planar_map/Leda_window/input_files/smallgrid.e b/Packages/Planar_map/demo/Planar_map/Leda_window/input_files/smallgrid.e new file mode 100644 index 00000000000..033ba5d3c59 --- /dev/null +++ b/Packages/Planar_map/demo/Planar_map/Leda_window/input_files/smallgrid.e @@ -0,0 +1,23 @@ +9 +0/1 0/1 +0/1 1/1 +0/1 2/1 +1/1 0/1 +1/1 1/1 +1/1 2/1 +2/1 0/1 +2/1 1/1 +2/1 2/1 +12 +0 1 +1 2 +3 4 +4 5 +6 7 +7 8 +0 3 +3 6 +1 4 +4 7 +2 5 +5 8 diff --git a/Packages/Planar_map/demo/Planar_map/Leda_window/input_files/window.e b/Packages/Planar_map/demo/Planar_map/Leda_window/input_files/window.e new file mode 100644 index 00000000000..b830666bb82 --- /dev/null +++ b/Packages/Planar_map/demo/Planar_map/Leda_window/input_files/window.e @@ -0,0 +1,34 @@ +15 +10/1 10/1 +100/1 10/1 +200/1 10/1 +10/1 200/1 +100/1 200/1 +200/1 200/1 +30/1 30/1 +70/1 30/1 +30/1 70/1 +70/1 70/1 +150/1 100/1 +120/1 160/1 +180/1 160/1 +20/1 160/1 +80/1 160/1 +17 +0 1 +1 2 +2 5 +5 4 +4 3 +3 0 +6 7 +7 9 +9 8 +8 6 +10 12 +12 11 +11 10 +4 1 +8 13 +13 14 +14 9 diff --git a/Packages/Planar_map/demo/Planar_map/Leda_window/input_files/window.f b/Packages/Planar_map/demo/Planar_map/Leda_window/input_files/window.f new file mode 100644 index 00000000000..20edee49b91 --- /dev/null +++ b/Packages/Planar_map/demo/Planar_map/Leda_window/input_files/window.f @@ -0,0 +1,34 @@ +15 +10 10 +100 10 +200 10 +10 200 +100 200 +200 200 +30 30 +70 30 +30 70 +70 70 +150 100 +120 160 +180 160 +20 160 +80 160 +17 +0 1 +1 2 +2 5 +5 4 +4 3 +3 0 +6 7 +7 9 +9 8 +8 6 +10 12 +12 11 +11 10 +4 1 +8 13 +13 14 +14 9 diff --git a/Packages/Planar_map/demo/Planar_map/Leda_window/inter.h b/Packages/Planar_map/demo/Planar_map/Leda_window/inter.h new file mode 100644 index 00000000000..330c58ebd22 --- /dev/null +++ b/Packages/Planar_map/demo/Planar_map/Leda_window/inter.h @@ -0,0 +1,370 @@ +#ifndef _INTER_H +#define _INTER_H + + +#define EPSILON (0.000001) + +template +class Lines +{ +public: + class pmpoint; + class pmcurve; + + Lines(int fp = 1) + { + use_fp = fp; + } + + int use_fp; + + void Intersect(pmpoint* pnts, int num_points, + pmcurve* cvs, int num_curves, + pmpoint* &intr_pnts, int &intr_np, + pmcurve* &intr_cvs, int &intr_nc) + { + int *cvs2 = new int[num_curves]; + int i; + + for (i = 0; i < num_curves; i++) // if cvs[i] is false then it was + cvs2[i] = 1; // merged with another curve - hence, should + // be ignored. + + // upper boundary for the number of + // intersection points + endpoints. + int PNUM = num_points * (num_points + 1); + pmpoint * pnt_buff = new pmpoint[PNUM]; + + // initializing with the endpoints. + for (i = 0; i < num_points; i++) + { + pnt_buff[i] = pnts[i]; + pnt_buff[i].n = i; + } + PNUM = num_points; + + // upper boundary on the number of segments. + int CNUM = num_curves * num_curves; + pmcurve * crv_buff = new pmcurve[CNUM]; + CNUM = 0; + + int k, n; + // an auxilary points buffer for keeping the intersection + // points of one curve. + pmpoint * pnt_aux_buff = new pmpoint[num_curves]; + + for (i = 0; i < num_curves; i++) + { + // n = number of intersections of the line + // pnt_aux_buff will contain the n intersection points. + // Intersect is the only place where cvs2[i] can turn to false. + n = Intersect(i, num_curves, cvs, cvs2, pnt_aux_buff); + + // sort the n points from source to target. + // if cvs[i] intersects two curves in one point- + // the sort process will eliminate one. + n = Sort(n, pnt_aux_buff, cvs[i]); + + + if (cvs2[i]) + { + // adding the new segments + crv_buff[CNUM].s = cvs[i].s; + + for (k = 0; k < n; k++) + { + // add the intersection points to the buffer + pnt_aux_buff[k].n = PNUM; + pnt_buff[PNUM] = pnt_aux_buff[k]; + PNUM++; + + crv_buff[CNUM].t = pnt_aux_buff[k]; + CNUM++; + + crv_buff[CNUM].s = pnt_aux_buff[k]; + } + crv_buff[CNUM].t = cvs[i].t; + CNUM++; + } + } + + intr_np = PNUM; + intr_nc = CNUM; + intr_pnts = pnt_buff; + intr_cvs = crv_buff; + } + + int Intersect(int i, int num_curves, pmcurve * cvs, + int* cvs2, pmpoint *pnt_aux_buff) + { + int j, n = 0; + pmcurve cv; + pmpoint p; + + for (j = 0; j < num_curves; j++) // checking intersection with every segment + { + if ((j != i) && (cvs2[j])) + { + if ( (!is_vertical(cvs[i])) && + (!is_vertical(cvs[j])) && + is_same(a(cvs[i]),a(cvs[j])) ) + { + // case 1:the segments have the same derivitive + // (however they are not vertical) + if ( is_same(b(cvs[i]), b(cvs[j]))) + // the segments are on the same line + if (is_in_x_range(cvs[i],cvs[j].s) || + is_in_x_range(cvs[i],cvs[j].t) || + is_in_x_range(cvs[j],cvs[i].s) ) + { + // the segments overlap + if (j > i) // always true (?) + { + cv.s = leftmost( leftmost(cvs[i].s, cvs[j].s), + leftmost(cvs[i].t, cvs[j].t) ); + cv.t = rightmost(rightmost(cvs[i].s, cvs[j].s), + rightmost(cvs[i].t, cvs[j].t)); + cvs[j] = cv; + cvs2[i] = 0; + return 0; + } + } + // else - the segments don't intersect + // else - the segments don't intersect (parralel) + } // end of case 1. + else + { + if (is_vertical(cvs[i]) && is_vertical(cvs[j])) + { + // case 2: both of the segments are vertical + if ( is_same(cvs[i].s.x, cvs[j].s.x) && + (is_in_y_range(cvs[i], cvs[j].s) || + is_in_y_range(cvs[i], cvs[j].t) || + is_in_y_range(cvs[j], cvs[i].s)) ) + { + // the segments overlap + if (j > i) // always true (?) + { + cv.s = lowest( lowest(cvs[i].s, cvs[j].s), + lowest(cvs[i].t, cvs[j].t) ); + cv.t = highest(highest(cvs[i].s, cvs[j].s), + highest(cvs[i].t, cvs[j].t)); + cvs[j] = cv; + cvs2[i] = 0; + return 0; + } + } + // if the segments are parralel - do nothing + } + else + { + if (is_vertical(cvs[i])) + { + // case 3: cvs[i] is vertical but cvs[j] isn't + p.x = cvs[i].s.x; + p.y = a(cvs[j]) * p.x + b(cvs[j]); + } + else + if (is_vertical(cvs[j])) + { + // case 3: cvs[j] is vertical but cvs[i] isn't + p.x = cvs[j].s.x; + p.y = a(cvs[i]) * p.x + b(cvs[i]); + } + else + { + p.x = (b(cvs[i]) - b(cvs[j]))/(a(cvs[j]) - a(cvs[i])); + p.y = a(cvs[i]) * p.x + b(cvs[i]); + } + + if (is_in_x_range(cvs[i],p) && is_in_x_range(cvs[j],p) && + is_in_y_range(cvs[i],p) && is_in_y_range(cvs[j],p) && + (!is_same(p,cvs[i].s)) && (!is_same(p,cvs[i].t))) + { + pnt_aux_buff[n] = p; + n++; + } + } + } + } + } + return n; + } + + + int Sort(int n, pmpoint* buff, pmcurve &cv) + { + if (n == 0) return 0; + + int flag1, flag2; + flag1 = flag2 = 0; + if (is_same_x(cv.s, cv.t)) + { + flag1 = 1; // indicates that we have to compare on the y-axes + if (is_higher(cv.s, cv.t)) + flag2 = 1; // we have to sort from high to low + } + else + if (is_right(cv.s, cv.t)) + flag2 = 1; + + //cases: flag1 = 0: flag2 = 0 from left to right + // flag2 = 1 from right to left + // flag1 = 1: flag2 = 0 from low to up + // flag2 = 1 from up to low + + pmpoint tmp; + int i, j; + + for (i = 0; i < n - 1; i++) // buff[i] contains the min in the i+1'th iteration + for (j = i+1; j < n; j++) + { + if ( ((!flag1) && (!flag2) && (is_left(buff[j], buff[i]))) || + ((!flag1) && (flag2) && (is_right(buff[j], buff[i]))) || + ((flag1) && (!flag2) && (is_lower(buff[j], buff[i]))) || + ((flag1) && (flag2) && (is_higher(buff[j], buff[i]))) ) + { + tmp = buff[i]; + buff[i] = buff[j]; + buff[j] = tmp; + } + } + + int n2 = n; + for (i = n-1; i > 0; i--) + { + if (is_same(buff[i], buff[i-1])) + { + for (j = i; j < n2 - 1; j++) + buff[j] = buff[j+1]; + n2--; + } + } + + return n2; + } + + + + class pmpoint + { + public: + number_type x; + number_type y; + int n; + }; + + + int is_left(const pmpoint &p1, const pmpoint &p2) + { + return (p1.x < p2.x); + } + + int is_right(const pmpoint &p1, const pmpoint &p2) + { + return (p1.x > p2.x); + } + + int is_same_x(const pmpoint &p1, const pmpoint &p2) + { + return (p1.x == p2.x); + } + + int is_lower(const pmpoint &p1, const pmpoint &p2) + { + return (p1.y < p2.y); + } + + int is_higher(const pmpoint &p1, const pmpoint &p2) + { + return (p1.y > p2.y); + } + + int is_same_y(const pmpoint &p1, const pmpoint &p2) + { + return (p1.y == p2.y); + } + + int is_same(number_type d1, number_type d2) + { + return (d1 == d2); + } + + int is_same(const pmpoint &p1, const pmpoint &p2) + { + if (!use_fp) + { + return is_same_x(p1,p2) && is_same_y(p1,p2); + } + else + { + number_type d = (p1.x - p2.x)*(p1.x - p2.x) + + (p1.y - p2.y)*(p1.y - p2.y); + if (d < EPSILON * EPSILON) + return 1; + else + return 0; + // return (check_left(p1,p2) == 0) && (check_lower(p1,p2) == 0); + } + } + + pmpoint leftmost(const pmpoint &p1, const pmpoint &p2) + { return (is_left(p1, p2) ? p1 : p2); } + + pmpoint rightmost(const pmpoint &p1, const pmpoint &p2) + { return (is_right(p1, p2) ? p1 : p2); } + + pmpoint lowest(const pmpoint &p1, const pmpoint &p2) + { return (is_lower(p1, p2) ? p1 : p2); } + + pmpoint highest(const pmpoint &p1, const pmpoint &p2) + { return (is_higher(p1, p2) ? p1 : p2); } + + + number_type a(pmcurve &c) + { + if (is_same_x(c.s ,c.t)) + return 0; + return (c.t.y - c.s.y)/(c.t.x - c.s.x); + } + + number_type b(pmcurve &c) + { + if (is_same_x(c.s ,c.t)) + return 0; + return (c.t.y * c.s.x - c.s.y * c.t.x )/(c.s.x - c.t.x); + } + + int is_vertical(pmcurve &c) + { + return (c.s.x == c.t.x); + } + + + class pmcurve + { + public: + pmpoint s; + pmpoint t; + }; + + + int is_in_x_range(pmcurve &cv, pmpoint &q) + { + int r = !( is_right(q, rightmost(cv.t, cv.s)) || + is_left(q, leftmost(cv.t, cv.s)) ); + return r; + } + + int is_in_y_range(pmcurve &cv, pmpoint &q) + { + int r = !( is_higher(q, highest(cv.t, cv.s)) || + is_lower(q, lowest(cv.t, cv.s)) ); + return r; + } + +}; + + + +#endif diff --git a/Packages/Planar_map/demo/Planar_map/Leda_window/makefile b/Packages/Planar_map/demo/Planar_map/Leda_window/makefile new file mode 100644 index 00000000000..26c96144474 --- /dev/null +++ b/Packages/Planar_map/demo/Planar_map/Leda_window/makefile @@ -0,0 +1,209 @@ +# This is the makefile for compiling a CGAL application. +#---------------------------------------------------------------------# +# include platform specific settings +#---------------------------------------------------------------------# +# Choose the right include file from the /make directory. + +OBJ_EXT = .wrong_cgal_makefile + +#CGAL_MAKEFILE = ENTER_YOUR_INCLUDE_MAKEFILE_HERE +include $(CGAL_MAKEFILE) + +#---------------------------------------------------------------------# +# compiler flags +#---------------------------------------------------------------------# + +CXXFLAGS = \ + -I../../../include \ + -I../../../../Trapezoidal_decomposition/include \ + -I../../../../Sweep_line_2/include \ + $(EXTRA_FLAGS) \ + $(CGAL_CXXFLAGS) \ + $(LONG_NAME_PROBLEM_CXXFLAGS) \ + $(DEBUG_OPT) + +#---------------------------------------------------------------------# +# linker flags +#---------------------------------------------------------------------# + +LIBPATH = \ + $(CGAL_WINDOW_LIBPATH) + +LDFLAGS = \ + $(LONG_NAME_PROBLEM_LDFLAGS) \ + $(CGAL_WINDOW_LDFLAGS) + +#---------------------------------------------------------------------# +# target entries +#---------------------------------------------------------------------# + +demo$(EXE_EXT): demo$(OBJ_EXT) draw_map$(OBJ_EXT) + $(CGAL_CXX) $(LIBPATH) $(EXE_OPT)demo demo$(OBJ_EXT) draw_map$(OBJ_EXT) $(LDFLAGS) + +helputil$(EXE_EXT): helputil$(OBJ_EXT) + $(CGAL_CXX) $(LIBPATH) $(EXE_OPT)helputil helputil$(OBJ_EXT) $(LDFLAGS) + +########################################################################### +#The following lines compile the demo with different options, we use +#them for experiments only. + +demo.all: \ + demo.float.rebuild\ + demo.rational.rebuild\ + demo.leda.rational.rebuild\ + demo.float.no-rebuild\ + demo.rational.no-rebuild\ + demo.leda.rational.no-rebuild\ + demo.float.walk\ + demo.rational.walk\ + demo.leda.rational.walk\ + demo.float.naive\ + demo.rational.naive\ + demo.leda.rational.naive + +# executables ... default strategy +demo.float.rebuild$(EXE_EXT): demo.float.rebuild$(OBJ_EXT) draw_map.float.rebuild$(OBJ_EXT) + $(CGAL_CXX) $(LIBPATH) $(EXE_OPT)demo.float.rebuild demo.float.rebuild$(OBJ_EXT) draw_map.float.rebuild$(OBJ_EXT) $(LDFLAGS) + +demo.rational.rebuild$(EXE_EXT): demo.rational.rebuild$(OBJ_EXT) draw_map.rational.rebuild$(OBJ_EXT) + $(CGAL_CXX) $(LIBPATH) $(EXE_OPT)demo.rational.rebuild demo.rational.rebuild$(OBJ_EXT) draw_map.rational.rebuild$(OBJ_EXT) $(LDFLAGS) + +demo.leda.rational.rebuild$(EXE_EXT): demo.leda.rational.rebuild$(OBJ_EXT) draw_map.leda.rational.rebuild$(OBJ_EXT) + $(CGAL_CXX) $(LIBPATH) $(EXE_OPT)demo.leda.rational.rebuild demo.leda.rational.rebuild$(OBJ_EXT) draw_map.leda.rational.rebuild$(OBJ_EXT) $(LDFLAGS) + +# executables ... default strategy without rebuilds +demo.float.no-rebuild$(EXE_EXT): demo.float.no-rebuild$(OBJ_EXT) draw_map.float.no-rebuild$(OBJ_EXT) + $(CGAL_CXX) $(LIBPATH) $(EXE_OPT)demo.float.no-rebuild demo.float.no-rebuild$(OBJ_EXT) draw_map.float.no-rebuild$(OBJ_EXT) $(LDFLAGS) + +demo.rational.no-rebuild$(EXE_EXT): demo.rational.no-rebuild$(OBJ_EXT) draw_map.rational.no-rebuild$(OBJ_EXT) + $(CGAL_CXX) $(LIBPATH) $(EXE_OPT)demo.rational.no-rebuild demo.rational.no-rebuild$(OBJ_EXT) draw_map.rational.no-rebuild$(OBJ_EXT) $(LDFLAGS) + +demo.leda.rational.no-rebuild$(EXE_EXT): demo.leda.rational.no-rebuild$(OBJ_EXT) draw_map.leda.rational.no-rebuild$(OBJ_EXT) + $(CGAL_CXX) $(LIBPATH) $(EXE_OPT)demo.leda.rational.no-rebuild demo.leda.rational.no-rebuild$(OBJ_EXT) draw_map.leda.rational.no-rebuild$(OBJ_EXT) $(LDFLAGS) + +# executables ... walk strategy +demo.float.walk$(EXE_EXT): demo.float.walk$(OBJ_EXT) draw_map.float.walk$(OBJ_EXT) + $(CGAL_CXX) $(LIBPATH) $(EXE_OPT)demo.float.walk demo.float.walk$(OBJ_EXT) draw_map.float.walk$(OBJ_EXT) $(LDFLAGS) + +demo.rational.walk$(EXE_EXT): demo.rational.walk$(OBJ_EXT) draw_map.rational.walk$(OBJ_EXT) + $(CGAL_CXX) $(LIBPATH) $(EXE_OPT)demo.rational.walk demo.rational.walk$(OBJ_EXT) draw_map.rational.walk$(OBJ_EXT) $(LDFLAGS) + +demo.leda.rational.walk$(EXE_EXT): demo.leda.rational.walk$(OBJ_EXT) draw_map.leda.rational.walk$(OBJ_EXT) + $(CGAL_CXX) $(LIBPATH) $(EXE_OPT)demo.leda.rational.walk demo.leda.rational.walk$(OBJ_EXT) draw_map.leda.rational.walk$(OBJ_EXT) $(LDFLAGS) + +# executables ... naive strategy +demo.float.naive$(EXE_EXT): demo.float.naive$(OBJ_EXT) draw_map.float.naive$(OBJ_EXT) + $(CGAL_CXX) $(LIBPATH) $(EXE_OPT)demo.float.naive demo.float.naive$(OBJ_EXT) draw_map.float.naive$(OBJ_EXT) $(LDFLAGS) + +demo.rational.naive$(EXE_EXT): demo.rational.naive$(OBJ_EXT) draw_map.rational.naive$(OBJ_EXT) + $(CGAL_CXX) $(LIBPATH) $(EXE_OPT)demo.rational.naive demo.rational.naive$(OBJ_EXT) draw_map.rational.naive$(OBJ_EXT) $(LDFLAGS) + +demo.leda.rational.naive$(EXE_EXT): demo.leda.rational.naive$(OBJ_EXT) draw_map.leda.rational.naive$(OBJ_EXT) + $(CGAL_CXX) $(LIBPATH) $(EXE_OPT)demo.leda.rational.naive demo.leda.rational.naive$(OBJ_EXT) draw_map.leda.rational.naive$(OBJ_EXT) $(LDFLAGS) + +# demo object files +demo.float.rebuild$(OBJ_EXT): demo.C draw_map.h makefile + $(CGAL_CXX) $(CXXFLAGS) $(EXE_OPT)demo.float.rebuild$(OBJ_EXT) $(OBJ_OPT) demo.C + +demo.rational.rebuild$(OBJ_EXT): demo.C draw_map.h makefile + $(CGAL_CXX) $(CXXFLAGS) -DUSE_RATIONAL $(EXE_OPT)demo.rational.rebuild$(OBJ_EXT) $(OBJ_OPT) demo.C + +demo.leda.rational.rebuild$(OBJ_EXT): demo.C draw_map.h makefile + $(CGAL_CXX) $(CXXFLAGS) -DUSE_LEDA_RAT_KERNEL $(EXE_OPT)demo.leda.rational.rebuild$(OBJ_EXT) $(OBJ_OPT) demo.C + +demo.float.no-rebuild$(OBJ_EXT): demo.C draw_map.h makefile + $(CGAL_CXX) $(CXXFLAGS) -DUSE_DEFAULT_WITHOUT_REBUILD $(EXE_OPT)demo.float.no-rebuild$(OBJ_EXT) $(OBJ_OPT) demo.C + +demo.rational.no-rebuild$(OBJ_EXT): demo.C draw_map.h makefile + $(CGAL_CXX) $(CXXFLAGS) -DUSE_DEFAULT_WITHOUT_REBUILD -DUSE_RATIONAL $(EXE_OPT)demo.rational.no-rebuild$(OBJ_EXT) $(OBJ_OPT) demo.C + +demo.leda.rational.no-rebuild$(OBJ_EXT): demo.C draw_map.h makefile + $(CGAL_CXX) $(CXXFLAGS) -DUSE_DEFAULT_WITHOUT_REBUILD -DUSE_LEDA_RAT_KERNEL $(EXE_OPT)demo.leda.rational.no-rebuild$(OBJ_EXT) $(OBJ_OPT) demo.C + +demo.float.walk$(OBJ_EXT): demo.C draw_map.h makefile + $(CGAL_CXX) $(CXXFLAGS) -DUSE_WALK_POINT_LOCATION $(EXE_OPT)demo.float.walk$(OBJ_EXT) $(OBJ_OPT) demo.C + +demo.rational.walk$(OBJ_EXT): demo.C draw_map.h makefile + $(CGAL_CXX) $(CXXFLAGS) -DUSE_WALK_POINT_LOCATION -DUSE_RATIONAL $(EXE_OPT)demo.rational.walk$(OBJ_EXT) $(OBJ_OPT) demo.C + +demo.leda.rational.walk$(OBJ_EXT): demo.C draw_map.h makefile + $(CGAL_CXX) $(CXXFLAGS) -DUSE_WALK_POINT_LOCATION -DUSE_LEDA_RAT_KERNEL $(EXE_OPT)demo.leda.rational.walk$(OBJ_EXT) $(OBJ_OPT) demo.C + + +demo.float.naive$(OBJ_EXT): demo.C draw_map.h makefile + $(CGAL_CXX) $(CXXFLAGS) -DUSE_NAIVE_POINT_LOCATION $(EXE_OPT)demo.float.naive$(OBJ_EXT) $(OBJ_OPT) demo.C + +demo.rational.naive$(OBJ_EXT): demo.C draw_map.h makefile + $(CGAL_CXX) $(CXXFLAGS) -DUSE_NAIVE_POINT_LOCATION -DUSE_RATIONAL $(EXE_OPT)demo.rational.naive$(OBJ_EXT) $(OBJ_OPT) demo.C + +demo.leda.rational.naive$(OBJ_EXT): demo.C draw_map.h makefile + $(CGAL_CXX) $(CXXFLAGS) -DUSE_NAIVE_POINT_LOCATION -DUSE_LEDA_RAT_KERNEL $(EXE_OPT)demo.leda.rational.naive$(OBJ_EXT) $(OBJ_OPT) demo.C + + +#draw_map object file +draw_map.float.rebuild$(OBJ_EXT): draw_map.C draw_map.h makefile + $(CGAL_CXX) $(CXXFLAGS) $(EXE_OPT)draw_map.float.rebuild$(OBJ_EXT) $(OBJ_OPT) draw_map.C + +draw_map.rational.rebuild$(OBJ_EXT): draw_map.C draw_map.h makefile + $(CGAL_CXX) $(CXXFLAGS) -DUSE_RATIONAL $(EXE_OPT)draw_map.rational.rebuild$(OBJ_EXT) $(OBJ_OPT) draw_map.C + +draw_map.leda.rational.rebuild$(OBJ_EXT): draw_map.C draw_map.h makefile + $(CGAL_CXX) $(CXXFLAGS) -DUSE_LEDA_RAT_KERNEL $(EXE_OPT)draw_map.leda.rational.rebuild$(OBJ_EXT) $(OBJ_OPT) draw_map.C + +draw_map.float.no-rebuild$(OBJ_EXT): draw_map.C draw_map.h makefile + $(CGAL_CXX) $(CXXFLAGS) -DUSE_DEFAULT_WITHOUT_REBUILD $(EXE_OPT)draw_map.float.no-rebuild$(OBJ_EXT) $(OBJ_OPT) draw_map.C + +draw_map.rational.no-rebuild$(OBJ_EXT): draw_map.C draw_map.h makefile + $(CGAL_CXX) $(CXXFLAGS) -DUSE_DEFAULT_WITHOUT_REBUILD -DUSE_RATIONAL $(EXE_OPT)draw_map.rational.no-rebuild$(OBJ_EXT) $(OBJ_OPT) draw_map.C + +draw_map.leda.rational.no-rebuild$(OBJ_EXT): draw_map.C draw_map.h makefile + $(CGAL_CXX) $(CXXFLAGS) -DUSE_DEFAULT_WITHOUT_REBUILD -DUSE_LEDA_RAT_KERNEL $(EXE_OPT)draw_map.leda.rational.no-rebuild$(OBJ_EXT) $(OBJ_OPT) draw_map.C + +draw_map.float.walk$(OBJ_EXT): draw_map.C draw_map.h makefile + $(CGAL_CXX) $(CXXFLAGS) -DUSE_WALK_POINT_LOCATION $(EXE_OPT)draw_map.float.walk$(OBJ_EXT) $(OBJ_OPT) draw_map.C + +draw_map.rational.walk$(OBJ_EXT): draw_map.C draw_map.h makefile + $(CGAL_CXX) $(CXXFLAGS) -DUSE_WALK_POINT_LOCATION -DUSE_RATIONAL $(EXE_OPT)draw_map.rational.walk$(OBJ_EXT) $(OBJ_OPT) draw_map.C + +draw_map.leda.rational.walk$(OBJ_EXT): draw_map.C draw_map.h makefile + $(CGAL_CXX) $(CXXFLAGS) -DUSE_WALK_POINT_LOCATION -DUSE_LEDA_RAT_KERNEL $(EXE_OPT)draw_map.leda.rational.walk$(OBJ_EXT) $(OBJ_OPT) draw_map.C + +draw_map.float.naive$(OBJ_EXT): draw_map.C draw_map.h makefile + $(CGAL_CXX) $(CXXFLAGS) -DUSE_NAIVE_POINT_LOCATION $(EXE_OPT)draw_map.float.naive$(OBJ_EXT) $(OBJ_OPT) draw_map.C + +draw_map.rational.naive$(OBJ_EXT): draw_map.C draw_map.h makefile + $(CGAL_CXX) $(CXXFLAGS) -DUSE_NAIVE_POINT_LOCATION -DUSE_RATIONAL $(EXE_OPT)draw_map.rational.naive$(OBJ_EXT) $(OBJ_OPT) draw_map.C + +draw_map.leda.rational.naive$(OBJ_EXT): draw_map.C draw_map.h makefile + $(CGAL_CXX) $(CXXFLAGS) -DUSE_NAIVE_POINT_LOCATION -DUSE_LEDA_RAT_KERNEL $(EXE_OPT)draw_map.leda.rational.naive$(OBJ_EXT) $(OBJ_OPT) draw_map.C + + +all: demo \ + helputil + +#---------------------------------------------------------------------# +# suffix rules +#---------------------------------------------------------------------# + +.C$(OBJ_EXT): + $(CGAL_CXX) $(CXXFLAGS) $(OBJ_OPT) $< + +clean: + rm -f -r *$(OBJ_EXT) demo$(EXE_EXT) \ + demo.float.rebuild$(EXE_EXT) \ + demo.rational.rebuild$(EXE_EXT) \ + demo.leda.rational.rebuild$(EXE_EXT) \ + demo.float.no-rebuild$(EXE_EXT) \ + demo.rational.no-rebuild$(EXE_EXT) \ + demo.leda.rational.no-rebuild$(EXE_EXT) \ + demo.float.walk$(EXE_EXT) \ + demo.rational.walk$(EXE_EXT) \ + demo.leda.rational.walk$(EXE_EXT) \ + demo.float.naive$(EXE_EXT) \ + demo.rational.naive$(EXE_EXT) \ + demo.leda.rational.naive$(EXE_EXT) \ + helputil$(EXE_EXT) \ + ii_files \ + core + +# note - we use many compile flag dependent executables for optimization diff --git a/Packages/Planar_map/demo/Planar_map/Leda_window/makefile.ms b/Packages/Planar_map/demo/Planar_map/Leda_window/makefile.ms new file mode 100644 index 00000000000..1dd6a92d282 --- /dev/null +++ b/Packages/Planar_map/demo/Planar_map/Leda_window/makefile.ms @@ -0,0 +1,232 @@ +# This is the makefile for compiling a CGAL application. +#---------------------------------------------------------------------# +# include platform specific settings +#---------------------------------------------------------------------# +# Choose the right include file from the /make directory. + +OBJ_EXT = .wrong_cgal_makefile + +#CGAL_MAKEFILE = ENTER_YOUR_INCLUDE_MAKEFILE_HERE +!include $(CGAL_MAKEFILE) + +#---------------------------------------------------------------------# +# compiler flags +#---------------------------------------------------------------------# + +CXXFLAGS = \ + $(EXTRA_FLAGS) \ + $(CGAL_CXXFLAGS) \ + $(LONG_NAME_PROBLEM_CXXFLAGS) \ + $(DEBUG_OPT) + +#---------------------------------------------------------------------# +# linker flags +#---------------------------------------------------------------------# + +LIBPATH = \ + $(CGAL_WINDOW_LIBPATH) + +LDFLAGS = \ + $(LONG_NAME_PROBLEM_LDFLAGS) \ + $(CGAL_WINDOW_LDFLAGS) + +#---------------------------------------------------------------------# +# target entries +#---------------------------------------------------------------------# + +demo: demo$(EXE_EXT) + +demo$(EXE_EXT): demo$(OBJ_EXT) draw_map$(OBJ_EXT) + $(CGAL_CXX) $(LIBPATH) $(EXE_OPT)demo demo$(OBJ_EXT) draw_map$(OBJ_EXT) $(LDFLAGS) + +helputil: helputil$(EXE_EXT) + +helputil$(EXE_EXT): helputil$(OBJ_EXT) + $(CGAL_CXX) $(LIBPATH) $(EXE_OPT)helputil helputil$(OBJ_EXT) $(LDFLAGS) + +########################################################################### +#The following lines compile the demo with different options, we use +#them for experiments only. + +demo.all: \ + demo.float.rebuild\ + demo.rational.rebuild\ + demo.leda.rational.rebuild\ + demo.float.no-rebuild\ + demo.rational.no-rebuild\ + demo.leda.rational.no-rebuild\ + demo.float.walk\ + demo.rational.walk\ + demo.leda.rational.walk\ + demo.float.naive\ + demo.rational.naive\ + demo.leda.rational.naive + +demo.float.rebuild: demo.float.rebuild$(EXE_EXT) + +demo.rational.rebuild: demo.rational.rebuild$(EXE_EXT) + +demo.leda.rational.rebuild: demo.leda.rational.rebuild$(EXE_EXT) + +demo.float.no-rebuild: demo.float.no-rebuild$(EXE_EXT) + +demo.rational.no-rebuild: demo.rational.no-rebuild$(EXE_EXT) + +demo.leda.rational.no-rebuild: demo.leda.rational.no-rebuild$(EXE_EXT) + +demo.float.walk: demo.float.walk$(EXE_EXT) + +demo.rational.walk: demo.rational.walk$(EXE_EXT) + +demo.leda.rational.walk: demo.leda.rational.walk$(EXE_EXT) + +demo.float.naive: demo.float.naive$(EXE_EXT) + +demo.rational.naive: demo.rational.naive$(EXE_EXT) + +demo.leda.rational.naive: demo.leda.rational.naive$(EXE_EXT) + +# executables ... default strategy +demo.float.rebuild$(EXE_EXT): demo.float.rebuild$(OBJ_EXT) draw_map.float.rebuild$(OBJ_EXT) + $(CGAL_CXX) $(LIBPATH) $(EXE_OPT)demo.float.rebuild demo.float.rebuild$(OBJ_EXT) draw_map.float.rebuild$(OBJ_EXT) $(LDFLAGS) + +demo.rational.rebuild$(EXE_EXT): demo.rational.rebuild$(OBJ_EXT) draw_map.rational.rebuild$(OBJ_EXT) + $(CGAL_CXX) $(LIBPATH) $(EXE_OPT)demo.rational.rebuild demo.rational.rebuild$(OBJ_EXT) draw_map.rational.rebuild$(OBJ_EXT) $(LDFLAGS) + +demo.leda.rational.rebuild$(EXE_EXT): demo.leda.rational.rebuild$(OBJ_EXT) draw_map.leda.rational.rebuild$(OBJ_EXT) + $(CGAL_CXX) $(LIBPATH) $(EXE_OPT)demo.leda.rational.rebuild demo.leda.rational.rebuild$(OBJ_EXT) draw_map.leda.rational.rebuild$(OBJ_EXT) $(LDFLAGS) + +# executables ... default strategy without rebuilds +demo.float.no-rebuild$(EXE_EXT): demo.float.no-rebuild$(OBJ_EXT) draw_map.float.no-rebuild$(OBJ_EXT) + $(CGAL_CXX) $(LIBPATH) $(EXE_OPT)demo.float.no-rebuild demo.float.no-rebuild$(OBJ_EXT) draw_map.float.no-rebuild$(OBJ_EXT) $(LDFLAGS) + +demo.rational.no-rebuild$(EXE_EXT): demo.rational.no-rebuild$(OBJ_EXT) draw_map.rational.no-rebuild$(OBJ_EXT) + $(CGAL_CXX) $(LIBPATH) $(EXE_OPT)demo.rational.no-rebuild demo.rational.no-rebuild$(OBJ_EXT) draw_map.rational.no-rebuild$(OBJ_EXT) $(LDFLAGS) + +demo.leda.rational.no-rebuild$(EXE_EXT): demo.leda.rational.no-rebuild$(OBJ_EXT) draw_map.leda.rational.no-rebuild$(OBJ_EXT) + $(CGAL_CXX) $(LIBPATH) $(EXE_OPT)demo.leda.rational.no-rebuild demo.leda.rational.no-rebuild$(OBJ_EXT) draw_map.leda.rational.no-rebuild$(OBJ_EXT) $(LDFLAGS) + +# executables ... walk strategy +demo.float.walk$(EXE_EXT): demo.float.walk$(OBJ_EXT) draw_map.float.walk$(OBJ_EXT) + $(CGAL_CXX) $(LIBPATH) $(EXE_OPT)demo.float.walk demo.float.walk$(OBJ_EXT) draw_map.float.walk$(OBJ_EXT) $(LDFLAGS) + +demo.rational.walk$(EXE_EXT): demo.rational.walk$(OBJ_EXT) draw_map.rational.walk$(OBJ_EXT) + $(CGAL_CXX) $(LIBPATH) $(EXE_OPT)demo.rational.walk demo.rational.walk$(OBJ_EXT) draw_map.rational.walk$(OBJ_EXT) $(LDFLAGS) + +demo.leda.rational.walk$(EXE_EXT): demo.leda.rational.walk$(OBJ_EXT) draw_map.leda.rational.walk$(OBJ_EXT) + $(CGAL_CXX) $(LIBPATH) $(EXE_OPT)demo.leda.rational.walk demo.leda.rational.walk$(OBJ_EXT) draw_map.leda.rational.walk$(OBJ_EXT) $(LDFLAGS) + +# executables ... naive strategy +demo.float.naive$(EXE_EXT): demo.float.naive$(OBJ_EXT) draw_map.float.naive$(OBJ_EXT) + $(CGAL_CXX) $(LIBPATH) $(EXE_OPT)demo.float.naive demo.float.naive$(OBJ_EXT) draw_map.float.naive$(OBJ_EXT) $(LDFLAGS) + +demo.rational.naive$(EXE_EXT): demo.rational.naive$(OBJ_EXT) draw_map.rational.naive$(OBJ_EXT) + $(CGAL_CXX) $(LIBPATH) $(EXE_OPT)demo.rational.naive demo.rational.naive$(OBJ_EXT) draw_map.rational.naive$(OBJ_EXT) $(LDFLAGS) + +demo.leda.rational.naive$(EXE_EXT): demo.leda.rational.naive$(OBJ_EXT) draw_map.leda.rational.naive$(OBJ_EXT) + $(CGAL_CXX) $(LIBPATH) $(EXE_OPT)demo.leda.rational.naive demo.leda.rational.naive$(OBJ_EXT) draw_map.leda.rational.naive$(OBJ_EXT) $(LDFLAGS) + +# demo object files +demo.float.rebuild$(OBJ_EXT): demo.C draw_map.h makefile + $(CGAL_CXX) $(CXXFLAGS) $(EXE_OPT)demo.float.rebuild$(OBJ_EXT) $(OBJ_OPT) demo.C + +demo.rational.rebuild$(OBJ_EXT): demo.C draw_map.h makefile + $(CGAL_CXX) $(CXXFLAGS) -DUSE_RATIONAL $(EXE_OPT)demo.rational.rebuild$(OBJ_EXT) $(OBJ_OPT) demo.C + +demo.leda.rational.rebuild$(OBJ_EXT): demo.C draw_map.h makefile + $(CGAL_CXX) $(CXXFLAGS) -DUSE_LEDA_RAT_KERNEL $(EXE_OPT)demo.leda.rational.rebuild$(OBJ_EXT) $(OBJ_OPT) demo.C + +demo.float.no-rebuild$(OBJ_EXT): demo.C draw_map.h makefile + $(CGAL_CXX) $(CXXFLAGS) -DUSE_DEFAULT_WITHOUT_REBUILD $(EXE_OPT)demo.float.no-rebuild$(OBJ_EXT) $(OBJ_OPT) demo.C + +demo.rational.no-rebuild$(OBJ_EXT): demo.C draw_map.h makefile + $(CGAL_CXX) $(CXXFLAGS) -DUSE_DEFAULT_WITHOUT_REBUILD -DUSE_RATIONAL $(EXE_OPT)demo.rational.no-rebuild$(OBJ_EXT) $(OBJ_OPT) demo.C + +demo.leda.rational.no-rebuild$(OBJ_EXT): demo.C draw_map.h makefile + $(CGAL_CXX) $(CXXFLAGS) -DUSE_DEFAULT_WITHOUT_REBUILD -DUSE_LEDA_RAT_KERNEL $(EXE_OPT)demo.leda.rational.no-rebuild$(OBJ_EXT) $(OBJ_OPT) demo.C + +demo.float.walk$(OBJ_EXT): demo.C draw_map.h makefile + $(CGAL_CXX) $(CXXFLAGS) -DUSE_WALK_POINT_LOCATION $(EXE_OPT)demo.float.walk$(OBJ_EXT) $(OBJ_OPT) demo.C + +demo.rational.walk$(OBJ_EXT): demo.C draw_map.h makefile + $(CGAL_CXX) $(CXXFLAGS) -DUSE_WALK_POINT_LOCATION -DUSE_RATIONAL $(EXE_OPT)demo.rational.walk$(OBJ_EXT) $(OBJ_OPT) demo.C + +demo.leda.rational.walk$(OBJ_EXT): demo.C draw_map.h makefile + $(CGAL_CXX) $(CXXFLAGS) -DUSE_WALK_POINT_LOCATION -DUSE_LEDA_RAT_KERNEL $(EXE_OPT)demo.leda.rational.walk$(OBJ_EXT) $(OBJ_OPT) demo.C + + +demo.float.naive$(OBJ_EXT): demo.C draw_map.h makefile + $(CGAL_CXX) $(CXXFLAGS) -DUSE_NAIVE_POINT_LOCATION $(EXE_OPT)demo.float.naive$(OBJ_EXT) $(OBJ_OPT) demo.C + +demo.rational.naive$(OBJ_EXT): demo.C draw_map.h makefile + $(CGAL_CXX) $(CXXFLAGS) -DUSE_NAIVE_POINT_LOCATION -DUSE_RATIONAL $(EXE_OPT)demo.rational.naive$(OBJ_EXT) $(OBJ_OPT) demo.C + +demo.leda.rational.naive$(OBJ_EXT): demo.C draw_map.h makefile + $(CGAL_CXX) $(CXXFLAGS) -DUSE_NAIVE_POINT_LOCATION -DUSE_LEDA_RAT_KERNEL $(EXE_OPT)demo.leda.rational.naive$(OBJ_EXT) $(OBJ_OPT) demo.C + + +#draw_map object file +draw_map.float.rebuild$(OBJ_EXT): draw_map.C draw_map.h makefile + $(CGAL_CXX) $(CXXFLAGS) $(EXE_OPT)draw_map.float.rebuild$(OBJ_EXT) $(OBJ_OPT) draw_map.C + +draw_map.rational.rebuild$(OBJ_EXT): draw_map.C draw_map.h makefile + $(CGAL_CXX) $(CXXFLAGS) -DUSE_RATIONAL $(EXE_OPT)draw_map.rational.rebuild$(OBJ_EXT) $(OBJ_OPT) draw_map.C + +draw_map.leda.rational.rebuild$(OBJ_EXT): draw_map.C draw_map.h makefile + $(CGAL_CXX) $(CXXFLAGS) -DUSE_LEDA_RAT_KERNEL $(EXE_OPT)draw_map.leda.rational.rebuild$(OBJ_EXT) $(OBJ_OPT) draw_map.C + +draw_map.float.no-rebuild$(OBJ_EXT): draw_map.C draw_map.h makefile + $(CGAL_CXX) $(CXXFLAGS) -DUSE_DEFAULT_WITHOUT_REBUILD $(EXE_OPT)draw_map.float.no-rebuild$(OBJ_EXT) $(OBJ_OPT) draw_map.C + +draw_map.rational.no-rebuild$(OBJ_EXT): draw_map.C draw_map.h makefile + $(CGAL_CXX) $(CXXFLAGS) -DUSE_DEFAULT_WITHOUT_REBUILD -DUSE_RATIONAL $(EXE_OPT)draw_map.rational.no-rebuild$(OBJ_EXT) $(OBJ_OPT) draw_map.C + +draw_map.leda.rational.no-rebuild$(OBJ_EXT): draw_map.C draw_map.h makefile + $(CGAL_CXX) $(CXXFLAGS) -DUSE_DEFAULT_WITHOUT_REBUILD -DUSE_LEDA_RAT_KERNEL $(EXE_OPT)draw_map.leda.rational.no-rebuild$(OBJ_EXT) $(OBJ_OPT) draw_map.C + +draw_map.float.walk$(OBJ_EXT): draw_map.C draw_map.h makefile + $(CGAL_CXX) $(CXXFLAGS) -DUSE_WALK_POINT_LOCATION $(EXE_OPT)draw_map.float.walk$(OBJ_EXT) $(OBJ_OPT) draw_map.C + +draw_map.rational.walk$(OBJ_EXT): draw_map.C draw_map.h makefile + $(CGAL_CXX) $(CXXFLAGS) -DUSE_WALK_POINT_LOCATION -DUSE_RATIONAL $(EXE_OPT)draw_map.rational.walk$(OBJ_EXT) $(OBJ_OPT) draw_map.C + +draw_map.leda.rational.walk$(OBJ_EXT): draw_map.C draw_map.h makefile + $(CGAL_CXX) $(CXXFLAGS) -DUSE_WALK_POINT_LOCATION -DUSE_LEDA_RAT_KERNEL $(EXE_OPT)draw_map.leda.rational.walk$(OBJ_EXT) $(OBJ_OPT) draw_map.C + +draw_map.float.naive$(OBJ_EXT): draw_map.C draw_map.h makefile + $(CGAL_CXX) $(CXXFLAGS) -DUSE_NAIVE_POINT_LOCATION $(EXE_OPT)draw_map.float.naive$(OBJ_EXT) $(OBJ_OPT) draw_map.C + +draw_map.rational.naive$(OBJ_EXT): draw_map.C draw_map.h makefile + $(CGAL_CXX) $(CXXFLAGS) -DUSE_NAIVE_POINT_LOCATION -DUSE_RATIONAL $(EXE_OPT)draw_map.rational.naive$(OBJ_EXT) $(OBJ_OPT) draw_map.C + +draw_map.leda.rational.naive$(OBJ_EXT): draw_map.C draw_map.h makefile + $(CGAL_CXX) $(CXXFLAGS) -DUSE_NAIVE_POINT_LOCATION -DUSE_LEDA_RAT_KERNEL $(EXE_OPT)draw_map.leda.rational.naive$(OBJ_EXT) $(OBJ_OPT) draw_map.C + + +all: demo \ + helputil + +#---------------------------------------------------------------------# +# suffix rules +#---------------------------------------------------------------------# + +.C$(OBJ_EXT): + $(CGAL_CXX) $(CXXFLAGS) $(OBJ_OPT) $< + +clean: + $(RM) $(RMFLAGS) *$(OBJ_EXT) demo$(EXE_EXT) \ + demo.float.rebuild$(EXE_EXT) \ + demo.rational.rebuild$(EXE_EXT) \ + demo.leda.rational.rebuild$(EXE_EXT) \ + demo.float.no-rebuild$(EXE_EXT) \ + demo.rational.no-rebuild$(EXE_EXT) \ + demo.leda.rational.no-rebuild$(EXE_EXT) \ + demo.float.walk$(EXE_EXT) \ + demo.rational.walk$(EXE_EXT) \ + demo.leda.rational.walk$(EXE_EXT) \ + demo.float.naive$(EXE_EXT) \ + demo.rational.naive$(EXE_EXT) \ + demo.leda.rational.naive$(EXE_EXT) \ + helputil$(EXE_EXT) + +# note - we use many compile flag dependent executables for optimization diff --git a/Packages/Planar_map/demo/Planar_map/Leda_window/read_inp.h b/Packages/Planar_map/demo/Planar_map/Leda_window/read_inp.h new file mode 100644 index 00000000000..66b61807f14 --- /dev/null +++ b/Packages/Planar_map/demo/Planar_map/Leda_window/read_inp.h @@ -0,0 +1,167 @@ +#ifndef READ_INP_H +#define READ_INP_H + +#include +#include + +template +class PM_input +{ +public: + typedef typename Traits::Point_2 Point; + typedef struct { int s, t; } Curve; + + PM_input() + { + num_pnts = num_cvs = 0; + pnts = NULL; + cvs = NULL; + } + + ~PM_input() + { + delete_all(); + } + + void delete_all() + { + if (pnts != NULL) + delete[] pnts; + if (cvs != NULL) + delete[] cvs; + num_pnts = num_cvs = 0; + pnts = NULL; + cvs = NULL; + } + + void alloc(int np, int nc) + { + delete_all(); + pnts = new Point[np]; + num_pnts = np; + cvs = new Curve[nc]; + num_cvs = nc; + } + + void set(int i, int source, int target) + { + if ((i < 0) || (i >= num_cvs)) + return; + cvs[i].s = source; + cvs[i].t = target; + } + + void set(int i, const Point &p) + { + if ((i < 0) || (i >= num_pnts)) + return; + pnts[i] = p; + } + + bool get(int i, int &source, int &target) const + { + if ((i < 0) || (i >= num_cvs)) + return false; + source = cvs[i].s; + target = cvs[i].t; + return true; + } + + bool get(int i, Point &p) const + { + if ((i < 0) || (i >= num_pnts)) + return false; + p = pnts[i]; + return true; + } + + int curve_source(int i) const + { + if ((i < 0) || (i >= num_cvs)) + return -1; + return cvs[i].s; + } + + int curve_target(int i) const + { + if ((i < 0) || (i >= num_cvs)) + return -1; + return cvs[i].t; + } + + int get_num_pnts() const { return num_pnts; } + + int get_num_cvs() const { return num_cvs; } + + Point point(int i) const + { + if ((i < 0) || (i >= num_pnts)) + return Point(0,0); + return pnts[i]; + } + + friend std::ostream &operator<<(std::ostream &os, const PM_input &pmi) + { + CGAL::set_ascii_mode(os); + os << pmi.num_pnts << std::endl; + int i; + for (i = 0; i < pmi.num_pnts; i++) + { + os << pmi.pnts[i] << std::endl; + } + os << pmi.num_cvs << std::endl; + for (i = 0; i < pmi.num_cvs; i++) + { + os << pmi.cvs[i].s << " " << pmi.cvs[i].t << std::endl; + } + return os; + } + + friend std::istream &operator>>(std::istream &is, PM_input &pmi) + { + CGAL::set_ascii_mode(is); + pmi.delete_all(); + Point p; + + is >> pmi.num_pnts; +#ifdef CGAL_PM_READ_DEBUG + std::cerr << "pmi.num_pnts " << pmi.num_pnts << std::endl; +#endif + pmi.pnts = new Point[pmi.num_pnts]; + CGAL_assertion(pmi.pnts != NULL); + int i; +#ifdef USE_LEDA_RAT_KERNEL + number_type x,y; +#endif + for (i = 0; i < pmi.num_pnts; i++) + { +#ifndef USE_LEDA_RAT_KERNEL + is >> pmi.pnts[i]; +#else + is >> x >> y; + pmi.pnts[i]=Point(x,y); +#endif + } + + is >> pmi.num_cvs; +#ifdef CGAL_PM_READ_DEBUG + std::cerr << "pmi.num_cvs " << pmi.num_cvs << std::endl; +#endif + pmi.cvs = new Curve[pmi.num_cvs]; + CGAL_assertion(pmi.cvs != NULL); + for (i = 0; i < pmi.num_cvs; i++) + { + is >> pmi.cvs[i].s >> pmi.cvs[i].t; + } + + return is; + } + +private: + Point *pnts; + Curve *cvs; + int num_pnts; + int num_cvs; +}; + +#endif