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/Aff_transformation_rep_2.h $ 00019 // $Id: Aff_transformation_rep_2.h 42805 2008-04-09 12:20:25Z spion $ 00020 // 00021 // 00022 // Author(s) : Andreas Fabri, Lutz Kettner 00023 00024 #ifndef CGAL_CARTESIAN_AFF_TRANSFORMATION_REP_2_H 00025 #define CGAL_CARTESIAN_AFF_TRANSFORMATION_REP_2_H 00026 00027 #include <CGAL/determinant.h> 00028 00029 CGAL_BEGIN_NAMESPACE 00030 00031 template < class R > 00032 class Aff_transformation_rep_baseC2 00033 : public Ref_counted_virtual 00034 { 00035 public: 00036 typedef typename R::FT FT; 00037 typedef typename R::Point_2 Point_2; 00038 typedef typename R::Vector_2 Vector_2; 00039 typedef typename R::Direction_2 Direction_2; 00040 typedef typename R::Aff_transformation_2 Aff_transformation_2; 00041 00042 virtual ~Aff_transformation_rep_baseC2() {} 00043 00044 virtual Point_2 transform(const Point_2 &p) const = 0; 00045 virtual Vector_2 transform(const Vector_2 &v) const = 0; 00046 virtual Direction_2 transform(const Direction_2 &d) const=0; 00047 00048 virtual Aff_transformation_2 operator*( 00049 const Aff_transformation_rep_baseC2 &t) const = 0; 00050 00051 virtual Aff_transformation_2 compose( 00052 const Aff_transformation_repC2<R> &t) const = 0; 00053 00054 virtual Aff_transformation_2 compose( 00055 const Translation_repC2<R> &t) const = 0; 00056 00057 virtual Aff_transformation_2 compose( 00058 const Rotation_repC2<R> &t) const = 0; 00059 00060 virtual Aff_transformation_2 compose( 00061 const Scaling_repC2<R> &t) const = 0; 00062 00063 virtual Aff_transformation_2 inverse() const = 0; 00064 virtual bool is_even() const = 0; 00065 virtual FT cartesian(int i, int j) const = 0; 00066 virtual std::ostream &print(std::ostream &os) const = 0; 00067 }; 00068 00069 template < class R > 00070 class Aff_transformation_repC2 00071 : public Aff_transformation_rep_baseC2<R> 00072 { 00073 public: 00074 typedef typename R::FT FT; 00075 typedef Aff_transformation_repC2<R> Self; 00076 typedef Aff_transformation_rep_baseC2<R> Aff_t_base; 00077 typedef typename Aff_t_base::Point_2 Point_2; 00078 typedef typename Aff_t_base::Vector_2 Vector_2; 00079 typedef typename Aff_t_base::Direction_2 Direction_2; 00080 typedef typename Aff_t_base::Aff_transformation_2 Aff_transformation_2; 00081 00082 friend class Translation_repC2<R>; 00083 friend class Rotation_repC2<R>; 00084 friend class Scaling_repC2<R>; 00085 00086 Aff_transformation_repC2() 00087 {} 00088 00089 Aff_transformation_repC2( const FT& m11, const FT& m12, 00090 const FT& m21, const FT& m22) 00091 : t11(m11), t12(m12), t13(0), 00092 t21(m21), t22(m22), t23(0) 00093 {} 00094 00095 Aff_transformation_repC2( const FT& m11, const FT& m12, const FT& m13, 00096 const FT& m21, const FT& m22, const FT& m23) 00097 : t11(m11), t12(m12), t13(m13), 00098 t21(m21), t22(m22), t23(m23) 00099 {} 00100 00101 Point_2 transform(const Point_2& p) const 00102 { 00103 typename R::Construct_point_2 construct_point_2; 00104 return construct_point_2(t11 * p.x() + t12 * p.y() + t13, 00105 t21 * p.x() + t22 * p.y() + t23); 00106 } 00107 00108 // note that a vector is not translated 00109 Vector_2 transform(const Vector_2& v) const 00110 { 00111 return Vector_2(t11 * v.x() + t12 * v.y(), 00112 t21 * v.x() + t22 * v.y()); 00113 } 00114 00115 // note that a direction is not translated 00116 Direction_2 transform(const Direction_2& dir) const 00117 { 00118 return Direction_2(t11 * dir.dx() + t12 * dir.dy(), 00119 t21 * dir.dx() + t22 * dir.dy()); 00120 } 00121 00122 // Note that Aff_transformation is not defined yet, 00123 // so the following 6 functions have to be implemented later... 00124 Aff_transformation_2 inverse() const; 00125 Aff_transformation_2 operator*(const Aff_t_base &t) const; 00126 Aff_transformation_2 compose(const Self &t) const; 00127 Aff_transformation_2 compose(const Translation_repC2<R> &t) const; 00128 Aff_transformation_2 compose(const Rotation_repC2<R> &t) const; 00129 Aff_transformation_2 compose(const Scaling_repC2<R> &t) const; 00130 00131 bool is_even() const 00132 { 00133 return sign_of_determinant(t11, t12, t21, t22) == POSITIVE; 00134 } 00135 00136 FT cartesian(int i, int j) const 00137 { 00138 switch (i) 00139 { 00140 case 0: switch (j) 00141 { 00142 case 0: return t11; 00143 case 1: return t12; 00144 case 2: return t13; 00145 } 00146 case 1: switch (j) 00147 { 00148 case 0: return t21; 00149 case 1: return t22; 00150 case 2: return t23; 00151 } 00152 case 2: switch (j) 00153 { 00154 case 0: return FT(0); 00155 case 1: return FT(0); 00156 case 2: return FT(1); 00157 } 00158 } 00159 return FT(0); 00160 } 00161 00162 std::ostream &print(std::ostream &os) const 00163 { 00164 os <<"Aff_transformationC2(" <<t11<<" "<<t12<<" "<<t13<<std::endl; 00165 os <<" " <<t21<<" "<<t22<<" "<<t23<<")"; 00166 return os; 00167 } 00168 00169 private: 00170 FT t11, t12, t13; 00171 FT t21, t22, t23; 00172 }; 00173 00174 template < class R > 00175 CGAL_KERNEL_LARGE_INLINE 00176 typename Aff_transformation_repC2<R>::Aff_transformation_2 00177 Aff_transformation_repC2<R>:: 00178 inverse() const 00179 { 00180 FT det = FT(1) / (t11 * t22 - t12 * t21); 00181 return Aff_transformation_2( 00182 det * t22, det * (-t12), det * (t12*t23-t13*t22), 00183 det * (-t21), det * t11 , det * (t13*t21-t11*t23)); 00184 } 00185 00186 template < class R > 00187 CGAL_KERNEL_INLINE 00188 typename Aff_transformation_repC2<R>::Aff_transformation_2 00189 Aff_transformation_repC2<R>:: 00190 operator*(const Aff_transformation_rep_baseC2<R> &t) const 00191 { 00192 return t.compose(*this); 00193 } 00194 00195 template < class R > 00196 CGAL_KERNEL_LARGE_INLINE 00197 typename Aff_transformation_repC2<R>::Aff_transformation_2 00198 Aff_transformation_repC2<R>:: 00199 compose(const Aff_transformation_repC2<R> &t) const 00200 { 00201 return Aff_transformation_2(t.t11*t11 + t.t12*t21, 00202 t.t11*t12 + t.t12*t22, 00203 t.t11*t13 + t.t12*t23 + t.t13, 00204 t.t21*t11 + t.t22*t21, 00205 t.t21*t12 + t.t22*t22, 00206 t.t21*t13 + t.t22*t23 + t.t23 ); 00207 } 00208 00209 template < class R > 00210 CGAL_KERNEL_LARGE_INLINE 00211 typename Aff_transformation_repC2<R>::Aff_transformation_2 00212 Aff_transformation_repC2<R>:: 00213 compose(const Translation_repC2<R> &t) const 00214 { 00215 return Aff_transformation_2(t11, 00216 t12, 00217 t13 + t.translationvector_.x(), 00218 t21, 00219 t22, 00220 t23 + t.translationvector_.y()); 00221 } 00222 00223 template < class R > 00224 CGAL_KERNEL_LARGE_INLINE 00225 typename Aff_transformation_repC2<R>::Aff_transformation_2 00226 Aff_transformation_repC2<R>:: 00227 compose(const Rotation_repC2<R> &t) const 00228 { 00229 return Aff_transformation_2(t.cosinus_*t11 - t.sinus_*t21, 00230 t.cosinus_*t12 - t.sinus_*t22, 00231 t.cosinus_*t13 - t.sinus_*t23, 00232 t.sinus_*t11 + t.cosinus_*t21, 00233 t.sinus_*t12 + t.cosinus_*t22, 00234 t.sinus_*t13 + t.cosinus_*t23); 00235 } 00236 00237 template < class R > 00238 CGAL_KERNEL_LARGE_INLINE 00239 typename Aff_transformation_repC2<R>::Aff_transformation_2 00240 Aff_transformation_repC2<R>:: 00241 compose(const Scaling_repC2<R> &t) const 00242 { 00243 return Aff_transformation_2(t.scalefactor_ * t11, 00244 t.scalefactor_ * t12, 00245 t.scalefactor_ * t13, 00246 t.scalefactor_ * t21, 00247 t.scalefactor_ * t22, 00248 t.scalefactor_ * t23); 00249 } 00250 00251 CGAL_END_NAMESPACE 00252 00253 #endif // CGAL_CARTESIAN_AFF_TRANSFORMATION_REP_2_H