BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/Cartesian/Aff_transformation_rep_3.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_rep_3.h $
00019 // $Id: Aff_transformation_rep_3.h 42811 2008-04-09 13:35:34Z spion $
00020 // 
00021 //
00022 // Author(s)     : Herve Bronnimann
00023 
00024 #ifndef CGAL_CARTESIAN_AFF_TRANSFORMATION_REP_3_H
00025 #define CGAL_CARTESIAN_AFF_TRANSFORMATION_REP_3_H
00026 
00027 #include <CGAL/determinant.h>
00028 
00029 CGAL_BEGIN_NAMESPACE
00030 
00031 template < class R >
00032 class Aff_transformation_rep_baseC3
00033   : public Ref_counted_virtual
00034 {
00035 public:
00036   typedef typename R::FT                   FT;
00037   typedef typename R::Point_3              Point_3;
00038   typedef typename R::Vector_3             Vector_3;
00039   typedef typename R::Direction_3          Direction_3;
00040   typedef typename R::Aff_transformation_3 Aff_transformation_3;
00041 
00042   virtual ~Aff_transformation_rep_baseC3(){}
00043 
00044   virtual Point_3     transform(const Point_3 &p) const = 0;
00045   virtual Vector_3    transform(const Vector_3 &v) const = 0;
00046   virtual Direction_3 transform(const Direction_3 &d) const = 0;
00047 
00048   virtual Aff_transformation_3 operator*(
00049                        const Aff_transformation_rep_baseC3 &t) const = 0;
00050 
00051   virtual Aff_transformation_3 compose(
00052                        const Translation_repC3<R> &t) const  = 0;
00053 
00054   virtual Aff_transformation_3 compose(
00055                        const Scaling_repC3<R> &t) const  = 0;
00056 
00057   virtual Aff_transformation_3 compose(
00058                        const Aff_transformation_repC3<R> &t) const  = 0;
00059 
00060   virtual Aff_transformation_3 inverse() const = 0;
00061   virtual Aff_transformation_3 transpose() const = 0;
00062   virtual bool                 is_even() const = 0;
00063   virtual FT                   cartesian(int i, int j) const = 0;
00064   virtual std::ostream         &print(std::ostream &os) const = 0;
00065 };
00066 
00067 template < class R >
00068 class Aff_transformation_repC3
00069   : public Aff_transformation_rep_baseC3<R>
00070 {
00071   friend class Translation_repC3<R>;
00072   friend class Scaling_repC3<R>;
00073 
00074 public:
00075   typedef typename R::FT                                FT;
00076   typedef Aff_transformation_repC3<R>                   Self;
00077   typedef Aff_transformation_rep_baseC3<R>              Transformation_base_3;
00078   typedef Aff_transformation_repC3<R>                   Transformation_3;
00079   typedef Translation_repC3<R>                          Translation_3;
00080   typedef Scaling_repC3<R>                              Scaling_3;
00081   typedef typename Transformation_base_3::Point_3       Point_3;
00082   typedef typename Transformation_base_3::Vector_3      Vector_3;
00083   typedef typename Transformation_base_3::Direction_3   Direction_3;
00084   typedef typename Transformation_base_3::
00085 	                           Aff_transformation_3 Aff_transformation_3;
00086 
00087   Aff_transformation_repC3()
00088   {}
00089 
00090   Aff_transformation_repC3(const FT& m11, const FT& m12, const FT& m13,
00091                            const FT& m21, const FT& m22, const FT& m23,
00092                            const FT& m31, const FT& m32, const FT& m33)
00093     : t11(m11), t12(m12), t13(m13), t14(FT(0)),
00094       t21(m21), t22(m22), t23(m23), t24(FT(0)),
00095       t31(m31), t32(m32), t33(m33), t34(FT(0))
00096   {}
00097 
00098   Aff_transformation_repC3(
00099      const FT& m11, const FT& m12, const FT& m13, const FT& m14,
00100      const FT& m21, const FT& m22, const FT& m23, const FT& m24,
00101      const FT& m31, const FT& m32, const FT& m33, const FT& m34
00102   )
00103     : t11(m11), t12(m12), t13(m13), t14(m14),
00104       t21(m21), t22(m22), t23(m23), t24(m24),
00105       t31(m31), t32(m32), t33(m33), t34(m34)
00106   {}
00107 
00108   virtual ~Aff_transformation_repC3()
00109   {}
00110 
00111   virtual Point_3 transform(const Point_3& p) const // FIXME : construction
00112   {
00113     typename R::Construct_point_3 construct_point_3;
00114     return construct_point_3(t11 * p.x() + t12 * p.y() + t13 * p.z() + t14,
00115                              t21 * p.x() + t22 * p.y() + t23 * p.z() + t24,
00116                              t31 * p.x() + t32 * p.y() + t33 * p.z() + t34);
00117   }
00118 
00119   // note that a vector is not translated
00120   virtual Vector_3 transform(const Vector_3& v) const // FIXME : construction
00121   {
00122     return Vector_3(t11 * v.x() + t12 * v.y() + t13 * v.z(),
00123                     t21 * v.x() + t22 * v.y() + t23 * v.z(),
00124                     t31 * v.x() + t32 * v.y() + t33 * v.z());
00125   }
00126 
00127   // note that a direction is not translated
00128   virtual Direction_3 transform(const Direction_3& dir) const
00129   { // FIXME : construction
00130     Vector_3 v = dir.to_vector();
00131     return Direction_3(t11 * v.x() + t12 * v.y() + t13 * v.z(),
00132                        t21 * v.x() + t22 * v.y() + t23 * v.z(),
00133                        t31 * v.x() + t32 * v.y() + t33 * v.z());
00134   }
00135 
00136   // Note that Aff_transformation is not defined yet,
00137   // so the following 6 functions have to be implemented
00138   // outside class body
00139   virtual Aff_transformation_3 inverse() const;
00140   virtual Aff_transformation_3 transpose() const;
00141   virtual Aff_transformation_3 operator*(const Transformation_base_3 &t) const;
00142   virtual Aff_transformation_3 compose(const Transformation_3 &t) const;
00143   virtual Aff_transformation_3 compose(const Translation_3 &t) const;
00144   virtual Aff_transformation_3 compose(const Scaling_3 &t) const;
00145      
00146   virtual bool is_even() const
00147   {
00148     return sign_of_determinant(t11, t12, t13,
00149                                   t21, t22, t23,
00150                                   t31, t32, t33) == POSITIVE;
00151   }
00152 
00153   virtual FT cartesian(int i, int j) const
00154   {
00155     switch (i)
00156     {
00157     case 0: switch (j)
00158             {
00159               case 0: return t11;
00160               case 1: return t12;
00161               case 2: return t13;
00162               case 3: return t14;
00163             }
00164     case 1: switch (j)
00165             {
00166               case 0: return t21;
00167               case 1: return t22;
00168               case 2: return t23;
00169               case 3: return t24;
00170             }
00171     case 2: switch (j)
00172             {
00173               case 0: return t31;
00174               case 1: return t32;
00175               case 2: return t33;
00176               case 3: return t34;
00177             }
00178     case 3: switch (j)
00179             {
00180               case 0: return FT(0);
00181               case 1: return FT(0);
00182               case 2: return FT(0);
00183               case 3: return FT(1);
00184             }
00185     }
00186   return FT(0);
00187   }
00188 
00189   virtual std::ostream &print(std::ostream &os) const
00190   {
00191     os <<"Aff_transformationC3("<<t11<<' '<<t12<<' '<<t13<<' '<<t14<<std::endl;
00192     os <<"                    "<< t21<<' '<<t22<<' '<<t23<<' '<<t24<<std::endl;
00193     os <<"                    "<< t31<<' '<<t32<<' '<<t33<<' '<<t34<<")";
00194     return os;
00195   }
00196 
00197 private:
00198   FT   t11, t12, t13, t14; // FIXME : Wouldn't this be better with an array ?
00199   FT   t21, t22, t23, t24;
00200   FT   t31, t32, t33, t34;
00201 };
00202 
00203 template < class R >
00204 CGAL_KERNEL_LARGE_INLINE
00205 typename Aff_transformation_repC3<R>::Aff_transformation_3
00206 Aff_transformation_repC3<R>::inverse() const // FIXME : construction
00207 {
00208   return Aff_transformation_3(
00209       determinant( t22, t23, t32, t33),         // i 11
00210      -determinant( t12, t13, t32, t33),         // i 12
00211       determinant( t12, t13, t22, t23),         // i 13
00212      -determinant( t12, t13, t14, t22, t23, t24, t32, t33, t34 ),
00213 
00214      -determinant( t21, t23, t31, t33),         // i 21 
00215       determinant( t11, t13, t31, t33),         // i 22
00216      -determinant( t11, t13, t21, t23),         // i 23
00217       determinant( t11, t13, t14, t21, t23, t24, t31, t33, t34 ),
00218 
00219       determinant( t21, t22, t31, t32),         // i 31
00220      -determinant( t11, t12, t31, t32),         // i 32
00221       determinant( t11, t12, t21, t22),         // i 33
00222      -determinant( t11, t12, t14, t21, t22, t24, t31, t32, t34 ),
00223 
00224       determinant( t11, t12, t13, t21, t22, t23, t31, t32, t33 ));
00225 }
00226 
00227 template < class R >
00228 CGAL_KERNEL_INLINE
00229 typename Aff_transformation_repC3<R>::Aff_transformation_3
00230 Aff_transformation_repC3<R>::
00231 operator*(const Aff_transformation_rep_baseC3<R> &t) const
00232 {
00233   return t.compose(*this);
00234 }
00235 
00236 template < class R >
00237 CGAL_KERNEL_LARGE_INLINE
00238 typename Aff_transformation_repC3<R>::Aff_transformation_3
00239 Aff_transformation_repC3<R>::
00240 compose(const Aff_transformation_repC3<R> &t) const // FIXME : construction
00241 {
00242   return Aff_transformation_3(t.t11*t11 + t.t12*t21 + t.t13*t31,
00243                               t.t11*t12 + t.t12*t22 + t.t13*t32,
00244                               t.t11*t13 + t.t12*t23 + t.t13*t33,
00245                               t.t11*t14 + t.t12*t24 + t.t13*t34 + t.t14,
00246 
00247                               t.t21*t11 + t.t22*t21 + t.t23*t31,
00248                               t.t21*t12 + t.t22*t22 + t.t23*t32,
00249                               t.t21*t13 + t.t22*t23 + t.t23*t33,
00250                               t.t21*t14 + t.t22*t24 + t.t23*t34 + t.t24,
00251 
00252                               t.t31*t11 + t.t32*t21 + t.t33*t31,
00253                               t.t31*t12 + t.t32*t22 + t.t33*t32,
00254                               t.t31*t13 + t.t32*t23 + t.t33*t33,
00255                               t.t31*t14 + t.t32*t24 + t.t33*t34 + t.t34);
00256 }
00257 
00258 template < class R >
00259 CGAL_KERNEL_LARGE_INLINE
00260 typename Aff_transformation_repC3<R>::Aff_transformation_3
00261 Aff_transformation_repC3<R>::
00262 compose(const Translation_repC3<R> &t) const // FIXME : construction
00263 {
00264   return Aff_transformation_3(t11,
00265                               t12,
00266                               t13,
00267                               t14 + t.translationvector_.x(),
00268 
00269                               t21,
00270                               t22,
00271                               t23,
00272                               t24 + t.translationvector_.y(),
00273 
00274                               t31,
00275                               t32,
00276                               t33,
00277                               t34 + t.translationvector_.z());
00278 }
00279 
00280 template < class R >
00281 CGAL_KERNEL_LARGE_INLINE
00282 typename Aff_transformation_repC3<R>::Aff_transformation_3
00283 Aff_transformation_repC3<R>::
00284 compose(const Scaling_repC3<R> &t) const // FIXME : construction
00285 {
00286   return Aff_transformation_3(t.scalefactor_ * t11,
00287                               t.scalefactor_ * t12,
00288                               t.scalefactor_ * t13,
00289                               t.scalefactor_ * t14,
00290                               
00291                               t.scalefactor_ * t21,
00292                               t.scalefactor_ * t22,
00293                               t.scalefactor_ * t23,
00294                               t.scalefactor_ * t24,
00295                               
00296                               t.scalefactor_ * t31,
00297                               t.scalefactor_ * t32,
00298                               t.scalefactor_ * t33,
00299                               t.scalefactor_ * t34);
00300 }
00301 
00302 template < class R >
00303 CGAL_KERNEL_LARGE_INLINE
00304 typename Aff_transformation_repC3<R>::Aff_transformation_3
00305 Aff_transformation_repC3<R>::transpose() const
00306 {
00307   return Aff_transformation_3( t11, t21, t31, t14,
00308                                t12, t22, t32, t24,
00309                                t13, t23, t33, t34);
00310 }
00311 
00312 CGAL_END_NAMESPACE
00313 
00314 #endif // CGAL_CARTESIAN_AFF_TRANSFORMATION_REP_3_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines