00001 //--------------------------------------------------------------------------- 00002 // 00003 // Project: OpenWalnut ( http://www.openwalnut.org ) 00004 // 00005 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS 00006 // For more information see http://www.openwalnut.org/copying 00007 // 00008 // This file is part of OpenWalnut. 00009 // 00010 // OpenWalnut is free software: you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as published by 00012 // the Free Software Foundation, either version 3 of the License, or 00013 // (at your option) any later version. 00014 // 00015 // OpenWalnut is distributed in the hope that it will be useful, 00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 // GNU Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public License 00021 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>. 00022 // 00023 //--------------------------------------------------------------------------- 00024 00025 #ifndef WGRIDTRANSFORMORTHO_H 00026 #define WGRIDTRANSFORMORTHO_H 00027 00028 #include "../common/math/WMatrix.h" 00029 #include "../common/math/linearAlgebra/WLinearAlgebra.h" 00030 00031 #include "WExportDataHandler.h" 00032 00033 /** 00034 * Implements an orthogonal grid transformation. 00035 * 00036 * \class WGridTransformOrtho 00037 */ 00038 class OWDATAHANDLER_EXPORT WGridTransformOrtho 00039 { 00040 public: 00041 /** 00042 * Constructs an identity transform. 00043 */ 00044 WGridTransformOrtho(); 00045 00046 /** 00047 * Construct a transformation that scales the grid space. 00048 * \param scaleX The scale in the x-direction. 00049 * \param scaleY The scale in the y-direction. 00050 * \param scaleZ The scale in the z-direction. 00051 */ 00052 WGridTransformOrtho( double scaleX, double scaleY, double scaleZ ); 00053 00054 /** 00055 * Construct a transformation from a transformation matrix. The provided matrix 00056 * represents the transformation from grid to world space. 00057 * \param mat The matrix. 00058 */ 00059 WGridTransformOrtho( WMatrix< double > const& mat ); // NOLINT 00060 00061 /** 00062 * Destructor. 00063 */ 00064 ~WGridTransformOrtho(); 00065 00066 /** 00067 * Transforms a position from grid space to world space. 00068 * \param position The position in grid space. 00069 * \return The same position in world space. 00070 */ 00071 WVector3d positionToWorldSpace( WVector3d const& position ) const; 00072 00073 /** 00074 * Transforms a position from world space to grid space. 00075 * \param position The position in world space. 00076 * \return The same position in grid space. 00077 */ 00078 WVector3d positionToGridSpace( WVector3d const& position ) const; 00079 00080 /** 00081 * Transforms a direction from grid space to world space. 00082 * \param direction The direction in grid space. 00083 * \return The same direction in world space. 00084 */ 00085 WVector3d directionToWorldSpace( WVector3d const& direction ) const; 00086 00087 /** 00088 * Transforms a direction from world space to grid space. 00089 * \param direction The position in world space. 00090 * \return The same position in grid space. 00091 */ 00092 WVector3d directionToGridSpace( WVector3d const& direction ) const; 00093 00094 /** 00095 * Returns the distance between samples in x direction. 00096 * \return The distance between samples in x direction. 00097 */ 00098 double getOffsetX() const; 00099 00100 /** 00101 * Returns the distance between samples in y direction. 00102 * \return The distance between samples in y direction. 00103 */ 00104 double getOffsetY() const; 00105 00106 /** 00107 * Returns the distance between samples in z direction. 00108 * \return The distance between samples in z direction. 00109 */ 00110 double getOffsetZ() const; 00111 00112 /** 00113 * Returns the vector determining the direction of samples in x direction. 00114 * Adding this vector to a grid position in world coordinates yields the position of the next sample 00115 * along the grids (world coordinate) x-axis. 00116 * \return The vector determining the direction of samples in x direction. 00117 */ 00118 WVector3d getDirectionX() const; 00119 00120 /** 00121 * Returns the vector determining the direction of samples in y direction. 00122 * Adding this vector to a grid position in world coordinates yields the position of the next sample 00123 * along the grids (world coordinate) y-axis. 00124 * \return The vector determining the direction of samples in y direction. 00125 */ 00126 WVector3d getDirectionY() const; 00127 00128 /** 00129 * Returns the vector determining the direction of samples in z direction. 00130 * Adding this vector to a grid position in world coordinates yields the position of the next sample 00131 * along the grids (world coordinate) z-axis. 00132 * \return The vector determining the direction of samples in z direction. 00133 */ 00134 WVector3d getDirectionZ() const; 00135 00136 /** 00137 * Returns the vector determining the unit (normalized) direction of samples in x direction. 00138 * \return The vector determining the unit (normalized) direction of samples in x direction. 00139 */ 00140 WVector3d getUnitDirectionX() const; 00141 00142 /** 00143 * Returns the vector determining the unit (normalized) direction of samples in y direction. 00144 * \return The vector determining the unit (normalized) direction of samples in y direction. 00145 */ 00146 WVector3d getUnitDirectionY() const; 00147 00148 /** 00149 * Returns the vector determining the unit (normalized) direction of samples in z direction. 00150 * \return The vector determining the unit (normalized) direction of samples in z direction. 00151 */ 00152 WVector3d getUnitDirectionZ() const; 00153 00154 /** 00155 * Returns the position of the origin of the grid. 00156 * \return The position of the origin of the grid. 00157 */ 00158 WPosition getOrigin() const; 00159 00160 /** 00161 * Returns a 4x4 matrix that represents the grid's transformaion. 00162 * \return The grid's transformation. 00163 */ 00164 // NOTE: this is temporary and should be removed as soon as all modules are 00165 // adapted to the grid transform object 00166 WMatrix< double > getTransformationMatrix() const; 00167 00168 /** 00169 * Cast the transformation to the corresponding 4x4 matrix. 00170 * 00171 * \return the matrix representing the transform 00172 */ 00173 operator WMatrix4d() const; 00174 00175 /** 00176 * Check if this transform does not include a rotation. 00177 * 00178 * \return True, if this transform only scales and translates. 00179 */ 00180 bool isNotRotated() const; 00181 00182 /** 00183 * Translate by a vector. 00184 * 00185 * \param vec The vector. 00186 */ 00187 template< typename VecType > 00188 void translate( VecType const& vec ); 00189 00190 /** 00191 * Scale the transform. 00192 * 00193 * \param scale A vector of scaling coeffs for the 3 directions. 00194 */ 00195 template< typename VecType > 00196 void scale( VecType const& scale ); 00197 00198 private: 00199 //! normalized direction of the grid's x-axis in world coordinates 00200 WVector3d m_directionX; 00201 00202 //! normalized direction of the grid's y-axis in world coordinates 00203 WVector3d m_directionY; 00204 00205 //! normalized direction of the grid's z-axis in world coordinates 00206 WVector3d m_directionZ; 00207 00208 //! the scaling factors for the 3 axes, i.e. the distance between samples 00209 WVector3d m_scaling; 00210 00211 //! the origin of the grid in world coordinates 00212 WVector3d m_origin; 00213 }; 00214 00215 template< typename VecType > 00216 void WGridTransformOrtho::translate( VecType const& vec ) 00217 { 00218 m_origin[ 0 ] += vec[ 0 ]; 00219 m_origin[ 1 ] += vec[ 1 ]; 00220 m_origin[ 2 ] += vec[ 2 ]; 00221 } 00222 00223 template< typename VecType > 00224 void WGridTransformOrtho::scale( VecType const& scale ) 00225 { 00226 m_scaling[ 0 ] *= scale[ 0 ]; 00227 m_scaling[ 1 ] *= scale[ 1 ]; 00228 m_scaling[ 2 ] *= scale[ 2 ]; 00229 } 00230 00231 #endif // WGRIDTRANSFORMORTHO_H