BWAPI
|
00001 // Copyright (c) 2006 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_spherical_gaussian_map_3/Arr_spherical_gaussian_map_3.h $ 00015 // $Id: Arr_spherical_gaussian_map_3.h 50366 2009-07-05 12:56:48Z efif $ 00016 // 00017 // Author(s) : Efi Fogel <efif@post.tau.ac.il> 00018 00019 #ifndef CGAL_ARR_SPHERICAL_GAUSSIAN_MAP_3_H 00020 #define CGAL_ARR_SPHERICAL_GAUSSIAN_MAP_3_H 00021 00031 #include <string> 00032 #include <vector> 00033 #include <list> 00034 #include <iostream> 00035 00036 #include <CGAL/Arrangement_on_surface_2.h> 00037 #include <CGAL/intersections.h> 00038 #include <CGAL/Polygon_2_algorithms.h> 00039 #include <CGAL/Arr_default_dcel.h> 00040 #include <CGAL/Arr_spherical_topology_traits_2.h> 00041 00042 #if defined(CGAL_USE_LEDA) 00043 #if CGAL_LEDA_VERSION < 500 00044 #include <LEDA/rational.h> 00045 #else 00046 #include <LEDA/numbers/rational.h> 00047 #endif 00048 #endif 00049 00050 CGAL_BEGIN_NAMESPACE 00051 00052 // #define CGAL_ARR_SPHERICAL_GAUSSIAN_MAP_3_DEBUG 1 00053 00064 template <class FT, class Point_2> 00065 class Sgm_normalizer { 00066 public: 00071 void operator()(Point_2 & p) {} 00072 }; 00073 00074 #if defined(CGAL_USE_LEDA) 00075 00080 template <class Point_2> 00081 class Sgm_normalizer<leda::rational, Point_2> { 00082 public: 00086 void operator()(Point_2 & p) 00087 { 00088 leda::rational x = p.x(); 00089 x.normalize(); 00090 leda::rational y = p.y(); 00091 y.normalize(); 00092 leda::rational z = p.z(); 00093 z.normalize(); 00094 p = Point_2(x, y, z); 00095 } 00096 }; 00097 #endif 00098 00103 template <typename Sgm, typename T_Traits = typename Sgm::Traits> 00104 class Arr_sgm_initializer { 00105 public: 00106 typedef T_Traits Traits; 00107 typedef typename Traits::Vector_3 Vector_3; 00108 00109 typedef typename Sgm::Geometry_traits_2 Geometry_traits_2; 00110 typedef typename Geometry_traits_2::Point_2 Point_2; 00111 typedef typename Geometry_traits_2::X_monotone_curve_2 X_monotone_curve_2; 00112 typedef typename Geometry_traits_2::Curve_2 Curve_2; 00113 00114 typedef typename Sgm::Vertex_handle Vertex_handle; 00115 typedef typename Sgm::Halfedge_handle Halfedge_handle; 00116 typedef typename Sgm::Face_handle Face_handle; 00117 00119 Arr_sgm_initializer(Sgm & sgm) : m_sgm(sgm) { } 00120 00122 virtual ~Arr_sgm_initializer() {} 00123 00129 Halfedge_handle insert_non_intersecting(const Vector_3 & normal1, 00130 const Vector_3 & normal2) 00131 { 00132 X_monotone_curve_2 xc(normal1.direction(), normal2.direction()); 00133 return insert_non_intersecting_curve(m_sgm, xc); 00134 } 00135 00138 template<typename OutputIterator> 00139 OutputIterator make_x_monotone(const Vector_3 & normal1, 00140 const Vector_3 & normal2, 00141 OutputIterator oi) 00142 { 00143 Curve_2 cv(normal1.direction(), normal2.direction()); 00144 const Geometry_traits_2 * traits = this->m_sgm.geometry_traits(); 00145 oi = traits->make_x_monotone_2_object()(cv, oi); 00146 return oi; 00147 } 00148 00157 template<typename OutputIterator> 00158 OutputIterator insert(const Vector_3 & normal1, const Vector_3 & normal2, 00159 OutputIterator oi) 00160 { 00161 std::list<CGAL::Object> x_objects; 00162 make_x_monotone(normal1, normal2, std::back_inserter(x_objects)); 00163 00164 typename std::list<CGAL::Object>::iterator it = x_objects.begin(); 00165 const X_monotone_curve_2 * xc = object_cast<X_monotone_curve_2>(&(*it)); 00166 #if CGAL_ARR_SPHERICAL_GAUSSIAN_MAP_3_DEBUG==1 00167 std::cout << "1.a. insert_in_face_interior(" << *xc << ")" << std::endl; 00168 #endif 00169 Halfedge_handle he = 00170 m_sgm.insert_in_face_interior(*xc, m_sgm.faces_begin()); 00171 if (!xc->is_directed_right()) he = he->twin(); 00172 *oi++ = he; 00173 00174 ++it; 00175 if (it == x_objects.end()) return oi; 00176 00177 xc = object_cast<X_monotone_curve_2>(&(*it)); 00178 #if CGAL_ARR_SPHERICAL_GAUSSIAN_MAP_3_DEBUG==1 00179 std::cout << "1.b. insert_from_vertex(" << *xc << ")" << std::endl; 00180 #endif 00181 *oi++ = (xc->is_directed_right()) ? 00182 m_sgm.insert_from_left_vertex(*xc, he->target()) : 00183 m_sgm.insert_from_right_vertex(*xc, he->target()); 00184 return oi; 00185 } 00186 00195 template<typename OutputIterator> 00196 OutputIterator insert(const Vector_3 & normal1, Vertex_handle vertex1, 00197 const Vector_3 & normal2, 00198 OutputIterator oi) 00199 { 00200 std::list<CGAL::Object> x_objects; 00201 make_x_monotone(normal1, normal2, std::back_inserter(x_objects)); 00202 00203 typename std::list<CGAL::Object>::iterator it = x_objects.begin(); 00204 const X_monotone_curve_2 * xc = object_cast<X_monotone_curve_2>(&(*it)); 00205 #if CGAL_ARR_SPHERICAL_GAUSSIAN_MAP_3_DEBUG==1 00206 std::cout << "2.a. insert_from_vertex(" << *xc << ", " 00207 << vertex1->point() << ")" << std::endl; 00208 #endif 00209 00210 Halfedge_handle he = (xc->is_directed_right()) ? 00211 m_sgm.insert_from_left_vertex(*xc, vertex1) : 00212 m_sgm.insert_from_right_vertex(*xc, vertex1); 00213 *oi++ = he; 00214 00215 ++it; 00216 if (it == x_objects.end()) return oi; 00217 00218 xc = object_cast<X_monotone_curve_2>(&(*it)); 00219 #if CGAL_ARR_SPHERICAL_GAUSSIAN_MAP_3_DEBUG==1 00220 std::cout << "2.b. insert_from_vertex(" << *xc << ")" << std::endl; 00221 #endif 00222 *oi++ = (xc->is_directed_right()) ? 00223 m_sgm.insert_from_left_vertex(*xc, he->target()) : 00224 m_sgm.insert_from_right_vertex(*xc, he->target()); 00225 return oi; 00226 } 00227 00236 template<typename OutputIterator> 00237 OutputIterator insert(const Vector_3 & normal1, 00238 const Vector_3 & normal2, Vertex_handle vertex2, 00239 OutputIterator oi) 00240 { 00241 std::list<CGAL::Object> x_objects; 00242 make_x_monotone(normal1, normal2, std::back_inserter(x_objects)); 00243 00244 typename std::list<CGAL::Object>::iterator it = x_objects.begin(); 00245 if (x_objects.size() == 1) { 00246 const X_monotone_curve_2 * xc = object_cast<X_monotone_curve_2>(&(*it)); 00247 #if CGAL_ARR_SPHERICAL_GAUSSIAN_MAP_3_DEBUG==1 00248 std::cout << "3. insert_from_vertex(" << *xc << ")" << std::endl; 00249 #endif 00250 Halfedge_handle he = (xc->is_directed_right()) ? 00251 m_sgm.insert_from_right_vertex(*xc, vertex2) : 00252 m_sgm.insert_from_left_vertex(*xc, vertex2); 00253 *oi++ = he->twin(); 00254 return oi; 00255 } 00256 00257 const X_monotone_curve_2 * xc1 = object_cast<X_monotone_curve_2>(&(*it++)); 00258 const X_monotone_curve_2 * xc2 = object_cast<X_monotone_curve_2>(&(*it)); 00259 00260 #if CGAL_ARR_SPHERICAL_GAUSSIAN_MAP_3_DEBUG==1 00261 std::cout << "3.a. insert_from_vertex(" << *xc2 << ")" << std::endl; 00262 #endif 00263 Halfedge_handle he2 = (xc2->is_directed_right()) ? 00264 m_sgm.insert_from_right_vertex(*xc2, vertex2) : 00265 m_sgm.insert_from_left_vertex(*xc2, vertex2); 00266 he2 = he2->twin(); 00267 #if CGAL_ARR_SPHERICAL_GAUSSIAN_MAP_3_DEBUG==1 00268 std::cout << "3.b. insert_from_vertex(" << *xc1 << ")" << std::endl; 00269 #endif 00270 Halfedge_handle he1 = (xc1->is_directed_right()) ? 00271 m_sgm.insert_from_right_vertex(*xc1, he2->source()) : 00272 m_sgm.insert_from_left_vertex(*xc1, he2->source()); 00273 he1 = he1->twin(); 00274 *oi++ = he1; 00275 *oi++ = he2; 00276 return oi; 00277 } 00278 00288 template<typename OutputIterator> 00289 OutputIterator insert(const Vector_3 & normal1, Vertex_handle vertex1, 00290 const Vector_3 & normal2, Vertex_handle vertex2, 00291 OutputIterator oi) 00292 { 00293 std::list<CGAL::Object> x_objects; 00294 make_x_monotone(normal1, normal2, std::back_inserter(x_objects)); 00295 typename std::list<CGAL::Object>::iterator it = x_objects.begin(); 00296 if (x_objects.size() == 1) { 00297 const X_monotone_curve_2 * xc = object_cast<X_monotone_curve_2>(&(*it)); 00298 #if CGAL_ARR_SPHERICAL_GAUSSIAN_MAP_3_DEBUG==1 00299 std::cout << "4. insert_at_vertices(" << *xc << ")" << std::endl; 00300 #endif 00301 *oi++ = m_sgm.insert_at_vertices(*xc, vertex1, vertex2); 00302 return oi; 00303 } 00304 00305 const X_monotone_curve_2 * xc1 = object_cast<X_monotone_curve_2>(&(*it++)); 00306 const X_monotone_curve_2 * xc2 = object_cast<X_monotone_curve_2>(&(*it)); 00307 00308 #if CGAL_ARR_SPHERICAL_GAUSSIAN_MAP_3_DEBUG==1 00309 std::cout << "4.a. insert_from_vertex(" << *xc1 00310 << "," << vertex1->point() << ")" << std::endl; 00311 #endif 00312 Halfedge_handle he = (xc1->is_directed_right()) ? 00313 m_sgm.insert_from_left_vertex(*xc1, vertex1) : 00314 m_sgm.insert_from_right_vertex(*xc1, vertex1); 00315 *oi++ = he; 00316 #if CGAL_ARR_SPHERICAL_GAUSSIAN_MAP_3_DEBUG==1 00317 std::cout << "4.b. insert_at_vertices(" << *xc2 << ")" << std::endl; 00318 #endif 00319 *oi++ = m_sgm.insert_at_vertices(*xc2, he->target(), vertex2); 00320 return oi; 00321 } 00322 00323 protected: 00325 Sgm & m_sgm; 00326 }; 00327 00328 /* Spherical_gaussian_map is a data dtructure that represents a Gaussinal map 00329 * embedded on the sphere. 00330 */ 00331 template <class T_Traits, 00332 #ifndef CGAL_CFG_NO_TMPL_IN_TMPL_PARAM 00333 template <class T> 00334 #endif 00335 class T_Dcel = Arr_default_dcel> 00336 class Arr_spherical_gaussian_map_3 : 00337 public Arrangement_on_surface_2<T_Traits, 00338 Arr_spherical_topology_traits_2<T_Traits, 00339 #ifndef CGAL_CFG_NO_TMPL_IN_TMPL_PARAM 00340 T_Dcel<T_Traits> 00341 #else 00342 typename T_Dcel::template Dcel<T_Traits> 00343 #endif 00344 > 00345 > 00346 { 00347 private: 00348 typedef Arr_spherical_gaussian_map_3<T_Traits, T_Dcel> Self; 00349 00350 public: 00351 typedef T_Traits Traits; 00352 typedef Traits Geometry_traits_2; 00353 00355 Arr_spherical_gaussian_map_3() { } 00356 00358 Arr_spherical_gaussian_map_3 00359 (const Arr_spherical_gaussian_map_3 & gaussian_map) 00360 { 00361 // Not implemented yet! 00362 CGAL_error(); 00363 } 00364 00366 virtual ~Arr_spherical_gaussian_map_3() { this->clear(); } 00367 00368 #if 0 00369 00370 void clear() 00371 { 00372 CGAL_error_msg( "Not implemented yet!"); 00373 } 00374 00376 bool is_empty() const 00377 { 00378 CGAL_error_msg( "Not implemented yet!"); 00379 return true; 00380 } 00381 00386 unsigned int degree(Vertex_const_handle vh) const 00387 { 00388 CGAL_error_msg( "Not implemented yet!"); 00389 return vh->degree(); 00390 } 00391 #endif 00392 00394 void print_stat() 00395 { 00396 std::cout << "No. vertices: " << this->number_of_vertices() 00397 << ", no. halfedges: " << this->number_of_halfedges() 00398 << ", no. faces: " << this->number_of_faces() 00399 << std::endl; 00400 } 00401 00403 friend class CGAL::Arr_sgm_initializer<Self>; 00404 }; 00405 00406 CGAL_END_NAMESPACE 00407 00408 #endif