HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GT_DataArray.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: GT_DataArray.h ( GT Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __GT_DataArray__
12 #define __GT_DataArray__
13 
14 #include "GT_API.h"
15 #include "GT_Types.h"
16 #include "GT_Handles.h"
17 #include <SYS/SYS_Hash.h>
18 #include <UT/UT_Assert.h>
19 #include <UT/UT_ParallelUtil.h>
20 #include <UT/UT_IntrusivePtr.h>
21 #include <UT/UT_Vector3.h>
22 #include <UT/UT_Vector4.h>
23 #include <UT/UT_Matrix3.h>
24 #include <UT/UT_Matrix4.h>
25 #include <UT/UT_BoundingBox.h>
26 #include <UT/UT_StackBuffer.h>
27 
28 class UT_StringArray;
29 class UT_JSONWriter;
31 
34 
35 /// @brief Abstract data class for an array of float, int or string data
36 ///
37 /// This is an abstract class. The data does not have to be owned by this
38 /// array. The data can be generated on the fly by the class. Or the data
39 /// might be flat numeric data.
41  : public UT_IntrusiveRefCounter<GT_DataArray>
42 {
43 public:
44  GT_DataArray();
46  virtual ~GT_DataArray();
47 
48  virtual const char *className() const = 0;
49 
50  /// Create a "hardened" version of the array
51  virtual GT_DataArrayHandle harden() const;
52 
53  /// Type of data stored in the array
54  virtual GT_Storage getStorage() const = 0;
55 
56  /// Number of entries in the array
57  virtual GT_Size entries() const = 0;
58 
59  /// Total number of array elements if this is an array attribute.
60  /// Sum of each entry's array length, as each entry's array length can vary.
61  virtual GT_Size getTotalArrayEntries() const { return 0; }
62 
63  /// Number of elements for each array element
64  virtual GT_Size getTupleSize() const = 0;
65 
66  /// Get an approximation of the memory usage. Since data is shared, this
67  /// may be an over-estimation of the memory used.
68  virtual int64 getMemoryUsage() const = 0;
69 
70  /// Return "type" information for the data. This defaults to GT_TYPE_NONE
71  virtual GT_Type getTypeInfo() const;
72 
73  /// Returns "true" if each entry is an array.
74  virtual bool hasArrayEntries() const { return false; }
75 
76  /// Return "true" if there's pointer aliasing
77  virtual bool getPointerAliasing(const void *data) const
78  { return false; }
79 
80  /// Data array is valid; can be sampled from.
81  virtual bool isValid() const { return true; }
82 
83  /// If the array has backing storage, this method can be used to access the
84  /// storage. The backing storage must be a flat array of interleaved
85  /// values of the given pod type. For example, if the array has 35 entries
86  /// of fpreal32 color (RGB) data, the pointer returned should be mapped to
87  /// an array that's (35*3) fpreal32 values with the first three values
88  /// representing the RGB values for the first item in the array.
89  virtual const void *getBackingData() const { return nullptr; }
90 
91  /// Return the "data id" associated with the data. The data ID will be
92  /// incremented if the data is modified. An ID less than 0 indicates that
93  /// the data ID should always be considered unique and will never be the
94  /// same across evaluations. This data ID can be used to detect whether
95  /// attribute data has changed in similar tesselations.
96  virtual int64 getDataId() const { return myDataId; }
97 
98  /// @{
99  /// Get data out of the data array
100  virtual uint8 getU8(GT_Offset offset, int idx=0) const = 0;
101  virtual int8 getI8(GT_Offset offset, int idx=0) const
102  { return getI32(offset, idx); }
103  virtual int16 getI16(GT_Offset offset, int idx=0) const
104  { return getI32(offset, idx); }
105  virtual int32 getI32(GT_Offset offset, int idx=0) const = 0;
106  virtual int64 getI64(GT_Offset offset, int idx=0) const
107  { return getI32(offset, idx); }
108 
109  virtual fpreal16 getF16(GT_Offset offset, int idx=0) const
110  { return getF32(offset, idx); }
111  virtual fpreal32 getF32(GT_Offset offset, int idx=0) const = 0;
112  virtual fpreal64 getF64(GT_Offset offset, int idx=0) const
113  { return getF32(offset, idx); }
114 
115  virtual GT_String getS(GT_Offset offset, int idx=0) const = 0;
116 
117  virtual bool getSA(UT_StringArray &a, GT_Offset offset) const
118  { return false; }
120  { return false; }
122  { return false; }
124  { return false; }
126  { return false; }
128  { return false; }
130  { return false; }
131  /// @}
132 
133  /// @{
134  /// Get raw access to the data buffer (or fill the data array passed in)
135  /// If the array is unable to provide a raw pointer to the underlying data,
136  /// the GT_DataArrayHandle will be allocated to store the data, and it's
137  /// raw data will be returned.
138  ///
139  /// This means that the data returned will be destructed when the buffer is
140  /// destructed. Beware.
141  virtual const uint8 *getU8Array(GT_DataArrayHandle &buffer) const;
142  virtual const int8 *getI8Array(GT_DataArrayHandle &buffer) const;
143  virtual const int16 *getI16Array(GT_DataArrayHandle &buffer) const;
144  virtual const int32 *getI32Array(GT_DataArrayHandle &buffer) const;
145  virtual const int64 *getI64Array(GT_DataArrayHandle &buffer) const;
146  virtual const fpreal16 *getF16Array(GT_DataArrayHandle &buffer) const;
147  virtual const fpreal32 *getF32Array(GT_DataArrayHandle &buffer) const;
148  virtual const fpreal64 *getF64Array(GT_DataArrayHandle &buffer) const;
149  const fpreal *getRealArray(GT_DataArrayHandle &buffer) const;
150  /// @}
151 
152  /// Template-friendly version of getU8Array() and related methods.
153  template <typename T>
154  const T *getArray(GT_DataArrayHandle &buffer) const;
155 
156  /// When an array of strings is based on an indexed list of strings, this
157  /// method can be used to query the maximum number of indices. If the
158  /// strings are not indexed, the method should return -1.
159  virtual GT_Size getStringIndexCount() const = 0;
160 
161  /// When an array of strings is based on an indexed list of strings, this
162  /// method can be used to query each element's index. If the strings are
163  /// not indexed, the method should return -1.
164  virtual GT_Offset getStringIndex(GT_Offset offset, int idx=0) const = 0;
165 
166  /// When an array of strings is based on an indexed list of strings, this
167  /// method can be used to extract all the strings and their corresponding
168  /// indicies. It's possible that the indices may not be contiguous or may
169  /// even be out of order.
170  virtual void getIndexedStrings(UT_StringArray &strings,
171  UT_IntArray &indices) const = 0;
172  /// When an array of strings is based on an indexed list of strings, this
173  /// method can be used to extract all the strings. If an index is not
174  /// used, the string array may contain a NULL pointer. When you call @c
175  /// getStringIndex(), you can look up directly into the @c strings array
176  /// returned here.
177  ///
178  /// Note, if the strings are not stored as an indexed list, this method
179  /// will return an empty array.
180  virtual void getStrings(UT_StringArray &strings) const;
181 
182  /// Fill an array of std::string with the strings corresponding to each
183  /// entry. There must be @c entries() strings in the array. Only a single
184  /// tuple index is extracted.
185  void fillStrings(std::string *strings,
186  int tuple_idx=0) const;
187 
188  /// Fill array of strings from start to length number of entries.
189  /// This should only be called for an array attribute of strings.
190  /// The @c data will contain a flattened array of strings, with
191  /// the @c sizes array containing the array length per entry.
194  GT_Offset start, GT_Size length) const {}
195 
196  /// @{
197  /// Extract data out of the array in a template friendly fashion.
198  /// Unlike the @c get() methods, these methods will @b always copy data
199  /// into the buffers. If the @c size is 0, the tuple size will be used.
200  /// The data buffer must be big enough.
201  ///
202  /// If the size given is larger than getTupleSize(), only the first
203  /// @c getTupleSize() elements will be filled out (leaving the others
204  /// untouched).
205  void import(GT_Offset idx, int8 *data, GT_Size size=0) const
206  { doImport(idx, data, size); }
207  void import(GT_Offset idx, int16 *data, GT_Size size=0) const
208  { doImport(idx, data, size); }
209  void import(GT_Offset idx, int32 *data, GT_Size size=0) const
210  { doImport(idx, data, size); }
211  void import(GT_Offset idx, int64 *data, GT_Size size=0) const
212  { doImport(idx, data, size); }
213  void import(GT_Offset idx, fpreal16 *data, GT_Size size=0) const
214  { doImport(idx, data, size); }
215  void import(GT_Offset idx, fpreal32 *data, GT_Size size=0) const
216  { doImport(idx, data, size); }
217  void import(GT_Offset idx, fpreal64 *data, GT_Size size=0) const
218  { doImport(idx, data, size); }
219  void import(GT_Offset idx, UT_ValArray<fpreal16> &data) const
220  { doImportArray(idx, data); }
221  void import(GT_Offset idx, UT_ValArray<fpreal32> &data) const
222  { doImportArray(idx, data); }
223  void import(GT_Offset idx, UT_ValArray<fpreal64> &data) const
224  { doImportArray(idx, data); }
225  void import(GT_Offset idx, UT_ValArray<int16> &data) const
226  { doImportArray(idx, data); }
227  void import(GT_Offset idx, UT_ValArray<int32> &data) const
228  { doImportArray(idx, data); }
229  void import(GT_Offset idx, UT_ValArray<int64> &data) const
230  { doImportArray(idx, data); }
231  void import(GT_Offset idx, UT_StringArray &data) const
232  { getSA(data, idx); }
233  void import(GT_Offset idx, uint8 *data, GT_Size size=0,
234  fpreal black=0, fpreal white=1) const
235  {
236  if (GTisFloat(getStorage()))
237  doImportQuantized(idx, data, size, black, white);
238  else
239  doImport(idx, data, size);
240  }
241  /// @}
242 
243  /// @{
244  /// Extract data for the entire array into a flat data array.
245  /// By default, this is implemented as: @code
246  /// if (tuple_size <= 0)
247  /// tuple_size = getTupleSize();
248  /// for (GT_Offset idx = 0; idx < length; ++idx, data += tuple_size)
249  /// import(idx+start, data, tuple_size);
250  /// @endcode
251  /// Obviously, the @c data array should be big enough to hold @c
252  /// length*tuple_size elements.
253  ///
254  /// The tuple size (@c tsize) specifies how many elements to extract from
255  /// each element of this array. The @c stride specifies how many items to
256  /// skip over for each element. With a stride of -1, the stride will be
257  /// set to the @c tsize. Otherwise the stride will be set to the maximum
258  /// of @c tsize and @c stride.
259  ///
260  /// The stride can be useful when trying to interleave data. For example:
261  /// @code
262  /// float uvbuf[ucoord->entries()*2];
263  /// ucoord->fillArray(&uvbuf[0], 0, ucoord->entries(), 1, 2);
264  /// vcoord->fillArray(&uvbuf[1], 0, vcoord->entries(), 1, 2);
265  /// @endcode
267  int tsize, int stride=-1) const
268  { doFillArray(data, start, length, tsize, stride); }
270  int tsize, int stride=-1) const
271  { doFillArray(data, start, length, tsize, stride); }
273  int tsize, int stride=-1) const
274  { doFillArray(data, start, length, tsize, stride); }
276  int tsize, int stride=-1) const
277  { doFillArray(data, start, length, tsize, stride); }
279  int tsize, int stride=-1) const
280  { doFillArray(data, start, length, tsize, stride); }
282  int tsize, int stride=-1) const
283  { doFillArray(data, start, length, tsize, stride); }
285  int tsize, int stride=-1) const
286  { doFillArray(data, start, length, tsize, stride); }
289  int tsize, int stride=-1,
290  fpreal black=0, fpreal white=1) const
291  {
292  if(GTisFloat(getStorage()))
293  doFillQuantizedArray(data, start, length, tsize,
294  stride, black, white);
295  else
296  doFillArray(data, start, length, tsize, stride);
297  }
298 
300  UT_BoundingBoxF &bbox, int tsize, int stride=-1)
301  {
302  UT_ASSERT_P(tsize==3);
303  doFillVec3BBox(dest, start, length, bbox,
304  tsize, stride);
305  }
307  UT_BoundingBoxD &bbox, int tsize, int stride=-1)
308  {
309  UT_ASSERT_P(tsize==3);
310  doFillVec3BBox(dest, start, length, bbox,
311  tsize, stride);
312  }
313  /// @}
314 
315  /// @{
316  /// Extract data for an array attribute into a flat data array.
317  /// Since each entry in an array attribute varies in terms of array size,
318  /// the sizes of each entry will be stored in the @c sizes array.
321  { doFillArrayAttr(data, sizes, start, length); }
324  { doFillArrayAttr(data, sizes, start, length); }
327  { doFillArrayAttr(data, sizes, start, length); }
330  { doFillArrayAttr(data, sizes, start, length); }
333  { doFillArrayAttr(data, sizes, start, length); }
336  { doFillArrayAttr(data, sizes, start, length); }
337  /// @}
338 
339  virtual void extendedFillArray(uint8 *data,
341  int tsize, int nrepeats,
342  int stride=-1,
343  fpreal black=0, fpreal white=1) const
344  {
345  doExtendedQuantizedFill(data, start, length, tsize,
346  nrepeats, stride, black, white);
347  }
348 
349  /// @{
350  /// Extract an element, but making @c nrepeats copies. The buffer
351  /// should be able to contain @c length*nrepeats*tsize elements
352  /// When filling an RGB color, with a repeat count of 4, the resulting
353  /// buffer will look like: @code
354  /// [ RGB0 RGB0 RGB0 RGB0 RGB1 RGB1 RGB1 RGB1 ... ]
355  /// @endcode
356  /// With a repeat count of 1, this is equivalent to @c fillArray()
358  int tsize, int nrepeats, int stride=-1) const
359  {
360  t_extendedFill(data, start, length, tsize,
361  nrepeats, stride);
362  }
364  int tsize, int nrepeats, int stride=-1) const
365  {
366  t_extendedFill(data, start, length, tsize,
367  nrepeats, stride);
368  }
370  int tsize, int nrepeats, int stride=-1) const
371  {
372  t_extendedFill(data, start, length, tsize,
373  nrepeats, stride);
374  }
376  int tsize, int nrepeats, int stride=-1) const
377  {
378  t_extendedFill(data, start, length, tsize,
379  nrepeats, stride);
380  }
382  int tsize, int nrepeats, int stride=-1) const
383  {
384  t_extendedFill(data, start, length, tsize,
385  nrepeats, stride);
386  }
388  int tsize, int nrepeats, int stride=-1) const
389  {
390  t_extendedFill(data, start, length, tsize,
391  nrepeats, stride);
392  }
394  int tsize, int nrepeats, int stride=-1) const
395  {
396  t_extendedFill(data, start, length, tsize,
397  nrepeats, stride);
398  }
400  int tsize, int nrepeats, int stride=-1) const
401  {
402  t_extendedFill(data, start, length, tsize,
403  nrepeats, stride);
404  }
405  /// @}
406 
407  /// @{
408  /// Copy the data out of the array as a tuple of @em size entries
409  /// The data may be copied, or the array may return a pointer to raw data.
410  /// That is, the sub-class may @b not copy the data into the storage.
411  virtual const uint8 *get(GT_Offset i, uint8 *store, int sz) const;
412  virtual const int8 *get(GT_Offset i, int8 *store, int sz) const;
413  virtual const int16 *get(GT_Offset i, int16 *store, int sz) const;
414  virtual const int32 *get(GT_Offset i, int32 *store, int sz) const;
415  virtual const int64 *get(GT_Offset i, int64 *store, int sz) const;
416  virtual const fpreal16 *get(GT_Offset i, fpreal16 *store, int z) const;
417  virtual const fpreal32 *get(GT_Offset i, fpreal32 *store, int z) const;
418  virtual const fpreal64 *get(GT_Offset i, fpreal64 *store, int z) const;
419  /// @}
420 
421  /// @{
422  /// Get the range of values in the array
423  virtual void getRange(exint &lo, exint &hi, int tuple_idx=0) const;
424  virtual void getRange(fpreal &lo, fpreal &hi, int tidx=0) const;
425  /// @}
426 
427  /// Compare whether two data arrays are equal.
428  virtual bool isEqual(const GT_DataArray &src) const;
429 
430  /// @{
431  /// Compute a hash of the data in the array. The base class hash is computed
432  /// @code
433  /// SYS_HashType hash = 0;
434  /// for (i = begin; i < end; ++i) {
435  /// import(i, tmp, getTupleSize());
436  /// for (t = 0; t < getTupleSize(); t++)
437  /// SYShashCombine(hash, hashNumeric(tmp[t]));
438  /// }
439  /// @endcode
440  /// Where @c hashNumeric returns the value for integer types. Real data is
441  /// cast to the corresponding unsigned integer values. For example, fpreal16 @code
442  /// void hashNumeric(SYS_HashType &hash, fpreal16 v) {
443  /// SYShashCombine(hash, *(const uint16 *)(&v));
444  /// }
445  /// void hashNumeric(SYS_HashType &hash, fpreal32 v) {
446  /// SYShashCombine(hash, *(const uint32 *)(&v));
447  /// }
448  /// @endcode
449  SYS_HashType hash() const { return hashRange(0, entries()); }
450  virtual SYS_HashType hashRange(exint begin, exint end) const;
451  /// @}
452 
453  /// Enlarge a bounding box with values of this 3-tuple array
455  {
456  // Initialize min/max
457  for (int i = 0, n = getTupleSize(); i < n; ++i)
458  {
459  min[i] = SYS_FP64_MAX;
460  max[i] = -SYS_FP64_MAX;
461  }
462  if (getStorage() == GT_STORE_STRING)
463  return false;
464  if (!entries())
465  return true;
466  return computeMinMax(min, max);
467  }
469  {
470  int tsize = getTupleSize();
471  UT_StackBuffer<fpreal64> min(tsize), max(tsize);
472  getMinMax(min, max);
473  b.enlargeBounds(min[0], min[1], min[2]);
474  b.enlargeBounds(max[0], max[1], max[2]);
475  return true;
476  }
477 
478  /// Test to see whether the data array requires int32 or int64 indexing.
479  GT_Storage checkIndexing(GT_IndexingMode mode) const;
480 
481  /// Quick & dirty test to see if a size is bigger than a 32 bit int
482  static bool isBigInteger(GT_Size size)
483  { return size >= (((int64)1) << 31); }
484 
485  /// For debugging, print values to stdout
486  void dumpValues(const char *msg=NULL) const;
487 
488  /// Save array to a JSON stream. The 'flat' determines how to output
489  /// arrays with a tuple size greater than 1. If 'flat' is true, the
490  /// output will be an uninterrupted stream of values. If 'flat' is
491  /// false, then the output will look something like [[1,2,3],[4,5,6], ... ]
492  bool save(UT_JSONWriter &w, bool flat = true) const;
493 
494  /// @{
495  /// For memory tracking, we override the new/delete operators
496  static void *operator new(size_t size);
497  static void *operator new(size_t size, void *p);
498  static void operator delete(void *p, size_t size);
499  /// @}
500 
501  /// Forcibly set the data id for the array. You take responsibility for
502  /// all artifacts and crashes if you call this indiscriminately.
503  void copyDataId(const GT_DataArray &src)
504  { setDataId(src.getDataId()); }
505 
506  /// Set the data id - This is used by geometry arrays to copy over the data
507  /// id from GA. As above, you take responsibility for all artifacts and
508  /// crashes if you set this incorrectly. Do not set this if you don't
509  /// know how data IDs work.
510  void setDataId(int64 id) { myDataId = id; }
511 
512  /// Update cached data, in case the underlying attribute changed.
513  virtual void updateGeoDetail(const GU_ConstDetailHandle &dtl,
514  const char *attrib_name,
515  GT_Owner attrib_owner,
516  const int expected_size) {}
517 
518 protected:
519  /// Compute the min & max values for an array. This fails for strings
521  {
522  public:
524  : myArray(array)
525  , myTupleSize(array.getTupleSize())
526  {
527  initBuffers();
528  for (int j = 0; j < myTupleSize; ++j)
529  {
530  myMin[j] = SYS_FP64_MAX;
531  myMax[j] = -SYS_FP64_MAX;
532  }
533  }
535  : myArray(src.myArray)
536  , myTupleSize(src.myTupleSize)
537  {
538  initBuffers();
539  std::copy(src.myMin, src.myMin+myTupleSize, myMin);
540  std::copy(src.myMax, src.myMax+myTupleSize, myMax);
541  }
543  {
544  if (myMin != myMinBuffer)
545  {
546  delete [] myMin;
547  delete [] myMax;
548  delete [] myPos;
549  }
550  }
552  {
553  for (GT_Size i = range.begin(), n = range.end(); i < n; ++i)
554  {
555  myArray.import(i, myPos, myTupleSize);
556  for (int j = 0; j < myTupleSize; ++j)
557  {
558  myMin[j] = SYSmin(myMin[j], myPos[j]);
559  myMax[j] = SYSmax(myMax[j], myPos[j]);
560  }
561  }
562  }
564  {
565  for (int j = 0; j < myTupleSize; ++j)
566  {
567  min[j] = SYSmin(min[j], myMin[j]);
568  max[j] = SYSmax(max[j], myMax[j]);
569  }
570  }
571  void join(const minMaxTask &src)
572  {
573  for (int j = 0; j < myTupleSize; ++j)
574  {
575  myMin[j] = SYSmin(myMin[j], src.myMin[j]);
576  myMax[j] = SYSmax(myMax[j], src.myMax[j]);
577  }
578  }
579  private:
580  void initBuffers()
581  {
582  if (myTupleSize > 16)
583  {
584  myMin = new fpreal64[myTupleSize];
585  myMax = new fpreal64[myTupleSize];
586  myPos = new fpreal64[myTupleSize];
587  }
588  else
589  {
590  myMin = myMinBuffer;
591  myMax = myMaxBuffer;
592  myPos = myPosBuffer;
593  }
594  }
595  const GT_DataArray &myArray;
596  fpreal64 *myMin;
597  fpreal64 *myMax;
598  fpreal64 *myPos;
599  fpreal64 myMinBuffer[16];
600  fpreal64 myMaxBuffer[16];
601  fpreal64 myPosBuffer[16];
602  int myTupleSize;
603  };
604  virtual bool computeMinMax(fpreal64 *min, fpreal64 *max) const
605  {
606  minMaxTask task(*this);
608  task.getResult(min, max);
609  return true;
610  }
611  /// Ensure the size is set properly when performing an import. If the size
612  /// isn't specified, we use the array's tuple size, otherwise we make sure
613  /// to clamp the tuple size.
616  {
617  return size == 0 ? tuple_size : SYSmin(size, tuple_size);
618  }
619 
620  /// @{
621  /// Virtual implementation for inline methods.
622  /// Note that @c doImport is for tuple data, while @c doImportArray
623  /// is for tuple array data.
624  virtual void doImport(GT_Offset idx, uint8 *data, GT_Size size) const;
625  virtual void doImport(GT_Offset idx, int8 *data, GT_Size size) const;
626  virtual void doImport(GT_Offset idx, int16 *data, GT_Size size) const;
627  virtual void doImport(GT_Offset idx, int32 *data, GT_Size size) const;
628  virtual void doImport(GT_Offset idx, int64 *data, GT_Size size) const;
629  virtual void doImport(GT_Offset idx, fpreal16 *data, GT_Size size) const;
630  virtual void doImport(GT_Offset idx, fpreal32 *data, GT_Size size) const;
631  virtual void doImport(GT_Offset idx, fpreal64 *data, GT_Size size) const;
632  virtual void doImportArray(GT_Offset idx, UT_ValArray<fpreal16> &data) const;
633  virtual void doImportArray(GT_Offset idx, UT_ValArray<fpreal32> &data) const;
634  virtual void doImportArray(GT_Offset idx, UT_ValArray<fpreal64> &data) const;
635  virtual void doImportArray(GT_Offset idx, UT_ValArray<int16> &data) const;
636  virtual void doImportArray(GT_Offset idx, UT_ValArray<int32> &data) const;
637  virtual void doImportArray(GT_Offset idx, UT_ValArray<int64> &data) const;
638  virtual void doImportQuantized(GT_Offset idx, uint8 *data, GT_Size size,
639  fpreal black, fpreal white) const;
640 
642  int tuple_size, int stride) const
643  { t_extendedFill(data, start, length, tuple_size, 1, stride); }
644 
646  int tuple_size, int stride) const
647  { t_extendedFill(data, start, length, tuple_size, 1, stride); }
649  int tuple_size, int stride) const
650  { t_extendedFill(data, start, length, tuple_size, 1, stride); }
652  int tuple_size, int stride) const
653  { t_extendedFill(data, start, length, tuple_size, 1, stride); }
655  int tuple_size, int stride) const
656  { t_extendedFill(data, start, length, tuple_size, 1, stride); }
658  int tuple_size, int stride) const
659  { t_extendedFill(data, start, length, tuple_size, 1, stride); }
661  int tuple_size, int stride) const
662  { t_extendedFill(data, start, length, tuple_size, 1, stride); }
664  int tuple_size, int stride) const
665  { t_extendedFill(data, start, length, tuple_size, 1, stride); }
667  GT_Offset start, GT_Size length) const
668  { t_extendedFillArray(data, sizes, start, length); }
670  GT_Offset start, GT_Size length) const
671  { t_extendedFillArray(data, sizes, start, length); }
673  GT_Offset start, GT_Size length) const
674  { t_extendedFillArray(data, sizes, start, length); }
676  GT_Offset start, GT_Size length) const
677  { t_extendedFillArray(data, sizes, start, length); }
679  GT_Offset start, GT_Size length) const
680  { t_extendedFillArray(data, sizes, start, length); }
682  GT_Offset start, GT_Size length) const
683  { t_extendedFillArray(data, sizes, start, length); }
684 
687  int tuple_size, int stride,
688  fpreal black, fpreal white) const
689  {
690  doExtendedQuantizedFill(data, start, length, tuple_size,
691  1, stride, black, white);
692  }
693  virtual void doExtendedQuantizedFill(uint8 *data,
695  int tuple_size, int nrepeats, int stride,
696  fpreal black, fpreal white) const;
697 
698  /// Nested class to perform filling for a POD array
699  template <typename T_POD>
701  {
702  public:
704  GT_Offset start, int stride)
705  : myArray(array)
706  , myData(data)
707  , myStart(start)
708  , myStride(stride)
709  {
710  myBox.initBounds();
711  }
713  : myArray(src.myArray)
714  , myBox(src.myBox)
715  , myData(src.myData)
716  , myStart(src.myStart)
717  , myStride(src.myStride)
718  {
719  }
721  {
722  exint i = range.begin();
723  T_POD *dest = myData + i*myStride;
724  for (; i != range.end(); ++i, dest += myStride)
725  {
726  myArray.import(i+myStart, dest, 3);
727  myBox.enlargeBounds(dest[0], dest[1], dest[2]);
728  }
729  }
730  void join(const fillV3BoxTask<T_POD> &src)
731  {
732  myBox.enlargeBounds(src.myBox);
733  }
734  const UT_BoundingBox &box() const { return myBox; }
735  private:
736  const GT_DataArray &myArray;
737  UT_BoundingBox myBox;
738  T_POD *myData;
739  GT_Offset myStart;
740  int myStride;
741  };
742 
744  UT_BoundingBoxF &bbox, int, int stride)
745  {
746  stride = SYSmax(stride, 3);
747  fillV3BoxTask<fpreal32> task(*this, dest, start, stride);
749  bbox = task.box();
750  }
752  UT_BoundingBoxD &bbox, int, int stride)
753  {
754  stride = SYSmax(stride, 3);
755  fillV3BoxTask<fpreal64> task(*this, dest, start, stride);
757  bbox = task.box();
758  }
759  /// @}
760 
761  /// Templated method to fill an array
762  template <typename T_POD> void
763  t_extendedFill(T_POD *dest, GT_Offset start, GT_Size length,
764  int tsize, int nrepeats, int stride) const;
765 
766  /// Templated method to fill an array attribute
767  template <typename T_POD> void
768  t_extendedFillArray(UT_Array<T_POD> &dest, UT_Array<int> &sizes,
769  GT_Offset start, GT_Size length) const;
770 
771 private:
772  /// @{
773  /// @private
774  /// Get more complicated POD data types out of the array
775  template <typename T, int tuplesize> class VectorPODAccessor
776  {
777  public:
778  static T getValue(const GT_DataArray &array, GT_Offset offset)
779  {
780  T result;
781  UT_ASSERT_P(array.getTupleSize() >= tuplesize);
782  array.get(offset, result.data(), tuplesize);
783  return result;
784  }
785  };
786  class I32Accessor {
787  public:
788  static int32 getValue(const GT_DataArray &a, GT_Offset i)
789  { return a.getI32(i); }
790  };
791  class I64Accessor {
792  public:
793  static int64 getValue(const GT_DataArray &a, GT_Offset i)
794  { return a.getI64(i); }
795  };
796  class F16Accessor {
797  public:
798  static fpreal16 getValue(const GT_DataArray &a, GT_Offset i)
799  { return a.getF16(i); }
800  };
801  class F32Accessor {
802  public:
803  static fpreal32 getValue(const GT_DataArray &a, GT_Offset i)
804  { return a.getF32(i); }
805  };
806  class F64Accessor {
807  public:
808  static fpreal64 getValue(const GT_DataArray &a, GT_Offset i)
809  { return a.getF64(i); }
810  };
811  /// @}
812 
813  /// @{
814  /// @private
815  /// Private template class to register POD accessors
816  template <typename T, int FAKE> class TypeInfo {};
817  /// @}
818 
819  /// @{
820  /// @private
821  /// Simple scalar and vector accessors
822  template <int FAKE> class TypeInfo<int32, FAKE>
823  { public: typedef I32Accessor Accessors; };
824  template <int FAKE> class TypeInfo<int64, FAKE>
825  { public: typedef I64Accessor Accessors; };
826  template <int FAKE> class TypeInfo<fpreal16, FAKE>
827  { public: typedef F16Accessor Accessors; };
828  template <int FAKE> class TypeInfo<fpreal32, FAKE>
829  { public: typedef F32Accessor Accessors; };
830  template <int FAKE> class TypeInfo<fpreal64, FAKE>
831  { public: typedef F64Accessor Accessors; };
832 
833  template <int FAKE> class TypeInfo<UT_Vector3F, FAKE>
834  { public: typedef VectorPODAccessor<UT_Vector3F, 3> Accessors; };
835  template <int FAKE> class TypeInfo<UT_Vector3D, FAKE>
836  { public: typedef VectorPODAccessor<UT_Vector3D, 3> Accessors; };
837  template <int FAKE> class TypeInfo<UT_Vector4F, FAKE>
838  { public: typedef VectorPODAccessor<UT_Vector4F, 4> Accessors; };
839  template <int FAKE> class TypeInfo<UT_Vector4D, FAKE>
840  { public: typedef VectorPODAccessor<UT_Vector4D, 4> Accessors; };
841  template <int FAKE> class TypeInfo<UT_Matrix3F, FAKE>
842  { public: typedef VectorPODAccessor<UT_Matrix3F, 9> Accessors; };
843  template <int FAKE> class TypeInfo<UT_Matrix3D, FAKE>
844  { public: typedef VectorPODAccessor<UT_Matrix3D, 9> Accessors; };
845  template <int FAKE> class TypeInfo<UT_Matrix4F, FAKE>
846  { public: typedef VectorPODAccessor<UT_Matrix4F, 16> Accessors; };
847  template <int FAKE> class TypeInfo<UT_Matrix4D, FAKE>
848  { public: typedef VectorPODAccessor<UT_Matrix4D, 16> Accessors; };
849  /// @}
850 public:
851  /// Public accessor for POD types
852  template <typename T> T
854  { return TypeInfo<T, 0>::Accessors::getValue(*this, index); }
855 
856  template <typename T> T
858  {
859  return (1-t)*getValue<T>(i0) + t*getValue<T>(i1);
860  }
861 
862  template <typename T> T
864  GT_Offset u0v1, GT_Offset u1v1, fpreal u, fpreal v)
865  {
866  T l = (1-v)*getValue<T>(u0v0) + v*getValue<T>(u0v1);
867  T r = (1-v)*getValue<T>(u1v0) + v*getValue<T>(u1v1);
868  return (1-u)*l + u*r;
869  }
870 
871 private:
872  int64 myDataId;
873 };
874 
875 #endif
SYS_HashType hash() const
Definition: GT_DataArray.h:449
#define SYSmax(a, b)
Definition: SYS_Math.h:1514
void fillArray(UT_Array< int32 > &data, UT_Array< int > &sizes, GT_Offset start, GT_Size length)
Definition: GT_DataArray.h:322
vint4 max(const vint4 &a, const vint4 &b)
Definition: simd.h:4703
GT_Storage
Definition: GT_Types.h:18
void fillArray(UT_Array< fpreal16 > &data, UT_Array< int > &sizes, GT_Offset start, GT_Size length)
Definition: GT_DataArray.h:328
virtual void updateGeoDetail(const GU_ConstDetailHandle &dtl, const char *attrib_name, GT_Owner attrib_owner, const int expected_size)
Update cached data, in case the underlying attribute changed.
Definition: GT_DataArray.h:513
GLenum GLint * range
Definition: glew.h:3500
virtual void extendedFill(int16 *data, GT_Offset start, GT_Size length, int tsize, int nrepeats, int stride=-1) const
Definition: GT_DataArray.h:369
virtual bool getIA32(UT_ValArray< int32 > &a, GT_Offset offset) const
Definition: GT_DataArray.h:127
virtual void doFillQuantizedArray(uint8 *data, GT_Offset start, GT_Size length, int tuple_size, int stride, fpreal black, fpreal white) const
Definition: GT_DataArray.h:685
virtual bool isValid() const
Data array is valid; can be sampled from.
Definition: GT_DataArray.h:81
GLuint id
Definition: glew.h:1679
GLsizeiptr size
Definition: glew.h:1681
GLenum src
Definition: glew.h:2410
int int32
Definition: SYS_Types.h:39
virtual fpreal16 getF16(GT_Offset offset, int idx=0) const
Definition: GT_DataArray.h:109
tbb::split UT_Split
Definition: GA_PolyCounts.h:24
void fillArray(UT_Array< fpreal32 > &data, UT_Array< int > &sizes, GT_Offset start, GT_Size length)
Definition: GT_DataArray.h:331
virtual void extendedFill(int32 *data, GT_Offset start, GT_Size length, int tsize, int nrepeats, int stride=-1) const
Definition: GT_DataArray.h:375
void fillArray(fpreal64 *data, GT_Offset start, GT_Size length, int tsize, int stride=-1) const
Definition: GT_DataArray.h:284
Nested class to perform filling for a POD array.
Definition: GT_DataArray.h:700
virtual bool getFA64(UT_ValArray< fpreal64 > &a, GT_Offset offset) const
Definition: GT_DataArray.h:123
virtual fpreal64 getF64(GT_Offset offset, int idx=0) const
Definition: GT_DataArray.h:112
T lerpValue(GT_Offset i0, GT_Offset i1, fpreal t) const
Definition: GT_DataArray.h:857
GLenum mode
Definition: glew.h:2163
FMT_CONSTEXPR auto begin(const C &c) -> decltype(c.begin())
Definition: format.h:251
virtual void fillStringArray(UT_StringArray &data, UT_ValArray< int > &sizes, GT_Offset start, GT_Size length) const
Definition: GT_DataArray.h:192
GLuint index
Definition: glew.h:1814
void join(const fillV3BoxTask< T_POD > &src)
Definition: GT_DataArray.h:730
GLboolean GLboolean GLboolean GLboolean a
Definition: glew.h:9477
virtual void doFillArray(int16 *data, GT_Offset start, GT_Size length, int tuple_size, int stride) const
Definition: GT_DataArray.h:648
bool enlargeBounds(UT_BoundingBox &b) const
Definition: GT_DataArray.h:468
GT_IndexingMode
Definition: GT_Types.h:92
virtual fpreal32 getF32(GT_Offset offset, int idx=0) const =0
virtual const void * getBackingData() const
Definition: GT_DataArray.h:89
#define GT_API
Definition: GT_API.h:11
int64 exint
Definition: SYS_Types.h:125
const UT_BoundingBox & box() const
Definition: GT_DataArray.h:734
GT_Type
Definition: GT_Types.h:34
virtual int64 getI64(GT_Offset offset, int idx=0) const
Definition: GT_DataArray.h:106
std::size_t SYS_HashType
Define the type for hash values.
Definition: SYS_Hash.h:19
static bool isBigInteger(GT_Size size)
Quick & dirty test to see if a size is bigger than a 32 bit int.
Definition: GT_DataArray.h:482
void fillArray(int16 *data, GT_Offset start, GT_Size length, int tsize, int stride=-1) const
Definition: GT_DataArray.h:269
virtual void extendedFill(fpreal16 *data, GT_Offset start, GT_Size length, int tsize, int nrepeats, int stride=-1) const
Definition: GT_DataArray.h:387
GLdouble l
Definition: glew.h:9122
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:34
const GLdouble * v
Definition: glew.h:1391
minMaxTask(const GT_DataArray &array)
Definition: GT_DataArray.h:523
virtual void extendedFill(int64 *data, GT_Offset start, GT_Size length, int tsize, int nrepeats, int stride=-1) const
Definition: GT_DataArray.h:381
void fillArray(UT_Array< fpreal64 > &data, UT_Array< int > &sizes, GT_Offset start, GT_Size length)
Definition: GT_DataArray.h:334
A reference counter base class for use with UT_IntrusivePtr.
virtual void doFillArray(int64 *data, GT_Offset start, GT_Size length, int tuple_size, int stride) const
Definition: GT_DataArray.h:654
float fpreal32
Definition: SYS_Types.h:200
#define SYS_FP64_MAX
Definition: SYS_Types.h:221
virtual void doFillVec3BBox(fpreal64 *dest, GT_Offset start, GT_Size length, UT_BoundingBoxD &bbox, int, int stride)
Definition: GT_DataArray.h:751
virtual void extendedFill(fpreal32 *data, GT_Offset start, GT_Size length, int tsize, int nrepeats, int stride=-1) const
Definition: GT_DataArray.h:393
virtual void doFillVec3BBox(fpreal32 *dest, GT_Offset start, GT_Size length, UT_BoundingBoxF &bbox, int, int stride)
Definition: GT_DataArray.h:743
void fillArray(fpreal32 *data, GT_Offset start, GT_Size length, int tsize, int stride=-1) const
Definition: GT_DataArray.h:281
virtual bool getIA64(UT_ValArray< int64 > &a, GT_Offset offset) const
Definition: GT_DataArray.h:129
virtual bool computeMinMax(fpreal64 *min, fpreal64 *max) const
Definition: GT_DataArray.h:604
virtual bool getIA16(UT_ValArray< int16 > &a, GT_Offset offset) const
Definition: GT_DataArray.h:125
GLdouble GLdouble z
Definition: glew.h:1559
double fpreal64
Definition: SYS_Types.h:201
unsigned char uint8
Definition: SYS_Types.h:36
virtual void extendedFill(int8 *data, GT_Offset start, GT_Size length, int tsize, int nrepeats, int stride=-1) const
Definition: GT_DataArray.h:363
virtual void doFillArrayAttr(UT_Array< fpreal16 > &data, UT_Array< int > &sizes, GT_Offset start, GT_Size length) const
Definition: GT_DataArray.h:675
void getResult(fpreal64 *min, fpreal64 *max) const
Definition: GT_DataArray.h:563
virtual void doFillArrayAttr(UT_Array< int32 > &data, UT_Array< int > &sizes, GT_Offset start, GT_Size length) const
Definition: GT_DataArray.h:669
Abstract data class for an array of float, int or string data.
Definition: GT_DataArray.h:40
virtual const uint8 * get(GT_Offset i, uint8 *store, int sz) const
virtual void extendedFill(uint8 *data, GT_Offset start, GT_Size length, int tsize, int nrepeats, int stride=-1) const
Definition: GT_DataArray.h:357
GLuint GLsizei const GLuint const GLintptr const GLsizeiptr * sizes
Definition: glew.h:5268
UT_IntrusivePtr< GT_DataArray > GT_DataArrayHandle
Definition: GT_DataArray.h:32
GLuint buffer
Definition: glew.h:1680
virtual void extendedFill(fpreal64 *data, GT_Offset start, GT_Size length, int tsize, int nrepeats, int stride=-1) const
Definition: GT_DataArray.h:399
virtual int64 getDataId() const
Definition: GT_DataArray.h:96
GLint GLenum GLsizei GLint GLsizei const void * data
Definition: glew.h:1379
#define UT_ASSERT_P(ZZ)
Definition: UT_Assert.h:134
fillV3BoxTask(const GT_DataArray &array, T_POD *data, GT_Offset start, int stride)
Definition: GT_DataArray.h:703
GLuint GLuint GLsizei GLenum const void * indices
Definition: glew.h:1253
virtual void doFillArray(int8 *data, GT_Offset start, GT_Size length, int tuple_size, int stride) const
Definition: GT_DataArray.h:645
virtual bool getFA32(UT_ValArray< fpreal32 > &a, GT_Offset offset) const
Definition: GT_DataArray.h:121
GLubyte GLubyte GLubyte GLubyte w
Definition: glew.h:1890
GLuint GLuint end
Definition: glew.h:1253
virtual bool getPointerAliasing(const void *data) const
Return "true" if there's pointer aliasing.
Definition: GT_DataArray.h:77
GLsizei n
Definition: glew.h:4040
GLuint GLsizei GLsizei * length
Definition: glew.h:1825
virtual void doFillArrayAttr(UT_Array< int16 > &data, UT_Array< int > &sizes, GT_Offset start, GT_Size length) const
Definition: GT_DataArray.h:666
int64 GT_Offset
Definition: GT_Types.h:114
long long int64
Definition: SYS_Types.h:116
GLsizei const GLchar *const * strings
Definition: glew.h:5883
virtual void doFillArray(uint8 *data, GT_Offset start, GT_Size length, int tuple_size, int stride) const
Definition: GT_DataArray.h:641
virtual void extendedFillArray(uint8 *data, GT_Offset start, GT_Size length, int tsize, int nrepeats, int stride=-1, fpreal black=0, fpreal white=1) const
Definition: GT_DataArray.h:339
virtual bool getSA(UT_StringArray &a, GT_Offset offset) const
Definition: GT_DataArray.h:117
#define SYS_STATIC_FORCE_INLINE
Definition: SYS_Inline.h:48
T getValue(GT_Offset index) const
Public accessor for POD types.
Definition: GT_DataArray.h:853
signed char int8
Definition: SYS_Types.h:35
void enlargeBounds(const UT_Vector3T< T > &min, const UT_Vector3T< T > &max)
void fillArray(fpreal16 *data, GT_Offset start, GT_Size length, int tsize, int stride=-1) const
Definition: GT_DataArray.h:278
void setDataId(int64 id)
Definition: GT_DataArray.h:510
fillV3BoxTask(fillV3BoxTask &src, UT_Split)
Definition: GT_DataArray.h:712
virtual void doFillArrayAttr(UT_Array< fpreal64 > &data, UT_Array< int > &sizes, GT_Offset start, GT_Size length) const
Definition: GT_DataArray.h:681
void copyDataId(const GT_DataArray &src)
Definition: GT_DataArray.h:503
GLuint start
Definition: glew.h:1253
GLsizei stride
Definition: glew.h:1523
GT_Owner
Definition: GT_Types.h:76
void operator()(const UT_BlockedRange< GT_Size > &range)
Definition: GT_DataArray.h:551
GLdouble GLdouble GLdouble b
Definition: glew.h:9122
minMaxTask(minMaxTask &src, UT_Split)
Definition: GT_DataArray.h:534
GLfloat GLfloat p
Definition: glew.h:16321
int64 GT_Size
Definition: GT_Types.h:113
void fillArray(int8 *data, GT_Offset start, GT_Size length, int tsize, int stride=-1) const
Definition: GT_DataArray.h:266
GLsizei const GLchar *const * string
Definition: glew.h:1844
virtual bool getFA16(UT_ValArray< fpreal16 > &a, GT_Offset offset) const
Definition: GT_DataArray.h:119
virtual void doFillArray(fpreal16 *data, GT_Offset start, GT_Size length, int tuple_size, int stride) const
Definition: GT_DataArray.h:657
void fillVec3BBox(fpreal64 *dest, GT_Offset start, GT_Size length, UT_BoundingBoxD &bbox, int tsize, int stride=-1)
Definition: GT_DataArray.h:306
virtual void doFillArray(fpreal32 *data, GT_Offset start, GT_Size length, int tuple_size, int stride) const
Definition: GT_DataArray.h:660
virtual void doFillArrayAttr(UT_Array< fpreal32 > &data, UT_Array< int > &sizes, GT_Offset start, GT_Size length) const
Definition: GT_DataArray.h:678
void fillArray(UT_Array< int16 > &data, UT_Array< int > &sizes, GT_Offset start, GT_Size length)
Definition: GT_DataArray.h:319
bool getMinMax(fpreal64 *min, fpreal64 *max) const
Enlarge a bounding box with values of this 3-tuple array.
Definition: GT_DataArray.h:454
virtual int16 getI16(GT_Offset offset, int idx=0) const
Definition: GT_DataArray.h:103
void operator()(const UT_BlockedRange< exint > &range)
Definition: GT_DataArray.h:720
void fillVec3BBox(fpreal32 *dest, GT_Offset start, GT_Size length, UT_BoundingBoxF &bbox, int tsize, int stride=-1)
Definition: GT_DataArray.h:299
short int16
Definition: SYS_Types.h:37
fpreal64 fpreal
Definition: SYS_Types.h:277
virtual bool hasArrayEntries() const
Returns "true" if each entry is an array.
Definition: GT_DataArray.h:74
virtual void doFillArray(fpreal64 *data, GT_Offset start, GT_Size length, int tuple_size, int stride) const
Definition: GT_DataArray.h:663
GLdouble GLdouble GLdouble r
Definition: glew.h:1406
OIIO_API bool copy(string_view from, string_view to, std::string &err)
void fillArray(uint8 *data, GT_Offset start, GT_Size length, int tsize, int stride=-1, fpreal black=0, fpreal white=1) const
Definition: GT_DataArray.h:287
virtual void doFillArrayAttr(UT_Array< int64 > &data, UT_Array< int > &sizes, GT_Offset start, GT_Size length) const
Definition: GT_DataArray.h:672
T bilerpValue(GT_Offset u0v0, GT_Offset u1v0, GT_Offset u0v1, GT_Offset u1v1, fpreal u, fpreal v)
Definition: GT_DataArray.h:863
GLuint64EXT * result
Definition: glew.h:14007
void fillArray(int32 *data, GT_Offset start, GT_Size length, int tsize, int stride=-1) const
Definition: GT_DataArray.h:272
GLenum array
Definition: glew.h:9066
void fillArray(UT_Array< int64 > &data, UT_Array< int > &sizes, GT_Offset start, GT_Size length)
Definition: GT_DataArray.h:325
vint4 min(const vint4 &a, const vint4 &b)
Definition: simd.h:4694
void fillArray(int64 *data, GT_Offset start, GT_Size length, int tsize, int stride=-1) const
Definition: GT_DataArray.h:275
virtual void doFillArray(int32 *data, GT_Offset start, GT_Size length, int tuple_size, int stride) const
Definition: GT_DataArray.h:651
void join(const minMaxTask &src)
Definition: GT_DataArray.h:571
virtual int32 getI32(GT_Offset offset, int idx=0) const =0
SYS_STATIC_FORCE_INLINE GT_Size fixImportTupleSize(GT_Size size, GT_Size tuple_size)
Definition: GT_DataArray.h:615
virtual int8 getI8(GT_Offset offset, int idx=0) const
Definition: GT_DataArray.h:101
virtual GT_Size getTupleSize() const =0
Number of elements for each array element.
#define SYSmin(a, b)
Definition: SYS_Math.h:1515
Declare prior to use.
GLdouble GLdouble t
Definition: glew.h:1398
Compute the min & max values for an array. This fails for strings.
Definition: GT_DataArray.h:520
virtual GT_Size getTotalArrayEntries() const
Definition: GT_DataArray.h:61
void UTparallelReduceLightItems(const Range &range, Body &body)
GLintptr offset
Definition: glew.h:1682