library of assembled shared sources

http://lass.cocamware.com

transformation_2d.h

Go to the documentation of this file.
00001 /** @file
00002  *  @author Bram de Greve (bramz@users.sourceforge.net)
00003  *  @author Tom De Muer (tomdemuer@users.sourceforge.net)
00004  *
00005  *  *** BEGIN LICENSE INFORMATION ***
00006  *  
00007  *  The contents of this file are subject to the Common Public Attribution License 
00008  *  Version 1.0 (the "License"); you may not use this file except in compliance with 
00009  *  the License. You may obtain a copy of the License at 
00010  *  http://lass.sourceforge.net/cpal-license. The License is based on the 
00011  *  Mozilla Public License Version 1.1 but Sections 14 and 15 have been added to cover 
00012  *  use of software over a computer network and provide for limited attribution for 
00013  *  the Original Developer. In addition, Exhibit A has been modified to be consistent 
00014  *  with Exhibit B.
00015  *  
00016  *  Software distributed under the License is distributed on an "AS IS" basis, WITHOUT 
00017  *  WARRANTY OF ANY KIND, either express or implied. See the License for the specific 
00018  *  language governing rights and limitations under the License.
00019  *  
00020  *  The Original Code is LASS - Library of Assembled Shared Sources.
00021  *  
00022  *  The Initial Developer of the Original Code is Bram de Greve and Tom De Muer.
00023  *  The Original Developer is the Initial Developer.
00024  *  
00025  *  All portions of the code written by the Initial Developer are:
00026  *  Copyright (C) 2004-2007 the Initial Developer.
00027  *  All Rights Reserved.
00028  *  
00029  *  Contributor(s):
00030  *
00031  *  Alternatively, the contents of this file may be used under the terms of the 
00032  *  GNU General Public License Version 2 or later (the GPL), in which case the 
00033  *  provisions of GPL are applicable instead of those above.  If you wish to allow use
00034  *  of your version of this file only under the terms of the GPL and not to allow 
00035  *  others to use your version of this file under the CPAL, indicate your decision by 
00036  *  deleting the provisions above and replace them with the notice and other 
00037  *  provisions required by the GPL License. If you do not delete the provisions above,
00038  *  a recipient may use your version of this file under either the CPAL or the GPL.
00039  *  
00040  *  *** END LICENSE INFORMATION ***
00041  */
00042 
00043 
00044 
00045 /** @class lass::prim::Transformation2D
00046  *  @brief a linear 2D transformation
00047  *  @author Bram de Greve [BdG]
00048  */
00049 
00050 #ifndef LASS_GUARDIAN_OF_INCLUSION_PRIM_TRANSFORMATION_2D_H
00051 #define LASS_GUARDIAN_OF_INCLUSION_PRIM_TRANSFORMATION_2D_H
00052 
00053 #include "prim_common.h"
00054 #include "point_2d.h"
00055 #include "xyz.h"
00056 #include "impl/prim_allocator.h"
00057 #include "../io/xml_o_stream.h"
00058 #include "../num/num_traits.h"
00059 #include "../util/shared_ptr.h"
00060 #include "../util/thread.h"
00061 
00062 namespace lass
00063 {
00064 namespace prim
00065 {
00066 namespace impl
00067 {
00068     template <typename T, typename Cascade>
00069     class Transformation2DStorage: public util::ArrayStorage<T, Cascade>
00070     {
00071     public:
00072         Transformation2DStorage(): util::ArrayStorage<T, Cascade>() {}
00073         Transformation2DStorage(T* p): util::ArrayStorage<T, Cascade>(p) {}
00074     protected:
00075         void dispose()
00076         {
00077             impl::deallocateArray(this->pointer(), 9);
00078         }
00079     };
00080 }
00081 
00082 template <typename T>
00083 class Transformation2D
00084 {
00085 public:
00086 
00087     typedef Transformation2D<T> TSelf;
00088 
00089     typedef typename util::CallTraits<T>::TValue TValue;
00090     typedef typename util::CallTraits<T>::TParam TParam;
00091     typedef typename util::CallTraits<T>::TReference TReference;
00092     typedef typename util::CallTraits<T>::TConstReference TConstReference;
00093     typedef num::NumTraits<T> TNumTraits;
00094     typedef size_t TSize;
00095 
00096     enum { dimension = 3 }; /**< number of dimensions of vector */
00097 
00098     template <typename U> struct Rebind
00099     {
00100         typedef Transformation2D<U> Type;
00101     };
00102 
00103     Transformation2D();
00104     template <typename InputIterator> Transformation2D(InputIterator first, InputIterator last);
00105 
00106     const Transformation2D<T> inverse() const;
00107 
00108     const TValue* matrix() const;
00109     void swap(TSelf& other);
00110 
00111     static const TSelf identity();
00112     static const TSelf translation(const Vector2D<T>& offset);
00113     static const TSelf scaler(const T& scale);
00114     static const TSelf scaler(const Vector2D<T>& scale);
00115     static const TSelf rotation(TParam radians);
00116 
00117 private:
00118 
00119     enum { matrixSize_ = 9 };
00120 
00121     typedef util::SharedPtr<TValue, impl::Transformation2DStorage> TMatrix;
00122 
00123     Transformation2D(const TMatrix& matrix, const TMatrix& inverseMatrix, bool dummy);
00124 
00125     static const TMatrix& getIdentityMatrix();
00126 
00127     TMatrix matrix_;
00128     mutable TMatrix inverseMatrix_;
00129 
00130     static TMatrix identityMatrix_;
00131 
00132     static util::Semaphore sync_;
00133 };
00134 
00135 template <typename T> Transformation2D<T> concatenate(const Transformation2D<T>& first, const Transformation2D<T>& second);
00136 
00137 template <typename T> Vector2D<T> transform(const Vector2D<T>& subject, const Transformation2D<T>& transformation);
00138 template <typename T> Point2D<T> transform(const Point2D<T>& subject, const Transformation2D<T>& transformation);
00139 template <typename T> Vector2D<T> normalTransform(const Vector2D<T>& subject, const Transformation2D<T>& transformation);
00140 template <typename T> std::pair<Vector2D<T>, T> normalTransform(const std::pair<Vector2D<T>, T>& subject, const Transformation2D<T>& transformation);
00141 
00142 template<typename T, typename Char, typename Traits>
00143 std::basic_ostream<Char, Traits>& operator<<(std::basic_ostream<Char, Traits>& stream, const Transformation2D<T>& transformation);
00144 
00145 template<typename T> io::XmlOStream& operator<<(io::XmlOStream& stream, const Transformation2D<T>& transformation);
00146 
00147 // static member initialisation
00148 
00149 template <typename T> util::Semaphore Transformation2D<T>::sync_;
00150 
00151 }
00152 
00153 }
00154 
00155 #include "transformation_2d.inl"
00156 
00157 #define LASS_PRIM_HAVE_PY_EXPORT_TRAITS_TRANSFORMATION_2D
00158 #ifdef LASS_GUARDIAN_OF_INCLUSION_UTIL_PYOBJECT_PLUS_H
00159 #   include "pyobject_util.h"
00160 #endif
00161 
00162 #ifdef LASS_GUARDIAN_OF_INCLUSION_PRIM_AABB_2D_H
00163 #   include "aabb_2d_transformation_2d.h"
00164 #endif
00165 
00166 #endif
00167 
00168 // EOF

Generated on Mon Nov 10 14:21:40 2008 for Library of Assembled Shared Sources by doxygen 1.5.7.1
SourceForge.net Logo