00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef __GB_GenericData_h__
00022 #define __GB_GenericData_h__
00023
00024 #include "GB_API.h"
00025 #include <SYS/SYS_Types.h>
00026
00027 #include "GB_AttributeDefines.h"
00028 #include "GB_AttributeElem.h"
00029
00030 #include <UT/UT_Vector2.h>
00031 #include <UT/UT_Vector3.h>
00032 #include <UT/UT_Vector4.h>
00033 #include <UT/UT_Matrix3.h>
00034 #include <UT/UT_Matrix4.h>
00035 class UT_String;
00036 class UT_Quaternion;
00037
00038 class GB_GenericDataIndex;
00039
00040 class GB_API GB_GenericData
00041 {
00042 public:
00043
00044 GB_GenericData();
00045 ~GB_GenericData();
00046
00047
00048
00049 void setData(GB_Attribute *attrib,
00050 GB_AttributeStorage storage,
00051 int vectorsize, void *data = NULL,
00052 bool readonly = false);
00053
00054
00055
00056
00057 void copyDefinition(const GB_GenericData &src);
00058
00059
00060
00061 void setDataPointer(void *data, bool readonly);
00062
00063
00064
00065
00066 void setDataPointer(const void *);
00067
00068
00069 bool isValid() const;
00070
00071
00072 int entries() const { return myVectorSize; }
00073
00074
00075 void setF(fpreal val, int index=0);
00076 fpreal getF(int index=0) const;
00077
00078 void setI(int val, int index=0);
00079 int getI(int index=0) const;
00080
00081 void setV2(const UT_Vector2 &val, int idx=0);
00082 UT_Vector2 getV2(int idx=0) const;
00083
00084 void setV3(const UT_Vector3 &val, int index=0);
00085 UT_Vector3 getV3(int index=0) const;
00086
00087 void setV4(const UT_Vector4 &val, int index=0);
00088 UT_Vector4 getV4(int index=0) const;
00089
00090
00091 void setP4(const UT_Vector4 &val, int index=0);
00092 UT_Vector4 getP4(int index=0) const;
00093
00094 void setQ(const UT_Quaternion &val, int index=0);
00095 UT_Quaternion getQ(int index=0) const;
00096
00097 void setM3(const UT_Matrix3 &m, int index=0);
00098 UT_Matrix3 getM3(int index=0) const;
00099
00100 void setM4(const UT_Matrix4 &m, int index=0);
00101 UT_Matrix4 getM4(int index=0) const;
00102
00103
00104
00105 template<typename T> T *getPointer(int index=0)
00106 {
00107 if (isValid())
00108 return &(((T *)myRawData)[index]);
00109 else
00110 return (T *)(NULL);
00111 }
00112 template<typename T>
00113 const T *getPointer(int index=0) const
00114 {
00115 if (isValid())
00116 return &(((T *)myRawData)[index]);
00117 else
00118 return (T *)(NULL);
00119 }
00120
00121
00122
00123
00124
00125 bool setString(const UT_String &str, int index=0);
00126 bool getString(UT_String &str, int index=0,
00127 bool harden=true) const;
00128
00129
00130
00131 GB_GenericDataIndex beginIterator() const;
00132 GB_GenericDataIndex beginIterator();
00133
00134
00135 void multiply(fpreal val);
00136 void setValue(fpreal val);
00137
00138
00139
00140
00141
00142
00143
00144
00145 void transform(const UT_Matrix4 &xform,
00146 const UT_Matrix4 &inverse,
00147 bool keep_lengths=false);
00148
00149
00150 void addScale(const GB_GenericData &d, fpreal scale);
00151
00152
00153 void multiply(const GB_GenericData &d);
00154 void divide(const GB_GenericData &d);
00155
00156
00157 void lerp(const GB_GenericData &d, fpreal w);
00158 void lerp(const GB_GenericData &d0,
00159 const GB_GenericData &d1,
00160 fpreal weight);
00161
00162 template<typename T> bool import(T &result) const
00163 { return GVEXimportData(*this, result); }
00164
00165
00166 bool equalData(const GB_GenericData &src,
00167 fpreal64 tol) const;
00168
00169
00170
00171 void copyDataFrom(const GB_GenericData &src);
00172 void copyDataFrom(const void *src);
00173 void copyDataTo(void *dest) const;
00174
00175
00176
00177 void resetData();
00178
00179
00180
00181 void flush() const;
00182
00183
00184
00185
00186 const GB_Attribute *getAttribute() const { return myAttribute; }
00187 GB_Attribute *getAttribute() { return myAttribute; }
00188
00189
00190
00191 protected:
00192
00193 int64 sizeInBytes() const;
00194
00195 private:
00196 int myVectorSize;
00197
00198 GB_AttributeStorage myRawStorage;
00199 void *myRawData;
00200
00201
00202
00203 GB_Attribute *myAttribute;
00204
00205
00206
00207 bool myReadOnly;
00208 };
00209
00210 template<typename T>
00211 static inline bool
00212 GVEXimportData(const GB_GenericData &data, T &result)
00213 { return false; }
00214
00215
00216
00217
00218
00219 #ifdef NEED_SPECIALIZATION_STORAGE
00220 #define STATIC_INLINE_SPECIALIZATION static inline
00221 #else
00222 #define STATIC_INLINE_SPECIALIZATION
00223 #endif
00224
00225 #define GVEX_IMPORT_SPECIALIZATION(TYPE, METHOD) \
00226 template<> STATIC_INLINE_SPECIALIZATION bool \
00227 GVEXimportData(const GB_GenericData &data, TYPE &result) \
00228 { result = data.METHOD; return true; }
00229
00230 GVEX_IMPORT_SPECIALIZATION(int, getI(0) )
00231 GVEX_IMPORT_SPECIALIZATION(fpreal32, getF(0) )
00232 GVEX_IMPORT_SPECIALIZATION(fpreal64, getF(0) )
00233 GVEX_IMPORT_SPECIALIZATION(UT_Vector2, getV2() )
00234 GVEX_IMPORT_SPECIALIZATION(UT_Vector3, getV3() )
00235 GVEX_IMPORT_SPECIALIZATION(UT_Vector4, getV4() )
00236 GVEX_IMPORT_SPECIALIZATION(UT_Matrix3, getM3() )
00237 GVEX_IMPORT_SPECIALIZATION(UT_Matrix4, getM4() )
00238
00239 #undef STATIC_INLINE_SPECIALIZATION
00240
00241 #endif