BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/Cartesian/Aff_transformation_2.h
Go to the documentation of this file.
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_2.h $
00019 // $Id: Aff_transformation_2.h 28567 2006-02-16 14:30:13Z lsaboret $
00020 // 
00021 //
00022 // Author(s)     : Andreas Fabri, Lutz Kettner
00023 
00024 #ifndef CGAL_CARTESIAN_AFF_TRANSFORMATION_2_H
00025 #define CGAL_CARTESIAN_AFF_TRANSFORMATION_2_H
00026 
00027 #include <cmath>
00028 #include <CGAL/Handle_for_virtual.h>
00029 
00030 CGAL_BEGIN_NAMESPACE
00031 
00032 class Identity_transformation;
00033 template < class R > class Aff_transformation_rep_baseC2;
00034 template < class R > class Aff_transformation_repC2;
00035 template < class R > class Translation_repC2;
00036 template < class R > class Rotation_repC2;
00037 template < class R > class Scaling_repC2;
00038 
00039 CGAL_END_NAMESPACE
00040 
00041 #include <CGAL/Cartesian/Aff_transformation_rep_2.h>
00042 #include <CGAL/Cartesian/Translation_rep_2.h>
00043 #include <CGAL/Cartesian/Rotation_rep_2.h>
00044 #include <CGAL/Cartesian/Scaling_rep_2.h>
00045 
00046 CGAL_BEGIN_NAMESPACE
00047 
00048 template < class R_ >
00049 class Aff_transformationC2
00050   : public Handle_for_virtual< Aff_transformation_rep_baseC2<R_> >
00051 {
00052   typedef typename R_::FT                   FT;
00053   typedef Aff_transformation_rep_baseC2<R_> Aff_t_base;
00054 
00055   typedef typename R_::Point_2              Point_2;
00056   typedef typename R_::Vector_2             Vector_2;
00057   typedef typename R_::Direction_2          Direction_2;
00058   typedef typename R_::Line_2               Line_2;
00059   typedef typename R_::Aff_transformation_2 Aff_transformation_2;
00060 
00061 public:
00062   typedef R_                                R;
00063    
00064   Aff_transformationC2()
00065   {
00066     initialize_with(Aff_transformation_repC2<R>(FT(1), FT(0), FT(0), FT(1)));
00067   }
00068 
00069   Aff_transformationC2(const Identity_transformation)
00070   {
00071     initialize_with(Aff_transformation_repC2<R>(FT(1), FT(0), FT(0), FT(1)));
00072   }
00073 
00074   Aff_transformationC2(const Translation, const Vector_2 &v)
00075   {
00076     initialize_with(Translation_repC2<R>(v));
00077   }
00078 
00079   // Rational Rotation:
00080   Aff_transformationC2(const Rotation,
00081                        const Direction_2 &d,
00082                        const FT &num,
00083                        const FT &den = FT(1))
00084   {
00085     initialize_with(Rotation_repC2<R>(d, num, den));
00086   }
00087 
00088   Aff_transformationC2(const Rotation,
00089                        const FT &sine,
00090                        const FT &cosine,
00091                        const FT &w = FT(1))
00092   {
00093     if (w != FT(1))
00094       initialize_with(Rotation_repC2<R>(sine/w, cosine/w));
00095     else
00096       initialize_with(Rotation_repC2<R>(sine, cosine));
00097   }
00098 
00099   Aff_transformationC2(const Scaling, const FT &s, const FT &w = FT(1))
00100   {
00101     if (w != FT(1))
00102       initialize_with(Scaling_repC2<R>(s/w));
00103     else
00104       initialize_with(Scaling_repC2<R>(s));
00105   }
00106 
00107   // The general case:
00108   // a 3x2 matrix for the operations combining rotation, scaling, translation
00109   Aff_transformationC2(const FT & m11, const FT & m12, const FT & m13,
00110                        const FT & m21, const FT & m22, const FT & m23,
00111                        const FT &w = FT(1))
00112   {
00113     if (w != FT(1))
00114       initialize_with(Aff_transformation_repC2<R>(m11/w, m12/w, m13/w,
00115                                                   m21/w, m22/w, m23/w));
00116     else
00117       initialize_with(Aff_transformation_repC2<R>(m11, m12, m13,
00118                                                   m21, m22, m23));
00119   }
00120 
00121   Aff_transformationC2(const FT & m11, const FT & m12,
00122                        const FT & m21, const FT & m22,
00123                        const FT &w = FT(1))
00124   {
00125     initialize_with(Aff_transformation_repC2<R>(m11/w, m12/w, m21/w, m22/w));
00126   }
00127 
00128   Point_2
00129   transform(const Point_2 &p) const 
00130   { return this->Ptr()->transform(p); } 
00131 
00132   Point_2
00133   operator()(const Point_2 &p) const
00134   { return transform(p); }
00135 
00136   Vector_2
00137   transform(const Vector_2 &v) const 
00138   { return this->Ptr()->transform(v); }
00139 
00140   Vector_2
00141   operator()(const Vector_2 &v) const
00142   { return transform(v); } // FIXME : not compiled by the test-suite.
00143 
00144   Direction_2
00145   transform(const Direction_2 &d) const
00146   { return this->Ptr()->transform(d); }
00147 
00148   Direction_2
00149   operator()(const Direction_2 &d) const
00150   { return transform(d); }
00151 
00152   Line_2
00153   transform(const Line_2 &l) const
00154   { return l.transform(*this); }
00155 
00156   Line_2
00157   operator()(const Line_2 &l) const
00158   { return transform(l); }
00159 
00160   Aff_transformation_2 inverse() const { return this->Ptr()->inverse(); }
00161 
00162   bool is_even() const { return this->Ptr()->is_even(); }
00163   bool is_odd() const { return ! (this->Ptr()->is_even()); }
00164 
00165   FT cartesian(int i, int j) const { return this->Ptr()->cartesian(i,j); }
00166   FT homogeneous(int i, int j) const { return cartesian(i,j); }
00167   FT m(int i, int j) const { return cartesian(i,j); }
00168   FT hm(int i, int j) const { return cartesian(i,j); }
00169 
00170   Aff_transformation_2 operator*(const Aff_transformationC2 &t) const
00171   {
00172     return (*(this->Ptr())) * (*t.Ptr());
00173   }
00174 
00175   std::ostream &
00176   print(std::ostream &os) const;
00177 };
00178 
00179 template < class R >
00180 std::ostream&
00181 Aff_transformationC2<R>::print(std::ostream &os) const
00182 {
00183   this->Ptr()->print(os);
00184   return os;
00185 }
00186 
00187 #ifndef CGAL_NO_OSTREAM_INSERT_AFF_TRANSFORMATIONC2
00188 template < class R >
00189 std::ostream&
00190 operator<<(std::ostream& os, const Aff_transformationC2<R>& t)
00191 {
00192   t.print(os);
00193   return os;
00194 }
00195 #endif // CGAL_NO_OSTREAM_INSERT_AFF_TRANSFORMATIONC2
00196 
00197 CGAL_END_NAMESPACE
00198 
00199 #endif // CGAL_CARTESIAN_AFF_TRANSFORMATION_2_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines