BWAPI
|
00001 // Copyright (c) 1999 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/Homogeneous_kernel/include/CGAL/Homogeneous/Iso_cuboidH3.h $ 00019 // $Id: Iso_cuboidH3.h 49057 2009-04-30 14:03:52Z spion $ 00020 // 00021 // 00022 // Author(s) : Stefan Schirra 00023 00024 #ifndef CGAL_ISO_CUBOIDH3_H 00025 #define CGAL_ISO_CUBOIDH3_H 00026 00027 #include <CGAL/array.h> 00028 00029 CGAL_BEGIN_NAMESPACE 00030 00031 template <class R_> 00032 class Iso_cuboidH3 00033 { 00034 typedef typename R_::RT RT; 00035 typedef typename R_::FT FT; 00036 typedef typename R_::Point_3 Point_3; 00037 typedef typename R_::Aff_transformation_3 Aff_transformation_3; 00038 00039 typedef cpp0x::array<Point_3, 2> Rep; 00040 typedef typename R_::template Handle<Rep>::type Base; 00041 00042 Base base; 00043 00044 public: 00045 typedef R_ R; 00046 00047 Iso_cuboidH3() {} 00048 00049 Iso_cuboidH3(const Point_3& p, const Point_3& q, int) 00050 : base(CGAL::make_array(p, q)) 00051 { 00052 CGAL_kernel_assertion(p.x()<=q.x()); 00053 CGAL_kernel_assertion(p.y()<=q.y()); 00054 CGAL_kernel_assertion(p.z()<=q.z()); 00055 } 00056 00057 Iso_cuboidH3(const Point_3& p, const Point_3& q); 00058 00059 Iso_cuboidH3(const Point_3& left, const Point_3& right, 00060 const Point_3& bottom, const Point_3& top, 00061 const Point_3& far_, const Point_3& close); 00062 00063 Iso_cuboidH3(const RT& min_hx, const RT& min_hy, const RT& min_hz, 00064 const RT& max_hx, const RT& max_hy, const RT& max_hz, 00065 const RT& hw); 00066 00067 Iso_cuboidH3(const RT& min_hx, const RT& min_hy, const RT& min_hz, 00068 const RT& max_hx, const RT& max_hy, const RT& max_hz); 00069 00070 bool operator==(const Iso_cuboidH3<R>& s) const; 00071 bool operator!=(const Iso_cuboidH3<R>& s) const; 00072 00073 const Point_3 & min BOOST_PREVENT_MACRO_SUBSTITUTION () const; 00074 const Point_3 & max BOOST_PREVENT_MACRO_SUBSTITUTION () const; 00075 Point_3 vertex(int i) const; 00076 Point_3 operator[](int i) const; 00077 00078 Iso_cuboidH3<R> 00079 transform(const Aff_transformation_3& t) const; 00080 Bounded_side 00081 bounded_side(const Point_3& p) const; 00082 bool has_on(const Point_3& p) const; 00083 bool has_on_boundary(const Point_3& p) const; 00084 bool has_on_bounded_side(const Point_3& p) const; 00085 bool has_on_unbounded_side(const Point_3& p) const; 00086 bool is_degenerate() const; 00087 FT xmin() const; 00088 FT ymin() const; 00089 FT zmin() const; 00090 FT xmax() const; 00091 FT ymax() const; 00092 FT zmax() const; 00093 FT min_coord(int i) const; 00094 FT max_coord(int i) const; 00095 00096 FT volume() const; 00097 00098 }; 00099 00100 template < class R > 00101 CGAL_KERNEL_LARGE_INLINE 00102 Iso_cuboidH3<R>:: 00103 Iso_cuboidH3(const typename Iso_cuboidH3<R>::Point_3& p, 00104 const typename Iso_cuboidH3<R>::Point_3& q) 00105 { 00106 bool px_k_qx = ( p.hx()*q.hw() < q.hx()*p.hw() ); 00107 bool py_k_qy = ( p.hy()*q.hw() < q.hy()*p.hw() ); 00108 bool pz_k_qz = ( p.hz()*q.hw() < q.hz()*p.hw() ); 00109 00110 RT minx; 00111 RT miny; 00112 RT minz; 00113 RT maxx; 00114 RT maxy; 00115 RT maxz; 00116 RT minw = p.hw()*q.hw(); 00117 RT maxw = p.hw()*q.hw(); 00118 if ( px_k_qx ) 00119 { 00120 minx = p.hx()*q.hw(); 00121 maxx = q.hx()*p.hw(); 00122 } 00123 else 00124 { 00125 minx = q.hx()*p.hw(); 00126 maxx = p.hx()*q.hw(); 00127 } 00128 if ( py_k_qy ) 00129 { 00130 miny = p.hy()*q.hw(); 00131 maxy = q.hy()*p.hw(); 00132 } 00133 else 00134 { 00135 miny = q.hy()*p.hw(); 00136 maxy = p.hy()*q.hw(); 00137 } 00138 if ( pz_k_qz ) 00139 { 00140 minz = p.hz()*q.hw(); 00141 maxz = q.hz()*p.hw(); 00142 } 00143 else 00144 { 00145 minz = q.hz()*p.hw(); 00146 maxz = p.hz()*q.hw(); 00147 } 00148 base = Rep(CGAL::make_array(Point_3(minx, miny, minz, minw), 00149 Point_3(maxx, maxy, maxz, maxw))); 00150 } 00151 00152 template < class R > 00153 CGAL_KERNEL_LARGE_INLINE 00154 Iso_cuboidH3<R>:: 00155 Iso_cuboidH3(const typename Iso_cuboidH3<R>::Point_3& left, 00156 const typename Iso_cuboidH3<R>::Point_3& right, 00157 const typename Iso_cuboidH3<R>::Point_3& bottom, 00158 const typename Iso_cuboidH3<R>::Point_3& top, 00159 const typename Iso_cuboidH3<R>::Point_3& far_, 00160 const typename Iso_cuboidH3<R>::Point_3& close) 00161 : base(CGAL::make_array(Point_3(left.hx() * bottom.hw() * far_.hw(), 00162 bottom.hy() * left.hw() * far_.hw(), 00163 far_.hz() * left.hw() * bottom.hw(), 00164 left.hw() * bottom.hw() * far_.hw()), 00165 Point_3(right.hx() * top.hw() * close.hw(), 00166 top.hy() * right.hw() * close.hw(), 00167 close.hz() * right.hw() * top.hw(), 00168 right.hw() * top.hw() * close.hw()))) 00169 { 00170 CGAL_kernel_precondition(!less_x(right, left)); 00171 CGAL_kernel_precondition(!less_y(top, bottom)); 00172 CGAL_kernel_precondition(!less_z(close, far_)); 00173 } 00174 00175 template < class R > 00176 CGAL_KERNEL_LARGE_INLINE 00177 Iso_cuboidH3<R>:: 00178 Iso_cuboidH3(const RT& min_hx, const RT& min_hy, const RT& min_hz, 00179 const RT& max_hx, const RT& max_hy, const RT& max_hz) 00180 : base(CGAL::make_array(Point_3(min_hx, min_hy, min_hz, RT(1)), 00181 Point_3(max_hx, max_hy, max_hz, RT(1)))) 00182 {} 00183 00184 template < class R > 00185 CGAL_KERNEL_LARGE_INLINE 00186 Iso_cuboidH3<R>:: 00187 Iso_cuboidH3(const RT& min_hx, const RT& min_hy, const RT& min_hz, 00188 const RT& max_hx, const RT& max_hy, const RT& max_hz, 00189 const RT& hw) 00190 : base(CGAL::make_array(Point_3(min_hx, min_hy, min_hz, hw), 00191 Point_3(max_hx, max_hy, max_hz, hw))) 00192 {} 00193 00194 template < class R > 00195 CGAL_KERNEL_INLINE 00196 bool 00197 Iso_cuboidH3<R>:: 00198 operator==(const Iso_cuboidH3<R>& r) const 00199 { return ((this->min)() == (r.min)()) && ((this->max)() == (r.max)()); } 00200 00201 template < class R > 00202 inline 00203 bool 00204 Iso_cuboidH3<R>:: 00205 operator!=(const Iso_cuboidH3<R>& r) const 00206 { return !(*this == r); } 00207 00208 template < class R > 00209 inline 00210 const typename Iso_cuboidH3<R>::Point_3 & 00211 Iso_cuboidH3<R>::min BOOST_PREVENT_MACRO_SUBSTITUTION () const 00212 { return get(base)[0]; } 00213 00214 template < class R > 00215 inline 00216 const typename Iso_cuboidH3<R>::Point_3 & 00217 Iso_cuboidH3<R>::max BOOST_PREVENT_MACRO_SUBSTITUTION () const 00218 { return get(base)[1]; } 00219 00220 template < class R > 00221 inline 00222 typename Iso_cuboidH3<R>::FT 00223 Iso_cuboidH3<R>::xmin() const 00224 { return FT( (this->min)().hx() ) / FT( (this->min)().hw() ); } 00225 00226 template < class R > 00227 inline 00228 typename Iso_cuboidH3<R>::FT 00229 Iso_cuboidH3<R>::ymin() const 00230 { return FT( (this->min)().hy() ) / FT( (this->min)().hw() ); } 00231 00232 template < class R > 00233 inline 00234 typename Iso_cuboidH3<R>::FT 00235 Iso_cuboidH3<R>::zmin() const 00236 { return FT( (this->min)().hz() ) / FT( (this->min)().hw() ); } 00237 00238 template < class R > 00239 inline 00240 typename Iso_cuboidH3<R>::FT 00241 Iso_cuboidH3<R>::xmax() const 00242 { return FT( (this->max)().hx() ) / FT( (this->max)().hw() ); } 00243 00244 template < class R > 00245 inline 00246 typename Iso_cuboidH3<R>::FT 00247 Iso_cuboidH3<R>::ymax() const 00248 { return FT( (this->max)().hy() ) / FT( (this->max)().hw() ); } 00249 00250 template < class R > 00251 inline 00252 typename Iso_cuboidH3<R>::FT 00253 Iso_cuboidH3<R>::zmax() const 00254 { return FT( (this->max)().hz() ) / FT( (this->max)().hw() ); } 00255 00256 template < class R > 00257 inline 00258 typename Iso_cuboidH3<R>::FT 00259 Iso_cuboidH3<R>::min_coord(int i) const 00260 { 00261 CGAL_kernel_precondition(i == 0 || i == 1 || i == 2); 00262 if ( i == 0 ) 00263 return xmin(); 00264 else if (i == 1) 00265 return ymin(); 00266 return zmin(); 00267 } 00268 00269 template < class R > 00270 inline 00271 typename Iso_cuboidH3<R>::FT 00272 Iso_cuboidH3<R>::max_coord(int i) const 00273 { 00274 CGAL_kernel_precondition(i == 0 || i == 1 || i == 2); 00275 if ( i == 0 ) 00276 return xmax(); 00277 else if ( i == 1 ) 00278 return ymax(); 00279 return zmax(); 00280 } 00281 00282 template < class R > 00283 inline 00284 typename Iso_cuboidH3<R>::FT 00285 Iso_cuboidH3<R>::volume() const 00286 { return (xmax() - xmin()) * (ymax() - ymin()) * (zmax() - zmin()); } 00287 00288 template < class R > 00289 CGAL_KERNEL_LARGE_INLINE 00290 typename Iso_cuboidH3<R>::Point_3 00291 Iso_cuboidH3<R>::vertex(int i) const 00292 { 00293 switch (i%8) 00294 { 00295 case 0: return (this->min)(); 00296 case 1: return Point_3( (this->max)().hx(), (this->min)().hy(), 00297 (this->min)().hz(), (this->min)().hw() ); 00298 case 2: return Point_3( (this->max)().hx(), (this->max)().hy(), 00299 (this->min)().hz(), (this->min)().hw() ); 00300 case 3: return Point_3( (this->min)().hx(), (this->max)().hy(), 00301 (this->min)().hz(), (this->min)().hw() ); 00302 case 4: return Point_3( (this->min)().hx(), (this->max)().hy(), 00303 (this->max)().hz(), (this->min)().hw() ); 00304 case 5: return Point_3( (this->min)().hx(), (this->min)().hy(), 00305 (this->max)().hz(), (this->min)().hw() ); 00306 case 6: return Point_3( (this->max)().hx(), (this->min)().hy(), 00307 (this->max)().hz(), (this->min)().hw() ); 00308 default: /*case 7:*/ return (this->max)(); 00309 } 00310 } 00311 00312 template < class R > 00313 inline 00314 typename Iso_cuboidH3<R>::Point_3 00315 Iso_cuboidH3<R>::operator[](int i) const 00316 { return vertex(i); } 00317 00318 template < class R > 00319 CGAL_KERNEL_MEDIUM_INLINE 00320 Bounded_side 00321 Iso_cuboidH3<R>:: 00322 bounded_side(const typename Iso_cuboidH3<R>::Point_3& p) const 00323 { 00324 if ( (p.hx()*(this->min)().hw() < (this->min)().hx()*p.hw() ) 00325 ||(p.hy()*(this->min)().hw() < (this->min)().hy()*p.hw() ) 00326 ||(p.hz()*(this->min)().hw() < (this->min)().hz()*p.hw() ) 00327 ||(p.hx()*(this->max)().hw() > (this->max)().hx()*p.hw() ) 00328 ||(p.hy()*(this->max)().hw() > (this->max)().hy()*p.hw() ) 00329 ||(p.hz()*(this->max)().hw() > (this->max)().hz()*p.hw() ) ) 00330 { return ON_UNBOUNDED_SIDE; } 00331 if ( (p.hx()*(this->min)().hw() == (this->min)().hx()*p.hw() ) 00332 ||(p.hy()*(this->min)().hw() == (this->min)().hy()*p.hw() ) 00333 ||(p.hz()*(this->min)().hw() == (this->min)().hz()*p.hw() ) 00334 ||(p.hx()*(this->max)().hw() == (this->max)().hx()*p.hw() ) 00335 ||(p.hy()*(this->max)().hw() == (this->max)().hy()*p.hw() ) 00336 ||(p.hz()*(this->max)().hw() == (this->max)().hz()*p.hw() ) ) 00337 { return ON_BOUNDARY; } 00338 else 00339 { return ON_BOUNDED_SIDE; } 00340 } 00341 00342 template < class R > 00343 inline 00344 bool 00345 Iso_cuboidH3<R>:: 00346 has_on_boundary(const typename Iso_cuboidH3<R>::Point_3& p) const 00347 { return ( bounded_side(p) == ON_BOUNDARY ); } 00348 00349 template < class R > 00350 inline 00351 bool 00352 Iso_cuboidH3<R>::has_on(const typename Iso_cuboidH3<R>::Point_3& p) const 00353 { return ( bounded_side(p) == ON_BOUNDARY ); } 00354 00355 template < class R > 00356 inline 00357 bool 00358 Iso_cuboidH3<R>:: 00359 has_on_bounded_side(const typename Iso_cuboidH3<R>::Point_3& p) const 00360 { return ( bounded_side(p) == ON_BOUNDED_SIDE ); } 00361 00362 template < class R > 00363 CGAL_KERNEL_INLINE 00364 bool 00365 Iso_cuboidH3<R>:: 00366 has_on_unbounded_side(const typename Iso_cuboidH3<R>::Point_3& p) const 00367 { 00368 return ( ( lexicographically_xyz_smaller(p,(this->min)() )) 00369 ||( lexicographically_xyz_smaller((this->max)(),p )) ); 00370 } 00371 00372 template < class R > 00373 CGAL_KERNEL_INLINE 00374 bool 00375 Iso_cuboidH3<R>::is_degenerate() const 00376 { 00377 return ( ( (this->min)().hx() == (this->max)().hx() ) 00378 || ( (this->min)().hy() == (this->max)().hy() ) 00379 || ( (this->min)().hz() == (this->max)().hz() ) ); 00380 } 00381 00382 template < class R > 00383 CGAL_KERNEL_INLINE 00384 Iso_cuboidH3<R> 00385 Iso_cuboidH3<R>:: 00386 transform(const typename Iso_cuboidH3<R>::Aff_transformation_3&t) const 00387 { 00388 return Iso_cuboidH3<R>(t.transform((this->min)() ), 00389 t.transform((this->max)() ) ); 00390 } 00391 00392 CGAL_END_NAMESPACE 00393 00394 #endif // CGAL_ISO_CUBOIDH3_H