HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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  ~GA_ATINumericArray() override;
80 
81  /// Report memory used
82  int64 getMemoryUsage(bool inclusive) const override;
83 
84  void countMemory(UT_MemoryCounter &counter, bool inclusive) const override;
85 
87  GA_Offset nelements) override;
88 
89  /// @{
90  /// Interface for defragmentation
91  void defragment(const GA_Defragment &defrag) override;
92  /// @}
93 
94  /// Adding entries is thread-safe, so we're only subject to GA_DataArray
95  /// limitations.
97  { return WRITE_CONCURRENCE_PAGE; }
98 
99  const GA_AIFCopyData *getAIFCopyData() const override
100  { return myAIFCopyData; }
101  const GA_AIFIndexPair *getAIFIndexPair() const override
102  { return 0; }
103  const GA_AIFMerge *getAIFMerge() const override
104  { return myAIFMerge; }
105  const GA_AIFEdit *getAIFEdit() const override
106  { return 0; }
107  const GA_AIFTuple *getAIFTuple() const override
108  { return 0; }
109  const GA_AIFMath *getAIFMath() const override
110  { return 0; }
111  const GA_AIFInterp *getAIFInterp() const override
112  { return 0; }
113  const GA_AIFCompare *getAIFCompare() const override
114  { return myAIFCompare; }
115  const GA_AIFNumericArray *getAIFNumericArray() const override
116  { return myAIFNumericArray; }
117 
118  /// @section JSON-GA_ATINumericArray JSON Schema: GA_ATINumericArray
119  /// @code
120  /// {
121  /// "name" : "GA_ATINumericArray",
122  /// "description" : "An array of arrays of tuples",
123  /// "type" : "orderedmap",
124  /// "properties": {
125  /// "size": {
126  /// "type" : "integer",
127  /// "minimum" : 1,
128  /// "description" : "Tuple size",
129  /// },
130  /// "storage": {
131  /// "type" : "string",
132  /// "description" : "Storage type for values",
133  /// "enum" : [ "uint8","int8","int16","int32","int64",
134  /// "fpreal16", "fpreal32", "fpreal64" ],
135  /// },
136  /// "values": {
137  /// "type" : {"$ref":"GA_DataArrayTuple"},
138  /// "description" : "Array values.",
139  /// },
140  /// },
141  /// }
142  /// @endcode
143  /// @see @ref JSON_FileFormat
144  const GA_AIFJSON *getAIFJSON() const override { return myAIFJSON; }
145 
146  GA_Storage getDataStorage() const;
147 
148  bool setDataStorage(GA_Storage storage);
149 
150  /// The size of the data tuple
151  int getDataTupleSize() const;
152 
153  /// Grow or shrink the array size
154  bool setArraySize(GA_Offset new_size) override;
155 
156  /// Try to compress data pages
157  void tryCompressAllPages(
158  GA_Offset start_offset = GA_Offset(0),
159  GA_Offset end_offset = GA_INVALID_OFFSET) override;
160 
161  /// Harden data pages
162  void hardenAllPages(
163  GA_Offset start_offset = GA_Offset(0),
164  GA_Offset end_offset = GA_INVALID_OFFSET) override;
165 
166  /// Returns true iff that is an attribute whose content can be copied
167  /// from this without any type conversions. This is important to
168  /// avoid reallocation of an attribute if its storage type,
169  /// including tuple size, matches the source attribute exactly.
170  bool matchesStorage(const GA_Attribute *that) const override
171  {
172  if (!GA_Attribute::matchesStorage(that))
173  return false;
174  const GA_ATINumericArray *thatn = UTverify_cast<const GA_ATINumericArray *>(that);
175  if (myData.getStorage() != thatn->myData.getStorage())
176  return false;
177  if (myData.getTupleSize() != thatn->myData.getTupleSize())
178  return false;
179  return true;
180  }
181 
182  /// This replaces the entirety of this attribute's content and non-
183  /// storage metadata (except the name) with that of the src attribute.
184  /// matchesStorage(src) should already return true.
185  /// This is primarily for use by GA_AttributeSet::replace().
186  /// NOTE: The internal content sizes may not match exactly if the
187  /// attribute type may overallocate, but the sizes should be such
188  /// that any real data will fit in the destination, so be careful
189  /// and deal with the myTailInitialize flag appropriately if
190  /// any extra elements aren't equal to the default.
191  void replace(const GA_Attribute &src) override;
192 
193 protected:
194  bool setDataTupleSize(int size);
195 
196  /// @{
197  /// Copy Data AIF
198  bool copyData(GA_Offset di, const GA_ATINumericArray &src,
199  GA_Offset si);
200  bool copyData(const GA_Range &di, const GA_ATINumericArray &src,
201  const GA_Range &si);
202  /// @}
203 
204  /// @{
205  /// Compare AIF
206  bool isAlmostEqual(GA_Offset di, const GA_ATINumericArray &src,
207  GA_Offset si, int ulps) const;
208  bool isAlmostEqual(const GA_Range &di, const GA_ATINumericArray &src,
209  const GA_Range &si, int ulps) const;
210  /// @}
211 
212  /// @{ GA_AIFMerge
213  /// Base class implementation of GA_AIFMerge::destroyDestination()
214  void mergeDestroyDestination(const GA_MergeMap &map,
215  GA_Attribute *dattrib) const;
216  /// Base class implementation of GA_AIFMerge::addDestination()
217  GA_Attribute *mergeAddDestination(const GA_MergeMap &map,
218  GA_Attribute *dattrib) const;
219  /// Base class implementation of GA_AIFMerge::copyArray()
220  bool mergeAppendData(const GA_MergeMap &map,
221  const GA_Attribute *sattrib);
222  void mergeGrowArray(const GA_MergeMap &map,
223  const GA_ATINumericArray &s);
224  /// @}
225 
226 protected:
228 
229 private:
230  GA_Attribute *doClone(const GA_IndexMap &index_map,
231  const UT_StringHolder &name) const override;
232 
233  /// @{ GA_AIFJSON
234  bool jsonSave(UT_JSONWriter &w, const GA_SaveMap &s) const;
235  bool jsonLoad(UT_JSONParser &p, const GA_LoadMap &l);
236  /// @}
237 
238  static GA_AIFMerge *myAIFMerge;
239  static GA_AIFCopyData *myAIFCopyData;
240  static GA_AIFJSON *myAIFJSON;
241  static GA_AIFCompare *myAIFCompare;
242  static GA_AIFNumericArray *myAIFNumericArray;
243 
244  static const GA_AttributeType *theAttributeType;
245 
246  /// @cond INTERNAL_DOX
247  friend class ga_ArrayDataMerge;
248  friend class ga_ArrayDataJSON;
249  friend class ga_ArrayDataCopyData;
250  friend class ga_ArrayDataCompare;
251  friend class ga_ArrayNumericArray;
252  /// @endcond
253 };
254 
255 #endif
256 
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:196
GLuint counter
Definition: glew.h:2745
Generic Attribute Interface class to access an attribute as a array.
Generic Attribute Interface class to get/set data as index pairs.
const GA_AIFCompare * getAIFCompare() const override
Return the attribute's comparison interface or NULL.
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)
const GA_AIFIndexPair * getAIFIndexPair() const override
Return the attribute's index pair interface or NULL.
The merge map keeps track of information when merging details.
Definition: GA_MergeMap.h:53
const GA_AIFEdit * getAIFEdit() const override
Return the attribute's edit interface or NULL.
const GA_AIFMath * getAIFMath() const override
Return the attribute's math interface or NULL.
virtual void reconstructElementBlock(GA_Offset offset, GA_Offset nelements)=0
static SYS_FORCE_INLINE const UT_StringHolder & getTypeName()
JSON reader class which handles parsing of JSON or bJSON files.
Definition: UT_JSONParser.h:88
virtual bool setArraySize(GA_Offset size)=0
#define GA_API
Definition: GA_API.h:14
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:35
SYS_FORCE_INLINE TO_T UTverify_cast(FROM_T from)
Definition: UT_Assert.h:244
GLuint const GLchar * name
Definition: glcorearb.h:785
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:744
GLenum src
Definition: glcorearb.h:1792
bool matchesStorage(const GA_Attribute *that) const override
virtual void tryCompressAllPages(GA_Offset start_offset=GA_Offset(0), GA_Offset end_offset=GA_INVALID_OFFSET)=0
An array of array of numbers with various storage types.
#define GA_INVALID_OFFSET
Definition: GA_Types.h:677
GLdouble l
Definition: glew.h:9164
A range of elements in an index-map.
Definition: GA_Range.h:42
static SYS_FORCE_INLINE GA_ATINumericArray * cast(GA_Attribute *attrib)
GLsizeiptr size
Definition: glcorearb.h:663
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:856
GA_Size GA_Offset
Definition: GA_Types.h:640
static SYS_FORCE_INLINE const GA_AttributeType & getType()
GA_Storage getStorage() const
Query the storage used for the array data.
GA_AttributeScope
Definition: GA_Types.h:141
GA_ArrayDataArray myData
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:107
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
const GA_AIFTuple * getAIFTuple() const override
Return the attribute's tuple interface or NULL.
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
const GA_AIFMerge * getAIFMerge() const override
Return the attribute's merge interface or NULL.
const GA_AIFJSON * getAIFJSON() const override
long long int64
Definition: SYS_Types.h:116
Attribute Interface class to perform comparisons on attributes.
Definition: GA_AIFCompare.h:27
GLfloat GLfloat p
Definition: glew.h:16656
Options during loading.
Definition: GA_LoadMap.h:42
Defragmentation of IndexMaps.
Definition: GA_Defragment.h:45
const GA_AttributeType & getType() const
Definition: GA_Attribute.h:204
const GA_AIFCopyData * getAIFCopyData() const override
Return the attribute's copy interface or NULL.
const GA_AIFNumericArray * getAIFNumericArray() const override
Return the attribute's arraydata interface or NULL.
static SYS_FORCE_INLINE bool isType(const GA_Attribute *attrib)
Concurrent writes to separate pages supported.
Definition: GA_Attribute.h:365
getOption("OpenEXR.storage") storage
Definition: HDK_Image.dox:276
Attribute Interface class to copy attribute data.
GLintptr offset
Definition: glcorearb.h:664
const GA_AIFInterp * getAIFInterp() const override
Return the attribute's interpolation interface or NULL.
Attribute Interface for file I/O.
Definition: GA_AIFJSON.h:39
AIF to record changes to attribute values.
Definition: GA_AIFEdit.h:397
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
GLdouble s
Definition: glew.h:1395
GA_Storage
Definition: GA_Types.h:49
WriteConcurrence getSupportedWriteConcurrence() const override