HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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<fpreal32> &values) const;
115  void get(GA_Offset off, UT_Array<fpreal64> &values) const;
116  void get(GA_Offset off, UT_Array<int32> &values) const;
117  void get(GA_Offset off, UT_Array<int64> &values) const;
118 
119  void append(GA_Offset off, UT_PackedArrayOfArrays<fpreal32> &values) const;
120  void append(GA_Offset off, UT_PackedArrayOfArrays<fpreal64> &values) const;
121  void append(GA_Offset off, UT_PackedArrayOfArrays<int32> &values) const;
122  void append(GA_Offset off, UT_PackedArrayOfArrays<int64> &values) const;
123 
124 #define GETBLOCKFROMINDEX(ITYPE, DTYPE) \
125  void getBlockFromIndices(const GA_IndexMap &map, \
126  GA_Index start, GA_Size nelem, \
127  UT_Array<ITYPE> &index, \
128  UT_Array<DTYPE> &data) const;
137 #undef GETBLOCKFROMINDEX
138 
139  /// For efficiency, should already have set the length. If a resize
140  /// is forced, will convert the touched page to POINTERS
141  void set(GA_Offset off, const UT_Array<fpreal32> &values);
142  void set(GA_Offset off, const UT_Array<fpreal64> &values);
143  void set(GA_Offset off, const UT_Array<int32> &values);
144  void set(GA_Offset off, const UT_Array<int64> &values);
145 
146  /// @{
147  /// Interface for defragmentation
148  void swapRange(GA_Offset a, GA_Offset b, GA_Size n);
149  void moveRange(GA_Offset src, GA_Offset dest, GA_Size n);
150  void defragment(const GA_Defragment &defrag);
151  /// @}
152 
153  /// Save data to a JSON stream.
154  /// @section JSON-GA_DataArray JSON Schema: GA_DataArray
155  /// @code
156  /// {
157  /// "name" : "GA_ArrayDataArray",
158  /// "description" : "An array of arrays of numbers",
159  /// "type" : "array",
160  /// "items" : "number",
161  /// }
162  /// @endcode
163  /// @see @ref JSON_FileFormat
164  bool jsonSave(UT_JSONWriter &w, const GA_Range &it) const;
165 
166  /// Load from a JSON stream.
167  bool jsonLoad(UT_JSONParser &p,
168  const GA_LoadMap &map, GA_AttributeOwner owner);
169 
170  /// Save with an integer translation. This method is just like the
171  /// standard jsonSave() method. However each value is used as an index
172  /// into the integer array. The value stored in the array is written
173  /// instead of the raw value.
174  /// @code
175  /// for (GA_Iterator it(range); !it.atEnd(); ++it) {
176  /// idx = getInteger(it.getOffset());
177  /// json.write( idx < 0 || idx >= map.entries() ? -1 : map(idx) );
178  /// }
179  /// @endcode
180  bool jsonSave(UT_JSONWriter &w, const GA_Range &range,
181  const UT_IntArray *map, int defvalue=-1) const;
182 
183  // Return whether the attribute storage & size match
184  inline bool isSameType(const GA_ArrayDataArray &b) const
185  {
186  return myStorage == b.myStorage && mySize == b.mySize
187  && getTupleSize() == b.getTupleSize();
188  }
189 
190  /// Try to compress data pages
191  /// Will try to compress *all* pages overlapping the specified offset range.
192  void tryCompressAllPages(GA_Offset start_offset = GA_Offset(0),
193  GA_Offset end_offset = GA_INVALID_OFFSET);
194  /// Compresses a specific page.
195  /// Pass in the offset whose page you wish to compress, *not*
196  /// the page id.
197  void tryCompressSinglePage(GA_Offset pageoffset);
198 
199  /// Harden data pages
200  /// Will harden *all* pages overlapping the specified offset range.
201  void hardenAllPages(GA_Offset start_offset = GA_Offset(0),
202  GA_Offset end_offset = GA_INVALID_OFFSET);
203 
204  /// Remaps all numbers through the lookup table. Negative numbers
205  /// get mapped to -1. Counts the number of occurrences of each
206  /// number in the counter, which should be pre-allocated to your
207  /// maximum size.
208  /// Inclusive
209  /// count measures the *source* indices, not destination.
210  void remapAndCount(GA_Offset start_offset,
211  GA_Offset end_offset,
212  const UT_IntArray &old2new,
213  UT_IntArray &count);
214 
215 private:
216 
217 private:
218  ga_PageArrayTable *myPageTable;
219  GA_Offset mySize;
220  GA_Storage myStorage;
221 };
222 
223 #endif
224 
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
GLenum GLint * range
Definition: glcorearb.h:1924
bool isSameType(const GA_ArrayDataArray &b) const
The merge map keeps track of information when merging details.
Definition: GA_MergeMap.h:53
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1221
JSON reader class which handles parsing of JSON or bJSON files.
Definition: UT_JSONParser.h:72
#define GA_API
Definition: GA_API.h:12
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:32
exint GA_Size
Defines the bit width for index and offset types in GA.
Definition: GA_Types.h:211
GLsizeiptr size
Definition: glcorearb.h:663
An array of array of numbers with various storage types.
#define GA_INVALID_OFFSET
Definition: GA_Types.h:654
A range of elements in an index-map.
Definition: GA_Range.h:42
GA_Size GA_Offset
Definition: GA_Types.h:617
long long int64
Definition: SYS_Types.h:100
GLdouble n
Definition: glcorearb.h:2007
GA_Size getTupleSize() const
Queries the size of each tuple stored in the arrays.
int64 exint
Definition: SYS_Types.h:109
double fpreal64
Definition: SYS_Types.h:185
GLintptr offset
Definition: glcorearb.h:664
Keeps track of offset mapping when merging index lists.
Options during loading.
Definition: GA_LoadMap.h:42
GLenum GLsizei GLsizei GLint * values
Definition: glcorearb.h:1601
Defragmentation of IndexMaps.
Definition: GA_Defragment.h:45
int int32
Definition: SYS_Types.h:28
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1221
GLint GLsizei count
Definition: glcorearb.h:404
GA_Offset getArraySize() const
Query the size of the array.
GA_AttributeOwner
Definition: GA_Types.h:33
#define GETBLOCKFROMINDEX(ITYPE, DTYPE)
getOption("OpenEXR.storage") storage
Definition: HDK_Image.dox:276
png_infop png_uint_32 int num
Definition: png.h:2158
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:856
float fpreal32
Definition: SYS_Types.h:184
GA_Storage
Definition: GA_Types.h:48
GLenum src
Definition: glcorearb.h:1792