430 likes | 577 Views
2D Arrangements in CGAL: Recent Developments. CGAL Team School of Computer Science Tel Aviv University. Eti Ezra, Eyal Flato, Efi Fogel, Dan Halperin, Shai Hirsch, Eran Leiserowitz, Eli Packer, Tali Zvi, Ron Wein. Outline. Introduction The Packages in Brief Exploiting the Kernel
E N D
2D Arrangements in CGAL:Recent Developments CGAL Team School of Computer Science Tel Aviv University Eti Ezra, Eyal Flato, Efi Fogel, Dan Halperin, Shai Hirsch, Eran Leiserowitz, Eli Packer, Tali Zvi, Ron Wein
Outline • Introduction • The Packages in Brief • Exploiting the Kernel • Categorizing the Traits • Benchmarking • More Work
Outline • Introduction • The Package in Brief • Exploiting the Kernel • Categorizing the Traits • Benchmarking • More Work
Introduction “Bypasses are devices that allow some people to dash from point A to point B very fast while other people dash from point B to point A very fast. People living at point C, being a point directly in between, are often given to wonder what's so great about point A that so many people from point B are so keen to get there and what's so great about point B that so many people from point A are so keen to get there. They often wish that people would just once and for all work out where the hell they wanted to be.” Douglas Adams
Definitions Planar Maps Planar graphs that are embedded in the plane
Definitions (cont.) Planar Arrangements Given a collection Γ of planar curves, the arrangementA(Γ) is the partition of the plane to vertices, edges and faces induced by the curves of Γ
Application: GIS [Nguyen Dong Ha, et al.]
Application: Robot Motion Planning [Flato, Halperin]
Outline • Introduction • The Package in Brief • Exploiting the Kernel • Categorizing the Traits • Benchmarking • More Work
The Package in Brief “A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools.” Douglas Adams
The Package in Brief • Goal: Construct, maintain, modify, traverse, query and present subdivisions of the plane • Exact • Generic • Handles all degeneracies • Efficient
Topological_map • Maintains topological maps of finite edges • Planar_map_2 • Maintains planar maps of interior-disjoint x-monotone curves • Planar_map_with_intersections_2 • Maintains planar maps of general curves (may intersect, may be non-x-monotone) • Arrangement_2 • Maintains planar maps of intersecting curves along with curve history
Functionality • Creation & Destruction • I/O • Save, Load, Print (ASCII streams) • Draw (graphic streams) • Flexibility (Adaptable and Extensible, Verbose mode, I/O of specific elements) • Modification • Insertion, Removal, Split, Merge • Traversal • Queries • Number of Vertices, Halfedges, & Faces • Is Point in Face • Point Location, Vertical ray shoot
Traversal • Element Traversal • Vertex Iterator • Face Iterator • Edge Iterator • Halfedge Iterator • Map Traversal • Connected Component of the Boundary (CCB) Halfedge Circulator • Around Vertex Halfedge Circulator • Hole Iterator
Point Location Strategies • Naive • No preprocessing, no internal data • Linear query time • Walk along a line • No preprocessing, no internal data • Linear query time with heuristics • Trapezoidal decomposition based • Preprocessing, internal data • Expected logarithmic query time
Traits Classes • Geometric Interface • Parameter of package • Defines the family of curves in interest • Package can be used with any family of curves for which a traits class is supplied • Aggregate • geometric types (points, curves) • Operations over types (accessors, predicates, constructors)
Traits Classes • Supplied Traits Classes • Segments, Polylines, Circular arcs and Line segments, Conics (and line segments). • Other Known Traits Classes • Circular arcs, Canonical Parabola, Bezier Curves
Insertions • Non intersecting insert Halfedge_handle non_intersecting_insert(const X_curve_2 & cv, Change_notification * en = NULL); • Intersecting insert Halfedge_handle insert(const X_curve_2 & cv, Change_notification * en = NULL);
Insertions • Incremental Insert • Aggregate Insert • Often information is known in advance • Containing face Insert in face interior • Incident vertices Insert from vertex, between vertices • Order around vertex Insert from halfedge target, between halfedge targets
Aggregate Insert • Inserts a container into the map template <classcurve_iterator> Halfedge_iterator insert(const curve_iterator & begin, const curve_iterator & end, Change_notification * en = NULL); • Two versions • Simplified - planar map no intersections • General - planar map with intersections • Sweep based • If planar map is not empty, use overlay
Outline • Introduction • The Package in Brief • Exploiting the Kernel • Categorizing the Traits • Benchmarking • More Work
Exploiting the Kernel “Human beings, who are almost unique in having the ability to learn from the experience of others, are also remarkable for their apparent disinclination to do so.” Douglas Adams
CGAL Kernel Context • CGAL consists of three major parts • Kernel • Basic geometric data structures and algorithms • Convex Hull, Planar_map, Arrangement, etc. • Non-geometric support facilities
CGAL Kernel • Encapsulates • Constant-size non-modifiable geometric primitive object representations • Point, Segments, hopefully Conics, etc • operations (and predicates) on these objects • Adaptable and Extensible • Efficient • Used as a traits class for algorithms
Adapting the kernel • Exchange of representation classes • Representation classes are parameterized by a number type • Geometric objects are extracted from a representation class template <classKernel> classPm_segment_traits_2 : publicKernel { public typedeftypenameKernel::Point_2 Point_2; typedeftypenameKernel::Segment_2 X_curve_2; … };
Adapting the kernel • Functors provide the functionality • Functor – a class that define an appropriate operator() • Object for functors are obtained through access member functions template <classKernel> classPm_segment_traits_2 : publicKernel { Comparison_result compare_x(const Point_2 & p1, const Point_2 & p2) const { return compare_x_2_object()(p1, p2); } };
Adapting the kernel • Code reduction • Implementation is simple and concise • Traits reduction • Matthias Baesken LEDA Kernel makes the dedicated LEDA Traits obsolete #if defined(USE_LEDA_KERNEL) typedefCGAL::leda_rat_kernel_traits Kernel; #else typedef leda_rational NT; typedefCGAL::Cartesian<NT> Kernel; #endif typedefCGAL::Pm_segment_traits_2<Kernel> Traits;
Outline • Introduction • The Package in Brief • Exploiting the Kernel • Categorizing the Traits • Benchmarking • More Work
Categorizing the Traits “It is a mistake to think you can solve any major problems just with potatoes.” Douglas Adams
Categorizing the Traits • In the past – 2 levels of refinements • Planar map Traits • Planar map of intersecting curves Traits • In the future – multiple categories • Each category identifies a behavior • Multiple Tags • All categories identify the Traits
Dispatching Algorithms • Tailored Algorithms • Curve category • Segments, Circular Arcs, Conics template <class Kernel> classArr_segment_traits_2 { typedef Segment_tag Curve_category; }; template <class Kernel> classArr_conic_traits_2 { typedef Conic_tag Curve_category; };
Dispatching Algorithms • Trading between efficiency and complexity • Intersection Category • Lazy, Efficient typedef Lazy_intersection_tag Intersection_category; Point_2 reflect_point(const Point_2 & pt) const; X_curve_2 reflect_curve(const X_curve_2 & cv) const; Bool nearest_intersection_to_right(…) const; typedef Efficient_intersection_tag Intersection_category; Bool nearest_intersection_to_right(…) const; Bool nearest_intersection_to_left(…) const;
Tightening the Traits • Different operations may have • Different requirements • Different preconditions • Minimal set of requirements • Sweep has less requirement bool do_intersect_to_left(c1, c2, pt) bool do_intersect_to_right(c1, c2, pt) bool nearest_intersection_to_left(c1, c2, pt, …) bool nearest_intersection_to_right(c1, c2, pt, …) result curve_compare_at_x_left(cv1, cv2, pt) result curve_compare_at_x_right(cv1, cv2, pt)
Specialization • Caching • Avoid computations (intersection points) • Avoid construction (extreme end-points) • Code Reuse • Caching of intersection points is currently implemented as part of the conic traits • Requires redefinition of some classes (e.g., halfedge) Work in progress
Outline • Introduction • The Package in Brief • Exploiting the Kernel • Categorizing the Traits • Benchmarking • More Work
Outline • Introduction • The Package in Brief • Exploiting the Kernel • Categorizing the Traits • Benchmarking • More Work
More Work “Capital letters were always the best way of dealing with things you didn't have a good answer to.” Douglas Adams
More Work • Consolidate Pm and Pmwx into a unified class Planar_map_2 • Introduce more Specialization categories and options • Introduce more Point Location Strategies • Introduce Traits classes for complex curves • Move up to higher dimensions