HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GA_ATINumericArray.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_ATINumericArray.h (GA Library, C++)
7  *
8  * COMMENTS: Array DAta ATI (Attribute Type Implementation)
9  *
10  * Each element can have a different sized array
11  * of data. This is *not* the same as a tuple as the
12  * size is variable!
13  */
14 
15 #pragma once
16 
17 #ifndef __GA_ATINumericArray
18 #define __GA_ATINumericArray
19 
20 #include "GA_API.h"
21 #include "GA_Attribute.h"
22 #include "GA_AttributeType.h"
23 #include "GA_ArrayDataArray.h"
24 #include "GA_Range.h"
25 #include "GA_Types.h"
26 
27 #include <UT/UT_StringHolder.h>
28 #include <SYS/SYS_Types.h>
29 
30 class GA_AIFCompare;
31 class GA_AIFCopyData;
32 class GA_AIFEdit;
33 class GA_AIFJSON;
34 class GA_Defragment;
35 class GA_IndexMap;
36 class GA_LoadMap;
37 class GA_MergeMap;
38 class GA_SaveMap;
39 
40 class UT_JSONParser;
41 class UT_JSONWriter;
42 
43 
45 {
46 public:
47  static void registerType();
48 
50  static const UT_StringHolder &getTypeName()
51  { return theAttributeType->getTypeName(); }
53  static const GA_AttributeType &getType() { return *theAttributeType; }
54 
56  static bool isType(const GA_Attribute *attrib)
57  {
58  return attrib && &attrib->getType() == theAttributeType;
59  }
62  {
63  if (attrib && &attrib->getType() == theAttributeType)
64  return static_cast<GA_ATINumericArray *>(attrib);
65  return NULL;
66  }
68  static const GA_ATINumericArray *cast(const GA_Attribute *attrib)
69  {
70  if (attrib && &attrib->getType() == theAttributeType)
71  return static_cast<const GA_ATINumericArray *>(attrib);
72  return NULL;
73  }
74 
76  const GA_IndexMap &index_map, GA_AttributeScope scope,
77  const UT_StringHolder &name,
78  GA_Storage value_store, int tuple_size);
79  virtual ~GA_ATINumericArray();
80 
81  /// Report memory used
82  virtual int64 getMemoryUsage(bool inclusive) const;
83 
84  virtual void countMemory(UT_MemoryCounter &counter, bool inclusive) const;
85 
86  virtual void reconstructElementBlock(GA_Offset offset, GA_Offset nelements);
87 
88  /// @{
89  /// Interface for defragmentation
90  virtual void defragment(const GA_Defragment &defrag);
91  /// @}
92 
93  /// Adding entries is thread-safe, so we're only subject to GA_DataArray
94  /// limitations.
96  { return WRITE_CONCURRENCE_PAGE; }
97 
98  virtual const GA_AIFCopyData *getAIFCopyData() const
99  { return myAIFCopyData; }
100  virtual const GA_AIFIndexPair *getAIFIndexPair() const
101  { return 0; }
102  virtual const GA_AIFMerge *getAIFMerge() const
103  { return myAIFMerge; }
104  virtual const GA_AIFEdit *getAIFEdit() const
105  { return 0; }
106  virtual const GA_AIFTuple *getAIFTuple() const
107  { return 0; }
108  virtual const GA_AIFMath *getAIFMath() const
109  { return 0; }
110  virtual const GA_AIFInterp *getAIFInterp() const
111  { return 0; }
112  virtual const GA_AIFCompare *getAIFCompare() const
113  { return myAIFCompare; }
114  virtual const GA_AIFNumericArray *getAIFNumericArray() const
115  { return myAIFNumericArray; }
116 
117  /// @section JSON-GA_ATINumericArray JSON Schema: GA_ATINumericArray
118  /// @code
119  /// {
120  /// "name" : "GA_ATINumericArray",
121  /// "description" : "An array of arrays of tuples",
122  /// "type" : "orderedmap",
123  /// "properties": {
124  /// "size": {
125  /// "type" : "integer",
126  /// "minimum" : 1,
127  /// "description" : "Tuple size",
128  /// },
129  /// "storage": {
130  /// "type" : "string",
131  /// "description" : "Storage type for values",
132  /// "enum" : [ "uint8","int8","int16","int32","int64",
133  /// "fpreal16", "fpreal32", "fpreal64" ],
134  /// },
135  /// "values": {
136  /// "type" : {"$ref":"GA_DataArrayTuple"},
137  /// "description" : "Array values.",
138  /// },
139  /// },
140  /// }
141  /// @endcode
142  /// @see @ref JSON_FileFormat
143  virtual const GA_AIFJSON *getAIFJSON() const { return myAIFJSON; }
144 
145  GA_Storage getDataStorage() const;
146 
147  bool setDataStorage(GA_Storage storage);
148 
149  /// The size of the data tuple
150  int getDataTupleSize() const;
151 
152  /// Grow or shrink the array size
153  virtual bool setArraySize(GA_Offset new_size);
154 
155  /// Try to compress data pages
156  virtual void tryCompressAllPages(
157  GA_Offset start_offset = GA_Offset(0),
158  GA_Offset end_offset = GA_INVALID_OFFSET);
159 
160  /// Harden data pages
161  virtual void hardenAllPages(
162  GA_Offset start_offset = GA_Offset(0),
163  GA_Offset end_offset = GA_INVALID_OFFSET);
164 
165  /// Returns true iff that is an attribute whose content can be copied
166  /// from this without any type conversions. This is important to
167  /// avoid reallocation of an attribute if its storage type,
168  /// including tuple size, matches the source attribute exactly.
169  virtual bool matchesStorage(const GA_Attribute *that) const
170  {
171  if (!GA_Attribute::matchesStorage(that))
172  return false;
173  const GA_ATINumericArray *thatn = UTverify_cast<const GA_ATINumericArray *>(that);
174  if (myData.getStorage() != thatn->myData.getStorage())
175  return false;
176  if (myData.getTupleSize() != thatn->myData.getTupleSize())
177  return false;
178  return true;
179  }
180 
181  /// This replaces the entirety of this attribute's content and non-
182  /// storage metadata (except the name) with that of the src attribute.
183  /// matchesStorage(src) should already return true.
184  /// This is primarily for use by GA_AttributeSet::replace().
185  /// NOTE: The internal content sizes may not match exactly if the
186  /// attribute type may overallocate, but the sizes should be such
187  /// that any real data will fit in the destination, so be careful
188  /// and deal with the myTailInitialize flag appropriately if
189  /// any extra elements aren't equal to the default.
190  virtual void replace(const GA_Attribute &src);
191 
192 protected:
193  bool setDataTupleSize(int size);
194 
195  /// @{
196  /// Copy Data AIF
197  bool copyData(GA_Offset di, const GA_ATINumericArray &src,
198  GA_Offset si);
199  bool copyData(const GA_Range &di, const GA_ATINumericArray &src,
200  const GA_Range &si);
201  /// @}
202 
203  /// @{
204  /// Compare AIF
205  bool isAlmostEqual(GA_Offset di, const GA_ATINumericArray &src,
206  GA_Offset si, int ulps) const;
207  bool isAlmostEqual(const GA_Range &di, const GA_ATINumericArray &src,
208  const GA_Range &si, int ulps) const;
209  /// @}
210 
211  /// @{ GA_AIFMerge
212  /// Base class implementation of GA_AIFMerge::destroyDestination()
213  void mergeDestroyDestination(const GA_MergeMap &map,
214  GA_Attribute *dattrib) const;
215  /// Base class implementation of GA_AIFMerge::addDestination()
216  GA_Attribute *mergeAddDestination(const GA_MergeMap &map,
217  GA_Attribute *dattrib) const;
218  /// Base class implementation of GA_AIFMerge::copyArray()
219  bool mergeAppendData(const GA_MergeMap &map,
220  const GA_Attribute *sattrib);
221  void mergeGrowArray(const GA_MergeMap &map,
222  const GA_ATINumericArray &s);
223  /// @}
224 
225 protected:
227 
228 private:
229  virtual GA_Attribute *doClone(const GA_IndexMap &index_map,
230  const UT_StringHolder &name) const;
231 
232  /// @{ GA_AIFJSON
233  bool jsonSave(UT_JSONWriter &w, const GA_SaveMap &s) const;
234  bool jsonLoad(UT_JSONParser &p, const GA_LoadMap &l);
235  /// @}
236 
237  static GA_AIFMerge *myAIFMerge;
238  static GA_AIFCopyData *myAIFCopyData;
239  static GA_AIFJSON *myAIFJSON;
240  static GA_AIFCompare *myAIFCompare;
241  static GA_AIFNumericArray *myAIFNumericArray;
242 
243  static const GA_AttributeType *theAttributeType;
244 
245  /// @cond INTERNAL_DOX
246  friend class ga_ArrayDataMerge;
247  friend class ga_ArrayDataJSON;
248  friend class ga_ArrayDataCopyData;
249  friend class ga_ArrayDataCompare;
250  friend class ga_ArrayNumericArray;
251  /// @endcond
252 };
253 
254 #endif
255 
A class to manage an ordered array which has fixed offset handles.
Definition: GA_IndexMap.h:63
Definition of a geometry attribute.
Definition: GA_Attribute.h:189
virtual const GA_AIFNumericArray * getAIFNumericArray() const
Return the attribute's arraydata interface or NULL.
Generic Attribute Interface class to access an attribute as a array.
Generic Attribute Interface class to get/set data as index pairs.
Used to pass options and map offset values during saving.
Definition: GA_SaveMap.h:48
Attribute Interface class to perform numeric operations on attributes.
Definition: GA_AIFMath.h:88
static SYS_FORCE_INLINE const GA_ATINumericArray * cast(const GA_Attribute *attrib)
virtual bool matchesStorage(const GA_Attribute *that) const
The merge map keeps track of information when merging details.
Definition: GA_MergeMap.h:53
static SYS_FORCE_INLINE const UT_StringHolder & getTypeName()
JSON reader class which handles parsing of JSON or bJSON files.
Definition: UT_JSONParser.h:72
virtual bool setArraySize(GA_Offset size)=0
#define GA_API
Definition: GA_API.h:12
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:32
virtual const GA_AIFCopyData * getAIFCopyData() const
Return the attribute's copy interface or NULL.
virtual void countMemory(UT_MemoryCounter &counter, bool inclusive) const =0
virtual int64 getMemoryUsage(bool inclusive) const =0
virtual bool matchesStorage(const GA_Attribute *that) const
Definition: GA_Attribute.h:680
virtual void tryCompressAllPages(GA_Offset start_offset=GA_Offset(0), GA_Offset end_offset=GA_INVALID_OFFSET)=0
GLsizeiptr size
Definition: glcorearb.h:663
An array of array of numbers with various storage types.
virtual const GA_AIFTuple * getAIFTuple() const
Return the attribute's tuple interface or NULL.
#define GA_INVALID_OFFSET
Definition: GA_Types.h:654
A range of elements in an index-map.
Definition: GA_Range.h:42
static SYS_FORCE_INLINE GA_ATINumericArray * cast(GA_Attribute *attrib)
GA_Size GA_Offset
Definition: GA_Types.h:617
static SYS_FORCE_INLINE const GA_AttributeType & getType()
GA_Storage getStorage() const
Query the storage used for the array data.
long long int64
Definition: SYS_Types.h:100
virtual const GA_AIFIndexPair * getAIFIndexPair() const
Return the attribute's index pair interface or NULL.
virtual const GA_AIFMath * getAIFMath() const
Return the attribute's math interface or NULL.
GA_AttributeScope
Definition: GA_Types.h:121
GA_ArrayDataArray myData
virtual const GA_AIFCompare * getAIFCompare() const
Return the attribute's comparison interface or NULL.
GA_Size getTupleSize() const
Queries the size of each tuple stored in the arrays.
virtual void replace(const GA_Attribute &src)=0
Attribute Interface for merging attribute data between details.
Definition: GA_AIFMerge.h:56
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
GLintptr offset
Definition: glcorearb.h:664
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
virtual WriteConcurrence getSupportedWriteConcurrence() const
GLuint const GLchar * name
Definition: glcorearb.h:785
SYS_FORCE_INLINE TO_T UTverify_cast(FROM_T from)
Definition: UT_Assert.h:175
const GA_AttributeType & getType() const
Definition: GA_Attribute.h:197
virtual const GA_AIFInterp * getAIFInterp() const
Return the attribute's interpolation interface or NULL.
static SYS_FORCE_INLINE bool isType(const GA_Attribute *attrib)
virtual const GA_AIFEdit * getAIFEdit() const
Return the attribute's edit interface or NULL.
Concurrent writes to separate pages supported.
Definition: GA_Attribute.h:338
virtual const GA_AIFMerge * getAIFMerge() const
Return the attribute's merge interface or NULL.
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
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
Generic Attribute Interface class to access an attribute as a tuple.
Definition: GA_AIFTuple.h:32
virtual void defragment(const GA_Defragment &defrag)=0
GA_Storage
Definition: GA_Types.h:48
virtual const GA_AIFJSON * getAIFJSON() const
GLenum src
Definition: glcorearb.h:1792
virtual void reconstructElementBlock(GA_Offset offset, GA_Offset nelements)