BWAPI
|
00001 // Copyright (c) 1997 Utrecht University (The Netherlands), 00002 // ETH Zurich (Switzerland), Freie Universitaet Berlin (Germany), 00003 // INRIA Sophia-Antipolis (France), Martin-Luther-University Halle-Wittenberg 00004 // (Germany), Max-Planck-Institute Saarbruecken (Germany), RISC Linz (Austria), 00005 // and Tel-Aviv University (Israel). All rights reserved. 00006 // 00007 // This file is part of CGAL (www.cgal.org); you can redistribute it and/or 00008 // modify it under the terms of the GNU Lesser General Public License as 00009 // published by the Free Software Foundation; version 2.1 of the License. 00010 // See the file LICENSE.LGPL distributed with CGAL. 00011 // 00012 // Licensees holding a valid commercial license may use this file in 00013 // accordance with the commercial license agreement provided with the software. 00014 // 00015 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00016 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00017 // 00018 // $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.5-branch/HalfedgeDS/include/CGAL/HalfedgeDS_items_decorator.h $ 00019 // $Id: HalfedgeDS_items_decorator.h 28567 2006-02-16 14:30:13Z lsaboret $ 00020 // 00021 // 00022 // Author(s) : Lutz Kettner <kettner@mpi-sb.mpg.de> 00023 00024 #ifndef CGAL_HALFEDGEDS_ITEMS_DECORATOR_H 00025 #define CGAL_HALFEDGEDS_ITEMS_DECORATOR_H 1 00026 00027 #include <CGAL/basic.h> 00028 #include <cstddef> 00029 00030 CGAL_BEGIN_NAMESPACE 00031 00032 template < class p_HDS > 00033 class HalfedgeDS_items_decorator { 00034 public: 00035 00036 // TYPES 00037 // ---------------------------------- 00038 typedef p_HDS HDS; 00039 typedef p_HDS HalfedgeDS; 00040 typedef typename HDS::Traits Traits; 00041 typedef typename HDS::Vertex Vertex; 00042 typedef typename HDS::Halfedge Halfedge; 00043 typedef typename HDS::Face Face; 00044 00045 typedef typename HDS::Vertex_handle Vertex_handle; 00046 typedef typename HDS::Vertex_const_handle Vertex_const_handle; 00047 typedef typename HDS::Vertex_iterator Vertex_iterator; 00048 typedef typename HDS::Vertex_const_iterator Vertex_const_iterator; 00049 00050 typedef typename HDS::Halfedge_handle Halfedge_handle; 00051 typedef typename HDS::Halfedge_const_handle Halfedge_const_handle; 00052 typedef typename HDS::Halfedge_iterator Halfedge_iterator; 00053 typedef typename HDS::Halfedge_const_iterator Halfedge_const_iterator; 00054 00055 typedef typename HDS::Face_handle Face_handle; 00056 typedef typename HDS::Face_const_handle Face_const_handle; 00057 typedef typename HDS::Face_iterator Face_iterator; 00058 typedef typename HDS::Face_const_iterator Face_const_iterator; 00059 00060 typedef typename HDS::size_type size_type; 00061 typedef typename HDS::difference_type difference_type; 00062 typedef typename HDS::iterator_category iterator_category; 00063 00064 // The following types are equal to either `Tag_true' or `Tag_false', 00065 // dependent whether the named feature is supported or not. 00066 00067 typedef typename HDS::Supports_vertex_halfedge 00068 Supports_vertex_halfedge; 00069 typedef typename HDS::Supports_halfedge_prev Supports_halfedge_prev; 00070 typedef typename HDS::Supports_halfedge_vertex 00071 Supports_halfedge_vertex; 00072 typedef typename HDS::Supports_halfedge_face Supports_halfedge_face; 00073 typedef typename HDS::Supports_face_halfedge Supports_face_halfedge; 00074 00075 typedef typename HDS::Supports_removal Supports_removal; 00076 00077 protected: 00078 typedef typename Vertex::Base VBase; 00079 typedef typename Halfedge::Base HBase; 00080 typedef typename Halfedge::Base_base HBase_base; 00081 typedef typename Face::Base FBase; 00082 00083 public: 00084 00085 // CREATION 00086 // ---------------------------------- 00087 00088 HalfedgeDS_items_decorator() {} 00089 00090 // Access Functions 00091 // ---------------------------------- 00092 00093 Halfedge_handle get_vertex_halfedge( Vertex_handle v) const { 00094 // returns the incident halfedge of v if supported, 00095 // `Halfedge_handle()' otherwise. 00096 return get_vertex_halfedge( v, Supports_vertex_halfedge()); 00097 } 00098 00099 Vertex_handle get_vertex( Halfedge_handle h) const { 00100 // returns the incident vertex of h if supported, 00101 // `Vertex_handle()' otherwise. 00102 return get_vertex( h, Supports_halfedge_vertex()); 00103 } 00104 00105 Halfedge_handle get_prev( Halfedge_handle h) const { 00106 // returns the previous halfedge of h if supported, 00107 // `Halfedge_handle()' otherwise. 00108 return get_prev( h, Supports_halfedge_prev()); 00109 } 00110 00111 Halfedge_handle find_prev( Halfedge_handle h) const { 00112 // returns the previous halfedge of h. Uses the `prev()' method if 00113 // supported or performs a search around the face using `next()'. 00114 return find_prev( h, Supports_halfedge_prev()); 00115 } 00116 00117 Halfedge_handle find_prev_around_vertex( Halfedge_handle h) const { 00118 // returns the previous halfedge of h. Uses the `prev()' method if 00119 // supported or performs a search around the vertex using `next()'. 00120 return find_prev_around_vertex( h, Supports_halfedge_prev()); 00121 } 00122 00123 Face_handle get_face( Halfedge_handle h) const { 00124 // returns the incident face of h if supported, 00125 // `Face_handle()' otherwise. 00126 return get_face( h, Supports_halfedge_face()); 00127 } 00128 00129 Halfedge_handle get_face_halfedge( Face_handle f) const { 00130 // returns the incident halfedge of f if supported, 00131 // `Halfedge_handle()' otherwise. 00132 return get_face_halfedge( f, Supports_face_halfedge()); 00133 } 00134 00135 // Const Access Functions 00136 // ---------------------------------- 00137 00138 Halfedge_const_handle 00139 get_vertex_halfedge( Vertex_const_handle v) const { 00140 return get_vertex_halfedge( v, Supports_vertex_halfedge()); 00141 } 00142 00143 Vertex_const_handle get_vertex( Halfedge_const_handle h) const { 00144 return get_vertex( h, Supports_halfedge_vertex()); 00145 } 00146 00147 Halfedge_const_handle get_prev( Halfedge_const_handle h) const { 00148 return get_prev( h, Supports_halfedge_prev()); 00149 } 00150 00151 Halfedge_const_handle find_prev( Halfedge_const_handle h) const { 00152 return find_prev( h, Supports_halfedge_prev()); 00153 } 00154 00155 Halfedge_const_handle 00156 find_prev_around_vertex( Halfedge_const_handle h) const { 00157 return find_prev_around_vertex( h, Supports_halfedge_prev()); 00158 } 00159 00160 Face_const_handle get_face( Halfedge_const_handle h) const { 00161 return get_face( h, Supports_halfedge_face()); 00162 } 00163 00164 Halfedge_const_handle get_face_halfedge( Face_const_handle f) const { 00165 return get_face_halfedge( f, Supports_face_halfedge()); 00166 } 00167 00168 // Modifying Functions (Primitives) 00169 // ---------------------------------- 00170 00171 void set_vertex_halfedge( Vertex_handle v, Halfedge_handle g) const { 00172 // sets the incident halfedge of v to g. 00173 set_vertex_halfedge( v, g, Supports_vertex_halfedge()); 00174 } 00175 00176 void set_vertex_halfedge( Halfedge_handle h) const { 00177 // sets the incident halfedge of the vertex incident to h to h. 00178 set_vertex_halfedge( h, h, Supports_halfedge_vertex()); 00179 } 00180 00181 void set_vertex( Halfedge_handle h, Vertex_handle v) const { 00182 // sets the incident vertex of h to v. 00183 set_vertex(h, v, Supports_halfedge_vertex()); 00184 } 00185 00186 void set_prev( Halfedge_handle h, Halfedge_handle g) const { 00187 // sets the previous link of h to g. 00188 set_prev( h, g, Supports_halfedge_prev()); 00189 } 00190 00191 void set_face( Halfedge_handle h, Face_handle f) const { 00192 // sets the incident face of h to f. 00193 set_face(h, f, Supports_halfedge_face()); 00194 } 00195 00196 void set_face_halfedge( Face_handle f, Halfedge_handle g) const { 00197 // sets the incident halfedge of f to g. 00198 set_face_halfedge( f, g, Supports_face_halfedge()); 00199 } 00200 00201 void set_face_halfedge( Halfedge_handle h) const { 00202 // sets the incident halfedge of the face incident to h to h. 00203 set_face_halfedge( h, h, Supports_halfedge_face()); 00204 } 00205 00206 // Modifying Functions (Composed) 00207 // ---------------------------------- 00208 00209 void close_tip( Halfedge_handle h) const { 00210 // makes `h->opposite()' the successor of h. 00211 h->HBase::set_next( h->opposite()); 00212 set_prev( h->opposite(), h); 00213 } 00214 00215 void close_tip( Halfedge_handle h, Vertex_handle v) const { 00216 // makes `h->opposite()' the successor of h and sets the incident 00217 // vertex of h to v. 00218 h->HBase::set_next( h->opposite()); 00219 set_prev( h->opposite(), h); 00220 set_vertex( h, v); 00221 set_vertex_halfedge( h); 00222 } 00223 00224 void insert_tip( Halfedge_handle h, Halfedge_handle v) const { 00225 // inserts the tip of the edge h into the halfedges around the 00226 // vertex pointed to by v. Halfedge `h->opposite()' is the new 00227 // successor of v and `h->next()' will be set to `v->next()'. The 00228 // vertex of h will be set to the vertex v refers to if vertices 00229 // are supported. 00230 h->HBase::set_next( v->next()); 00231 v->HBase::set_next( h->opposite()); 00232 set_prev( h->next(), h); 00233 set_prev( h->opposite(), v); 00234 set_vertex( h, get_vertex( v)); 00235 } 00236 00237 void remove_tip( Halfedge_handle h) const { 00238 // removes the edge `h->next()->opposite()' from the halfedge 00239 // circle around the vertex referred to by h. The new successor 00240 // halfedge of h will be `h->next()->opposite()->next()'. 00241 h->HBase::set_next( h->next()->opposite()->next()); 00242 set_prev( h->next(), h); 00243 } 00244 00245 void insert_halfedge( Halfedge_handle h, Halfedge_handle f) const { 00246 // inserts the halfedge h between f and `f->next()'. The face of h 00247 // will be the one f refers to if faces are supported. 00248 h->HBase::set_next( f->next()); 00249 f->HBase::set_next( h); 00250 set_prev( h->next(), h); 00251 set_prev( h, f); 00252 set_face( h, get_face( f)); 00253 } 00254 00255 void remove_halfedge( Halfedge_handle h) const { 00256 // removes edge `h->next()' from the halfedge circle around the 00257 // face referred to by h. The new successor of h will be 00258 // `h->next()->next()'. 00259 h->HBase::set_next( h->next()->next()); 00260 set_prev( h->next(), h); 00261 } 00262 00263 void set_vertex_in_vertex_loop( Halfedge_handle h, Vertex_handle v, 00264 Tag_false) const {} 00265 void set_vertex_in_vertex_loop( Halfedge_handle h, Vertex_handle v, 00266 Tag_true) const { 00267 CGAL_assertion_code( std::size_t termination_count = 0;) 00268 Halfedge_handle end = h; 00269 do { 00270 CGAL_assertion( ++termination_count != 0); 00271 h->HBase::set_vertex( v); 00272 h = h->next()->opposite(); 00273 } while ( h != end); 00274 } 00275 00276 void 00277 set_vertex_in_vertex_loop( Halfedge_handle h, Vertex_handle v) const { 00278 // loops around the vertex incident to h and sets all vertex 00279 // pointers to v. Precondition: `h != Halfedge_handle()'. 00280 CGAL_precondition( h != Halfedge_handle()); 00281 set_vertex_in_vertex_loop( h, v, Supports_halfedge_vertex()); 00282 } 00283 00284 void set_face_in_face_loop( Halfedge_handle h, Face_handle f, 00285 Tag_false) const {} 00286 void set_face_in_face_loop( Halfedge_handle h, Face_handle f, 00287 Tag_true) const { 00288 CGAL_assertion_code( std::size_t termination_count = 0;) 00289 Halfedge_handle end = h; 00290 do { 00291 CGAL_assertion( ++termination_count != 0); 00292 h->HBase::set_face( f); 00293 h = h->next(); 00294 } while ( h != end); 00295 } 00296 00297 void set_face_in_face_loop( Halfedge_handle h, Face_handle f) const { 00298 // loops around the face incident to h and sets all face pointers 00299 // to f. Precondition: `h != Halfedge_handle()'. 00300 CGAL_precondition( h != Halfedge_handle()); 00301 set_face_in_face_loop( h, f, Supports_halfedge_face()); 00302 } 00303 00304 Halfedge_handle flip_edge( Halfedge_handle h) const { 00305 // performs an edge flip. It returns h after 00306 // rotating the edge h one vertex in the direction of the face 00307 // orientation. Precondition: `h != Halfedge_handle()' and both 00308 // incident faces of h are triangles. 00309 CGAL_precondition( h != Halfedge_handle()); 00310 CGAL_precondition( h == h->next()->next()->next()); 00311 CGAL_precondition( h->opposite() == 00312 h->opposite()->next()->next()->next()); 00313 Halfedge_handle hprev = h->next()->next(); 00314 Halfedge_handle gprev = h->opposite()->next()->next(); 00315 remove_tip( hprev); 00316 remove_tip( gprev); 00317 set_face_halfedge( hprev); 00318 set_face_halfedge( gprev); 00319 set_vertex_halfedge( hprev); 00320 set_vertex_halfedge( gprev); 00321 set_face( hprev->next(), hprev->face()); 00322 set_face( gprev->next(), gprev->face()); 00323 hprev = hprev->next(); 00324 gprev = gprev->next(); 00325 insert_tip( h, gprev); 00326 insert_tip( h->opposite(), hprev); 00327 CGAL_postcondition( h == h->next()->next()->next()); 00328 CGAL_postcondition( h->opposite() == 00329 h->opposite()->next()->next()->next()); 00330 return h; 00331 } 00332 00333 // Implementing These Functions. 00334 // ==================================================== 00335 // Access Functions 00336 // ---------------------------------- 00337 00338 Halfedge_handle 00339 get_vertex_halfedge( Vertex_handle , Tag_false) const { 00340 return Halfedge_handle(); 00341 } 00342 Halfedge_handle 00343 get_vertex_halfedge( Vertex_handle v, Tag_true) const { 00344 return v->halfedge(); 00345 } 00346 00347 Vertex_handle get_vertex( Halfedge_handle , Tag_false) const { 00348 return Vertex_handle(); 00349 } 00350 Vertex_handle get_vertex( Halfedge_handle h, Tag_true) const { 00351 return h->vertex(); 00352 } 00353 00354 Halfedge_handle get_prev( Halfedge_handle , Tag_false) const { 00355 return Halfedge_handle(); 00356 } 00357 Halfedge_handle get_prev( Halfedge_handle h, Tag_true) const { 00358 return h->HBase::prev(); 00359 } 00360 00361 Halfedge_handle find_prev( Halfedge_handle h, Tag_true) const { 00362 return h->HBase::prev(); 00363 } 00364 Halfedge_handle find_prev( Halfedge_handle h, Tag_false) const { 00365 Halfedge_handle g = h; 00366 while ( g->next() != h) 00367 g = g->next(); 00368 return g; 00369 } 00370 00371 Halfedge_handle find_prev_around_vertex( Halfedge_handle h, 00372 Tag_true) const { 00373 return h->HBase::prev(); 00374 } 00375 Halfedge_handle find_prev_around_vertex( Halfedge_handle h, 00376 Tag_false) const { 00377 Halfedge_handle g = h->opposite(); 00378 while ( g->next() != h) 00379 g = g->next()->opposite(); 00380 return g; 00381 } 00382 00383 Face_handle get_face( Halfedge_handle , Tag_false) const { 00384 return Face_handle(); 00385 } 00386 Face_handle get_face( Halfedge_handle h, Tag_true) const { 00387 return h->face(); 00388 } 00389 00390 Halfedge_handle get_face_halfedge( Face_handle , Tag_false) const { 00391 return Halfedge_handle(); 00392 } 00393 Halfedge_handle get_face_halfedge( Face_handle f, Tag_true) const { 00394 return f->halfedge(); 00395 } 00396 00397 // Const Access Functions 00398 // ---------------------------------- 00399 00400 Halfedge_const_handle 00401 get_vertex_halfedge( Vertex_const_handle ,Tag_false) const { 00402 return Halfedge_const_handle(); 00403 } 00404 Halfedge_const_handle 00405 get_vertex_halfedge( Vertex_const_handle v,Tag_true) const { 00406 return v->halfedge(); 00407 } 00408 00409 Vertex_const_handle 00410 get_vertex( Halfedge_const_handle , Tag_false) const { 00411 return Vertex_const_handle(); 00412 } 00413 Vertex_const_handle 00414 get_vertex( Halfedge_const_handle h, Tag_true) const { 00415 return h->vertex(); 00416 } 00417 00418 Halfedge_const_handle 00419 get_prev( Halfedge_const_handle , Tag_false) const { 00420 return Halfedge_const_handle(); 00421 } 00422 Halfedge_const_handle 00423 get_prev( Halfedge_const_handle h, Tag_true) const { 00424 return h->HBase::prev(); 00425 } 00426 00427 Halfedge_const_handle 00428 find_prev( Halfedge_const_handle h, Tag_true) const { 00429 return h->HBase::prev(); 00430 } 00431 Halfedge_const_handle 00432 find_prev( Halfedge_const_handle h, Tag_false) const { 00433 Halfedge_const_handle g = h; 00434 while ( g->next() != h) 00435 g = g->next(); 00436 return g; 00437 } 00438 00439 Halfedge_const_handle 00440 find_prev_around_vertex( Halfedge_const_handle h, Tag_true) const { 00441 return h->HBase::prev(); 00442 } 00443 Halfedge_const_handle 00444 find_prev_around_vertex( Halfedge_const_handle h, Tag_false) const { 00445 Halfedge_const_handle g = h->opposite(); 00446 while ( g->next() != h) 00447 g = g->next()->opposite(); 00448 return g; 00449 } 00450 00451 Face_const_handle 00452 get_face( Halfedge_const_handle , Tag_false) const { 00453 return Face_const_handle(); 00454 } 00455 Face_const_handle 00456 get_face( Halfedge_const_handle h, Tag_true) const { 00457 return h->face(); 00458 } 00459 00460 Halfedge_const_handle 00461 get_face_halfedge( Face_const_handle , Tag_false) const { 00462 return Halfedge_const_handle(); 00463 } 00464 Halfedge_const_handle 00465 get_face_halfedge( Face_const_handle f, Tag_true) const { 00466 return f->halfedge(); 00467 } 00468 00469 // Modifying Function Primitives 00470 // ---------------------------------- 00471 00472 void set_vertex_halfedge( Vertex_handle, 00473 Halfedge_handle, 00474 Tag_false) const {} 00475 void set_vertex_halfedge( Vertex_handle v, 00476 Halfedge_handle g, 00477 Tag_true) const { 00478 v->VBase::set_halfedge(g); 00479 } 00480 00481 void set_vertex_halfedge( Halfedge_handle, 00482 Halfedge_handle, 00483 Tag_false) const {} 00484 void set_vertex_halfedge( Halfedge_handle h, 00485 Halfedge_handle g, 00486 Tag_true) const { 00487 set_vertex_halfedge( h->vertex(), g); 00488 } 00489 00490 void set_vertex( Halfedge_handle, Vertex_handle, Tag_false) const {} 00491 void set_vertex( Halfedge_handle h, Vertex_handle v, Tag_true) const { 00492 h->HBase::set_vertex(v); 00493 } 00494 00495 void set_prev( Halfedge_handle, Halfedge_handle, Tag_false) const {} 00496 void set_prev( Halfedge_handle h, Halfedge_handle g, Tag_true) const { 00497 h->HBase::set_prev( g); 00498 } 00499 00500 void set_face( Halfedge_handle, Face_handle, Tag_false) const {} 00501 void set_face( Halfedge_handle h, Face_handle f, Tag_true) const { 00502 h->HBase::set_face(f); 00503 } 00504 00505 void set_face_halfedge( Face_handle, 00506 Halfedge_handle, 00507 Tag_false) const {} 00508 void set_face_halfedge( Face_handle f, 00509 Halfedge_handle g, 00510 Tag_true) const { 00511 f->FBase::set_halfedge(g); 00512 } 00513 00514 void set_face_halfedge( Halfedge_handle, 00515 Halfedge_handle, 00516 Tag_false) const {} 00517 void set_face_halfedge( Halfedge_handle h, 00518 Halfedge_handle g, 00519 Tag_true) const { 00520 set_face_halfedge( h->face(), g); 00521 } 00522 }; 00523 00524 CGAL_END_NAMESPACE 00525 00526 #endif // CGAL_HALFEDGEDS_ITEMS_DECORATOR_H // 00527 // EOF //