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/Tetrahedron_3.h $ 00019 // $Id: Tetrahedron_3.h 49057 2009-04-30 14:03:52Z spion $ 00020 // 00021 // 00022 // Author(s) : Andreas Fabri 00023 00024 #ifndef CGAL_CARTESIAN_TETRAHEDRON_3_H 00025 #define CGAL_CARTESIAN_TETRAHEDRON_3_H 00026 00027 #include <CGAL/array.h> 00028 #include <CGAL/Handle_for.h> 00029 #include <vector> 00030 #include <functional> 00031 00032 CGAL_BEGIN_NAMESPACE 00033 00034 template <class R_> 00035 class TetrahedronC3 00036 { 00037 typedef typename R_::FT FT; 00038 typedef typename R_::Point_3 Point_3; 00039 typedef typename R_::Plane_3 Plane_3; 00040 typedef typename R_::Tetrahedron_3 Tetrahedron_3; 00041 00042 typedef cpp0x::array<Point_3, 4> Rep; 00043 typedef typename R_::template Handle<Rep>::type Base; 00044 00045 Base base; 00046 00047 public: 00048 typedef R_ R; 00049 00050 TetrahedronC3() {} 00051 00052 TetrahedronC3(const Point_3 &p, const Point_3 &q, const Point_3 &r, 00053 const Point_3 &s) 00054 : base(CGAL::make_array(p, q, r, s)) {} 00055 00056 const Point_3 & vertex(int i) const; 00057 const Point_3 & operator[](int i) const; 00058 00059 typename R::Boolean operator==(const TetrahedronC3 &t) const; 00060 typename R::Boolean operator!=(const TetrahedronC3 &t) const; 00061 00062 typename R::Orientation orientation() const; 00063 typename R::Oriented_side oriented_side(const Point_3 &p) const; 00064 typename R::Bounded_side bounded_side(const Point_3 &p) const; 00065 00066 typename R::Boolean has_on_boundary(const Point_3 &p) const; 00067 typename R::Boolean has_on_positive_side(const Point_3 &p) const; 00068 typename R::Boolean has_on_negative_side(const Point_3 &p) const; 00069 typename R::Boolean has_on_bounded_side(const Point_3 &p) const; 00070 typename R::Boolean has_on_unbounded_side(const Point_3 &p) const; 00071 00072 typename R::Boolean is_degenerate() const; 00073 }; 00074 00075 template < class R > 00076 typename R::Boolean 00077 TetrahedronC3<R>:: 00078 operator==(const TetrahedronC3<R> &t) const 00079 { 00080 if (CGAL::identical(base, t.base)) 00081 return true; 00082 if (orientation() != t.orientation()) 00083 return false; 00084 00085 std::vector< Point_3 > V1; 00086 std::vector< Point_3 > V2; 00087 typename std::vector< Point_3 >::iterator uniq_end1; 00088 typename std::vector< Point_3 >::iterator uniq_end2; 00089 int k; 00090 for ( k=0; k < 4; k++) V1.push_back( vertex(k)); 00091 for ( k=0; k < 4; k++) V2.push_back( t.vertex(k)); 00092 typename R::Less_xyz_3 Less_object = R().less_xyz_3_object(); 00093 std::sort(V1.begin(), V1.end(), Less_object); 00094 std::sort(V2.begin(), V2.end(), Less_object); 00095 uniq_end1 = std::unique( V1.begin(), V1.end()); 00096 uniq_end2 = std::unique( V2.begin(), V2.end()); 00097 V1.erase( uniq_end1, V1.end()); 00098 V2.erase( uniq_end2, V2.end()); 00099 return V1 == V2; 00100 } 00101 00102 template < class R > 00103 inline 00104 typename R::Boolean 00105 TetrahedronC3<R>:: 00106 operator!=(const TetrahedronC3<R> &t) const 00107 { 00108 return !(*this == t); 00109 } 00110 00111 template < class R > 00112 const typename TetrahedronC3<R>::Point_3 & 00113 TetrahedronC3<R>:: 00114 vertex(int i) const 00115 { 00116 if (i<0) i=(i%4)+4; 00117 else if (i>3) i=i%4; 00118 switch (i) 00119 { 00120 case 0: return get(base)[0]; 00121 case 1: return get(base)[1]; 00122 case 2: return get(base)[2]; 00123 default: return get(base)[3]; 00124 } 00125 } 00126 00127 template < class R > 00128 inline 00129 const typename TetrahedronC3<R>::Point_3 & 00130 TetrahedronC3<R>:: 00131 operator[](int i) const 00132 { 00133 return vertex(i); 00134 } 00135 00136 template < class R > 00137 typename R::Orientation 00138 TetrahedronC3<R>:: 00139 orientation() const 00140 { 00141 return R().orientation_3_object()(vertex(0), vertex(1), 00142 vertex(2), vertex(3)); 00143 } 00144 00145 template < class R > 00146 typename R::Oriented_side 00147 TetrahedronC3<R>:: 00148 oriented_side(const typename TetrahedronC3<R>::Point_3 &p) const 00149 { 00150 typename R::Orientation o = orientation(); 00151 if (o != ZERO) 00152 return enum_cast<Oriented_side>(bounded_side(p)) * o; 00153 00154 CGAL_kernel_assertion (!is_degenerate()); 00155 return ON_ORIENTED_BOUNDARY; 00156 } 00157 00158 template < class R > 00159 typename R::Bounded_side 00160 TetrahedronC3<R>:: 00161 bounded_side(const typename TetrahedronC3<R>::Point_3 &p) const 00162 { 00163 return R().bounded_side_3_object() 00164 (static_cast<const typename R::Tetrahedron_3>(*this), p); 00165 } 00166 00167 template < class R > 00168 inline 00169 typename R::Boolean 00170 TetrahedronC3<R>::has_on_boundary 00171 (const typename TetrahedronC3<R>::Point_3 &p) const 00172 { 00173 return oriented_side(p) == ON_ORIENTED_BOUNDARY; 00174 } 00175 00176 template < class R > 00177 inline 00178 typename R::Boolean 00179 TetrahedronC3<R>::has_on_positive_side 00180 (const typename TetrahedronC3<R>::Point_3 &p) const 00181 { 00182 return oriented_side(p) == ON_POSITIVE_SIDE; 00183 } 00184 00185 template < class R > 00186 inline 00187 typename R::Boolean 00188 TetrahedronC3<R>::has_on_negative_side 00189 (const typename TetrahedronC3<R>::Point_3 &p) const 00190 { 00191 return oriented_side(p) == ON_NEGATIVE_SIDE; 00192 } 00193 00194 template < class R > 00195 inline 00196 typename R::Boolean 00197 TetrahedronC3<R>::has_on_bounded_side 00198 (const typename TetrahedronC3<R>::Point_3 &p) const 00199 { 00200 return bounded_side(p) == ON_BOUNDED_SIDE; 00201 } 00202 00203 template < class R > 00204 inline 00205 typename R::Boolean 00206 TetrahedronC3<R>::has_on_unbounded_side 00207 (const typename TetrahedronC3<R>::Point_3 &p) const 00208 { 00209 return bounded_side(p) == ON_UNBOUNDED_SIDE; 00210 } 00211 00212 template < class R > 00213 inline 00214 typename R::Boolean 00215 TetrahedronC3<R>::is_degenerate() const 00216 { 00217 return orientation() == COPLANAR; 00218 } 00219 00220 CGAL_END_NAMESPACE 00221 00222 #endif // CGAL_CARTESIAN_TETRAHEDRON_3_H