HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GA_ATIIndexPair.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: GA_ATIIndexPair.h ( GA Library, C++)
7  *
8  * COMMENTS: Index Pair ATI (Attribute Type Implementation)
9  *
10  * Currently implemented with two data array tuples,
11  * one for the indices, and one for the values.
12  *
13  * We should support a single index mapping to a value tuple,
14  * instead of just a single value. The basic GA_Attribute
15  * interface simply accesses the first entry in any value
16  * tuple.
17  *
18  * The GA_Attribute level tuple size refers to the number of
19  * index pair entries. However, the defaults set at the base
20  * class are the defaults for a single entry, and so should match
21  * the tuple size of the value tuple.
22  *
23  * // TODO: Turn the base GA_Attribute interface into a sparse
24  * // array interface. getTupleSize() would return an
25  * // upper bound on the index and the get/set methods
26  * // would function implement an abstract
27  * // maximum index
28  */
29 
30 #pragma once
31 
32 #ifndef __GA_ATIIndexPair
33 #define __GA_ATIIndexPair
34 
35 #include "GA_API.h"
36 #include "GA_Attribute.h"
37 #include "GA_AttributeType.h"
38 #include "GA_DataArray.h"
39 #include "GA_DataArrayTuple.h"
40 #include "GA_Defaults.h"
41 #include "GA_Range.h"
42 #include "GA_Types.h"
43 
44 #include <UT/UT_ConcurrentVector.h>
45 #include <UT/UT_Lock.h>
46 #include <UT/UT_StringHolder.h>
47 #include <UT/UT_VectorTypes.h>
48 
49 #include <SYS/SYS_AtomicInt.h>
50 #include <SYS/SYS_Types.h>
51 
52 
53 class GA_AIFCompare;
54 class GA_AIFCopyData;
55 class GA_AIFEdit;
56 class GA_AIFIndexPair;
58 class GA_AIFInterp;
59 class GA_AIFJSON;
60 class GA_AIFMath;
61 class GA_AIFMerge;
62 class GA_AIFTuple;
63 class GA_Defragment;
64 class GA_IndexMap;
65 class GA_LoadMap;
66 class GA_MergeMap;
67 class GA_SaveMap;
68 class ga_IndexPairObjectSets;
69 
70 class UT_JSONParser;
71 class UT_JSONWriter;
72 
73 
75 {
76 public:
77  static void registerType();
79  static const UT_StringHolder &getTypeName()
80  { return theAttributeType->getTypeName(); }
82  static const GA_AttributeType &getType() { return *theAttributeType; }
83 
85  static bool isType(const GA_Attribute *attrib)
86  {
87  return attrib && &attrib->getType() == theAttributeType;
88  }
91  {
92  if (attrib && &attrib->getType() == theAttributeType)
93  return static_cast<GA_ATIIndexPair *>(attrib);
94  return NULL;
95  }
97  static const GA_ATIIndexPair *cast(const GA_Attribute *attrib)
98  {
99  if (attrib && &attrib->getType() == theAttributeType)
100  return static_cast<const GA_ATIIndexPair *>(attrib);
101  return NULL;
102  }
103 
105  const GA_IndexMap &index_map, GA_AttributeScope scope,
106  const UT_StringHolder &name,
107  GA_Storage value_store, int entries, int tuple_size,
108  const GA_Defaults &index_default,
109  const GA_Defaults &value_defaults);
110  virtual ~GA_ATIIndexPair();
111 
112  /// Report memory used
113  virtual int64 getMemoryUsage(bool inclusive) const;
114 
115  virtual void countMemory(UT_MemoryCounter &counter, bool inclusive) const;
116 
117  virtual void reconstructElementBlock(GA_Offset offset, GA_Offset nelements);
118 
119  /// @{
120  /// Interface for defragmentation
121  virtual void defragment(const GA_Defragment &defrag);
122  /// @}
123 
124  /// Adding entries is thread-safe, so we're only subject to GA_DataArray
125  /// limitations.
127  { return WRITE_CONCURRENCE_PAGE; }
128 
129  virtual const GA_AIFCopyData *getAIFCopyData() const
130  { return myAIFCopyData; }
131  virtual const GA_AIFIndexPair *getAIFIndexPair() const
132  { return myAIFPair; }
133  virtual const GA_AIFMerge *getAIFMerge() const
134  { return myAIFMerge; }
135  virtual const GA_AIFEdit *getAIFEdit() const
136  { return myAIFEdit; }
137  virtual const GA_AIFTuple *getAIFTuple() const
138  { return myAIFTuple; }
139  virtual const GA_AIFMath *getAIFMath() const
140  { return myAIFMath; }
141  virtual const GA_AIFInterp *getAIFInterp() const
142  { return myAIFInterp; }
143  virtual const GA_AIFCompare *getAIFCompare() const
144  { return myAIFCompare; }
145 
146  /// @section JSON-GA_ATIIndexPair JSON Schema: GA_ATIIndexPair
147  /// @code
148  /// {
149  /// "name" : "GA_ATIIndexPair",
150  /// "description" : "An tuple array of indexed strings",
151  /// "type" : "orderedmap",
152  /// "properties": {
153  /// "idefault": {
154  /// "type" : {"$ref":"GA_Defaults"},
155  /// "description" : "Defaults for index values",
156  /// "optional" : true,
157  /// },
158  /// "vdefault": {
159  /// "type" : {"$ref":"GA_Defaults"},
160  /// "description" : "Defaults for values",
161  /// "optional" : true,
162  /// },
163  /// "entries": {
164  /// "type" : "integer",
165  /// "description" : "Number of entries for index/values tuples",
166  /// },
167  /// "istorage": {
168  /// "type" : "string",
169  /// "description" : "Storage type for index values",
170  /// "enum" : [ "int8", "int16", "int32", "int64" ],
171  /// },
172  /// "vstorage": {
173  /// "type" : "string",
174  /// "description" : "Storage type for values",
175  /// "enum" : [ "fpreal16", "fpreal32", "fpreal64" ],
176  /// },
177  /// "index": {
178  /// "type" : {"$ref":"GA_DataArrayTuple"},
179  /// "description" : "Index values.",
180  /// },
181  /// "value": {
182  /// "type" : {"$ref":"GA_DataArrayTuple"},
183  /// "description" : "Weight values.",
184  /// },
185  /// },
186  /// }
187  /// @endcode
188  /// @see @ref JSON_FileFormat
189  virtual const GA_AIFJSON *getAIFJSON() const { return myAIFJSON; }
190 
191  int getEntries() const { return myEntryCapacity.relaxedLoad(); }
192  /// setEntries() is NOT thread-safe. To concurrently grow the entry
193  /// capacity, use growEntriesTo(size, true).
194  bool setEntries(int size);
195  /// Use growEntriesTo() instead of setEntries() to ensure that the entry
196  /// capacity never shrinks. This is necessary for concurrent growing of
197  /// the entry capacity to properly handle the situation where one thread
198  /// tries to grow the entries less than another. Set the concurrent arg
199  /// if more than one thread can call this method concurrently.
200  bool growEntriesTo(int size, bool concurrent = false);
201 
202  bool setDataStorage(GA_Storage storage);
203  bool setIndexStorage(GA_Storage storage);
204 
205  const GA_Defaults &getValueDefaults() const { return myValueDefaults; }
207  { return myValueOperationalDefaults; }
208 
209  /// The size of the data tuple
210  int getDataTupleSize() const { return myTupleSize; }
211 
212  /// Grow or shrink the array size
213  virtual bool setArraySize(GA_Offset new_size);
214 
215  /// Try to compress data pages
216  virtual void tryCompressAllPages(
217  GA_Offset start_offset = GA_Offset(0),
218  GA_Offset end_offset = GA_INVALID_OFFSET);
219 
220  /// Harden data pages
221  virtual void hardenAllPages(
222  GA_Offset start_offset = GA_Offset(0),
223  GA_Offset end_offset = GA_INVALID_OFFSET);
224 
225  /// Returns true iff that is an attribute whose content can be copied
226  /// from this without any type conversions. This is important to
227  /// avoid reallocation of an attribute if its storage type,
228  /// including tuple size, matches the source attribute exactly.
229  virtual bool matchesStorage(const GA_Attribute *that) const
230  {
231  if (!GA_Attribute::matchesStorage(that))
232  return false;
233  const GA_ATIIndexPair *thatn = UTverify_cast<const GA_ATIIndexPair *>(that);
234  if (getDataStorage() != thatn->getDataStorage())
235  return false;
236  if (myIndexStorage != thatn->myIndexStorage)
237  return false;
238  if (getDataTupleSize() != thatn->getDataTupleSize())
239  return false;
240  if (getEntries() != thatn->getEntries())
241  return false;
242  return true;
243  }
244  /// In the case that we're copying from an attribute whose storage
245  /// type matches this exactly, this function copies the metadata
246  /// not associated with the storage, e.g. myOptions,
247  /// *excluding* the name and the data ID.
248  virtual void copyNonStorageMetadata(const GA_Attribute *that);
249 
250  /// This replaces the entirety of this attribute's content and non-
251  /// storage metadata (except the name) with that of the src attribute.
252  /// matchesStorage(src) should already return true.
253  /// This is primarily for use by GA_AttributeSet::replace().
254  /// NOTE: The internal content sizes may not match exactly if the
255  /// attribute type may overallocate, but the sizes should be such
256  /// that any real data will fit in the destination, so be careful
257  /// and deal with the myTailInitialize flag appropriately if
258  /// any extra elements aren't equal to the default.
259  virtual void replace(const GA_Attribute &src);
260 
261 protected:
262  int getObjectSetCount() const;
263  void setObjectSetCount(int n);
264 
265  const GA_AIFIndexPairObjects *getObjectsConst(int s = 0) const;
266  GA_AIFIndexPairObjects *getObjects(int s = 0);
267 
268  bool hasSameProperties(const GA_ATIIndexPair *sattrib) const;
269  bool copyProperties(const GA_ATIIndexPair *sattrib);
270  bool mergeObjectValues(const GA_ATIIndexPair *sattrib, UT_IntArray &new_indices);
271 
272  bool setTupleSize(int size);
273  GA_Storage getDataStorage() const { return myDataStorage; }
274  bool getIndex(GA_Offset ai, int entry, int32 &index) const { myIndex[entry]->get(ai, index); return true; }
275  bool getData(GA_Offset ai, int entry, fpreal32 &data, int data_component = 0) const { myData[entry]->getData(data_component)->get(ai, data); return true; }
276  bool getData(GA_Offset ai, int entry, fpreal64 &data, int data_component = 0) const { myData[entry]->getData(data_component)->get(ai, data); return true; }
277  bool getData(GA_Offset ai, int entry, int32 &data, int data_component = 0) const { myData[entry]->getData(data_component)->get(ai, data); return true; }
278  bool getData(GA_Offset ai, int entry, int64 &data, int data_component = 0) const { myData[entry]->getData(data_component)->get(ai, data); return true; }
279  bool setIndex(GA_Offset ai, int entry, int32 index) { myIndex[entry]->set(ai, index); return true; }
280  bool setIndex(const GA_Range &ai, int entry, int32 index) { myIndex[entry]->set(ai, index); return true; }
281  bool setData(GA_Offset ai, int entry, fpreal32 data, int data_component = 0) { myData[entry]->getData(data_component)->set(ai, data); return true; }
282  bool setData(GA_Offset ai, int entry, fpreal64 data, int data_component = 0) { myData[entry]->getData(data_component)->set(ai, data); return true; }
283  bool setData(GA_Offset ai, int entry, int32 data, int data_component = 0) { myData[entry]->getData(data_component)->set(ai, data); return true; }
284  bool setData(GA_Offset ai, int entry, int64 data, int data_component = 0) { myData[entry]->getData(data_component)->set(ai, data); return true; }
285 
286  bool removeIndex(int index);
287  void invalidateTrailingEntries(GA_Offset ai, int start_entry);
288  void invalidateTrailingEntries(const GA_Range &ai, int start_entry);
289 
290  /// @{
291  /// Copy Data AIF
292  bool copyData(GA_Offset di, const GA_ATIIndexPair &src,
293  GA_Offset si);
294  bool copyData(const GA_Range &di, const GA_ATIIndexPair &src,
295  const GA_Range &si);
296  /// @}
297 
298  /// @{
299  /// Compare AIF
300  bool isAlmostEqual(GA_Offset di, const GA_ATIIndexPair &src,
301  GA_Offset si, int ulps) const;
302  bool isAlmostEqual(const GA_Range &di, const GA_ATIIndexPair &src,
303  const GA_Range &si, int ulps) const;
304  /// @}
305 
306  /// @{ GA_AIFMerge
307  /// Base class implementation of GA_AIFMerge::destroyDestination()
308  void mergeDestroyDestination(const GA_MergeMap &map,
309  GA_Attribute *dattrib) const;
310  /// Base class implementation of GA_AIFMerge::addDestination()
311  GA_Attribute *mergeAddDestination(const GA_MergeMap &map,
312  GA_Attribute *dattrib) const;
313  /// Base class implementation of GA_AIFMerge::copyArray()
314  bool mergeAppendData(const GA_MergeMap &map,
315  const GA_Attribute *sattrib);
316  /// @}
317 
318  /// @{
319  /// GA_AIFTuple
320  /// The AIFTuple has a tuple with 2*getEntries() entries. The entries are
321  /// interleaved with ( index0, value0, index1, value1, ...)
322  int tupleGetSize() const
323  { return (myTupleSize + 1) * getEntries(); }
324  bool tupleSetSize(int size);
325  GA_Storage tupleGetStorage() const;
326  bool tupleSetStorage(GA_Storage storage);
327  bool isNan(GA_Offset ai) const;
328  bool isNan(const GA_Range &ai) const;
329  template <typename T> inline bool
330  tupleGet(GA_Offset ai, T &v, int index) const;
331  template <typename T> inline bool
332  tupleGet(GA_Offset ai, T *v, int count, int start) const;
333  template <typename T> inline bool
334  tupleSet(GA_Offset ai, T v, int vi);
335  template <typename T> inline bool
336  tupleSet(GA_Offset ai, const T *v, int count, int start);
337  template <typename T> inline bool
338  tupleSet(const GA_Range &di, T v, int vi);
339  template <typename T> inline bool
340  tupleSet(const GA_Range &di, const T *v, int count, int start);
341  inline bool tupleSet(GA_Offset di, const GA_ATIIndexPair &s,
342  GA_Offset si, int component);
343  inline bool tupleSet(const GA_Range &di, const GA_ATIIndexPair &s,
344  const GA_Range &si, int component);
345  /// @}
346 
347 protected:
348  // Protected Data
349  ga_IndexPairObjectSets *myObjects;
350  UT_ConcurrentVector<GA_DataArray *> myIndex;
351  UT_ConcurrentVector<GA_DataArrayTuple *> myData;
360 
361  /// Scale all weights by the given amount (used in weighted sums)
362  void interpScale(GA_Offset di, fpreal scale);
363 
364 private:
365  virtual GA_Attribute *doClone(const GA_IndexMap &index_map,
366  const UT_StringHolder &name) const;
367 
368  /// @{ GA_AIFJSON
369  bool jsonSave(UT_JSONWriter &w, const GA_SaveMap &s) const;
370  bool jsonLoad(UT_JSONParser &p, const GA_LoadMap &l);
371  /// @}
372 
373  static GA_AIFIndexPair *myAIFPair;
374  static GA_AIFMerge *myAIFMerge;
375  static GA_AIFCopyData *myAIFCopyData;
376  static GA_AIFEdit *myAIFEdit;
377  static GA_AIFJSON *myAIFJSON;
378  static GA_AIFTuple *myAIFTuple;
379  static GA_AIFMath *myAIFMath;
380  static GA_AIFInterp *myAIFInterp;
381  static GA_AIFCompare *myAIFCompare;
382 
383  static const GA_AttributeType *theAttributeType;
384 
385  /// @cond INTERNAL_DOX
386  friend class ga_IndexPairAccess;
387  friend class ga_IndexPairMerge;
388  friend class ga_IndexPairEdit;
389  friend class ga_IndexPairEditDelta;
390  friend class ga_IndexPairEditSnapshot;
391  friend class ga_IndexPairJSON;
392  friend class ga_IndexPairTuple;
393  friend class ga_IndexPairMath;
394  friend class ga_IndexPairInterp;
395  friend class ga_IndexPairCopyData;
396  friend class ga_IndexPairCompare;
397  /// @endcond
398 };
399 
400 #endif
401 
virtual const GA_AIFCopyData * getAIFCopyData() const
Return the attribute's copy interface or NULL.
A class to manage an ordered array which has fixed offset handles.
Definition: GA_IndexMap.h:63
SYS_AtomicInt32 myEntryCapacity
Definition of a geometry attribute.
Definition: GA_Attribute.h:190
UT_ConcurrentVector< GA_DataArrayTuple * > myData
Generic Attribute Interface class to get/set data as index pairs.
virtual const GA_AIFEdit * getAIFEdit() const
Return the attribute's edit interface or NULL.
Used to pass options and map offset values during saving.
Definition: GA_SaveMap.h:48
bool getData(GA_Offset ai, int entry, int64 &data, int data_component=0) const
virtual bool matchesStorage(const GA_Attribute *that) const
Class which stores the default values for a GA_Attribute.
Definition: GA_Defaults.h:35
GA_Storage getDataStorage() const
Attribute Interface class to perform numeric operations on attributes.
Definition: GA_AIFMath.h:88
const GLdouble * v
Definition: glcorearb.h:836
static SYS_FORCE_INLINE const GA_AttributeType & getType()
GLuint start
Definition: glcorearb.h:474
virtual const GA_AIFCompare * getAIFCompare() const
Return the attribute's comparison interface or NULL.
virtual const GA_AIFJSON * getAIFJSON() const
virtual const GA_AIFTuple * getAIFTuple() const
Return the attribute's tuple interface or NULL.
const GA_Defaults & getValueDefaults() const
The merge map keeps track of information when merging details.
Definition: GA_MergeMap.h:53
JSON reader class which handles parsing of JSON or bJSON files.
Definition: UT_JSONParser.h:75
virtual bool setArraySize(GA_Offset size)=0
bool setIndex(const GA_Range &ai, int entry, int32 index)
#define GA_API
Definition: GA_API.h:12
bool isNan(const Tuple< SIZE, T > &t)
Return true if a Nan is present in the tuple.
Definition: Tuple.h:243
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:32
SYS_FORCE_INLINE TO_T UTverify_cast(FROM_T from)
Definition: UT_Assert.h:199
virtual void countMemory(UT_MemoryCounter &counter, bool inclusive) const =0
int getDataTupleSize() const
The size of the data tuple.
virtual int64 getMemoryUsage(bool inclusive) const =0
virtual bool matchesStorage(const GA_Attribute *that) const
Definition: GA_Attribute.h:677
bool setData(GA_Offset ai, int entry, int64 data, int data_component=0)
UT_ConcurrentVector< GA_DataArray * > myIndex
virtual void tryCompressAllPages(GA_Offset start_offset=GA_Offset(0), GA_Offset end_offset=GA_INVALID_OFFSET)=0
GA_Defaults myValueDefaults
int tupleGetSize() const
GLsizeiptr size
Definition: glcorearb.h:663
#define GA_INVALID_OFFSET
Definition: GA_Types.h:654
static SYS_FORCE_INLINE const GA_ATIIndexPair * cast(const GA_Attribute *attrib)
GA_Storage myDataStorage
A range of elements in an index-map.
Definition: GA_Range.h:42
GA_Defaults myValueOperationalDefaults
GA_Size GA_Offset
Definition: GA_Types.h:617
long long int64
Definition: SYS_Types.h:107
GA_API const UT_StringHolder scale
const GA_Defaults & getValueOperationalDefaults() const
GA_AttributeScope
Definition: GA_Types.h:121
GLdouble n
Definition: glcorearb.h:2007
static SYS_FORCE_INLINE GA_ATIIndexPair * cast(GA_Attribute *attrib)
virtual const GA_AIFMerge * getAIFMerge() const
Return the attribute's merge interface or NULL.
bool setData(GA_Offset ai, int entry, fpreal32 data, int data_component=0)
int getEntries() const
virtual void replace(const GA_Attribute &src)=0
Attribute Interface for merging attribute data between details.
Definition: GA_AIFMerge.h:56
GA_Defaults myIndexDefault
double fpreal64
Definition: SYS_Types.h:192
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
GLintptr offset
Definition: glcorearb.h:664
bool getData(GA_Offset ai, int entry, int32 &data, int data_component=0) const
ga_IndexPairObjectSets * myObjects
virtual const GA_AIFInterp * getAIFInterp() const
Return the attribute's interpolation interface or NULL.
Attribute Interface class to perform comparisons on attributes.
Definition: GA_AIFCompare.h:27
Options during loading.
Definition: GA_LoadMap.h:42
Defragmentation of IndexMaps.
Definition: GA_Defragment.h:45
GLboolean * data
Definition: glcorearb.h:130
GLuint const GLchar * name
Definition: glcorearb.h:785
int int32
Definition: SYS_Types.h:35
virtual void copyNonStorageMetadata(const GA_Attribute *that)
Definition: GA_Attribute.h:691
static SYS_FORCE_INLINE const UT_StringHolder & getTypeName()
GLint GLsizei count
Definition: glcorearb.h:404
bool setData(GA_Offset ai, int entry, int32 data, int data_component=0)
const GA_AttributeType & getType() const
Definition: GA_Attribute.h:198
static SYS_FORCE_INLINE bool isType(const GA_Attribute *attrib)
bool setIndex(GA_Offset ai, int entry, int32 index)
double fpreal
Definition: SYS_Types.h:270
png_infop png_sPLT_tpp entries
Definition: png.h:2481
bool getData(GA_Offset ai, int entry, fpreal64 &data, int data_component=0) const
virtual WriteConcurrence getSupportedWriteConcurrence() const
GLuint index
Definition: glcorearb.h:785
bool setData(GA_Offset ai, int entry, fpreal64 data, int data_component=0)
bool getIndex(GA_Offset ai, int entry, int32 &index) const
virtual const GA_AIFMath * getAIFMath() const
Return the attribute's math interface or NULL.
Concurrent writes to separate pages supported.
Definition: GA_Attribute.h:335
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:107
getOption("OpenEXR.storage") storage
Definition: HDK_Image.dox:276
Attribute Interface class to copy attribute data.
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:856
Attribute Interface for file I/O.
Definition: GA_AIFJSON.h:39
UT_Lock myEntryGrowthLock
AIF to record changes to attribute values.
Definition: GA_AIFEdit.h:393
virtual void hardenAllPages(GA_Offset start_offset=GA_Offset(0), GA_Offset end_offset=GA_INVALID_OFFSET)=0
virtual void defragment(const GA_Defragment &defrag)=0
Generic Attribute Interface class to access an attribute as a tuple.
Definition: GA_AIFTuple.h:32
bool getData(GA_Offset ai, int entry, fpreal32 &data, int data_component=0) const
float fpreal32
Definition: SYS_Types.h:191
GA_Storage
Definition: GA_Types.h:48
GA_Storage myIndexStorage
virtual const GA_AIFIndexPair * getAIFIndexPair() const
Return the attribute's index pair interface or NULL.
GLenum src
Definition: glcorearb.h:1792
virtual void reconstructElementBlock(GA_Offset offset, GA_Offset nelements)