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<int16> &values) const;
118  void get(GA_Offset off, UT_Array<int32> &values) const;
119  void get(GA_Offset off, UT_Array<int64> &values) const;
120 
121  void append(GA_Offset off, UT_PackedArrayOfArrays<fpreal16> &values) const;
122  void append(GA_Offset off, UT_PackedArrayOfArrays<fpreal32> &values) const;
123  void append(GA_Offset off, UT_PackedArrayOfArrays<fpreal64> &values) const;
124  void append(GA_Offset off, UT_PackedArrayOfArrays<int16> &values) const;
125  void append(GA_Offset off, UT_PackedArrayOfArrays<int32> &values) const;
126  void append(GA_Offset off, UT_PackedArrayOfArrays<int64> &values) const;
127 
128 #define GETBLOCKFROMINDEX(ITYPE, DTYPE) \
129  bool getBlockFromIndices(const GA_IndexMap &map, \
130  GA_Index start, GA_Size nelem, \
131  UT_Array<ITYPE> &index, \
132  UT_Array<DTYPE> &data) const;
145 #undef GETBLOCKFROMINDEX
146 
147  /// For efficiency, should already have set the length. If a resize
148  /// is forced, will convert the touched page to POINTERS
149  void set(GA_Offset off, const UT_Array<fpreal16> &values);
150  void set(GA_Offset off, const UT_Array<fpreal32> &values);
151  void set(GA_Offset off, const UT_Array<fpreal64> &values);
152  void set(GA_Offset off, const UT_Array<int16> &values);
153  void set(GA_Offset off, const UT_Array<int32> &values);
154  void set(GA_Offset off, const UT_Array<int64> &values);
155 
156  /// @{
157  /// Interface for defragmentation
158  void swapRange(GA_Offset a, GA_Offset b, GA_Size n);
159  void moveRange(GA_Offset src, GA_Offset dest, GA_Size n);
160  void defragment(const GA_Defragment &defrag);
161  /// @}
162 
163  /// Save data to a JSON stream.
164  /// @section JSON-GA_DataArray JSON Schema: GA_DataArray
165  /// @code
166  /// {
167  /// "name" : "GA_ArrayDataArray",
168  /// "description" : "An array of arrays of numbers",
169  /// "type" : "array",
170  /// "items" : "number",
171  /// }
172  /// @endcode
173  /// @see @ref JSON_FileFormat
174  bool jsonSave(UT_JSONWriter &w, const GA_Range &it) const;
175 
176  /// Load from a JSON stream.
177  bool jsonLoad(UT_JSONParser &p,
178  const GA_LoadMap &map, GA_AttributeOwner owner);
179 
180  /// Save with an integer translation. This method is just like the
181  /// standard jsonSave() method. However each value is used as an index
182  /// into the integer array. The value stored in the array is written
183  /// instead of the raw value.
184  /// @code
185  /// for (GA_Iterator it(range); !it.atEnd(); ++it) {
186  /// idx = getInteger(it.getOffset());
187  /// json.write( idx < 0 || idx >= map.entries() ? -1 : map(idx) );
188  /// }
189  /// @endcode
190  bool jsonSave(UT_JSONWriter &w, const GA_Range &range,
191  const UT_IntArray *map, int defvalue=-1) const;
192 
193  // Return whether the attribute storage & size match
194  inline bool isSameType(const GA_ArrayDataArray &b) const
195  {
196  return myStorage == b.myStorage && mySize == b.mySize
197  && getTupleSize() == b.getTupleSize();
198  }
199 
200  /// Try to compress data pages
201  /// Will try to compress *all* pages overlapping the specified offset range.
202  void tryCompressAllPages(GA_Offset start_offset = GA_Offset(0),
203  GA_Offset end_offset = GA_INVALID_OFFSET);
204  /// Compresses a specific page.
205  /// Pass in the offset whose page you wish to compress, *not*
206  /// the page id.
207  void tryCompressSinglePage(GA_Offset pageoffset);
208 
209  /// Harden data pages
210  /// Will harden *all* pages overlapping the specified offset range.
211  void hardenAllPages(GA_Offset start_offset = GA_Offset(0),
212  GA_Offset end_offset = GA_INVALID_OFFSET);
213 
214  /// Remaps all numbers through the lookup table. Negative numbers
215  /// get mapped to -1. Counts the number of occurrences of each
216  /// number in the counter, which should be pre-allocated to your
217  /// maximum size.
218  /// Inclusive
219  /// count measures the *source* indices, not destination.
220  void remapAndCount(GA_Offset start_offset,
221  GA_Offset end_offset,
222  const UT_IntArray &old2new,
223  UT_IntArray &count);
224 
225 private:
226 
227 private:
228  ga_PageArrayTable *myPageTable;
229  GA_Offset mySize;
230  GA_Storage myStorage;
231 };
232 
233 #endif
234 
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:190
GLsizeiptr size
Definition: glew.h:1681
GLenum src
Definition: glew.h:2410
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
JSON reader class which handles parsing of JSON or bJSON files.
Definition: UT_JSONParser.h:75
#define GA_API
Definition: GA_API.h:12
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:32
GLboolean reset
Definition: glew.h:4959
exint GA_Size
Defines the bit width for index and offset types in GA.
Definition: GA_Types.h:231
An array of array of numbers with various storage types.
#define GA_INVALID_OFFSET
Definition: GA_Types.h:674
A range of elements in an index-map.
Definition: GA_Range.h:42
GA_Size GA_Offset
Definition: GA_Types.h:637
long long int64
Definition: SYS_Types.h:111
GA_Size getTupleSize() const
Queries the size of each tuple stored in the arrays.
int64 exint
Definition: SYS_Types.h:120
double fpreal64
Definition: SYS_Types.h:196
GLubyte GLubyte GLubyte GLubyte w
Definition: glew.h:1890
Keeps track of offset mapping when merging index lists.
GLsizei n
Definition: glew.h:4040
Options during loading.
Definition: GA_LoadMap.h:42
Defragmentation of IndexMaps.
Definition: GA_Defragment.h:45
int int32
Definition: SYS_Types.h:39
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
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
short int16
Definition: SYS_Types.h:37
float fpreal32
Definition: SYS_Types.h:195
GA_Storage
Definition: GA_Types.h:49
GLintptr offset
Definition: glew.h:1682