|
BWAPI
|
00001 // Copyright (c) 2003,2004,2005,2006 INRIA Sophia-Antipolis (France) and 00002 // Notre Dame University (U.S.A.). 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/Segment_Delaunay_graph_2/include/CGAL/Segment_Delaunay_graph_storage_site_2.h $ 00015 // $Id: Segment_Delaunay_graph_storage_site_2.h 46222 2008-10-13 09:56:02Z afabri $ 00016 // 00017 // 00018 // Author(s) : Menelaos Karavelas <mkaravel@cse.nd.edu> 00019 00020 00021 00022 #ifndef CGAL_SEGMENT_DELAUNAY_GRAPH_STORAGE_SITE_H 00023 #define CGAL_SEGMENT_DELAUNAY_GRAPH_STORAGE_SITE_H 00024 00025 #include <iostream> 00026 #include <CGAL/assertions.h> 00027 00028 #include <CGAL/Segment_Delaunay_graph_2/basic.h> 00029 00030 CGAL_BEGIN_NAMESPACE 00031 00036 CGAL_SEGMENT_DELAUNAY_GRAPH_2_BEGIN_NAMESPACE 00037 00038 template<class STraits> class Construct_storage_site_2; 00039 00040 CGAL_SEGMENT_DELAUNAY_GRAPH_2_END_NAMESPACE 00041 00042 00043 template <class STraits> 00044 class Segment_Delaunay_graph_storage_site_2 00045 { 00046 friend class 00047 CGAL_SEGMENT_DELAUNAY_GRAPH_2_NS::Construct_storage_site_2<STraits>; 00048 00049 public: 00050 typedef STraits Storage_traits; 00051 typedef typename Storage_traits::Geom_traits Geom_traits; 00052 typedef typename Geom_traits::Site_2 Site_2; 00053 typedef typename Storage_traits::Point_handle Point_handle; 00054 00055 protected: 00056 typedef Point_handle Handle; 00057 00058 typedef Segment_Delaunay_graph_storage_site_2<Storage_traits> Self; 00059 00060 protected: 00061 // constructs point site using input point 00062 static Self construct_storage_site_2(const Handle& hp) { 00063 Self t; 00064 t.initialize_site(hp); 00065 return t; 00066 } 00067 00068 // constructs segment site corresponding to the segment (*hp1,*hp2) 00069 static Self construct_storage_site_2(const Handle& hp1, 00070 const Handle& hp2) { 00071 Self t; 00072 t.initialize_site(hp1, hp2); 00073 return t; 00074 } 00075 00076 // constructs point site using the point of intersection of the 00077 // segments (*hp1,*hp2) and (*hq1,*hq2) 00078 static Self construct_storage_site_2(const Handle& hp1, 00079 const Handle& hp2, 00080 const Handle& hq1, 00081 const Handle& hq2) { 00082 Self t; 00083 t.initialize_site(hp1, hp2, hq1, hq2); 00084 return t; 00085 } 00086 00087 // constructs segment site whose endpoints are the points of 00088 // intersection of the pairs of segments (*hp1,*hp2), (*hq1,*hq2) 00089 // and (*hp1,*hp2), (*hr1,*hr2) 00090 static Self construct_storage_site_2(const Handle& hp1, 00091 const Handle& hp2, 00092 const Handle& hq1, 00093 const Handle& hq2, 00094 const Handle& hr1, 00095 const Handle& hr2) { 00096 Self t; 00097 t.initialize_site(hp1, hp2, hq1, hq2, hr1, hr2); 00098 return t; 00099 } 00100 00101 // constructs segment site using either the source or the target of 00102 // (*hp1,*hp2) (that depends on the boolean is_first_exact) and the 00103 // intersection of (*hp1,*hp2) with (*hq1,*hq2) as the other endpoint 00104 static Self construct_storage_site_2(const Handle& hp1, 00105 const Handle& hp2, 00106 const Handle& hq1, 00107 const Handle& hq2, 00108 bool is_first_exact) { 00109 Self t; 00110 t.initialize_site(hp1, hp2, hq1, hq2, is_first_exact); 00111 return t; 00112 } 00113 00114 00115 public: 00116 // DEFAULT CONSTRUCTOR 00117 //-------------------- 00118 Segment_Delaunay_graph_storage_site_2() : type_(0) {} 00119 00120 // COPY CONSTRUCTOR 00121 //----------------- 00122 Segment_Delaunay_graph_storage_site_2(const Self& other) { 00123 copy_from(other); 00124 } 00125 00126 // ASSIGNMENT OPERATOR 00127 //-------------------- 00128 Self& operator=(const Self& other) { 00129 copy_from(other); 00130 return *this; 00131 } 00132 00133 public: 00134 // PREDICATES 00135 //----------- 00136 bool is_defined() const { return type_ != 0; } 00137 bool is_point() const { return (type_ & 3) == 1; } 00138 bool is_segment() const { return (type_ & 3) == 2; } 00139 bool is_input() const { return !(type_ & 12); } 00140 bool is_input(unsigned int i) const { 00141 CGAL_precondition( is_segment() && i < 2 ); 00142 if ( i == 0 ) { return !(type_ & 4); } 00143 return !(type_ & 8); 00144 } 00145 00146 // ACCESS METHODS 00147 //--------------- 00148 const Handle& point() const { 00149 CGAL_precondition( is_point() && is_input() ); 00150 return h_[0]; 00151 } 00152 00153 const Handle& source_of_supporting_site() const { 00154 CGAL_precondition( is_segment() ); 00155 return h_[0]; 00156 } 00157 00158 const Handle& target_of_supporting_site() const { 00159 CGAL_precondition( is_segment() ); 00160 return h_[1]; 00161 } 00162 00163 const Handle& source_of_supporting_site(unsigned int i) const { 00164 CGAL_precondition( is_point() && !is_input() ); 00165 return (i == 0) ? h_[2] : h_[4]; 00166 } 00167 00168 const Handle& target_of_supporting_site(unsigned int i) const { 00169 CGAL_precondition( is_point() && !is_input() ); 00170 return (i == 0) ? h_[3] : h_[5]; 00171 } 00172 00173 const Handle& source_of_crossing_site(unsigned int i) const { 00174 CGAL_precondition( is_segment() && !is_input(i) ); 00175 return (i == 0) ? h_[2] : h_[4]; 00176 } 00177 00178 const Handle& target_of_crossing_site(unsigned int i) const { 00179 CGAL_precondition( is_segment() && !is_input(i) ); 00180 return (i == 0) ? h_[3] : h_[5]; 00181 } 00182 00183 Self source_site() const { 00184 CGAL_precondition( is_segment() ); 00185 if ( is_input() || is_input(0) ) { 00186 return construct_storage_site_2(h_[0]); 00187 } else { 00188 return construct_storage_site_2(h_[0], h_[1], h_[2], h_[3]); 00189 } 00190 } 00191 00192 Self target_site() const { 00193 CGAL_precondition( is_segment() ); 00194 if ( is_input() || is_input(1) ) { 00195 return construct_storage_site_2(h_[1]); 00196 } else { 00197 return construct_storage_site_2(h_[0], h_[1], h_[4], h_[5]); 00198 } 00199 } 00200 00201 Self supporting_site() const { 00202 CGAL_precondition( is_segment() ); 00203 return construct_storage_site_2(h_[0], h_[1]); 00204 } 00205 00206 Self supporting_site(unsigned int i) const { 00207 CGAL_precondition( is_point() && !is_input() && i < 2 ); 00208 if ( i == 0 ) { 00209 return construct_storage_site_2(h_[2], h_[3]); 00210 } else { 00211 return construct_storage_site_2(h_[4], h_[5]); 00212 } 00213 } 00214 00215 Self crossing_site(unsigned int i) const { 00216 CGAL_precondition( is_segment() && !is_input() ); 00217 CGAL_precondition( i < 2 && !is_input(i) ); 00218 if ( i == 0 ) { 00219 return construct_storage_site_2(h_[2], h_[3]); 00220 } else { 00221 return construct_storage_site_2(h_[4], h_[5]); 00222 } 00223 } 00224 00225 Site_2 site() const { 00226 if ( is_point() ) { 00227 if ( is_input() ) { 00228 return Site_2::construct_site_2(*h_[0]); 00229 } else { 00230 return Site_2::construct_site_2(*h_[2], *h_[3], *h_[4], *h_[5]); 00231 } 00232 } else { 00233 if ( is_input() ) { 00234 return Site_2::construct_site_2(*h_[0], *h_[1]); 00235 } else if ( is_input(0) ) { 00236 return Site_2::construct_site_2(*h_[0], *h_[1], *h_[4], 00237 *h_[5], true); 00238 } else if ( is_input(1) ) { 00239 return Site_2::construct_site_2(*h_[0], *h_[1], *h_[2], 00240 *h_[3], false); 00241 } else { 00242 return Site_2::construct_site_2(*h_[0], *h_[1], *h_[2], 00243 *h_[3], *h_[4], *h_[5]); 00244 } 00245 } 00246 } 00247 00248 protected: 00249 // INITIALIZATION 00250 //--------------- 00251 void initialize_site(const Handle& hp) 00252 { 00253 type_ = 1; 00254 h_[0] = hp; 00255 } 00256 00257 void initialize_site(const Handle& hp1, const Handle& hp2) 00258 { 00259 type_ = 2; 00260 h_[0] = hp1; 00261 h_[1] = hp2; 00262 } 00263 void initialize_site(const Handle& hp1, const Handle& hp2, 00264 const Handle& hq1, const Handle& hq2) 00265 { 00266 // MK: Sort the segments s1 and s2 in lexicographical order so 00267 // that the computation of the intersection point is always 00268 // done in the same manner (?) 00269 type_ = 5; 00270 h_[2] = hp1; 00271 h_[3] = hp2; 00272 h_[4] = hq1; 00273 h_[5] = hq2; 00274 } 00275 00276 00277 void initialize_site(const Handle& hp1, const Handle& hp2, 00278 const Handle& hq1, const Handle& hq2, 00279 const Handle& hr1, const Handle& hr2) 00280 { 00281 type_ = 14; 00282 h_[0] = hp1; 00283 h_[1] = hp2; 00284 h_[2] = hq1; 00285 h_[3] = hq2; 00286 h_[4] = hr1; 00287 h_[5] = hr2; 00288 } 00289 00290 void initialize_site(const Handle& hp1, const Handle& hp2, 00291 const Handle& hq1, const Handle& hq2, 00292 bool is_first_exact) 00293 { 00294 type_ = (is_first_exact ? 10 : 6); 00295 h_[0] = hp1; 00296 h_[1] = hp2; 00297 if ( is_first_exact ) { 00298 h_[4] = hq1; 00299 h_[5] = hq2; 00300 } else { 00301 h_[2] = hq1; 00302 h_[3] = hq2; 00303 } 00304 } 00305 00306 void copy_from(const Self& other) { 00307 type_ = other.type_; 00308 00309 if ( !other.is_defined() ) { return; } 00310 00311 if ( other.is_point() ) { 00312 if ( other.is_input() ) { 00313 h_[0] = other.h_[0]; 00314 } else { 00315 h_[2] = other.h_[2]; 00316 h_[3] = other.h_[3]; 00317 h_[4] = other.h_[4]; 00318 h_[5] = other.h_[5]; 00319 } 00320 } else { 00321 h_[0] = other.h_[0]; 00322 h_[1] = other.h_[1]; 00323 if ( !other.is_input() ) { 00324 if ( other.is_input(0) ) { 00325 h_[4] = other.h_[4]; 00326 h_[5] = other.h_[5]; 00327 } else if ( other.is_input(1) ) { 00328 h_[2] = other.h_[2]; 00329 h_[3] = other.h_[3]; 00330 } else { 00331 h_[2] = other.h_[2]; 00332 h_[3] = other.h_[3]; 00333 h_[4] = other.h_[4]; 00334 h_[5] = other.h_[5]; 00335 } 00336 } 00337 } 00338 } 00339 00340 protected: 00341 Handle h_[6]; 00342 char type_; 00343 }; 00344 00345 //------------------------------------------------------------------------- 00346 00347 CGAL_END_NAMESPACE 00348 00349 #endif // CGAL_SEGMENT_DELAUNAY_GRAPH_STORAGE_SITE_H
1.7.6.1