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