00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef __GA_ATINumeric
00019 #define __GA_ATINumeric
00020
00021 #include "GA_API.h"
00022 #include "GA_AIFDelta.h"
00023 #include "GA_Attribute.h"
00024 #include "GA_DataArray.h"
00025 #include "GA_DataArrayPageTableImpl.h"
00026 #include "GA_DataArrayTuple.h"
00027 #include "GA_Defaults.h"
00028 #include "GA_TempBuffer.h"
00029
00030
00031 class UT_IStream;
00032
00033
00034
00035
00036
00037 #ifdef WIN32
00038 #define GA_TMPL_FUNC_OVERLOAD(NAME, SUFFIX) NAME##SUFFIX
00039 #else
00040 #define GA_TMPL_FUNC_OVERLOAD(NAME, SUFFIX) NAME
00041 #endif
00042
00043 class GA_API GA_ATINumeric : public GA_Attribute
00044 {
00045 public:
00046 static void registerType();
00047
00048 GA_ATINumeric(const GA_AttributeType &type,
00049 const GA_IndexMap &index_map,
00050 GA_AttributeScope scope,
00051 const char *name,
00052 GA_Storage store,
00053 int tuple_size,
00054 const GA_Defaults &defaults);
00055 virtual ~GA_ATINumeric();
00056
00057 virtual int64 getMemoryUsage() const;
00058
00059
00060
00061 virtual void defragment(const GA_Defragment &defrag);
00062
00063
00064 virtual void reconstructElement(GA_Offset offset);
00065
00066
00067 virtual WriteConcurrence getSupportedWriteConcurrence() const
00068 { return WRITE_CONCURRENCE_PAGE; }
00069
00070 virtual const GA_AIFCopyData *getAIFCopyData() const {return myAIFCopyData;}
00071 virtual const GA_AIFDelta *getAIFDelta() const { return myAIFDelta; }
00072 virtual const GA_AIFEdit *getAIFEdit() const { return myAIFEdit; }
00073 virtual const GA_AIFTuple *getAIFTuple() const { return myAIFTuple; }
00074 virtual const GA_AIFMath *getAIFMath() const
00075 { return myDoMath ? myAIFMath:myAIFNoMath; }
00076 virtual const GA_AIFMerge *getAIFMerge() const { return myAIFMerge; }
00077 virtual const GA_AIFInterp *getAIFInterp() const { return myAIFInterp; }
00078 virtual const GA_AIFCompare *getAIFCompare() const { return myAIFCompare; }
00079
00080 typedef void (*GAprobeGeneric)();
00081
00082 private:
00083 class AdapterBase
00084 {
00085 protected:
00086 static const GA_DataArray *const* getData(const GA_Attribute *atr)
00087 {
00088 return static_cast<const GA_ATINumeric *>(atr)->myData.getDataPtr();
00089 }
00090 static GA_DataArray *const* getData(GA_Attribute *atr)
00091 {
00092 return static_cast<GA_ATINumeric *>(atr)->myData.getDataPtr();
00093 }
00094 };
00095 typedef GA_DataArray::directAttributeAdapter<AdapterBase> DataArrayAdapter;
00096 public:
00097
00098
00099 #define EACHSTORAGE(FUNC) \
00100 switch (atr->getStorage()) \
00101 { \
00102 case GA_STORE_UINT8: \
00103 return DataArrayAdapter::direct##FUNC<T, uint8>; \
00104 case GA_STORE_INT8: \
00105 return DataArrayAdapter::direct##FUNC<T, int8>; \
00106 case GA_STORE_INT16: \
00107 return DataArrayAdapter::direct##FUNC<T, int16>; \
00108 case GA_STORE_INT32: \
00109 return DataArrayAdapter::direct##FUNC<T, int32>; \
00110 case GA_STORE_INT64: \
00111 return DataArrayAdapter::direct##FUNC<T, int64>; \
00112 case GA_STORE_REAL16: \
00113 return DataArrayAdapter::direct##FUNC<T, fpreal16>; \
00114 case GA_STORE_REAL32: \
00115 return DataArrayAdapter::direct##FUNC<T, fpreal32>; \
00116 case GA_STORE_REAL64: \
00117 return DataArrayAdapter::direct##FUNC<T, fpreal64>; \
00118 default: \
00119 return 0; \
00120 } \
00121
00122
00123 #define EACHSTORAGEFP(FUNC) \
00124 switch (atr->getStorage()) \
00125 { \
00126 case GA_STORE_REAL32: \
00127 return DataArrayAdapter::direct##FUNC<T, fpreal32>; \
00128 case GA_STORE_REAL64: \
00129 return DataArrayAdapter::direct##FUNC<T, fpreal64>; \
00130 default: \
00131 return 0; \
00132 } \
00133
00134 #define EACHPACKING(FUNC) \
00135 if (atr->getPacking() == GA_DataArrayTuple::PACK_NONE) \
00136 { \
00137 EACHSTORAGE(FUNC); \
00138 } \
00139 else if (atr->getPacking() == GA_DataArrayTuple::PACK_VECTOR3) \
00140 { \
00141 EACHSTORAGEFP(Vector3##FUNC); \
00142 } \
00143 else return 0; \
00144
00145
00146 template <typename T>
00147 class binderScalar
00148 {
00149 public:
00150 typedef T (*GAprobeAttribGetter)(const GA_Attribute *atr, GA_Offset, int );
00151 typedef void (*GAprobeAttribSetter)(GA_Attribute *atr, GA_Offset, int, T);
00152
00153 static GAprobeAttribGetter bindGetter(const GA_ATINumeric *atr)
00154 { EACHPACKING(GetterScalar) }
00155
00156 static GAprobeAttribSetter bindSetter(GA_ATINumeric *atr)
00157 { EACHPACKING(SetterScalar) }
00158
00159 static GAprobeAttribSetter bindAdder(GA_ATINumeric *atr)
00160 { EACHPACKING(AdderScalar) }
00161 };
00162
00163 template <typename T>
00164 class binderVector
00165 {
00166 public:
00167 typedef void (*GAprobeAttribGetter)(T &value, const GA_Attribute *atr, GA_Offset);
00168 typedef void (*GAprobeAttribSetter)(GA_Attribute *atr, GA_Offset, const T &);
00169
00170 static GAprobeAttribGetter bindGetter(const GA_ATINumeric *atr)
00171 { EACHPACKING(GetterVector) }
00172
00173 static GAprobeAttribSetter bindSetter(GA_ATINumeric *atr)
00174 { EACHPACKING(SetterVector) }
00175
00176 static GAprobeAttribSetter bindAdder(GA_ATINumeric *atr)
00177 { EACHPACKING(AdderVector) }
00178 };
00179
00180 #undef EACHSTORAGE
00181 #undef EACHSTORAGEFP
00182 #undef EACHPACKING
00183
00184 #define EACHSTORAGE(FUNC) \
00185 switch (atr->getStorage()) \
00186 { \
00187 case GA_STORE_UINT8: \
00188 return DataArrayAdapter::direct##FUNC<T, TB, uint8>; \
00189 case GA_STORE_INT8: \
00190 return DataArrayAdapter::direct##FUNC<T, TB, int8>; \
00191 case GA_STORE_INT16: \
00192 return DataArrayAdapter::direct##FUNC<T, TB, int16>; \
00193 case GA_STORE_INT32: \
00194 return DataArrayAdapter::direct##FUNC<T, TB, int32>; \
00195 case GA_STORE_INT64: \
00196 return DataArrayAdapter::direct##FUNC<T, TB, int64>; \
00197 case GA_STORE_REAL16: \
00198 return DataArrayAdapter::direct##FUNC<T, TB, fpreal16>; \
00199 case GA_STORE_REAL32: \
00200 return DataArrayAdapter::direct##FUNC<T, TB, fpreal32>; \
00201 case GA_STORE_REAL64: \
00202 return DataArrayAdapter::direct##FUNC<T, TB, fpreal64>; \
00203 default: \
00204 return 0; \
00205 } \
00206
00207
00208 #define EACHSTORAGEFP(FUNC) \
00209 switch (atr->getStorage()) \
00210 { \
00211 case GA_STORE_REAL32: \
00212 return DataArrayAdapter::direct##FUNC<T, TB, fpreal32>; \
00213 case GA_STORE_REAL64: \
00214 return DataArrayAdapter::direct##FUNC<T, TB, fpreal64>; \
00215 default: \
00216 return 0; \
00217 } \
00218
00219
00220 #define EACHPACKING(FUNC) \
00221 if (atr->getPacking() == GA_DataArrayTuple::PACK_NONE) \
00222 { \
00223 EACHSTORAGE(FUNC); \
00224 } \
00225 else if (atr->getPacking() == GA_DataArrayTuple::PACK_VECTOR3) \
00226 { \
00227 EACHSTORAGEFP(Vector3##FUNC); \
00228 } \
00229 else return 0; \
00230
00231
00232 template <typename T, typename TB>
00233 class binderPage
00234 {
00235 public:
00236 typedef T *(*GAprobeAttribPageGet)(GA_Attribute *atr, T *marshall, GA_Offset, int comp, bool &isconstant);
00237 typedef T *(*GAprobeAttribPageGetRO)(const GA_Attribute *atr, T *marshall, GA_Offset, int comp, bool &isconstant);
00238 typedef void (*GAprobeAttribPageSet)(GA_Attribute *atr, const T *marshall, GA_Offset, int comp);
00239
00240 static GAprobeAttribPageGet bindGetter(GA_ATINumeric *atr)
00241 { EACHPACKING(PageGetter) }
00242
00243 static GAprobeAttribPageGetRO bindGetterRO(const GA_ATINumeric *atr)
00244 { EACHPACKING(PageGetterRO) }
00245
00246 static GAprobeAttribPageSet bindSetter(GA_ATINumeric *atr)
00247 { EACHPACKING(PageSetter) }
00248 };
00249
00250 #undef EACHSTORAGE
00251 #undef EACHSTORAGEFP
00252 #undef EACHPACKING
00253
00254
00255
00256 void setTypePoint() { getOptions().setOptionS("type", "point"); }
00257 void setTypeVector() { getOptions().setOptionS("type", "vector"); }
00258 void setTypeNormal() { getOptions().setOptionS("type", "normal"); }
00259 void setTypeColor() { getOptions().setOptionS("type", "color"); }
00260 void setTypeMatrix3(){ getOptions().setOptionS("type", "matrix3"); }
00261 void setTypeMatrix() { getOptions().setOptionS("type", "matrix"); }
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294 virtual const GA_AIFJSON *getAIFJSON() const { return myAIFJSON; }
00295
00296
00297 bool jsonLoad(UT_JSONParser &p,
00298 const GA_LoadMap &map,
00299 const GA_Defaults &defs,
00300 int tuple_size,
00301 GA_Storage storage);
00302
00303 const GA_Defaults &getDefaults() const { return myDefaults; }
00304
00305 int getTupleSize() const { return myData.getTupleSize(); }
00306 GA_Storage getStorage() const { return myData.getStorage(); }
00307 GA_DataArrayTuple::ga_Packing getPacking() const { return myData.getPacking(); }
00308
00309 bool setTupleSize(int size);
00310 bool setStorage(GA_Storage storage);
00311
00312
00313 virtual bool debugValidateArrayCapacity(GA_Size sz) const;
00314
00315
00316 GA_Private::ga_DataArrayPageTableImplV3
00317 *getPageTableImplV3()
00318 { return myData.getPageTableImplV3(); }
00319
00320
00321 protected:
00322 virtual bool changeArraySize(GA_Size new_size);
00323 GA_DataArrayTuple myData;
00324 GA_Defaults myDefaults;
00325 bool myDoMath;
00326
00327 static GA_AIFCopyData *myAIFCopyData;
00328 static GA_AIFDelta *myAIFDelta;
00329 static GA_AIFEdit *myAIFEdit;
00330 static GA_AIFTuple *myAIFTuple;
00331 static GA_AIFMath *myAIFMath;
00332 static const GA_AIFMath *myAIFNoMath;
00333 static GA_AIFMerge *myAIFMerge;
00334 static GA_AIFInterp *myAIFInterp;
00335 static GA_AIFJSON *myAIFJSON;
00336 static GA_AIFCompare *myAIFCompare;
00337
00338 private:
00339 void updateIntegerTypeInfo();
00340
00341 virtual GA_Attribute *doClone(const GA_IndexMap &index_map,
00342 const char *name) const;
00343
00344
00345 template <typename T> inline bool
00346 tupleGet(GA_Offset di, T &v, int vi) const;
00347 template <typename T> inline bool
00348 tupleGet(GA_Offset di, T *v, int count, int start) const;
00349
00350
00351
00352
00353
00354 template <typename T> inline bool
00355 tupleGetArrayWithinBlock(GA_Offset s, GA_Offset e, T *v, int count, int start) const;
00356 template <typename T, typename MYTYPE> inline bool
00357 tupleGetPackV3(T *v, const GA_Range &range) const;
00358
00359
00360
00361
00362
00363 template <typename T> inline bool
00364 tupleSetArrayFromBlock(GA_Offset s, GA_Offset e, const T *src, int count, int start);
00365 template <typename T, typename MYTYPE> inline bool
00366 tupleSetPackV3(const GA_Range &range, const T *src);
00367
00368 template <typename T> inline bool
00369 tupleSet(GA_Offset di, T v, int vi);
00370 template <typename T> inline bool
00371 tupleSet(GA_Offset di, const T *v, int count, int start);
00372 template <typename T> inline bool
00373 tupleSet(const GA_Range &di, T v, int vi);
00374 template <typename T> inline bool
00375 tupleSet(const GA_Range &di, const T *v, int count, int start);
00376 inline bool
00377 tupleSet(GA_Offset di, const GA_ATINumeric &s,
00378 GA_Offset si, int component);
00379 inline bool
00380 tupleSet(const GA_Range &di, const GA_ATINumeric &s,
00381 const GA_Range &si, int component);
00382
00383 template <typename T> inline bool
00384 makeConstant(T v, int vi);
00385 template <typename T> inline bool
00386 makeConstant(const T *v, int count, int start);
00387
00388 bool isNan(GA_Offset ai) const;
00389 bool isNan(const GA_Range &ai) const;
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404 template <void (GA_DataArray::*CMPFUNC)(bool &result, const GA_Offset &ai, const GA_DataArray &b, const GA_Offset &bi, int ulps) const> inline bool
00405 GA_TMPL_FUNC_OVERLOAD(compareFunc, _OfOf)(bool &result, const GA_Offset &ai, const GA_ATINumeric &b, const GA_Offset &bi, int component, int ulps) const;
00406
00407 template <void (GA_DataArray::*CMPFUNC)(bool &result, const GA_Range &ai, const GA_DataArray &b, const GA_Range &bi, int ulps) const> inline bool
00408 GA_TMPL_FUNC_OVERLOAD(compareFunc, _ItIt)(bool &result, const GA_Range &ai, const GA_ATINumeric &b, const GA_Range &bi, int component, int ulps) const;
00409
00410
00411
00412 bool interpLerp(GA_Offset di,
00413 const GA_ATINumeric &a, GA_Offset ai,
00414 const GA_ATINumeric &b, GA_Offset bi,
00415 fpreal t);
00416 bool interpLerp(const GA_Range &di,
00417 const GA_ATINumeric &a, const GA_Range &ai,
00418 const GA_ATINumeric &b, const GA_Range &bi,
00419 fpreal t);
00420 bool interpSmooth(GA_Offset di, fpreal min, fpreal max,
00421 const GA_ATINumeric &a, GA_Offset ai);
00422 bool interpSmooth(const GA_Range &di, fpreal min, fpreal max,
00423 const GA_ATINumeric &a, const GA_Range &ai);
00424 bool interpFit(GA_Offset di, const GA_ATINumeric &a, GA_Offset ai,
00425 fpreal omin, fpreal omax,
00426 fpreal nmin, fpreal nmax);
00427 bool interpFit(const GA_Range &di,
00428 const GA_ATINumeric &a, const GA_Range &ai,
00429 fpreal omin, fpreal omax,
00430 fpreal nmin, fpreal nmax);
00431
00432
00433
00434 void mergeDestroyDestination(const GA_MergeMap &map,
00435 GA_Attribute *dattrib) const;
00436 GA_Attribute *mergeAddDestination(const GA_MergeMap &map,
00437 GA_Attribute *dattrib) const;
00438 void mergeGrowArray(const GA_MergeMap &map,
00439 const GA_ATINumeric &s);
00440 bool mergeAppendData(const GA_MergeMap &map,
00441 const GA_Attribute *sattrib);
00442
00443
00444
00445
00446 bool jsonSave(UT_JSONWriter &w, const GA_SaveMap &s) const;
00447
00448
00449
00450 friend class ga_NumericCopyData;
00451 friend class ga_NumericDelta;
00452 friend class ga_NumericEdit;
00453 template <typename T> friend class ga_NumericEditDelta;
00454 template <typename T> friend class ga_NumericEditSnapshot;
00455 friend class ga_NumericInterp;
00456 friend class ga_NumericJSON;
00457 friend class ga_NumericMarshal;
00458 friend class ga_NumericMath;
00459 friend class ga_NumericMerge;
00460 friend class ga_NumericTuple;
00461 friend class ga_NumericCompare;
00462
00463 template <typename T> friend class binderScalar;
00464 template <typename T> friend class binderVector;
00465 template <typename T, typename TB> friend class binderPage;
00466
00467 };
00468
00469 #undef GA_TMPL_FUNC_OVERLOAD
00470
00471 #endif
00472