OSGLinearTransform.inl
Go to the documentation of this file.00001 /*---------------------------------------------------------------------------*\ 00002 * OpenSG * 00003 * * 00004 * * 00005 * Copyright (C) 2000,2001 by the OpenSG Forum * 00006 * * 00007 * www.opensg.org * 00008 * * 00009 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de * 00010 * * 00011 \*---------------------------------------------------------------------------*/ 00012 /*---------------------------------------------------------------------------*\ 00013 * License * 00014 * * 00015 * This library is free software; you can redistribute it and/or modify it * 00016 * under the terms of the GNU Library General Public License as published * 00017 * by the Free Software Foundation, version 2. * 00018 * * 00019 * This library is distributed in the hope that it will be useful, but * 00020 * WITHOUT ANY WARRANTY; without even the implied warranty of * 00021 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00022 * Library General Public License for more details. * 00023 * * 00024 * You should have received a copy of the GNU Library General Public * 00025 * License along with this library; if not, write to the Free Software * 00026 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * 00027 * * 00028 \*---------------------------------------------------------------------------*/ 00029 /*---------------------------------------------------------------------------*\ 00030 * Changes * 00031 * * 00032 * Initial Version by Tobias Klug * 00033 * * 00034 * * 00035 * * 00036 * * 00037 \*---------------------------------------------------------------------------*/ 00038 00039 //--------------------------------------------------------------------------- 00040 // Includes 00041 //--------------------------------------------------------------------------- 00042 00043 OSG_BEGIN_NAMESPACE 00044 00045 //--------------------------------------------------------------------------- 00046 // Class 00047 //--------------------------------------------------------------------------- 00048 00066 /***************************************************************************\ 00067 * Types * 00068 \***************************************************************************/ 00069 00070 /***************************************************************************\ 00071 * Class variables * 00072 \***************************************************************************/ 00073 00074 /***************************************************************************\ 00075 * Class methods * 00076 \***************************************************************************/ 00077 00078 /*-------------------------------------------------------------------------*\ 00079 - public - 00080 \*-------------------------------------------------------------------------*/ 00081 00082 /*-------------------------------------------------------------------------*\ 00083 - protected - 00084 \*-------------------------------------------------------------------------*/ 00085 00086 /*-------------------------------------------------------------------------*\ 00087 - private - 00088 \*-------------------------------------------------------------------------*/ 00089 00090 /***************************************************************************\ 00091 * Instance methods * 00092 \***************************************************************************/ 00093 00094 /*-------------------------------------------------------------------------*\ 00095 - public - 00096 \*-------------------------------------------------------------------------*/ 00097 00098 /*------------- constructors & destructors --------------------------------*/ 00099 00102 00106 template<class ValueTypeT> 00107 LinearTransform<ValueTypeT>::LinearTransform(void) 00108 { 00109 UInt32 i; 00110 00111 for(i = 0; i < 4; i++) 00112 { 00113 _logMatrix[i][i] = TypeTraits<ValueType>::getOneElement(); 00114 } 00115 } 00116 00120 template<class ValueTypeT> inline 00121 LinearTransform<ValueTypeT>::LinearTransform( 00122 const LinearTransform &source) 00123 { 00124 UInt32 i; 00125 00126 for(i = 0; i < 4; i++) 00127 { 00128 _logMatrix[i] = source._logMatrix[i]; 00129 } 00130 } 00131 00135 template<class ValueTypeT> inline 00136 LinearTransform<ValueTypeT>::LinearTransform( 00137 const MatrixType &mat) 00138 { 00139 _logMatrix.logOf(mat); 00140 } 00141 00145 template<class ValueTypeT> inline 00146 LinearTransform<ValueTypeT>::~LinearTransform(void) 00147 { 00148 } 00149 00151 00152 /*------------------------- set functions -------------------------------*/ 00153 00156 00160 template<class ValueTypeT> inline 00161 void LinearTransform<ValueTypeT>::setIdentity(void) 00162 { 00163 UInt32 i; 00164 00165 for(i = 0; i < 4; i++) 00166 { 00167 _logMatrix[i].setNull(); 00168 _logMatrix[i][i] = TypeTraits<ValueType>::getOneElement(); 00169 } 00170 } 00171 00172 00176 template<class ValueTypeT> inline 00177 void LinearTransform<ValueTypeT>::setValue( 00178 const LinearTransform &mat) 00179 { 00180 for(UInt32 i = 0; i < 4; i++) 00181 { 00182 _logMatrix[i] = mat._logMatrix[i]; 00183 } 00184 } 00185 00189 template<class ValueTypeT> inline 00190 void LinearTransform<ValueTypeT>::setValue( 00191 const MatrixType &mat) 00192 { 00193 _logMatrix.logOf(mat); 00194 } 00195 00196 //Set the LogMatrix direct 00197 00198 template<class ValueTypeT> inline 00199 void LinearTransform<ValueTypeT>::setLogMatrix( 00200 MatrixType &mat ) 00201 { 00202 _logMatrix = mat; 00203 } 00204 00205 //Get the LogMatrix direct 00206 00207 template<class ValueTypeT> inline 00208 TransformationMatrix<ValueTypeT> LinearTransform<ValueTypeT>::getLogMatrix() 00209 { 00210 return _logMatrix; 00211 } 00212 00214 00215 //Get the LogMatrix direct as const 00216 00217 template<class ValueTypeT> inline 00218 const TransformationMatrix<ValueTypeT> LinearTransform<ValueTypeT>::getLogMatrixConst() const 00219 { 00220 return _logMatrix; 00221 } 00222 00224 00225 /*------------------------- create transformation -------------------------*/ 00226 00229 00232 template<class ValueTypeT> inline 00233 TransformationMatrix<ValueTypeT> LinearTransform<ValueTypeT>::getTransform() 00234 { 00235 MatrixType mat; 00236 mat.expOf(_logMatrix); 00237 return mat; 00238 } 00239 00240 template<class ValueTypeT> inline 00241 LinearTransform<ValueTypeT>::operator 00242 MatrixType() 00243 { 00244 MatrixType mat; 00245 mat.expOf(_logMatrix); 00246 return mat; 00247 } 00249 00250 00251 /*-------------------------- assignment -----------------------------------*/ 00252 00255 00259 template<class ValueTypeT> inline 00260 LinearTransform<ValueTypeT> & 00261 LinearTransform<ValueTypeT>::operator = ( 00262 const LinearTransform &source) 00263 { 00264 UInt32 i; 00265 00266 if (this == &source) 00267 return *this; 00268 00269 for(i = 0; i < 4; i++) 00270 _logMatrix[i] = source._logMatrix[i]; 00271 00272 return *this; 00273 } 00274 00276 00277 /*-------------------------- comparison -----------------------------------*/ 00278 00281 00285 template<class ValueTypeT> inline 00286 bool LinearTransform<ValueTypeT>::operator == ( 00287 const LinearTransform &other) const 00288 { 00289 return (_logMatrix == other._logMatrix); 00290 } 00291 00296 template<class ValueTypeT> inline 00297 bool LinearTransform<ValueTypeT>::operator != ( 00298 const LinearTransform &other) const 00299 { 00300 return ! (*this == other); 00301 } 00302 00304 00305 /*-------------------------- operators -----------------------------------*/ 00306 00309 00313 template<class ValueTypeT> inline 00314 LinearTransform<ValueTypeT> 00315 LinearTransform<ValueTypeT>::operator + ( 00316 const LinearTransform <) const 00317 { 00318 LinearTransform sum; 00319 for (int i=0; i < 4; i++) 00320 for (int j=0; j < 4; j++) 00321 sum._logMatrix[i][j] = _logMatrix[i][j] + 00322 lt._logMatrix[i][j]; 00323 return sum; 00324 } 00325 00329 template<class ValueTypeT> inline 00330 LinearTransform<ValueTypeT> 00331 LinearTransform<ValueTypeT>::operator * ( 00332 const ValueTypeT s) const 00333 { 00334 LinearTransform pro; 00335 for (int i=0; i < 4; i++) 00336 for (int j=0; j < 4; j++) 00337 pro._logMatrix[i][j] = s * _logMatrix[i][j]; 00338 return pro; 00339 } 00340 00344 template<class ValueTypeT> inline 00345 LinearTransform<ValueTypeT> & 00346 LinearTransform<ValueTypeT>::operator += ( 00347 const LinearTransform <) 00348 { 00349 for (int i=0; i < 4; i++) 00350 for (int j=0; j < 4; j++) 00351 _logMatrix[i][j] += lt._logMatrix[i][j]; 00352 return *this; 00353 } 00354 00358 template<class ValueTypeT> inline 00359 LinearTransform<ValueTypeT> & 00360 LinearTransform<ValueTypeT>::operator *= ( 00361 const ValueTypeT s) 00362 { 00363 for (int i=0; i < 4; i++) 00364 for (int j=0; j < 4; j++) 00365 _logMatrix[i][j] *= s; 00366 return *this; 00367 } 00368 00372 template<class ValueTypeT> inline 00373 LinearTransform<ValueTypeT> 00374 operator * ( const ValueTypeT s, const LinearTransform<ValueTypeT> <) 00375 { 00376 TransformationMatrix<ValueTypeT> ltMat, proMat; 00377 LinearTransform<ValueTypeT> pro(lt); 00378 ltMat = pro.getLogMatrix(); 00379 00380 for (int i=0; i < 4; i++) 00381 for (int j=0; j < 4; j++) 00382 proMat[i][j] = s * ltMat[i][j]; 00383 00384 pro.setLogMatrix( proMat ); 00385 return pro; 00386 } 00387 00389 00390 /*-------------------------------------------------------------------------*\ 00391 - protected - 00392 \*-------------------------------------------------------------------------*/ 00393 00394 OSG_END_NAMESPACE
