HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GA_ArrayDataArray.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_ArrayDataArray.h ( GA Library, C++)
7  *
8  * COMMENTS: A very simple array of arrays used to store attribute data.
9  */
10 
11 #ifndef __GA_ArrayDataArray__
12 #define __GA_ArrayDataArray__
13 
14 #include "GA_API.h"
15 #include "GA_Types.h"
16 #include <UT/UT_VectorTypes.h>
18 #include <UT/UT_Span.h>
19 #include <SYS/SYS_Types.h>
20 
21 class GA_Attribute;
22 class GA_Defragment;
23 class GA_LoadMap;
24 class GA_MergeMap;
25 class GA_MergeOffsetMap;
26 class GA_Range;
27 class GA_IndexMap;
28 class UT_BitArray;
29 class UT_JSONParser;
30 class UT_JSONWriter;
31 class UT_MemoryCounter;
32 template <typename T> class UT_Array;
33 template <typename T> class UT_ValArray;
34 
35 class ga_PageArrayTable;
36 
37 
38 /// @brief An array of array of numbers with various storage types.
39 ///
40 /// GA_ArrayDataArray provides a way of storing arrays of tuples of scalar
41 /// values.
42 /// The array can have various storage types from 8-bit integer to 64-bit
43 /// reals.
44 ///
46 {
47 public:
48  GA_ArrayDataArray(GA_Storage storage, int tuplesize);
49 
52 
54 
55  /// Report memory usage
56  int64 getMemoryUsage(bool inclusive) const;
57 
58  /// Count memory usage using a UT_MemoryCounter in order to count
59  /// shared memory correctly.
60  /// If inclusive is true, the size of this object is counted,
61  /// else only memory owned by this object is counted.
62  /// If this is pointed to by the calling object, inclusive should be true.
63  /// If this is contained in the calling object, inclusive should be false.
64  /// (Its memory was already counted in the size of the calling object.)
65  void countMemory(UT_MemoryCounter &counter, bool inclusive) const;
66 
67  /// Change the size of the array
68  void setArraySize(GA_Offset size);
69 
70  /// Query the size of the array
71  GA_Offset getArraySize() const { return mySize; }
72 
73  /// The maximum length of any of our sub-arrays, requries running
74  /// over the entire array
75  exint findMaximumArrayLength() const;
76 
77  /// Query the storage used for the array data.
78  GA_Storage getStorage() const;
79 
80  /// Changes the storage, copying the data to the new format.
81  void setStorage(GA_Storage newstorage);
82 
83  /// Queries the size of each tuple stored in the arrays.
84  GA_Size getTupleSize() const;
85 
86  /// Adjusts the tuple size, note this does not affect the
87  /// actual data layout!
88  void setTupleSize(GA_Size size);
89 
90  /// Empties the array, creating an empty array.
91  void clear();
92 
93  /// Empties a specific subset of the array, [off, off+num)
94  void clearOffset(GA_Offset off, GA_Size num);
95 
96  /// mergeGrowArrayAndCopy() is called to grow the data array while copying
97  /// data from the source.
98  void mergeGrowArrayAndCopy(const GA_MergeMap &map,
99  GA_AttributeOwner owner,
100  const GA_ArrayDataArray &src);
101 
102  /// Clear the particular indices to empty arrays.
103  /// @{
104  void reset(GA_Offset di);
105  void reset(const GA_Range &di);
106  /// @}
107 
108  /// Copies
109  /// @{
110  void copy(GA_Offset di, const GA_ArrayDataArray *src, GA_Offset si);
111  void copy(const GA_Range &dr, const GA_ArrayDataArray *src,
112  const GA_Range &sr);
113  /// @}
114 
115  /// Return the array size for a given offset
116  exint arraySize(GA_Offset offset) const;
117 
118  /// Read/Write individual elements
119  /// If you have tuplesize 3, the values will be multiple of 3!
120  void get(GA_Offset off, UT_Array<fpreal16> &values) const;
121  void get(GA_Offset off, UT_Array<fpreal32> &values) const;
122  void get(GA_Offset off, UT_Array<fpreal64> &values) const;
123  void get(GA_Offset off, UT_Array<uint8> &values) const;
124  void get(GA_Offset off, UT_Array<int8> &values) const;
125  void get(GA_Offset off, UT_Array<int16> &values) const;
126  void get(GA_Offset off, UT_Array<int32> &values) const;
127  void get(GA_Offset off, UT_Array<int64> &values) const;
128 
129  void append(GA_Offset off, UT_PackedArrayOfArrays<fpreal16> &values) const;
130  void append(GA_Offset off, UT_PackedArrayOfArrays<fpreal32> &values) const;
131  void append(GA_Offset off, UT_PackedArrayOfArrays<fpreal64> &values) const;
132  void append(GA_Offset off, UT_PackedArrayOfArrays<uint8> &values) const;
133  void append(GA_Offset off, UT_PackedArrayOfArrays<int8> &values) const;
134  void append(GA_Offset off, UT_PackedArrayOfArrays<int16> &values) const;
135  void append(GA_Offset off, UT_PackedArrayOfArrays<int32> &values) const;
136  void append(GA_Offset off, UT_PackedArrayOfArrays<int64> &values) const;
137 
138 #define GETBLOCKFROMINDEX(ITYPE, DTYPE) \
139  bool getBlockFromIndices(const GA_IndexMap &map, \
140  GA_Index start, GA_Size nelem, \
141  UT_Array<ITYPE> &index, \
142  UT_Array<DTYPE> &data) const;
159 #undef GETBLOCKFROMINDEX
160 
161  /// For efficiency, should already have set the length. If a resize
162  /// is forced, will convert the touched page to POINTERS
163  void set(GA_Offset off, const UT_Span<const fpreal16> &values);
164  void set(GA_Offset off, const UT_Span<const fpreal32> &values);
165  void set(GA_Offset off, const UT_Span<const fpreal64> &values);
166  void set(GA_Offset off, const UT_Span<const uint8> &values);
167  void set(GA_Offset off, const UT_Span<const int8> &values);
168  void set(GA_Offset off, const UT_Span<const int16> &values);
169  void set(GA_Offset off, const UT_Span<const int32> &values);
170  void set(GA_Offset off, const UT_Span<const int64> &values);
171 
172  /// @{
173  /// Interface for defragmentation
174  void swapRange(GA_Offset a, GA_Offset b, GA_Size n);
175  void moveRange(GA_Offset src, GA_Offset dest, GA_Size n);
176  void defragment(const GA_Defragment &defrag);
177  /// @}
178 
179  /// Save data to a JSON stream.
180  /// @section JSON-GA_DataArray JSON Schema: GA_DataArray
181  /// @code
182  /// {
183  /// "name" : "GA_ArrayDataArray",
184  /// "description" : "An array of arrays of numbers",
185  /// "type" : "array",
186  /// "items" : "number",
187  /// }
188  /// @endcode
189  /// @see @ref JSON_FileFormat
190  bool jsonSave(UT_JSONWriter &w, const GA_Range &it) const;
191 
192  /// Load from a JSON stream.
193  bool jsonLoad(UT_JSONParser &p,
194  const GA_LoadMap &map, GA_AttributeOwner owner);
195 
196  /// Save with an integer translation. This method is just like the
197  /// standard jsonSave() method. However each value is used as an index
198  /// into the integer array. The value stored in the array is written
199  /// instead of the raw value.
200  /// @code
201  /// for (GA_Iterator it(range); !it.atEnd(); ++it) {
202  /// idx = getInteger(it.getOffset());
203  /// json.write( idx < 0 || idx >= map.entries() ? -1 : map(idx) );
204  /// }
205  /// @endcode
206  bool jsonSave(UT_JSONWriter &w, const GA_Range &range,
207  const UT_IntArray *map, int defvalue=-1) const;
208 
209  // Return whether the attribute storage & size match
210  inline bool isSameType(const GA_ArrayDataArray &b) const
211  {
212  return myStorage == b.myStorage && mySize == b.mySize
213  && getTupleSize() == b.getTupleSize();
214  }
215 
216  /// Try to compress data pages
217  /// Will try to compress *all* pages overlapping the specified offset range.
218  void tryCompressAllPages(GA_Offset start_offset = GA_Offset(0),
219  GA_Offset end_offset = GA_INVALID_OFFSET);
220  /// Compresses a specific page.
221  /// Pass in the offset whose page you wish to compress, *not*
222  /// the page id.
223  void tryCompressSinglePage(GA_Offset pageoffset);
224 
225  /// Harden data pages
226  /// Will harden *all* pages overlapping the specified offset range.
227  void hardenAllPages(GA_Offset start_offset = GA_Offset(0),
228  GA_Offset end_offset = GA_INVALID_OFFSET);
229 
230  /// Remaps all numbers through the lookup table. Negative numbers
231  /// get mapped to -1. Counts the number of occurrences of each
232  /// number in the counter, which should be pre-allocated to your
233  /// maximum size.
234  /// Inclusive
235  /// count measures the *source* indices, not destination.
236  void remapAndCount(GA_Offset start_offset,
237  GA_Offset end_offset,
238  const UT_IntArray &old2new,
239  UT_IntArray &count);
240 
241 private:
242 
243 private:
244  ga_PageArrayTable *myPageTable;
245  GA_Offset mySize;
246  GA_Storage myStorage;
247 };
248 
249 #endif
250 
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:198
int int32
Definition: SYS_Types.h:39
GLenum GLint * range
Definition: glcorearb.h:1925
getFileOption("OpenEXR:storage") storage
Definition: HDK_Image.dox:276
OIIO_UTIL_API bool copy(string_view from, string_view to, std::string &err)
bool isSameType(const GA_ArrayDataArray &b) const
The merge map keeps track of information when merging details.
Definition: GA_MergeMap.h:53
int64 exint
Definition: SYS_Types.h:125
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
JSON reader class which handles parsing of JSON or bJSON files.
Definition: UT_JSONParser.h:87
#define GA_API
Definition: GA_API.h:14
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:37
float fpreal32
Definition: SYS_Types.h:200
exint GA_Size
Defines the bit width for index and offset types in GA.
Definition: GA_Types.h:236
An array of array of numbers with various storage types.
#define GA_INVALID_OFFSET
Definition: GA_Types.h:687
A range of elements in an index-map.
Definition: GA_Range.h:42
double fpreal64
Definition: SYS_Types.h:201
unsigned char uint8
Definition: SYS_Types.h:36
GA_Size GA_Offset
Definition: GA_Types.h:646
GLdouble n
Definition: glcorearb.h:2008
GLintptr offset
Definition: glcorearb.h:665
GLboolean reset
Definition: glad.h:5138
GA_Size getTupleSize() const
Queries the size of each tuple stored in the arrays.
Keeps track of offset mapping when merging index lists.
long long int64
Definition: SYS_Types.h:116
Options during loading.
Definition: GA_LoadMap.h:42
Defragmentation of IndexMaps.
Definition: GA_Defragment.h:45
signed char int8
Definition: SYS_Types.h:35
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
GA_Offset getArraySize() const
Query the size of the array.
GLsizeiptr size
Definition: glcorearb.h:664
GA_AttributeOwner
Definition: GA_Types.h:35
GLenum GLsizei GLsizei GLint * values
Definition: glcorearb.h:1602
short int16
Definition: SYS_Types.h:37
LeafData & operator=(const LeafData &)=delete
#define GETBLOCKFROMINDEX(ITYPE, DTYPE)
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
GA_Storage
Definition: GA_Types.h:51
GLint GLsizei count
Definition: glcorearb.h:405
GLenum src
Definition: glcorearb.h:1793