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 00044 #include <stdlib.h> 00045 #include <stdio.h> 00046 00047 #include <iostream> 00048 #include <iomanip> 00049 00050 #include <OSGLog.h> 00051 00052 OSG_BEGIN_NAMESPACE 00053 00054 //--------------------------------------------------------------------------- 00055 // Class 00056 //--------------------------------------------------------------------------- 00057 00075 /***************************************************************************\ 00076 * Types * 00077 \***************************************************************************/ 00078 00079 /***************************************************************************\ 00080 * Class variables * 00081 \***************************************************************************/ 00082 00083 //template<class ValueTypeT> 00084 //char LinearTransform<ValueTypeT>::cvsid[] = "@(#)$Id: $"; 00085 00086 00087 /***************************************************************************\ 00088 * Class methods * 00089 \***************************************************************************/ 00090 00091 /*-------------------------------------------------------------------------*\ 00092 - public - 00093 \*-------------------------------------------------------------------------*/ 00094 00095 /*-------------------------------------------------------------------------*\ 00096 - protected - 00097 \*-------------------------------------------------------------------------*/ 00098 00099 /*-------------------------------------------------------------------------*\ 00100 - private - 00101 \*-------------------------------------------------------------------------*/ 00102 00103 /***************************************************************************\ 00104 * Instance methods * 00105 \***************************************************************************/ 00106 00107 /*-------------------------------------------------------------------------*\ 00108 - public - 00109 \*-------------------------------------------------------------------------*/ 00110 00111 /*------------- constructors & destructors --------------------------------*/ 00112 00115 00119 template<class ValueTypeT> 00120 LinearTransform<ValueTypeT>::LinearTransform(void) 00121 { 00122 UInt32 i; 00123 00124 for(i = 0; i < 4; i++) 00125 { 00126 _logMatrix[i][i] = TypeTraits<ValueType>::getOneElement(); 00127 } 00128 } 00129 00133 template<class ValueTypeT> inline 00134 LinearTransform<ValueTypeT>::LinearTransform( 00135 const LinearTransform &source) 00136 { 00137 UInt32 i; 00138 00139 for(i = 0; i < 4; i++) 00140 { 00141 _logMatrix[i] = source._logMatrix[i]; 00142 } 00143 } 00144 00148 template<class ValueTypeT> inline 00149 LinearTransform<ValueTypeT>::LinearTransform( 00150 const MatrixType &mat) 00151 { 00152 _logMatrix.logOf(mat); 00153 } 00154 00158 template<class ValueTypeT> inline 00159 LinearTransform<ValueTypeT>::~LinearTransform(void) 00160 { 00161 } 00162 00164 00165 /*------------------------- set functions -------------------------------*/ 00166 00169 00173 template<class ValueTypeT> inline 00174 void LinearTransform<ValueTypeT>::setIdentity(void) 00175 { 00176 UInt32 i; 00177 00178 for(i = 0; i < 4; i++) 00179 { 00180 _logMatrix[i].setNull(); 00181 _logMatrix[i][i] = TypeTraits<ValueType>::getOneElement(); 00182 } 00183 } 00184 00185 00189 template<class ValueTypeT> inline 00190 void LinearTransform<ValueTypeT>::setValue( 00191 const LinearTransform &mat) 00192 { 00193 for(UInt32 i = 0; i < 4; i++) 00194 { 00195 _logMatrix[i] = mat._logMatrix[i]; 00196 } 00197 } 00198 00202 template<class ValueTypeT> inline 00203 void LinearTransform<ValueTypeT>::setValue( 00204 const MatrixType &mat) 00205 { 00206 _logMatrix.logOf(mat); 00207 } 00208 00209 //Set the LogMatrix direct 00210 00211 template<class ValueTypeT> inline 00212 void LinearTransform<ValueTypeT>::setLogMatrix( 00213 MatrixType &mat ) 00214 { 00215 _logMatrix = mat; 00216 } 00217 00218 //Get the LogMatrix direct 00219 00220 template<class ValueTypeT> inline 00221 TransformationMatrix<ValueTypeT> LinearTransform<ValueTypeT>::getLogMatrix() 00222 { 00223 return _logMatrix; 00224 } 00225 00227 00228 //Get the LogMatrix direct as const 00229 00230 template<class ValueTypeT> inline 00231 const TransformationMatrix<ValueTypeT> LinearTransform<ValueTypeT>::getLogMatrixConst() const 00232 { 00233 return _logMatrix; 00234 } 00235 00237 00238 /*------------------------- create transformation -------------------------*/ 00239 00242 00245 template<class ValueTypeT> inline 00246 TransformationMatrix<ValueTypeT> LinearTransform<ValueTypeT>::getTransform() 00247 { 00248 MatrixType mat; 00249 mat.expOf(_logMatrix); 00250 return mat; 00251 } 00252 00253 template<class ValueTypeT> inline 00254 LinearTransform<ValueTypeT>::operator 00255 TransformationMatrix<ValueTypeT>() 00256 { 00257 MatrixType mat; 00258 mat.expOf(_logMatrix); 00259 return mat; 00260 } 00262 00263 00264 /*-------------------------- assignment -----------------------------------*/ 00265 00268 00272 template<class ValueTypeT> inline 00273 LinearTransform<ValueTypeT> & 00274 LinearTransform<ValueTypeT>::operator = ( 00275 const LinearTransform &source) 00276 { 00277 UInt32 i; 00278 00279 if (this == &source) 00280 return *this; 00281 00282 for(i = 0; i < 4; i++) 00283 _logMatrix[i] = source._logMatrix[i]; 00284 00285 return *this; 00286 } 00287 00289 00290 /*-------------------------- comparison -----------------------------------*/ 00291 00294 00298 template<class ValueTypeT> inline 00299 bool LinearTransform<ValueTypeT>::operator == ( 00300 const LinearTransform &other) const 00301 { 00302 return (_logMatrix == other._logMatrix); 00303 } 00304 00309 template<class ValueTypeT> inline 00310 bool LinearTransform<ValueTypeT>::operator != ( 00311 const LinearTransform &other) const 00312 { 00313 return ! (*this == other); 00314 } 00315 00317 00318 /*-------------------------- operators -----------------------------------*/ 00319 00322 00326 template<class ValueTypeT> inline 00327 LinearTransform<ValueTypeT> 00328 LinearTransform<ValueTypeT>::operator + ( 00329 const LinearTransform <) const 00330 { 00331 LinearTransform sum; 00332 for (int i=0; i < 4; i++) 00333 for (int j=0; j < 4; j++) 00334 sum._logMatrix[i][j] = _logMatrix[i][j] + 00335 lt._logMatrix[i][j]; 00336 return sum; 00337 } 00338 00342 template<class ValueTypeT> inline 00343 LinearTransform<ValueTypeT> 00344 LinearTransform<ValueTypeT>::operator * ( 00345 const ValueTypeT s) const 00346 { 00347 LinearTransform pro; 00348 for (int i=0; i < 4; i++) 00349 for (int j=0; j < 4; j++) 00350 pro._logMatrix[i][j] = s * _logMatrix[i][j]; 00351 return pro; 00352 } 00353 00357 template<class ValueTypeT> inline 00358 LinearTransform<ValueTypeT> & 00359 LinearTransform<ValueTypeT>::operator += ( 00360 const LinearTransform <) 00361 { 00362 for (int i=0; i < 4; i++) 00363 for (int j=0; j < 4; j++) 00364 _logMatrix[i][j] += lt._logMatrix[i][j]; 00365 return *this; 00366 } 00367 00371 template<class ValueTypeT> inline 00372 LinearTransform<ValueTypeT> & 00373 LinearTransform<ValueTypeT>::operator *= ( 00374 const ValueTypeT s) 00375 { 00376 for (int i=0; i < 4; i++) 00377 for (int j=0; j < 4; j++) 00378 _logMatrix[i][j] *= s; 00379 return *this; 00380 } 00381 00385 template<class ValueTypeT> inline 00386 LinearTransform<ValueTypeT> 00387 operator * ( const ValueTypeT s, const LinearTransform<ValueTypeT> <) 00388 { 00389 TransformationMatrix<ValueTypeT> ltMat, proMat; 00390 LinearTransform<ValueTypeT> pro(lt); 00391 ltMat = pro.getLogMatrix(); 00392 00393 for (int i=0; i < 4; i++) 00394 for (int j=0; j < 4; j++) 00395 proMat[i][j] = s * ltMat[i][j]; 00396 00397 pro.setLogMatrix( proMat ); 00398 return pro; 00399 } 00400 00402 00403 /*-------------------------------------------------------------------------*\ 00404 - protected - 00405 \*-------------------------------------------------------------------------*/ 00406 00407 #define OSGLINEARTRANSFORM_INLINE_CVSID "@(#)$Id: $" 00408 00409 OSG_END_NAMESPACE
1.5.5