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<Matrix4d> :
00183 public FieldTraitsRecurseBase<Matrix4d>
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 "SFMatrix4d"; }
00193 static Char8 *getMName (void) { return "MFMatrix4d"; }
00194
00195 static Matrix4d getDefault (void) { return Matrix4d(); }
00196
00197 static bool getFromString( Matrix4d &outVal,
00198 const Char8 *&inVal)
00199 {
00200 outVal.setValue(inVal, false);
00201 return true;
00202 }
00203
00204 static void putToString (const Matrix4d &inVal,
00205 std::string &outStr)
00206 {
00207 typedef TypeTraits<Matrix4d::ValueType> TypeTrait;
00208
00209 outStr.assign(TypeTrait::putToString((inVal.getValues())[0]));
00210 outStr.append(" ");
00211 outStr.append(TypeTrait::putToString((inVal.getValues())[4]));
00212 outStr.append(" ");
00213 outStr.append(TypeTrait::putToString((inVal.getValues())[8]));
00214 outStr.append(" ");
00215 outStr.append(TypeTrait::putToString((inVal.getValues())[12]));
00216
00217 outStr.append(" ");
00218 outStr.append(TypeTrait::putToString((inVal.getValues())[1]));
00219 outStr.append(" ");
00220 outStr.append(TypeTrait::putToString((inVal.getValues())[5]));
00221 outStr.append(" ");
00222 outStr.append(TypeTrait::putToString((inVal.getValues())[9]));
00223 outStr.append(" ");
00224 outStr.append(TypeTrait::putToString((inVal.getValues())[13]));
00225
00226 outStr.append(" ");
00227 outStr.append(TypeTrait::putToString((inVal.getValues())[2]));
00228 outStr.append(" ");
00229 outStr.append(TypeTrait::putToString((inVal.getValues())[6]));
00230 outStr.append(" ");
00231 outStr.append(TypeTrait::putToString((inVal.getValues())[10]));
00232 outStr.append(" ");
00233 outStr.append(TypeTrait::putToString((inVal.getValues())[14]));
00234
00235 outStr.append(" ");
00236 outStr.append(TypeTrait::putToString((inVal.getValues())[3]));
00237 outStr.append(" ");
00238 outStr.append(TypeTrait::putToString((inVal.getValues())[7]));
00239 outStr.append(" ");
00240 outStr.append(TypeTrait::putToString((inVal.getValues())[11]));
00241 outStr.append(" ");
00242 outStr.append(TypeTrait::putToString((inVal.getValues())[15]));
00243 }
00244
00245 static UInt32 getBinSize (const Matrix4d &)
00246 {
00247 return sizeof(Real64) * 16;
00248 }
00249
00250 static UInt32 getBinSize (const Matrix4d *,
00251 UInt32 uiNumObjects)
00252 {
00253 return sizeof(Real64) * 16 * uiNumObjects;
00254 }
00255
00256 static void copyToBin ( BinaryDataHandler &pMem,
00257 const Matrix4d &oObject)
00258 {
00259 pMem.putValues(&oObject[0][0], 16);
00260 }
00261
00262
00263 static void copyFromBin( BinaryDataHandler &pMem,
00264 Matrix4d &oObject)
00265 {
00266 pMem.getValues(&oObject[0][0], 16);
00267 }
00268
00269 static void copyToBin( BinaryDataHandler &pMem,
00270 const Matrix4d *pObjectStore,
00271 UInt32 uiNumObjects)
00272 {
00273 pMem.putValues(&pObjectStore[0][0][0], uiNumObjects * 16);
00274 }
00275
00276 static void copyFromBin( BinaryDataHandler &pMem,
00277 Matrix4d *pObjectStore,
00278 UInt32 uiNumObjects)
00279 {
00280 pMem.getValues(&pObjectStore[0][0][0], uiNumObjects * 16);
00281 }
00282 };
00283
00284 #if !defined(OSG_DOC_DEV_TRAITS)
00285
00287 #endif
00288
00291 #if !defined(OSG_DOC_DEV_TRAITS)
00292
00293 #endif
00294
00295 template <>
00296 struct OSG_BASE_DLLMAPPING FieldDataTraits<Quaternion> :
00297 public FieldTraitsRecurseBase<Quaternion>
00298 {
00299 static DataType _type;
00300
00301 enum { StringConvertable = ToStringConvertable |
00302 FromStringConvertable };
00303
00304 static DataType &getType (void) { return _type; }
00305
00306 static Char8 *getSName (void) { return "SFQuaternion"; }
00307 static Char8 *getMName (void) { return "MFQuaternion"; }
00308
00309 static Quaternion getDefault (void) { return Quaternion(); }
00310
00311 static bool getFromString( Quaternion &outVal,
00312 const Char8 *&inVal)
00313 {
00314
00315 outVal.setValueAsAxisRad(inVal);
00316
00317 return true;
00318 }
00319
00320 static void putToString (const Quaternion &inVal,
00321 std::string &outStr)
00322 {
00323 typedef Quaternion::VectorType::ValueType ValueType;
00324 typedef TypeTraits<ValueType> TypeTrait;
00325
00326 ValueType axisX;
00327 ValueType axisY;
00328 ValueType axisZ;
00329 ValueType angleRad;
00330
00331 inVal.getValueAsAxisRad(axisX, axisY, axisZ, angleRad);
00332
00333 outStr.assign(TypeTrait::putToString(axisX));
00334
00335 outStr.append( " " );
00336 outStr.append(TypeTrait::putToString(axisY));
00337
00338 outStr.append( " " );
00339 outStr.append(TypeTrait::putToString(axisZ) );
00340
00341 outStr.append( " " );
00342 outStr.append(TypeTrait::putToString(angleRad) );
00343 }
00344
00345 static UInt32 getBinSize (const Quaternion &)
00346 {
00347 return sizeof(Real32) * 4;
00348 }
00349
00350 static UInt32 getBinSize (const Quaternion *,
00351 UInt32 uiNumObjects)
00352 {
00353 return sizeof(Real32)* 4 *uiNumObjects;
00354 }
00355
00356 static void copyToBin ( BinaryDataHandler &pMem,
00357 const Quaternion &oObject)
00358 {
00359 pMem.putValues(&oObject[0], 4);
00360 }
00361
00362
00363 static void copyFromBin( BinaryDataHandler &pMem,
00364 Quaternion &oObject)
00365 {
00366 pMem.getValues(&oObject[0], 4);
00367 }
00368
00369 static void copyToBin( BinaryDataHandler &pMem,
00370 const Quaternion *pObjectStore,
00371 UInt32 uiNumObjects)
00372 {
00373 for(UInt32 i = 0; i < uiNumObjects; ++i)
00374 {
00375 copyToBin(pMem, pObjectStore[i]);
00376 }
00377 }
00378
00379 static void copyFromBin(BinaryDataHandler &pMem,
00380 Quaternion *pObjectStore,
00381 UInt32 uiNumObjects)
00382 {
00383 for(UInt32 i = 0; i < uiNumObjects; ++i)
00384 {
00385 copyFromBin(pMem, pObjectStore[i]);
00386 }
00387 }
00388 };
00389
00390 #if !defined(OSG_DOC_DEV_TRAITS)
00391
00393 #endif
00394
00395 #endif // !defined(OSG_DO_DOC) || (OSG_DOC_LEVEL >= 3)
00396
00397 OSG_END_NAMESPACE
00398
00399 #define OSGMATHFIELDDATATYPE_HEADER_CVSID "@(#)$Id: $"
00400
00401 #endif
00402