OSGMathFieldTraits.h

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002  *                                OpenSG                                     *
00003  *                                                                           *
00004  *                                                                           *
00005  *           Copyright (C) 2003 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  *                                                                           *
00033  *                                                                           *
00034  *                                                                           *
00035  *                                                                           *
00036  *                                                                           *
00037 \*---------------------------------------------------------------------------*/
00038
00039 #ifndef _OSGMATHFIELDTRAITS_H_
00040 #define _OSGMATHFIELDTRAITS_H_
00041 #ifdef __sgi
00042 #pragma once
00043 #endif
00044 
00045 #include "OSGFieldTraits.h"
00046 #include "OSGDataType.h"
00047
00048 #include "OSGMatrix.h"
00049 #include "OSGQuaternion.h"
00050
00051 OSG_BEGIN_NAMESPACE
00052
00057 template <>
00058 struct FieldTraits<Matrix> : public FieldTraitsTemplateBase<Matrix>
00059 {
00060   private:
00061
00062     static  DataType            _type;
00063
00064   public:
00065
00066     typedef FieldTraits<Matrix>  Self;
00067
00068     enum             { Convertible = (Self::FromStringConvertible |
00069                                       Self::ToStreamConvertible   ) };
00070
00071     static OSG_BASE_DLLMAPPING
00072                  DataType &getType      (void);
00073
00074     static const Char8    *getSName     (void) { return "SFMatrix";       }
00075     static const Char8    *getMName     (void) { return "MFMatrix";       }
00076
00077     static       Matrix    getDefault   (void) { return Matrix();         }
00078
00079
00080     static bool      getFromCString(      Matrix   &outVal,
00081                                     const Char8   *&inVal)
00082     {
00083         outVal.setValue(inVal, false);
00084         return true;
00085     }
00086
00087     static void putToStream(const Matrix    &val,
00088                                   OutStream &outStr)
00089     {
00090         typedef TypeTraits<Matrix::ValueType> TypeTrait;
00091
00092         TypeTrait::putToStream((val.getValues())[0], outStr);
00093         outStr << " ";
00094         TypeTrait::putToStream((val.getValues())[4], outStr);
00095         outStr << " ";
00096         TypeTrait::putToStream((val.getValues())[8], outStr);
00097         outStr << " ";
00098         TypeTrait::putToStream((val.getValues())[12], outStr);
00099
00100         outStr << " ";
00101         TypeTrait::putToStream((val.getValues())[1], outStr);
00102         outStr << " ";
00103         TypeTrait::putToStream((val.getValues())[5], outStr);
00104         outStr << " ";
00105         TypeTrait::putToStream((val.getValues())[9], outStr);
00106         outStr << " ";
00107         TypeTrait::putToStream((val.getValues())[13], outStr);
00108
00109         outStr << " ";
00110         TypeTrait::putToStream((val.getValues())[2], outStr);
00111         outStr << " ";
00112         TypeTrait::putToStream((val.getValues())[6], outStr);
00113         outStr << " ";
00114         TypeTrait::putToStream((val.getValues())[10], outStr);
00115         outStr << " ";
00116         TypeTrait::putToStream((val.getValues())[14], outStr);
00117
00118         outStr << " ";
00119         TypeTrait::putToStream((val.getValues())[3], outStr);
00120         outStr << " ";
00121         TypeTrait::putToStream((val.getValues())[7], outStr);
00122         outStr << " ";
00123         TypeTrait::putToStream((val.getValues())[11], outStr);
00124         outStr << " ";
00125         TypeTrait::putToStream((val.getValues())[15], outStr);
00126     }
00127
00128     static       UInt32    getBinSize (const Matrix &)
00129     {
00130         return sizeof(Real32) * 16;
00131     }
00132
00133     static       UInt32    getBinSize (const Matrix  *,
00134                                              UInt32   uiNumObjects)
00135     {
00136         return sizeof(Real32) * 16 * uiNumObjects;
00137     }
00138
00139     static void   copyToBin  (      BinaryDataHandler &pMem,
00140                               const Matrix            &oObject)
00141     {
00142         pMem.putValues(&oObject[0][0], 16);
00143     }
00144
00145
00146     static void   copyFromBin(      BinaryDataHandler &pMem,
00147                                     Matrix            &oObject)
00148     {
00149         pMem.getValues(&oObject[0][0], 16);
00150     }
00151
00152     static void copyToBin(      BinaryDataHandler &pMem,
00153                                 const Matrix      *pObjectStore,
00154                                 UInt32             uiNumObjects)
00155     {
00156         pMem.putValues(&pObjectStore[0][0][0], uiNumObjects * 16);
00157     }
00158
00159     static void copyFromBin(    BinaryDataHandler &pMem,
00160                                 Matrix           *pObjectStore,
00161                                 UInt32             uiNumObjects)
00162     {
00163         pMem.getValues(&pObjectStore[0][0][0], uiNumObjects * 16);
00164     }
00165
00166 };
00167
00168
00173 template <>
00174 struct FieldTraits<Matrix4d> : public FieldTraitsTemplateBase<Matrix4d>
00175 {
00176   private:
00177
00178     static DataType _type;
00179
00180   public:
00181
00182     typedef FieldTraits<Matrix4d>  Self;
00183
00184     enum             { Convertible = (Self::FromStringConvertible |
00185                                       Self::ToStreamConvertible   ) };
00186
00187     static OSG_BASE_DLLMAPPING
00188                  DataType &getType       (void);
00189
00190     static const Char8    *getSName      (void) { return "SFMatrix4d";       }
00191     static const Char8    *getMName      (void) { return "MFMatrix4d";       }
00192
00193     static       Matrix4d  getDefault    (void) { return Matrix4d();         }
00194
00195     static bool      getFromCString(      Matrix4d   &outVal,
00196                                     const Char8     *&inVal)
00197     {
00198         outVal.setValue(inVal, false);
00199         return true;
00200     }
00201
00202     static void      putToStream  (const Matrix4d  &val,
00203                                          OutStream &outStr)
00204     {
00205         typedef TypeTraits<Matrix4d::ValueType> TypeTrait;
00206
00207         TypeTrait::putToStream((val.getValues())[0], outStr);
00208         outStr << " ";
00209         TypeTrait::putToStream((val.getValues())[4], outStr);
00210         outStr << " ";
00211         TypeTrait::putToStream((val.getValues())[8], outStr);
00212         outStr << " ";
00213         TypeTrait::putToStream((val.getValues())[12], outStr);
00214
00215         outStr << " ";
00216         TypeTrait::putToStream((val.getValues())[1], outStr);
00217         outStr << " ";
00218         TypeTrait::putToStream((val.getValues())[5], outStr);
00219         outStr << " ";
00220         TypeTrait::putToStream((val.getValues())[9], outStr);
00221         outStr << " ";
00222         TypeTrait::putToStream((val.getValues())[13], outStr);
00223
00224         outStr << " ";
00225         TypeTrait::putToStream((val.getValues())[2], outStr);
00226         outStr << " ";
00227         TypeTrait::putToStream((val.getValues())[6], outStr);
00228         outStr << " ";
00229         TypeTrait::putToStream((val.getValues())[10], outStr);
00230         outStr << " ";
00231         TypeTrait::putToStream((val.getValues())[14], outStr);
00232
00233         outStr << " ";
00234         TypeTrait::putToStream((val.getValues())[3], outStr);
00235         outStr << " ";
00236         TypeTrait::putToStream((val.getValues())[7], outStr);
00237         outStr << " ";
00238         TypeTrait::putToStream((val.getValues())[11], outStr);
00239         outStr << " ";
00240         TypeTrait::putToStream((val.getValues())[15], outStr);
00241     }
00242
00243     static       UInt32    getBinSize (const Matrix4d &)
00244     {
00245         return sizeof(Real64) * 16;
00246     }
00247
00248     static       UInt32    getBinSize (const Matrix4d  *,
00249                                              UInt32  uiNumObjects)
00250     {
00251         return sizeof(Real64) * 16 * uiNumObjects;
00252     }
00253
00254     static void   copyToBin  (      BinaryDataHandler &pMem,
00255                               const Matrix4d          &oObject)
00256     {
00257         pMem.putValues(&oObject[0][0], 16);
00258     }
00259
00260
00261     static void   copyFromBin(      BinaryDataHandler &pMem,
00262                                     Matrix4d          &oObject)
00263     {
00264         pMem.getValues(&oObject[0][0], 16);
00265     }
00266
00267     static void copyToBin(      BinaryDataHandler &pMem,
00268                           const Matrix4d          *pObjectStore,
00269                                 UInt32             uiNumObjects)
00270     {
00271         pMem.putValues(&pObjectStore[0][0][0], uiNumObjects * 16);
00272     }
00273
00274     static void copyFromBin(    BinaryDataHandler &pMem,
00275                                 Matrix4d          *pObjectStore,
00276                                 UInt32             uiNumObjects)
00277     {
00278         pMem.getValues(&pObjectStore[0][0][0], uiNumObjects * 16);
00279     }
00280 };
00281
00282
00283
00288 template <>
00289 struct FieldTraits<Matrix4fx> : public FieldTraitsTemplateBase<Matrix4fx>
00290 {
00291   private:
00292
00293     static  DataType               _type;
00294
00295   public:
00296
00297     typedef FieldTraits<Matrix4fx>  Self;
00298
00299     enum             { Convertible = Self::NotConvertible           };
00300
00301     static OSG_BASE_DLLMAPPING
00302                  DataType &getType      (void);
00303
00304     static const Char8    *getSName     (void) { return "SFMatrix4fx";    }
00305     static const Char8    *getMName     (void) { return "MFMatrix4fx";    }
00306
00307     static       Matrix4fx getDefault   (void) { return Matrix4fx();      }
00308
00309
00310     static bool      getFromString(      Matrix4fx &outVal,
00311                                    const Char8     *&inVal)
00312     {
00313         outVal.setValue(inVal, false);
00314         return true;
00315     }
00316
00317     static       UInt32    getBinSize (const Matrix4fx &)
00318     {
00319         return sizeof(Fixed32) * 16;
00320     }
00321
00322     static       UInt32    getBinSize (const Matrix4fx  *,
00323                                              UInt32      uiNumObjects)
00324     {
00325         return sizeof(Fixed32) * 16 * uiNumObjects;
00326     }
00327
00328     static void   copyToBin  (      BinaryDataHandler &pMem,
00329                               const Matrix4fx         &oObject)
00330     {
00331         pMem.putValues(&oObject[0][0], 16);
00332     }
00333
00334
00335     static void   copyFromBin(      BinaryDataHandler &pMem,
00336                                     Matrix4fx         &oObject)
00337     {
00338         pMem.getValues(&oObject[0][0], 16);
00339     }
00340
00341     static void copyToBin(      BinaryDataHandler &pMem,
00342                           const Matrix4fx         *pObjectStore,
00343                                 UInt32             uiNumObjects)
00344     {
00345         pMem.putValues(&pObjectStore[0][0][0], uiNumObjects * 16);
00346     }
00347
00348     static void copyFromBin(    BinaryDataHandler &pMem,
00349                                 Matrix4fx         *pObjectStore,
00350                                 UInt32             uiNumObjects)
00351     {
00352         pMem.getValues(&pObjectStore[0][0][0], uiNumObjects * 16);
00353     }
00354
00355 };
00356
00357
00361 template <>
00362 struct FieldTraits<Quaternion> : public FieldTraitsVec4TemplateBase<Quaternion>
00363 {
00364   private:
00365
00366     static  DataType                _type;
00367
00368   public:
00369
00370     typedef FieldTraits<Quaternion>  Self;
00371
00372     enum             { Convertible = (Self::FromStringConvertible |
00373                                       Self::ToStreamConvertible   ) };
00374
00375     static OSG_BASE_DLLMAPPING
00376                  DataType   &getType      (void);
00377
00378     static const Char8      *getSName     (void) { return "SFQuaternion"; }
00379     static const Char8      *getMName     (void) { return "MFQuaternion"; }
00380
00381     static       Quaternion  getDefault   (void) { return Quaternion();   }
00382
00383     static bool        getFromCString(      Quaternion  &outVal,
00384                                       const Char8      *&inVal)
00385     {
00386         // VRML requires axis and angle in radians
00387         outVal.setValueAsAxisRad(inVal);
00388
00389         return true;
00390     }
00391
00392 };
00393
00394
00399 template <>
00400 struct FieldTraits<Quaternionfx> :
00401     public FieldTraitsVec4TemplateBase<Quaternionfx>
00402 {
00403   private:
00404
00405     static  DataType                  _type;
00406
00407   public:
00408
00409     typedef FieldTraits<Quaternionfx>  Self;
00410
00411     enum               { Convertible = Self::ToStreamConvertible    };
00412
00413     static OSG_BASE_DLLMAPPING
00414                  DataType     &getType      (void);
00415
00416     static const Char8        *getSName     (void) { return "SFQuaternionfx"; }
00417     static const Char8        *getMName     (void) { return "MFQuaternionfx"; }
00418
00419     static       Quaternionfx  getDefault   (void) { return Quaternionfx();   }
00420
00421 };
00422
00423 OSG_END_NAMESPACE
00424
00425 #endif /* _OSGMATHFIELDTRAITS_H_ */