00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #ifndef _OSG_MATHFIELDDATATYPE_H_
00040 #define _OSG_MATHFIELDDATATYPE_H_
00041
00042 #include <OSGBase.h>
00043 #include <OSGFieldDataType.h>
00044 #include <OSGMatrix.h>
00045 #include <OSGQuaternion.h>
00046
00047 #include <string>
00048
00049 OSG_BEGIN_NAMESPACE
00050
00051 #if !defined(OSG_DO_DOC) || (OSG_DOC_LEVEL >= 3)
00052
00053 #ifdef OSG_DOC_FILES_IN_MODULE
00054
00058 #endif
00059
00060
00063 #if !defined(OSG_DOC_DEV_TRAITS)
00064
00065 #endif
00066
00067 template <>
00068 struct OSG_BASE_DLLMAPPING FieldDataTraits<Matrix> :
00069 public FieldTraitsRecurseBase<Matrix>
00070 {
00071 static DataType _type;
00072
00073 enum { StringConvertable = ToStringConvertable |
00074 FromStringConvertable };
00075
00076 static DataType &getType (void) { return _type; }
00077
00078 static Char8 *getSName (void) { return "SFMatrix"; }
00079 static Char8 *getMName (void) { return "MFMatrix"; }
00080
00081 static Matrix getDefault (void) { return Matrix(); }
00082
00083 static bool getFromString( Matrix &outVal,
00084 const Char8 *&inVal)
00085 {
00086 outVal.setValue(inVal, false);
00087 return true;
00088 }
00089
00090 static void putToString (const Matrix &inVal,
00091 std::string &outStr)
00092 {
00093 typedef TypeTraits<Matrix::ValueType> TypeTrait;
00094
00095 outStr.assign(TypeTrait::putToString((inVal.getValues())[0]));
00096 outStr.append(" ");
00097 outStr.append(TypeTrait::putToString((inVal.getValues())[4]));
00098 outStr.append(" ");
00099 outStr.append(TypeTrait::putToString((inVal.getValues())[8]));
00100 outStr.append(" ");
00101 outStr.append(TypeTrait::putToString((inVal.getValues())[12]));
00102
00103 outStr.append(" ");
00104 outStr.append(TypeTrait::putToString((inVal.getValues())[1]));
00105 outStr.append(" ");
00106 outStr.append(TypeTrait::putToString((inVal.getValues())[5]));
00107 outStr.append(" ");
00108 outStr.append(TypeTrait::putToString((inVal.getValues())[9]));
00109 outStr.append(" ");
00110 outStr.append(TypeTrait::putToString((inVal.getValues())[13]));
00111
00112 outStr.append(" ");
00113 outStr.append(TypeTrait::putToString((inVal.getValues())[2]));
00114 outStr.append(" ");
00115 outStr.append(TypeTrait::putToString((inVal.getValues())[6]));
00116 outStr.append(" ");
00117 outStr.append(TypeTrait::putToString((inVal.getValues())[10]));
00118 outStr.append(" ");
00119 outStr.append(TypeTrait::putToString((inVal.getValues())[14]));
00120
00121 outStr.append(" ");
00122 outStr.append(TypeTrait::putToString((inVal.getValues())[3]));
00123 outStr.append(" ");
00124 outStr.append(TypeTrait::putToString((inVal.getValues())[7]));
00125 outStr.append(" ");
00126 outStr.append(TypeTrait::putToString((inVal.getValues())[11]));
00127 outStr.append(" ");
00128 outStr.append(TypeTrait::putToString((inVal.getValues())[15]));
00129 }
00130
00131 static UInt32 getBinSize (const Matrix &)
00132 {
00133 return sizeof(Real32) * 16;
00134 }
00135
00136 static UInt32 getBinSize (const Matrix *,
00137 UInt32 uiNumObjects)
00138 {
00139 return sizeof(Real32) * 16 * uiNumObjects;
00140 }
00141
00142 static void copyToBin ( BinaryDataHandler &pMem,
00143 const Matrix &oObject)
00144 {
00145 pMem.putValues(&oObject[0][0], 16);
00146 }
00147
00148
00149 static void copyFromBin( BinaryDataHandler &pMem,
00150 Matrix &oObject)
00151 {
00152 pMem.getValues(&oObject[0][0], 16);
00153 }
00154
00155 static void copyToBin( BinaryDataHandler &pMem,
00156 const Matrix *pObjectStore,
00157 UInt32 uiNumObjects)
00158 {
00159 pMem.putValues(&pObjectStore[0][0][0], uiNumObjects * 16);
00160 }
00161
00162 static void copyFromBin( BinaryDataHandler &pMem,
00163 Matrix *pObjectStore,
00164 UInt32 uiNumObjects)
00165 {
00166 pMem.getValues(&pObjectStore[0][0][0], uiNumObjects * 16);
00167 }
00168 };
00169
00170 #if !defined(OSG_DOC_DEV_TRAITS)
00171
00173 #endif
00174
00177 #if !defined(OSG_DOC_DEV_TRAITS)
00178
00179 #endif
00180
00181 template <>
00182 struct OSG_BASE_DLLMAPPING FieldDataTraits<Quaternion> :
00183 public FieldTraitsRecurseBase<Quaternion>
00184 {
00185 static DataType _type;
00186
00187 enum { StringConvertable = ToStringConvertable |
00188 FromStringConvertable };
00189
00190 static DataType &getType (void) { return _type; }
00191
00192 static Char8 *getSName (void) { return "SFQuaternion"; }
00193 static Char8 *getMName (void) { return "MFQuaternion"; }
00194
00195 static Quaternion getDefault (void) { return Quaternion(); }
00196
00197 static bool getFromString( Quaternion &outVal,
00198 const Char8 *&inVal)
00199 {
00200
00201 outVal.setValueAsAxisRad(inVal);
00202
00203 return true;
00204 }
00205
00206 static void putToString (const Quaternion &inVal,
00207 std::string &outStr)
00208 {
00209 typedef Quaternion::VectorType::ValueType ValueType;
00210 typedef TypeTraits<ValueType> TypeTrait;
00211
00212 ValueType axisX;
00213 ValueType axisY;
00214 ValueType axisZ;
00215 ValueType angleRad;
00216
00217 inVal.getValueAsAxisRad(axisX, axisY, axisZ, angleRad);
00218
00219 outStr.assign(TypeTrait::putToString(axisX));
00220
00221 outStr.append( " " );
00222 outStr.append(TypeTrait::putToString(axisY));
00223
00224 outStr.append( " " );
00225 outStr.append(TypeTrait::putToString(axisZ) );
00226
00227 outStr.append( " " );
00228 outStr.append(TypeTrait::putToString(angleRad) );
00229 }
00230
00231 static UInt32 getBinSize (const Quaternion &)
00232 {
00233 return sizeof(Real32) * 4;
00234 }
00235
00236 static UInt32 getBinSize (const Quaternion *,
00237 UInt32 uiNumObjects)
00238 {
00239 return sizeof(Real32)* 4 *uiNumObjects;
00240 }
00241
00242 static void copyToBin ( BinaryDataHandler &pMem,
00243 const Quaternion &oObject)
00244 {
00245 pMem.putValues(&oObject[0], 4);
00246 }
00247
00248
00249 static void copyFromBin( BinaryDataHandler &pMem,
00250 Quaternion &oObject)
00251 {
00252 pMem.getValues(&oObject[0], 4);
00253 }
00254
00255 static void copyToBin( BinaryDataHandler &pMem,
00256 const Quaternion *pObjectStore,
00257 UInt32 uiNumObjects)
00258 {
00259 for(UInt32 i = 0; i < uiNumObjects; ++i)
00260 {
00261 copyToBin(pMem, pObjectStore[i]);
00262 }
00263 }
00264
00265 static void copyFromBin(BinaryDataHandler &pMem,
00266 Quaternion *pObjectStore,
00267 UInt32 uiNumObjects)
00268 {
00269 for(UInt32 i = 0; i < uiNumObjects; ++i)
00270 {
00271 copyFromBin(pMem, pObjectStore[i]);
00272 }
00273 }
00274 };
00275
00276 #if !defined(OSG_DOC_DEV_TRAITS)
00277
00279 #endif
00280
00281 #endif // !defined(OSG_DO_DOC) || (OSG_DOC_LEVEL >= 3)
00282
00283 OSG_END_NAMESPACE
00284
00285 #define OSGMATHFIELDDATATYPE_HEADER_CVSID "@(#)$Id: $"
00286
00287 #endif
00288