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