library of assembled shared sources

http://lass.cocamware.com

transformation_3d.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::Transformation3D
00046  *  @brief a linear 3D transformation
00047  *  @author Bram de Greve [BdG]
00048  */
00049 
00050 #ifndef LASS_GUARDIAN_OF_INCLUSION_PRIM_TRANSFORMATION_3D_H
00051 #define LASS_GUARDIAN_OF_INCLUSION_PRIM_TRANSFORMATION_3D_H
00052 
00053 #include "prim_common.h"
00054 #include "point_3d.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 Transformation3DStorage: public util::ArrayStorage<T, Cascade>
00070     {
00071     public:
00072         Transformation3DStorage(): util::ArrayStorage<T, Cascade>() {}
00073         Transformation3DStorage(T* p): util::ArrayStorage<T, Cascade>(p) {}
00074     protected:
00075         void dispose()
00076         {
00077             deallocateArray(this->pointer(), 16);
00078         }
00079     };
00080 }
00081 
00082 template <typename T>
00083 class Transformation3D
00084 {
00085 public:
00086 
00087     typedef Transformation3D<T> TSelf;
00088 
00089     typedef Point3D<T> TPoint;
00090     typedef typename TPoint::TVector TVector;
00091     typedef typename util::CallTraits<T>::TValue TValue;
00092     typedef typename util::CallTraits<T>::TParam TParam;
00093     typedef typename util::CallTraits<T>::TReference TReference;
00094     typedef typename util::CallTraits<T>::TConstReference TConstReference;
00095     typedef num::NumTraits<T> TNumTraits;
00096     typedef size_t TSize;
00097 
00098     enum { dimension = TPoint::dimension }; /**< number of dimensions of vector */
00099 
00100     template <typename U> struct Rebind
00101     {
00102         typedef Transformation3D<U> Type;
00103     };
00104 
00105     Transformation3D();
00106     Transformation3D(const TPoint& origin, const TVector& baseX, const TVector& baseY, 
00107         const TVector& baseZ);
00108     template <typename InputIterator> Transformation3D(InputIterator first, InputIterator last);
00109 
00110     const TSelf inverse() const;
00111 
00112     const TValue* matrix() const;
00113     void swap(TSelf& other);
00114 
00115     static const TSelf identity();
00116     static const TSelf translation(const Vector3D<T>& offset);
00117     static const TSelf scaler(const T& scale);
00118     static const TSelf scaler(const Vector3D<T>& scale);
00119     static const TSelf rotation(XYZ axis, TParam radians);
00120     static const TSelf rotation(const Vector3D<T>& axis, TParam radians);
00121 
00122 private:
00123 
00124     enum { matrixSize_ = 16 };
00125 
00126     typedef util::SharedPtr<TValue, impl::Transformation3DStorage> TMatrix;
00127 
00128     Transformation3D(const TMatrix& matrix, const TMatrix& inverseMatrix, bool dummy);
00129 
00130     TMatrix matrix_;
00131     mutable TMatrix inverseMatrix_;
00132 
00133     static T* allocate();
00134 
00135     static util::Semaphore sync_;
00136 };
00137 
00138 template <typename T> Transformation3D<T> concatenate(const Transformation3D<T>& first, const Transformation3D<T>& second);
00139 
00140 template <typename T> Vector3D<T> transform(const Vector3D<T>& subject, const Transformation3D<T>& transformation);
00141 template <typename T> Point3D<T> transform(const Point3D<T>& subject, const Transformation3D<T>& transformation);
00142 template <typename T> Vector3D<T> normalTransform(const Vector3D<T>& subject, const Transformation3D<T>& transformation);
00143 template <typename T> std::pair<Vector3D<T>, T> normalTransform(const std::pair<Vector3D<T>, T>& subject, const Transformation3D<T>& transformation);
00144 
00145 template<typename T, typename Char, typename Traits>
00146 std::basic_ostream<Char, Traits>& operator<<(std::basic_ostream<Char, Traits>& stream, const Transformation3D<T>& transformation);
00147 
00148 template<typename T> io::XmlOStream& operator<<(io::XmlOStream& stream, const Transformation3D<T>& transformation);
00149 
00150 // static member initialisation
00151 
00152 template <typename T> util::Semaphore Transformation3D<T>::sync_;
00153 
00154 }
00155 
00156 }
00157 
00158 #include "transformation_3d.inl"
00159 
00160 #define LASS_PRIM_HAVE_PY_EXPORT_TRAITS_TRANSFORMATION_3D
00161 #ifdef LASS_GUARDIAN_OF_INCLUSION_UTIL_PYOBJECT_PLUS_H
00162 #   include "pyobject_util.h"
00163 #endif
00164 
00165 #ifdef LASS_GUARDIAN_OF_INCLUSION_PRIM_AABB_3D_H
00166 #   include "aabb_3d_transformation_3d.h"
00167 #endif
00168 
00169 #ifdef LASS_GUARDIAN_OF_INCLUSION_PRIM_PLANE_3D_H
00170 #   include "plane_3d_transformation_3d.h"
00171 #endif
00172 
00173 #ifdef LASS_GUARDIAN_OF_INCLUSION_PRIM_RAY_3D_H
00174 #   include "ray_3d_transformation_3d.h"
00175 #endif
00176 
00177 #ifdef LASS_GUARDIAN_OF_INCLUSION_PRIM_COLOR_RGBA_H
00178 #   include "color_rgba_transformation_3d.h"
00179 #endif
00180 
00181 #endif
00182 
00183 // 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