00001 #ifndef BASICS_H
00002 #define BASICS_H
00003
00004 #include <MDSTk/Base/mdsSetup.h>
00005 #include <MDSTk/Base/mdsError.h>
00006 #include <MDSTk/Math/mdsMatrix.h>
00007 #include <MDSTk/Math/mdsVector.h>
00008 #include <MDSTk/Math/mdsMatrixFunctions.h>
00009
00010
00011 #include <osg/Geode>
00012 #include <osg/Geometry>
00013
00014 namespace conv
00015 {
00016
00017 template < class _From, class _To >
00018 inline _To convert( const _From & from )
00019 {
00020 throw mds::base::CError( "invalid conversion" );
00021 return _To(0);
00022 }
00023
00024 template <>
00025 inline mds::math::CDVector convert( const osg::Vec3 & from )
00026 {
00027 mds::math::CDVector result( 3 );
00028 result.get(0) = from[0];
00029 result.get(1) = from[1];
00030 result.get(2) = from[2];
00031 return result;
00032 }
00033
00034 template <>
00035 inline mds::math::CDVector convert( const osg::Vec4 & from )
00036 {
00037 mds::math::CDVector result( 4 );
00038 result.get(0) = from[0];
00039 result.get(1) = from[1];
00040 result.get(2) = from[2];
00041 result.get(3) = from[3];
00042 return result;
00043 }
00044
00045 template <>
00046 inline osg::Vec4 convert( const mds::math::CDVector & from )
00047 {
00048 osg::Vec4 result;
00049 result[0] = from.get(0);
00050 result[1] = from.get(1);
00051 result[2] = from.get(2);
00052 result[3] = from.get(3);
00053 return result;
00054 }
00055
00056 template <>
00057 inline osg::Vec3 convert( const mds::math::CDVector & from )
00058 {
00059 osg::Vec3 result;
00060 result[0] = from.get(0);
00061 result[1] = from.get(1);
00062 result[2] = from.get(2);
00063 return result;
00064 }
00065
00066 template <>
00067 inline osg::Matrix convert( const mds::math::CDMatrix & from )
00068 {
00069 osg::Matrix result = osg::Matrix::identity();
00070 for ( int i = 0; i < 3; i++ )
00071 {
00072 for ( int j = 0; j < 3; j++ )
00073 {
00074 result( i, j ) = from.get( i, j );
00075 }
00076 }
00077 return result;
00078 }
00079
00080 template <>
00081 inline mds::math::CDMatrix convert( const osg::Matrix & from )
00082 {
00083 mds::math::CDMatrix result( 4, 4 );
00084
00085 for ( int i = 0; i < 4; i++ )
00086 {
00087 for ( int j = 0; j < 4; j++ )
00088 {
00089 result.get( i, j ) = from( i, j );
00090 }
00091 }
00092 return result;
00093
00094 }
00095
00096 }
00097
00098 #endif // BASICS_H