BWAPI
|
00001 // Copyright (c) 2002 Utrecht University (The Netherlands). 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/Spatial_searching/include/CGAL/Splitters.h $ 00015 // $Id: Splitters.h 28567 2006-02-16 14:30:13Z lsaboret $ 00016 // 00017 // 00018 // Author(s) : Hans Tangelder (<hanst@cs.uu.nl>) 00019 00020 // Defines rules used for constructing a split node. That is, it implements, 00021 // in several ways, the concept 00022 // Boxtree_splitter<FT>. 00023 00024 #ifndef CGAL_SPLITTERS_H 00025 #define CGAL_SPLITTERS_H 00026 #include <CGAL/Point_container.h> 00027 #include <CGAL/Plane_separator.h> 00028 00029 namespace CGAL { 00030 00031 template <class FT> 00032 class Splitter_base { 00033 private: 00034 unsigned int the_bucket_size; 00035 FT the_aspect_ratio; 00036 00037 public: 00038 Splitter_base(unsigned int bucket_size = 3, 00039 FT aspect_ratio = FT(3)) 00040 : the_bucket_size(bucket_size), 00041 the_aspect_ratio(aspect_ratio) 00042 {} 00043 00044 FT 00045 aspect_ratio() const 00046 { 00047 return the_aspect_ratio; 00048 } 00049 00050 unsigned int 00051 bucket_size() const 00052 { 00053 return the_bucket_size; 00054 } 00055 00056 }; 00057 00058 00059 template <class SearchTraits, 00060 class Separator_= Plane_separator<typename SearchTraits::FT> > 00061 class Median_of_max_spread 00062 : public Splitter_base<typename SearchTraits::FT> 00063 { 00064 00065 typedef Splitter_base<typename SearchTraits::FT> Base; 00066 public: 00067 typedef typename SearchTraits::FT FT; 00068 typedef Point_container<SearchTraits> Container; 00069 typedef Separator_ Separator; 00070 00071 Median_of_max_spread() 00072 : Base() 00073 {} 00074 00075 Median_of_max_spread(unsigned int bucket_size) 00076 : Base(bucket_size) 00077 {} 00078 00079 void 00080 operator() (Separator& sep, 00081 Container& c0, 00082 Container& c1) 00083 { 00084 sep=Separator(c0.max_tight_span_coord(),FT(0)); 00085 sep.set_cutting_value(c0.median(sep.cutting_dimension())); 00086 c0.split(c1,sep,true); 00087 } 00088 }; 00089 00090 template <class SearchTraits, 00091 class Separator_= Plane_separator<typename SearchTraits::FT> > 00092 class Fair 00093 : public Splitter_base<typename SearchTraits::FT> 00094 { 00095 00096 typedef Splitter_base<typename SearchTraits::FT> Base; 00097 public: 00098 typedef typename SearchTraits::FT FT; 00099 typedef Point_container<SearchTraits> Container; 00100 typedef Separator_ Separator; 00101 00102 Fair() 00103 : Base() 00104 {} 00105 00106 Fair(unsigned int bucket_size, 00107 FT aspect_ratio=FT(3)) 00108 : Base(bucket_size, aspect_ratio) 00109 {} 00110 00111 void 00112 operator()(Separator& sep, Container& c0, Container& c1) 00113 { 00114 // find legal cut with max spread 00115 sep=Separator(c0.max_tight_span_coord_balanced(this->aspect_ratio()), 00116 FT(0)); 00117 sep.set_cutting_value(c0.balanced_fair(sep.cutting_dimension(), 00118 this->aspect_ratio())); 00119 c0.split(c1,sep); 00120 } 00121 }; 00122 00123 template <class SearchTraits, 00124 class Separator_= Plane_separator<typename SearchTraits::FT> > 00125 class Sliding_fair 00126 : public Splitter_base<typename SearchTraits::FT> 00127 { 00128 00129 typedef Splitter_base<typename SearchTraits::FT> Base; 00130 00131 public: 00132 typedef typename SearchTraits::FT FT; 00133 typedef Point_container<SearchTraits> Container; 00134 typedef Separator_ Separator; 00135 00136 Sliding_fair() 00137 : Base() 00138 {} 00139 00140 Sliding_fair(unsigned int bucket_size, 00141 FT aspect_ratio=FT(3)) 00142 : Base(bucket_size, aspect_ratio) 00143 {} 00144 00145 void 00146 operator() (Separator& sep, Container& c0, Container& c1) 00147 { 00148 // find legal cut with max spread 00149 00150 sep = Separator(c0.max_tight_span_coord_balanced(this->aspect_ratio()), 00151 FT(0)); 00152 00153 sep.set_cutting_value(c0.balanced_sliding_fair(sep.cutting_dimension(), 00154 this->aspect_ratio())); 00155 c0.split(c1,sep,true); 00156 } 00157 }; 00158 00159 00160 template <class SearchTraits, 00161 class Separator_= Plane_separator<typename SearchTraits::FT> > 00162 class Sliding_midpoint 00163 : public Splitter_base<typename SearchTraits::FT> 00164 { 00165 00166 typedef Splitter_base<typename SearchTraits::FT> Base; 00167 00168 public: 00169 typedef typename SearchTraits::FT FT; 00170 typedef Point_container<SearchTraits> Container; 00171 typedef Separator_ Separator; 00172 00173 Sliding_midpoint() 00174 : Base() 00175 {} 00176 00177 Sliding_midpoint(unsigned int bucket_size) 00178 : Base(bucket_size) 00179 {} 00180 00181 void 00182 operator()(Separator& sep, Container& c0, Container& c1) 00183 { 00184 CGAL_assertion(c0.is_valid()); 00185 CGAL_assertion(c1.is_valid()); 00186 sep = Separator(c0.max_span_coord(), 00187 (c0.max_span_upper() + c0.max_span_lower())/FT(2)); 00188 00189 FT max_span_lower = 00190 c0.tight_bounding_box().min_coord(c0.max_span_coord()); 00191 00192 CGAL_assertion(max_span_lower >= c0.max_span_lower()); 00193 FT max_span_upper = 00194 c0.tight_bounding_box().max_coord(c0.max_span_coord()); 00195 00196 CGAL_assertion(max_span_upper <= c0.max_span_upper()); 00197 if (max_span_upper <= sep.cutting_value()) { 00198 sep.set_cutting_value(max_span_upper); 00199 }; 00200 if (max_span_lower >= sep.cutting_value()) { 00201 sep.set_cutting_value(max_span_lower); 00202 }; 00203 c0.split(c1,sep,true); 00204 } 00205 }; 00206 00207 template <class SearchTraits, 00208 class Separator_= Plane_separator<typename SearchTraits::FT> > 00209 class Median_of_rectangle 00210 : public Splitter_base<typename SearchTraits::FT> 00211 { 00212 00213 typedef Splitter_base<typename SearchTraits::FT> Base; 00214 00215 public: 00216 typedef typename SearchTraits::FT FT; 00217 typedef Point_container<SearchTraits> Container; 00218 typedef Separator_ Separator; 00219 00220 00221 Median_of_rectangle() 00222 : Base() 00223 {} 00224 00225 Median_of_rectangle(unsigned int bucket_size) 00226 : Base(bucket_size) 00227 {} 00228 00229 void 00230 operator() (Separator& sep, Container& c0, Container& c1) 00231 { 00232 sep = Separator(c0.max_span_coord(),FT(0)); 00233 sep.set_cutting_value(c0.median(sep.cutting_dimension())); 00234 c0.split(c1,sep,true); 00235 } 00236 }; 00237 00238 template <class SearchTraits, 00239 class Separator_= Plane_separator<typename SearchTraits::FT> > 00240 class Midpoint_of_max_spread 00241 : public Splitter_base<typename SearchTraits::FT> 00242 { 00243 typedef Splitter_base<typename SearchTraits::FT> Base; 00244 00245 public: 00246 typedef typename SearchTraits::FT FT; 00247 typedef Point_container<SearchTraits> Container; 00248 typedef Separator_ Separator; 00249 00250 00251 Midpoint_of_max_spread() 00252 : Base() 00253 {} 00254 00255 Midpoint_of_max_spread(unsigned int bucket_size) 00256 : Base(bucket_size) 00257 {} 00258 00259 void 00260 operator()(Separator& sep, Container& c0, Container& c1) 00261 { 00262 sep = Separator(c0.max_tight_span_coord(), 00263 (c0.max_tight_span_upper() + c0.max_tight_span_lower())/FT(2)); 00264 c0.split(c1,sep); 00265 } 00266 }; 00267 00268 template <class SearchTraits, 00269 class Separator_= Plane_separator<typename SearchTraits::FT> > 00270 class Midpoint_of_rectangle 00271 : public Splitter_base<typename SearchTraits::FT> 00272 { 00273 00274 typedef Splitter_base<typename SearchTraits::FT> Base; 00275 public: 00276 typedef typename SearchTraits::FT FT; 00277 typedef Point_container<SearchTraits> Container; 00278 typedef Separator_ Separator; 00279 00280 00281 Midpoint_of_rectangle() 00282 : Base() 00283 {} 00284 00285 Midpoint_of_rectangle(unsigned int bucket_size) 00286 : Base(bucket_size) 00287 {} 00288 00289 void 00290 operator()(Separator& sep, Container& c0, Container& c1) 00291 { 00292 sep = Separator(c0.max_span_coord(), 00293 (c0.max_span_upper() + c0.max_span_lower())/FT(2)); 00294 c0.split(c1,sep); 00295 } 00296 00297 }; 00298 00299 } // namespace CGAL 00300 #endif // CGAL_SPLITTERS 00301 00302 00303