|
BWAPI
|
00001 // Copyright (c) 2005 Stanford University (USA). 00002 // All rights reserved. 00003 // 00004 // This file is part of CGAL (www.cgal.org); you can redistribute it and/or 00005 // modify it under the terms of the GNU Lesser General Public License as 00006 // published by the Free Software Foundation; version 2.1 of the License. 00007 // See the file LICENSE.LGPL distributed with CGAL. 00008 // 00009 // Licensees holding a valid commercial license may use this file in 00010 // accordance with the commercial license agreement provided with the software. 00011 // 00012 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00013 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00014 // 00015 // $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.5-branch/Kinetic_data_structures/include/CGAL/Kinetic/internal/triangulation_helpers_3.h $ 00016 // $Id: triangulation_helpers_3.h 28567 2006-02-16 14:30:13Z lsaboret $ 00017 // 00018 // 00019 // Author(s) : Daniel Russel <drussel@alumni.princeton.edu> 00020 00021 #ifndef CGAL_KINETIC_INTERNAL_TRIANGULATION_HELPERS_3_H 00022 #define CGAL_KINETIC_INTERNAL_TRIANGULATION_HELPERS_3_H 00023 #include <CGAL/Kinetic/basic.h> 00024 #include <CGAL/utility.h> 00025 #include <vector> 00026 00027 CGAL_KINETIC_BEGIN_INTERNAL_NAMESPACE 00028 00029 /*template <class C> 00030 typename C::first_type hi_there(C){ 00031 return NULL; 00032 }*/ 00033 00034 template <class C> 00035 typename C::first_type::value_type::Vertex_handle vertex_of_facet(const C& f, 00036 unsigned int i) 00037 { 00038 CGAL_precondition( i<3); 00039 int o; 00040 if (f.second%2==1) o = (f.second+i+1)%4; 00041 else { 00042 o= (f.second+(2-i)+1)%4; 00043 } 00044 return f.first->vertex(o); 00045 } 00046 00047 00048 template <class C> 00049 typename C::first_type::value_type::Vertex_handle vertex_of_edge(const C& f, 00050 unsigned int i) 00051 { 00052 CGAL_precondition(i<2); 00053 if (i==0) { 00054 return f.first->vertex(f.second); 00055 } 00056 else { 00057 return f.first->vertex(f.third); 00058 } 00059 } 00060 00061 00062 template <class F> 00063 void write_facet(F f, std::ostream &out) 00064 { 00065 std::vector<typename F::first_type::value_type::Point> pts; 00066 pts.push_back(vertex_of_facet(f,0)->point()); 00067 pts.push_back(vertex_of_facet(f,1)->point()); 00068 pts.push_back(vertex_of_facet(f,2)->point()); 00069 std::sort(pts.begin(), pts.end()); 00070 out << "{" << pts[0] << ", " << pts[1] << ", " << pts[2] << "}"; 00071 } 00072 00073 00074 template <class E> 00075 void write_edge(const E &e, std::ostream &out) 00076 { 00077 std::vector<typename E::first_type::value_type::Point> pts; 00078 pts.push_back(vertex_of_edge(e,0)->point()); 00079 pts.push_back(vertex_of_edge(e,1)->point()); 00080 std::sort(pts.begin(), pts.end()); 00081 out << "[" << pts[0] << ", " << pts[1] << "]"; 00082 } 00083 00084 00085 template <class T> 00086 bool has_degree_3(const T&t, const typename T::Edge &e) 00087 { 00088 typename T::Cell_circulator ccir= t.incident_cells(e), ecir= ccir; 00089 int degree=0; 00090 do { 00091 ++degree; 00092 if (degree >3) break; 00093 ++ccir; 00094 } while (ccir != ecir); 00095 bool ret=( degree==3); 00096 return ret; 00097 }; 00098 00099 template <class Tr> 00100 bool has_degree_4(const Tr &t, const typename Tr::Vertex_handle vh) 00101 { 00102 typename Tr::Cell_handle h= vh->cell(); 00103 int vi= h->index(vh); 00104 typename Tr::Vertex_handle ovh; 00105 bool ret=true; 00106 for (int i=0; i< 4; ++i) { 00107 if (i==vi) continue; 00108 if (ovh== typename Tr::Vertex_handle()) { 00109 ovh= t.mirror_vertex(h, i); //h->mirror_vertex(i); 00110 } 00111 else { 00112 if (ovh != t.mirror_vertex(h, i)) { 00113 ret=false; 00114 break; 00115 } 00116 } 00117 } 00118 #ifndef NDEBUG 00119 std::vector<typename Tr::Vertex_handle> vhs; 00120 t.incident_vertices(vh, std::back_insert_iterator<std::vector<typename Tr::Vertex_handle> >(vhs)); 00121 if (vhs.size()==4) CGAL_postcondition(ret); 00122 else CGAL_postcondition(!ret); 00123 #endif 00124 return ret; 00125 } 00126 00127 00128 template <class Stream, class Ch> 00129 void write_cell(const Ch h, Stream &out) 00130 { 00131 out << "["; 00132 for (unsigned int i=0; i< 4; ++i) { 00133 out << h->vertex(i)->point(); 00134 if (i !=3) out << " "; 00135 } 00136 out << "]"; 00137 } 00138 00139 00140 template <class Edge, class Cell_handle> 00141 Edge edge_in_cell(const Edge &e, const Cell_handle c) 00142 { 00143 if (e.first == c) return e; 00144 typename Cell_handle::value_type::Vertex_handle p0= e.first->vertex(e.second); 00145 typename Cell_handle::value_type::Vertex_handle p1= e.first->vertex(e.third); 00146 return Edge(c, c->index(p0), c->index(p1)); 00147 } 00148 00149 00150 template <class Tr> 00151 void set_edge_label(const Tr &tr, const typename Tr::Edge &e, typename Tr::Cell::Edge_label l) 00152 { 00153 typename Tr::Cell_circulator cc= tr.incident_cells(e), ce= cc; 00154 do { 00155 typename Tr::Edge ec= edge_in_cell(e, cc); 00156 ec.first->set_edge_label(ec.second, ec.third, l); 00157 //CGAL_postcondition(label(Edge(ec))==l); 00158 ++cc; 00159 } while (cc != ce); 00160 CGAL_postcondition(edge_label(e)==l); 00161 } 00162 00163 00164 template <class Facet, class Edge> 00165 typename Facet::first_type::value_type::Vertex_handle other_vertex(const Facet &f, const Edge &e) 00166 { 00167 //CGAL_precondition(e.first == f.first); 00168 for (int i=0; i< 4; ++i) { 00169 if (i== f.second) continue; 00170 if (f.first->vertex(i) == e.first->vertex(e.second)) continue; 00171 if (f.first->vertex(i) == e.first->vertex(e.third)) continue; 00172 return f.first->vertex(i); 00173 } 00174 CGAL_postcondition(0); 00175 return typename Facet::first_type::value_type::Vertex_handle(); 00176 } 00177 00178 00179 template <class Facet> 00180 typename Facet::first_type::value_type::Triangulation_data_structure::Edge facet_edge(const Facet &f, unsigned int i) 00181 { 00182 CGAL_precondition( i <3); 00183 int f0= (i+1)%3; 00184 int f1= (i+2)%3; 00185 int i0= (f.second+1+f0)%4; 00186 int i1= (f.second+1+f1)%4; 00187 if (i1== f.second) { 00188 i1= (i1+1)%4; 00189 } 00190 typename Facet::first_type::value_type::Triangulation_data_structure::Edge ret(f.first, i0, i1); 00191 CGAL_postcondition(i0 != f.second); 00192 CGAL_postcondition(i1 != f.second); 00193 return ret; 00194 } 00195 00196 00197 template <class Tr> 00198 bool has_degree_3(const Tr &t, const typename Tr::Facet &f) 00199 { 00200 /*CGAL_precondition_code(Edge e0= edge(f,0)); 00201 CGAL_precondition_code(Edge e1= edge(f,1)); 00202 CGAL_precondition_code(Edge e2= edge(f,2)); 00203 CGAL_precondition(vertex(e0,1)== vertex(e1,0)); 00204 CGAL_precondition(vertex(e1,1)== vertex(e2,0)); 00205 CGAL_precondition(vertex(e2,1)== vertex(e0,0)); 00206 CGAL_precondition(vertex(e0,0) != f.first->vertex(f.second)); 00207 CGAL_precondition(vertex(e1,0) != f.first->vertex(f.second)); 00208 CGAL_precondition(vertex(e2,0) != f.first->vertex(f.second)); 00209 CGAL_precondition(hd3(f)== hd3(opposite(f)));*/ 00210 for (unsigned int i=0; i<3 ;++i) { 00211 bool d3 = has_degree_3(t, facet_edge(f, i)); 00212 CGAL_assertion(has_degree_3(t, opposite_edge(facet_edge(f,i)))== d3); 00213 if (d3) return true; 00214 } 00215 return false; 00216 } 00217 00218 00219 template <class Facet> 00220 typename Facet::first_type::value_type::Facet_label facet_label(const Facet &f) 00221 { 00222 return f.first->facet_label(f.second); 00223 } 00224 00225 00226 template <class Edge> 00227 typename Edge::first_type::value_type::Edge_label edge_label(const Edge &f) 00228 { 00229 return f.first->edge_label(f.second, f.third); 00230 00231 /*CGAL_postcondition_code(Cell_circulator cc= incident_cells(f)); 00232 CGAL_postcondition_code(Cell_circulator ce= cc); 00233 CGAL_postcondition_code(do {) 00234 CGAL_postcondition_code( Edge ec= edge_in_cell(f, cc)); 00235 CGAL_postcondition(ec.first->edge_label(ec.second, ec.third)==ret); 00236 CGAL_postcondition_code(++cc); 00237 CGAL_postcondition_code(} while (cc != ce)); 00238 return ret;*/ 00239 } 00240 00241 00242 template <class Facet, class Label> 00243 void set_oriented_facet_label(const Facet &f, Label l) 00244 { 00245 f.first->set_facet_label(f.second, l); 00246 } 00247 00248 00249 template <class Triangulation, class Facet, class Label> 00250 void set_facet_label(const Triangulation &t, const Facet &f, Label l) 00251 { 00252 set_oriented_facet_label(f, l); 00253 set_oriented_facet_label(opposite_facet(t, f), l); 00254 CGAL_postcondition(facet_label(f)==l); 00255 } 00256 00257 00258 template <class Edge> 00259 Edge cross_edge(Edge &e) 00260 { 00261 int a=-1, b; 00262 for (int i=0; i<4; ++i) { 00263 if (i != e.second && i != e.third) { 00264 if (a==-1) { 00265 a=i; 00266 } 00267 else { 00268 b=i; 00269 break; 00270 } 00271 } 00272 } 00273 return Edge(e.first, a,b); 00274 } 00275 00276 00277 template <class Cell_handle, class Vertex_handle> 00278 typename Cell_handle::first_type::value_type::Triangulation::Edge edge_around_vertex(const Cell_handle cell, 00279 const Vertex_handle vh, 00280 unsigned int i) 00281 { 00282 CGAL_assertion(i<3); 00283 int vi= cell->index(vh); 00284 typename Cell_handle::first_type::value_type::Triangulation::Edge ret(cell, vi, (vi+i+1)%4); 00285 //CGAL_assertion(is_edge(ret.first, ret.second, ret.third)); 00286 return ret; 00287 } 00288 00289 00291 00294 template <class Cell_handle, class Vertex_handle> 00295 typename Cell_handle::first_type::value_type::Triangulation::Facet facet_around_vertex(const Cell_handle cell, 00296 const Vertex_handle vh, 00297 unsigned int i) 00298 { 00299 int vi= cell->index(vh); 00300 typename Cell_handle::first_type::value_type::Triangulation::Facet ret(cell, (vi+i+1)%4); 00301 #ifndef NDEBUG 00302 typename Cell_handle::first_type::value_type::Triangulation::Edge e= edge_around_vertex(cell, vh, i); 00303 00304 for (int j=0; j<3; ++j) { 00305 typename Cell_handle::first_type::value_type::Triangulation::Vertex_handle v2= vertex(ret, j); 00306 if (v2 != vh) { 00307 CGAL_assertion(v2 != cell->vertex(e.second) && 00308 v2 != cell->vertex(e.third)); 00309 } 00310 } 00311 #endif 00312 return ret; 00313 } 00314 00315 00316 template <class Cell_handle> 00317 void clear_cell_labels(Cell_handle h) 00318 { 00319 for (unsigned int i=0; i<4; ++i) { 00320 h->set_facet_label(i, typename Cell_handle::value_type::Facet_label()); 00321 for (unsigned int j=0; j<i; ++j) { 00322 h->set_edge_label(i,j, typename Cell_handle::value_type::Edge_label()); 00323 } 00324 } 00325 } 00326 00327 00328 /* Vertex_handle vertex(const Facet &f, unsigned int i) const { 00329 return vertex_of_facet(f, i); 00330 } 00331 00332 Vertex_handle vertex(const Edge &f, unsigned int i) const { 00333 //hi_there<Edge>(f); 00334 //hi_there(f); 00335 typedef typename Edge::first_type::value_type::Vertex_handle Q; 00336 Q q; 00337 return vertex_of_edge(f, i); 00338 }*/ 00339 00340 template <class Triangulation, class Facet> 00341 Facet opposite_facet(const Triangulation &t, const Facet &e) 00342 { 00343 return Facet(e.first->neighbor(e.second), 00344 t.mirror_index(e.first, e.second)); 00345 } 00346 00347 00348 template <class Edge> 00349 Edge opposite_edge(const Edge &e) 00350 { 00351 return Edge(e.first, e.third, e.second); 00352 } 00353 00354 00355 template <class Edge> 00356 bool equal_edge(const Edge &e0, const Edge &e1) 00357 { 00358 typename Edge::first_type::value_type::Triangulation::Vertex_handle e0a= e0.first->vertex(e0.second); 00359 typename Edge::first_type::value_type::Triangulation::Vertex_handle e0b= e0.first->vertex(e0.third); 00360 typename Edge::first_type::value_type::Triangulation::Vertex_handle e1a= e1.first->vertex(e1.second); 00361 typename Edge::first_type::value_type::Triangulation::Vertex_handle e1b= e1.first->vertex(e1.third); 00362 bool ret=( (e0a==e1a && e0b==e1b) || (e0a==e1b && e0b== e1a)); 00363 /*if (verbose) { 00364 std::cout << "Comparing "; 00365 rwite_edge(e0); 00366 std::cout << " and "; 00367 write_edge(e1); 00368 std::cout << " and getting " << ret << std::endl; 00369 }*/ 00370 return ret; 00371 } 00372 00373 00374 template <class Edge, class Stream> 00375 void write_edge(const Edge &e, Stream &out) 00376 { 00377 std::vector<typename Edge::first_type::value_type::Geom_traits::Point_3> pts; 00378 pts.push_back(vertex(e,0)->point()); 00379 pts.push_back(vertex(e,1)->point()); 00380 std::sort(pts.begin(), pts.end()); 00381 out << "[" << pts[0] << ", " << pts[1] << "]"; 00382 /*if (label(e) != Edge_label::null()){ 00383 out << " " << label(e); 00384 }*/ 00385 } 00386 00387 00388 /* 00389 template <class Stream> 00390 void write_labeled_facet(const Facet &f, Stream &out) const { 00391 std::vector<typename Tri::Geom_traits::Point_3> pts; 00392 pts.push_back(vertex(f,0)->point()); 00393 pts.push_back(vertex(f,1)->point()); 00394 pts.push_back(vertex(f,2)->point()); 00395 std::sort(pts.begin(), pts.end()); 00396 out << "[" << pts[0] << ", " << pts[1] << ", " << pts[2] << "]"; 00397 if (label(f)){ 00398 out << " " << label(f); 00399 } 00400 } 00401 00402 template <class Stream> 00403 void write_labeled_edge(const Edge &e, Stream &out) const { 00404 std::vector<typename Tri::Geom_traits::Point_3> pts; 00405 pts.push_back(vertex(e,0)->point()); 00406 pts.push_back(vertex(e,1)->point()); 00407 std::sort(pts.begin(), pts.end()); 00408 out << "[" << pts[0] << ", " << pts[1] << "]"; 00409 if (label(e) ){ 00410 out << " " << label(e); 00411 } 00412 } 00413 */ 00414 00415 CGAL_KINETIC_END_INTERNAL_NAMESPACE 00416 #endif
1.7.6.1