HyperspaceExplorer 0.7.1
|
00001 /* 00002 Hyperspace Explorer - vizualizing higher-dimensional geometry 00003 Copyright (C) 2010 Lene Preuss <lene.preuss@gmail.com> 00004 00005 This program is free software; you can redistribute it and/or modify 00006 it under the terms of the GNU General Public License as published by 00007 the Free Software Foundation; either version 2 of the License, or 00008 (at your option) any later version. 00009 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License along 00016 with this program; if not, write to the Free Software Foundation, Inc., 00017 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00018 00019 */ 00020 00021 #ifndef TRANSFORMATION_H 00022 #define TRANSFORMATION_H 00023 00024 #include "FunctionValueGrid.h" 00025 00026 #include "Rotation.h" 00027 00028 namespace TransformationUtil { 00029 template <unsigned N, typename NUM = double> 00030 inline VecMath::Vector<N, NUM> perform( 00031 const VecMath::Vector<N, NUM> &x, 00032 const VecMath::Matrix<N, NUM> &rot, 00033 const VecMath::Vector<N, NUM> &trans, 00034 const VecMath::Vector<N, NUM> &scale 00035 ) { 00036 return VecMath::scale(rot*(x+trans), scale); 00037 } 00038 00039 } 00040 00042 00051 template <unsigned N, unsigned P, typename NUM = double> 00052 class Transformation { 00053 00054 public: 00055 00057 typedef typename FunctionValueGrid< N, P, NUM >::value_storage_type value_storage_type; 00058 00059 static inline VecMath::Vector<N, NUM> perform( 00060 const VecMath::Vector<N, NUM> &x, 00061 const VecMath::Matrix<N, NUM> &rot, 00062 const VecMath::Vector<N, NUM> &trans, 00063 const VecMath::Vector<N, NUM> &scale 00064 ) { 00065 return TransformationUtil::perform(x, rot, trans, scale); 00066 } 00067 00069 00073 virtual value_storage_type transform(const value_storage_type &operand) const = 0; 00074 00075 virtual ~Transformation() { } 00076 00077 protected: 00078 00079 Transformation() { } 00080 00082 00086 Transformation(const VecMath::Rotation<N, NUM> &rotation, 00087 const VecMath::Vector<N, NUM> &translation, 00088 const VecMath::Vector<N, NUM> &scale); 00089 00090 }; 00091 00092 class TransformationFactory; 00093 00095 00104 template <unsigned N, unsigned P, typename NUM = double> 00105 class TransformationImpl: public Transformation< N, P, NUM > { 00106 00107 public: 00108 00110 typedef typename FunctionValueGrid< N, P, NUM >::value_storage_type value_storage_type; 00111 00112 protected: 00113 00115 00119 TransformationImpl(const VecMath::Rotation<N, NUM> &rotation, 00120 const VecMath::Vector<N, NUM> &translation, 00121 const VecMath::Vector<N, NUM> &scale); 00122 00123 VecMath::Rotation<N, NUM> rotation_; 00124 VecMath::Vector<N, NUM> translation_; 00125 VecMath::Vector<N, NUM> scale_; 00126 00127 friend class TransformationFactory; 00128 }; 00129 00130 #endif // TRANSFORMATION_H