BWAPI
|
00001 // Copyright (c) 2005 Tel-Aviv University (Israel). 00002 // All rights reserved. 00003 // 00004 // This file is part of CGAL (www.cgal.org); you may redistribute it under 00005 // the terms of the Q Public License version 1.0. 00006 // See the file LICENSE.QPL distributed with CGAL. 00007 // 00008 // Licensees holding a valid commercial license may use this file in 00009 // accordance with the commercial license agreement provided with the software. 00010 // 00011 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00012 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00013 // 00014 // $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.5-branch/Arrangement_on_surface_2/include/CGAL/Arr_accessor.h $ 00015 // $Id: Arr_accessor.h 50589 2009-07-13 13:29:46Z naamamay $ 00016 // 00017 // 00018 // Author(s) : Ron Wein <wein@post.tau.ac.il> 00019 // Efi Fogel <efif@post.tau.ac.il> 00020 00021 #ifndef CGAL_ARR_ACCESSOR_H 00022 #define CGAL_ARR_ACCESSOR_H 00023 00028 #include <CGAL/Arrangement_2/Arr_traits_adaptor_2.h> 00029 00030 CGAL_BEGIN_NAMESPACE 00031 00040 template <class Arrangement_> 00041 class Arr_accessor 00042 { 00043 public: 00044 00045 typedef Arrangement_ Arrangement_2; 00046 typedef Arr_accessor<Arrangement_2> Self; 00047 00048 typedef typename Arrangement_2::Size Size; 00049 typedef typename Arrangement_2::Point_2 Point_2; 00050 typedef typename Arrangement_2::X_monotone_curve_2 X_monotone_curve_2; 00051 00052 typedef typename Arrangement_2::Vertex_handle Vertex_handle; 00053 typedef typename Arrangement_2::Vertex_const_handle Vertex_const_handle; 00054 typedef typename Arrangement_2::Halfedge_handle Halfedge_handle; 00055 typedef typename Arrangement_2::Halfedge_const_handle Halfedge_const_handle; 00056 typedef typename Arrangement_2::Face_handle Face_handle; 00057 typedef typename Arrangement_2::Face_const_handle Face_const_handle; 00058 typedef typename Arrangement_2::Ccb_halfedge_circulator 00059 Ccb_halfedge_circulator; 00060 00061 private: 00062 00063 typedef typename Arrangement_2::DVertex DVertex; 00064 typedef typename Arrangement_2::DHalfedge DHalfedge; 00065 typedef typename Arrangement_2::DFace DFace; 00066 typedef typename Arrangement_2::DOuter_ccb DOuter_ccb; 00067 typedef typename Arrangement_2::DInner_ccb DInner_ccb; 00068 typedef typename Arrangement_2::DIso_vertex DIso_vertex; 00069 00070 private: 00071 00072 Arrangement_2 *p_arr; // The associated arrangement. 00073 00074 public: 00075 00077 Arr_accessor (Arrangement_2& arr) : 00078 p_arr (&arr) 00079 {} 00080 00081 /* Get the arrangement. */ 00082 Arrangement_2& arrangement () 00083 { 00084 return (*p_arr); 00085 } 00086 00087 /* Get the arrangement (const version). */ 00088 const Arrangement_2& arrangement() const 00089 { 00090 return (*p_arr); 00091 } 00092 00094 00095 00097 void notify_before_global_change () 00098 { 00099 p_arr->_notify_before_global_change(); 00100 } 00101 00103 void notify_after_global_change () 00104 { 00105 p_arr->_notify_after_global_change(); 00106 } 00108 00110 00111 00124 CGAL::Object locate_curve_end (const X_monotone_curve_2& cv, 00125 Arr_curve_end ind, 00126 Arr_parameter_space ps_x, 00127 Arr_parameter_space ps_y) const 00128 { 00129 CGAL_precondition (ps_x != ARR_INTERIOR || ps_y != ARR_INTERIOR); 00130 00131 // Use the topology traits to locate the unbounded curve end. 00132 CGAL::Object obj = 00133 p_arr->topology_traits()->locate_curve_end (cv, ind, 00134 ps_x, ps_y); 00135 00136 // Return a handle to the DCEL feature. 00137 DFace *f; 00138 00139 if (CGAL::assign (f, obj)) 00140 return (CGAL::make_object (p_arr->_const_handle_for (f))); 00141 00142 DHalfedge *he; 00143 00144 if (CGAL::assign (he, obj)) 00145 return (CGAL::make_object (p_arr->_const_handle_for (he))); 00146 00147 DVertex *v; 00148 00149 if (CGAL::assign (v, obj)) 00150 return (CGAL::make_object (p_arr->_const_handle_for (v))); 00151 00152 // We should never reach here: 00153 CGAL_error(); 00154 return Object(); 00155 } 00156 00166 Halfedge_handle locate_around_vertex (Vertex_handle vh, 00167 const X_monotone_curve_2& cv) const 00168 { 00169 typedef 00170 Arr_traits_basic_adaptor_2<typename Arrangement_2::Geometry_traits_2> 00171 Traits_adaptor_2; 00172 00173 const Traits_adaptor_2 *m_traits = 00174 static_cast<const Traits_adaptor_2*> (p_arr->geometry_traits()); 00175 00176 Arr_curve_end ind = ARR_MIN_END; 00177 00178 if (m_traits->is_closed_2_object() (cv, ARR_MAX_END) && 00179 m_traits->equal_2_object() (vh->point(), 00180 m_traits->construct_max_vertex_2_object()(cv))) 00181 { 00182 ind = ARR_MAX_END; 00183 } 00184 00185 DHalfedge * he = p_arr->_locate_around_vertex(p_arr->_vertex (vh), cv, ind); 00186 00187 CGAL_assertion (he != NULL); 00188 return (p_arr->_handle_for (he)); 00189 } 00190 00205 Halfedge_handle 00206 locate_around_boundary_vertex (Vertex_handle vh, 00207 const X_monotone_curve_2& cv, 00208 Arr_curve_end ind, 00209 Arr_parameter_space ps_x, 00210 Arr_parameter_space ps_y) const 00211 { 00212 CGAL_precondition (ps_x != ARR_INTERIOR || ps_y != ARR_INTERIOR); 00213 00214 // Use the topology traits to locate the unbounded curve end. 00215 DHalfedge* he = p_arr->topology_traits()-> 00216 locate_around_boundary_vertex (p_arr->_vertex (vh), 00217 cv, ind, ps_x, ps_y); 00218 00219 CGAL_assertion (he != NULL); 00220 return (p_arr->_handle_for (he)); 00221 } 00222 00231 int halfedge_distance (Halfedge_const_handle e1, 00232 Halfedge_const_handle e2) const 00233 { 00234 // If the two halfedges do not belong to the same component, return (-1). 00235 const DHalfedge *he1 = p_arr->_halfedge (e1); 00236 const DHalfedge *he2 = p_arr->_halfedge (e2); 00237 00238 if (he1 == he2) 00239 return (0); 00240 00241 const DInner_ccb *ic1 = (he1->is_on_inner_ccb()) ? he1->inner_ccb() : NULL; 00242 const DOuter_ccb *oc1 = (ic1 == NULL) ? he1->outer_ccb() : NULL; 00243 const DInner_ccb *ic2 = (he2->is_on_inner_ccb()) ? he2->inner_ccb() : NULL; 00244 const DOuter_ccb *oc2 = (ic2 == NULL) ? he2->outer_ccb() : NULL; 00245 00246 if (oc1 != oc2 || ic1 != ic2) 00247 return (-1); 00248 00249 // Compute the distance between the two halfedges. 00250 unsigned int dist = p_arr->_halfedge_distance (he1, he2); 00251 return (static_cast<int> (dist)); 00252 } 00253 00267 bool is_inside_new_face (Halfedge_handle prev1, 00268 Halfedge_handle prev2, 00269 const X_monotone_curve_2& cv) const 00270 { 00271 return (p_arr->_is_inside_new_face (p_arr->_halfedge (prev1), 00272 p_arr->_halfedge (prev2), 00273 cv)); 00274 } 00275 00286 bool are_equal (Vertex_const_handle v, 00287 const X_monotone_curve_2& cv, Arr_curve_end ind, 00288 Arr_parameter_space ps_x, Arr_parameter_space ps_y) const 00289 { 00290 return (p_arr->topology_traits()->are_equal (p_arr->_vertex (v), 00291 cv, ind, ps_x, ps_y)); 00292 } 00293 00301 bool is_on_outer_boundary (Halfedge_const_handle he) const 00302 { 00303 const DHalfedge *p_he = p_arr->_halfedge (he); 00304 00305 return (! p_he->is_on_inner_ccb()); 00306 } 00307 00315 bool is_on_inner_boundary (Halfedge_const_handle he) const 00316 { 00317 const DHalfedge *p_he = p_arr->_halfedge (he); 00318 00319 return (p_he->is_on_inner_ccb()); 00320 } 00321 00327 Vertex_handle create_vertex (const Point_2& p) 00328 { 00329 DVertex* v = p_arr->_create_vertex (p); 00330 00331 CGAL_assertion (v != NULL); 00332 return (p_arr->_handle_for (v)); 00333 } 00334 00346 Vertex_handle create_boundary_vertex (const X_monotone_curve_2& cv, 00347 Arr_curve_end ind, 00348 Arr_parameter_space ps_x, 00349 Arr_parameter_space ps_y, 00350 bool notify = true) 00351 { 00352 DVertex *v = p_arr->_create_boundary_vertex (cv, ind, ps_x, ps_y); 00353 00354 CGAL_assertion (v != NULL); 00355 00356 // Notify the topology traits on the creation of the boundary vertex. 00357 if (notify) 00358 { 00359 p_arr->topology_traits()->notify_on_boundary_vertex_creation(v, cv, ind, 00360 ps_x, ps_y); 00361 } 00362 00363 return (p_arr->_handle_for (v)); 00364 } 00365 00379 std::pair<Vertex_handle, Halfedge_handle> 00380 place_and_set_curve_end (Face_handle f, 00381 const X_monotone_curve_2& cv, Arr_curve_end ind, 00382 Arr_parameter_space ps_x, Arr_parameter_space ps_y) 00383 { 00384 DHalfedge *pred; 00385 DVertex *v = p_arr->_place_and_set_curve_end (p_arr->_face (f), cv, ind, 00386 ps_x, ps_y, &pred); 00387 00388 if (pred == NULL) 00389 // No predecessor halfedge, return just the vertex: 00390 return (std::make_pair (p_arr->_handle_for(v), Halfedge_handle())); 00391 00392 // Return a pair of the vertex and predecessor halfedge: 00393 return (std::make_pair (p_arr->_handle_for(v), p_arr->_handle_for(pred))); 00394 } 00395 00413 Halfedge_handle insert_at_vertices_ex (const X_monotone_curve_2& cv, 00414 Halfedge_handle prev1, 00415 Halfedge_handle prev2, 00416 Comparison_result res, 00417 bool& new_face) 00418 { 00419 DHalfedge* he = p_arr->_insert_at_vertices (cv, 00420 p_arr->_halfedge (prev1), 00421 p_arr->_halfedge (prev2), 00422 res, new_face); 00423 00424 CGAL_assertion (he != NULL); 00425 return (p_arr->_handle_for (he)); 00426 } 00427 00443 Halfedge_handle insert_from_vertex_ex (const X_monotone_curve_2& cv, 00444 Halfedge_handle prev, 00445 Vertex_handle v, 00446 Comparison_result res) 00447 { 00448 DVertex *p_v = p_arr->_vertex (v); 00449 00450 if (p_v->is_isolated()) 00451 { 00452 // Remove the isolated vertex record, which will not be isolated any 00453 // more. 00454 DIso_vertex *iv = p_v->isolated_vertex(); 00455 DFace *f = iv->face(); 00456 00457 f->erase_isolated_vertex (iv); 00458 p_arr->_dcel().delete_isolated_vertex (iv); 00459 } 00460 00461 DHalfedge* he = 00462 p_arr->_insert_from_vertex (cv, p_arr->_halfedge (prev), p_v, res); 00463 00464 CGAL_assertion (he != NULL); 00465 return (p_arr->_handle_for (he)); 00466 } 00467 00482 Halfedge_handle insert_in_face_interior_ex (const X_monotone_curve_2& cv, 00483 Face_handle f, 00484 Vertex_handle v1, 00485 Vertex_handle v2, 00486 Comparison_result res) 00487 { 00488 DVertex *p_v1 = p_arr->_vertex (v1); 00489 DVertex *p_v2 = p_arr->_vertex (v2); 00490 00491 if (p_v1->is_isolated()) 00492 { 00493 // Remove the isolated vertex record, which will not be isolated any 00494 // more. 00495 DIso_vertex *iv1 = p_v1->isolated_vertex(); 00496 DFace *f1 = iv1->face(); 00497 00498 f1->erase_isolated_vertex (iv1); 00499 p_arr->_dcel().delete_isolated_vertex (iv1); 00500 } 00501 00502 if (p_v2->is_isolated()) 00503 { 00504 // Remove the isolated vertex record, which will not be isolated any 00505 // more. 00506 DIso_vertex *iv2 = p_v2->isolated_vertex(); 00507 DFace *f2 = iv2->face(); 00508 00509 f2->erase_isolated_vertex (iv2); 00510 p_arr->_dcel().delete_isolated_vertex (iv2); 00511 } 00512 00513 DHalfedge* he = p_arr->_insert_in_face_interior (cv, 00514 p_arr->_face (f), 00515 p_v1, 00516 p_v2, 00517 res); 00518 00519 CGAL_assertion (he != NULL); 00520 return (p_arr->_handle_for (he)); 00521 00522 } 00523 00529 void insert_isolated_vertex (Face_handle f, Vertex_handle v) 00530 { 00531 p_arr->_insert_isolated_vertex (p_arr->_face (f), p_arr->_vertex(v)); 00532 } 00533 00543 void relocate_in_new_face (Halfedge_handle new_he) 00544 { 00545 p_arr->_relocate_in_new_face (p_arr->_halfedge (new_he)); 00546 return; 00547 } 00548 00549 void relocate_isolated_vertices_in_new_face (Halfedge_handle new_he) 00550 { 00551 p_arr->_relocate_isolated_vertices_in_new_face (p_arr->_halfedge(new_he)); 00552 return; 00553 } 00554 00555 void relocate_holes_in_new_face (Halfedge_handle new_he) 00556 { 00557 p_arr->_relocate_holes_in_new_face (p_arr->_halfedge(new_he)); 00558 return; 00559 } 00560 00567 void move_outer_ccb (Face_handle from_face, Face_handle to_face, 00568 Ccb_halfedge_circulator ccb) 00569 { 00570 p_arr->_move_outer_ccb (p_arr->_face (from_face), 00571 p_arr->_face (to_face), 00572 p_arr->_halfedge (ccb)); 00573 return; 00574 } 00575 00582 void move_inner_ccb (Face_handle from_face, Face_handle to_face, 00583 Ccb_halfedge_circulator ccb) 00584 { 00585 p_arr->_move_inner_ccb (p_arr->_face (from_face), 00586 p_arr->_face (to_face), 00587 p_arr->_halfedge (ccb)); 00588 return; 00589 } 00590 00597 void move_isolated_vertex (Face_handle from_face, Face_handle to_face, 00598 Vertex_handle v) 00599 { 00600 p_arr->_move_isolated_vertex (p_arr->_face (from_face), 00601 p_arr->_face (to_face), 00602 p_arr->_vertex (v)); 00603 return; 00604 } 00605 00610 void remove_isolated_vertex_ex (Vertex_handle v) 00611 { 00612 CGAL_precondition (v->is_isolated()); 00613 DVertex *iso_v = p_arr->_vertex (v); 00614 00615 p_arr->_remove_isolated_vertex (iso_v); 00616 return; 00617 } 00618 00626 Vertex_handle modify_vertex_ex (Vertex_handle v, 00627 const Point_2& p) 00628 { 00629 p_arr->_modify_vertex (p_arr->_vertex (v), 00630 p); 00631 00632 return (v); 00633 } 00634 00642 Halfedge_handle modify_edge_ex (Halfedge_handle e, 00643 const X_monotone_curve_2& cv) 00644 { 00645 p_arr->_modify_edge (p_arr->_halfedge (e), cv); 00646 00647 return (e); 00648 } 00649 00662 Halfedge_handle split_edge_ex (Halfedge_handle e, 00663 const Point_2& p, 00664 const X_monotone_curve_2& cv1, 00665 const X_monotone_curve_2& cv2) 00666 { 00667 DHalfedge* he = p_arr->_split_edge (p_arr->_halfedge (e), p, cv1, cv2); 00668 00669 CGAL_assertion (he != NULL); 00670 return (p_arr->_handle_for (he)); 00671 } 00672 00685 Halfedge_handle split_edge_ex (Halfedge_handle e, 00686 Vertex_handle v, 00687 const X_monotone_curve_2& cv1, 00688 const X_monotone_curve_2& cv2) 00689 { 00690 DHalfedge* he = p_arr->_split_edge (p_arr->_halfedge (e), 00691 p_arr->_vertex (v), 00692 cv1, cv2); 00693 00694 CGAL_assertion (he != NULL); 00695 return (p_arr->_handle_for (he)); 00696 } 00697 00705 Halfedge_handle split_fictitious_edge (Halfedge_handle e, Vertex_handle v) 00706 { 00707 CGAL_precondition (e->is_fictitious()); 00708 00709 DHalfedge *he = 00710 p_arr->topology_traits()->split_fictitious_edge (p_arr->_halfedge (e), 00711 p_arr->_vertex (v)); 00712 00713 return (p_arr->_handle_for (he)); 00714 } 00715 00727 Face_handle remove_edge_ex (Halfedge_handle e, 00728 bool remove_source = true, 00729 bool remove_target = true) 00730 { 00731 DFace* f = p_arr->_remove_edge (p_arr->_halfedge (e), 00732 remove_source, remove_target); 00733 00734 CGAL_assertion (f != NULL); 00735 return (p_arr->_handle_for (f)); 00736 } 00737 00744 bool are_on_same_inner_component (Halfedge_handle e1, Halfedge_handle e2) 00745 { 00746 DHalfedge *he1 = p_arr->_halfedge (e1); 00747 DHalfedge *he2 = p_arr->_halfedge (e2); 00748 00749 const DInner_ccb *ic1 = (he1->is_on_inner_ccb()) ? he1->inner_ccb() : NULL; 00750 00751 if (ic1 == NULL) 00752 return (false); 00753 00754 const DInner_ccb *ic2 = (he2->is_on_inner_ccb()) ? he2->inner_ccb() : NULL; 00755 00756 return (ic1 == ic2); 00757 } 00758 00765 bool are_on_same_outer_component (Halfedge_handle e1, Halfedge_handle e2) 00766 { 00767 DHalfedge *he1 = p_arr->_halfedge (e1); 00768 DHalfedge *he2 = p_arr->_halfedge (e2); 00769 00770 const DOuter_ccb *oc1 = (he1->is_on_outer_ccb()) ? he1->outer_ccb() : NULL; 00771 00772 if (oc1 == NULL) 00773 return (false); 00774 00775 const DOuter_ccb *oc2 = (he2->is_on_outer_ccb()) ? he2->outer_ccb() : NULL; 00776 00777 return (oc1 == oc2); 00778 } 00780 00782 00783 00788 typedef typename Arrangement_2::_Is_valid_vertex Is_valid_vertex; 00789 typedef typename Arrangement_2::_Valid_vertex_iterator Valid_vertex_iterator; 00790 00792 Valid_vertex_iterator valid_vertices_begin() 00793 { 00794 return (Valid_vertex_iterator 00795 (p_arr->topology_traits()->dcel().vertices_begin(), 00796 p_arr->topology_traits()->dcel().vertices_end(), 00797 Is_valid_vertex (p_arr->topology_traits()))); 00798 } 00799 00801 Valid_vertex_iterator valid_vertices_end() 00802 { 00803 return (Valid_vertex_iterator 00804 (p_arr->topology_traits()->dcel().vertices_end(), 00805 p_arr->topology_traits()->dcel().vertices_end(), 00806 Is_valid_vertex (p_arr->topology_traits()))); 00807 } 00808 00810 Size number_of_valid_vertices () const 00811 { 00812 return (p_arr->topology_traits()->number_of_valid_vertices()); 00813 } 00815 00817 00818 typedef typename Arrangement_2::Dcel Dcel; 00819 typedef typename Arrangement_2::DVertex_const_iter Dcel_vertex_iterator; 00820 typedef typename Arrangement_2::DEdge_const_iter Dcel_edge_iterator; 00821 typedef typename Arrangement_2::DFace_const_iter Dcel_face_iterator; 00822 typedef typename Arrangement_2::DOuter_ccb_const_iter 00823 Dcel_outer_ccb_iterator; 00824 typedef typename Arrangement_2::DInner_ccb_const_iter 00825 Dcel_inner_ccb_iterator; 00826 typedef typename Arrangement_2::DIso_vertex_const_iter 00827 Dcel_iso_vertex_iterator; 00828 00829 typedef DVertex Dcel_vertex; 00830 typedef DHalfedge Dcel_halfedge; 00831 typedef DFace Dcel_face; 00832 typedef DOuter_ccb Dcel_outer_ccb; 00833 typedef DInner_ccb Dcel_inner_ccb; 00834 typedef DIso_vertex Dcel_isolated_vertex; 00835 00839 const Dcel& dcel () const 00840 { 00841 return (p_arr->_dcel()); 00842 } 00843 00847 void clear_all () 00848 { 00849 p_arr->clear(); 00850 p_arr->_dcel().delete_all(); 00851 return; 00852 } 00853 00861 Dcel_vertex* set_vertex_boundary (const Vertex_handle v, 00862 Arr_parameter_space ps_x, Arr_parameter_space ps_y) 00863 { 00864 Dcel_vertex *v_to_set = p_arr->_vertex (v); 00865 00866 v_to_set->set_boundary (ps_x, ps_y); 00867 00868 return (v_to_set); 00869 } 00870 00879 Dcel_vertex* new_vertex (const Point_2 *p, 00880 Arr_parameter_space ps_x, Arr_parameter_space ps_y) 00881 { 00882 Dcel_vertex *new_v = p_arr->_dcel().new_vertex(); 00883 00884 if (p != NULL) 00885 { 00886 typename Dcel::Vertex::Point *p_pt = p_arr->_new_point(*p); 00887 new_v->set_point (p_pt); 00888 } 00889 else 00890 { 00891 CGAL_precondition (p_arr->is_open(ps_x, ps_y)); 00892 new_v->set_point (NULL); 00893 } 00894 00895 new_v->set_boundary (ps_x, ps_y); 00896 return (new_v); 00897 } 00898 00905 Dcel_halfedge* new_edge (const X_monotone_curve_2 *cv) 00906 { 00907 Dcel_halfedge *new_he = p_arr->_dcel().new_edge(); 00908 00909 if (cv != NULL) 00910 { 00911 typename Dcel::Halfedge::X_monotone_curve *p_cv = p_arr->_new_curve(*cv); 00912 new_he->set_curve (p_cv); 00913 } 00914 else 00915 { 00916 new_he->set_curve (NULL); 00917 } 00918 00919 return (new_he); 00920 } 00921 00926 Dcel_face* new_face () 00927 { 00928 return (p_arr->_dcel().new_face()); 00929 } 00930 00935 Dcel_outer_ccb* new_outer_ccb () 00936 { 00937 return (p_arr->_dcel().new_outer_ccb()); 00938 } 00939 00944 Dcel_inner_ccb* new_inner_ccb () 00945 { 00946 return (p_arr->_dcel().new_inner_ccb()); 00947 } 00948 00953 Dcel_isolated_vertex* new_isolated_vertex () 00954 { 00955 return (p_arr->_dcel().new_isolated_vertex()); 00956 } 00957 00961 void dcel_updated() 00962 { 00963 p_arr->topology_traits()->dcel_updated(); 00964 return; 00965 } 00967 00968 }; 00969 00970 CGAL_END_NAMESPACE 00971 00972 #endif