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