HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GABC_IGTArray.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) COPYRIGHTYEAR
3  * Side Effects Software Inc. All rights reserved.
4  *
5  * Redistribution and use of Houdini Development Kit samples in source and
6  * binary forms, with or without modification, are permitted provided that the
7  * following conditions are met:
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  * 2. The name of Side Effects Software may not be used to endorse or
11  * promote products derived from this software without specific prior
12  * written permission.
13  *
14  * THIS SOFTWARE IS PROVIDED BY SIDE EFFECTS SOFTWARE `AS IS' AND ANY EXPRESS
15  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
17  * NO EVENT SHALL SIDE EFFECTS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
18  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
19  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
20  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
21  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
22  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
23  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  *
25  *----------------------------------------------------------------------------
26  */
27 
28 #ifndef __GABC_IGTArray__
29 #define __GABC_IGTArray__
30 
31 #include "GABC_API.h"
32 #include <GT/GT_DataArray.h>
33 #include <GT/GT_DAIndexedString.h>
34 #include <UT/UT_ParallelUtil.h>
35 #include "GABC_IArray.h"
36 
37 namespace GABC_NAMESPACE
38 {
39 template <typename POD_T>
41 {
42 public:
43  GABC_IGTArray(const GABC_IArray &array)
44  : GT_DataArray()
45  , myArray(array)
46  , myData(static_cast<const POD_T *>(array.data()))
47  {
48  if (array.isConstant())
49  setDataId(1);
50  }
51  ~GABC_IGTArray() override
52  {
53  }
54 
55  /// Raw access to the data array
56  const POD_T *data() const { return myData; }
57 
58  /// Provide virtual access to the underlying backing data
59  const void *getBackingData() const override { return myData; }
60 
61  /// @{
62  /// Methods defined on GT_DataArray
63  const char *className() const override
64  { return "GABC_IGTArray"; }
65  GT_Storage getStorage() const override
66  { return GTstorage<POD_T>(); }
67  GT_Type getTypeInfo() const override
68  { return myArray.gtType(); }
69  GT_Size getTupleSize() const override
70  { return myArray.tupleSize(); }
71  GT_Size entries() const override
72  { return myArray.entries(); }
73  int64 getMemoryUsage() const override
74  {
75  return sizeof(*this)
76  + sizeof(POD_T)*entries()*getTupleSize();
77  }
78 
79  const uint8 *get(GT_Offset off, uint8 *buf, int sz) const override
80  {
81  off = off * getTupleSize();
82  for (int i = 0; i < sz; ++i)
83  buf[i] = myData[off+i];
84  return buf;
85  }
86  const int8 *get(GT_Offset off, int8 *buf, int sz) const override
87  {
88  off = off * getTupleSize();
89  for (int i = 0; i < sz; ++i)
90  buf[i] = myData[off+i];
91  return buf;
92  }
93  const int16 *get(GT_Offset off, int16 *buf, int sz) const override
94  {
95  off = off * getTupleSize();
96  for (int i = 0; i < sz; ++i)
97  buf[i] = myData[off+i];
98  return buf;
99  }
100  const int32 *get(GT_Offset off, int32 *buf, int sz) const override
101  {
102  off = off * getTupleSize();
103  for (int i = 0; i < sz; ++i)
104  buf[i] = myData[off+i];
105  return buf;
106  }
107  const int64 *get(GT_Offset off, int64 *buf, int sz) const override
108  {
109  off = off * getTupleSize();
110  for (int i = 0; i < sz; ++i)
111  buf[i] = myData[off+i];
112  return buf;
113  }
114  const fpreal16 *get(GT_Offset off, fpreal16 *buf, int sz) const override
115  {
116  off = off * getTupleSize();
117  for (int i = 0; i < sz; ++i)
118  buf[i] = myData[off+i];
119  return buf;
120  }
121  const fpreal64 *get(GT_Offset off, fpreal64 *buf, int sz) const override
122  {
123  off = off * getTupleSize();
124  for (int i = 0; i < sz; ++i)
125  buf[i] = myData[off+i];
126  return buf;
127  }
128  const fpreal32 *get(GT_Offset off,
129  fpreal32 *buf, int sz) const override
130  {
131  off = off * getTupleSize();
132  for (int i = 0; i < sz; ++i)
133  buf[i] = myData[off+i];
134  return buf;
135  }
136 
137  uint8 getU8(GT_Offset offset, int index=0) const override
138  {
139  offset = offset * getTupleSize() + index;
140  UT_ASSERT_P(offset>=0
141  && offset<entries()*getTupleSize());
142  return myData[offset];
143  }
144  int32 getI32(GT_Offset offset, int index=0) const override
145  {
146  offset = offset * getTupleSize() + index;
147  UT_ASSERT_P(offset>=0
148  && offset<entries()*getTupleSize());
149  return myData[offset];
150  }
151  int64 getI64(GT_Offset offset, int index=0) const override
152  {
153  offset = offset * getTupleSize() + index;
154  UT_ASSERT_P(offset>=0
155  && offset<entries()*getTupleSize());
156  return myData[offset];
157  }
158  fpreal16 getF16(GT_Offset offset, int index=0) const override
159  {
160  offset = offset * getTupleSize() + index;
161  UT_ASSERT_P(offset>=0
162  && offset<entries()*getTupleSize());
163  return myData[offset];
164  }
165  fpreal32 getF32(GT_Offset offset, int index=0) const override
166  {
167  offset = offset * getTupleSize() + index;
168  UT_ASSERT_P(offset>=0
169  && offset<entries()*getTupleSize());
170  return myData[offset];
171  }
172  fpreal64 getF64(GT_Offset offset, int index=0) const override
173  {
174  offset = offset * getTupleSize() + index;
175  UT_ASSERT_P(offset>=0
176  && offset<entries()*getTupleSize());
177  return myData[offset];
178  }
179  GT_String getS(GT_Offset, int) const override
181  GT_Size getStringIndexCount() const override
182  { return -1; }
183  GT_Offset getStringIndex(GT_Offset, int) const override
184  { return -1; }
186  UT_IntArray &) const override {}
187 
188  GT_Size getDictIndexCount() const override
189  { return -1; }
190  GT_Offset getDictIndex(GT_Offset, int) const override
191  { return -1; }
193  UT_IntArray &) const override {}
194 
195  const uint8 *getU8Array(GT_DataArrayHandle &buffer) const override
196  {
197  if (SYSisSame<POD_T, uint8>())
198  return reinterpret_cast<const uint8 *>(data());
199  return GT_DataArray::getU8Array(buffer);
200  }
201  const int32 *getI32Array(GT_DataArrayHandle &buffer) const override
202  {
203  if (SYSisSame<POD_T, int32>())
204  return reinterpret_cast<const int32 *>(data());
205  return GT_DataArray::getI32Array(buffer);
206  }
207  const int64 *getI64Array(GT_DataArrayHandle &buffer) const override
208  {
209  if (SYSisSame<POD_T, int64>())
210  return reinterpret_cast<const int64 *>(data());
211  return GT_DataArray::getI64Array(buffer);
212  }
214  {
215  if (SYSisSame<POD_T, fpreal16>())
216  return reinterpret_cast<const fpreal16 *>(data());
217  return GT_DataArray::getF16Array(buffer);
218  }
220  {
221  if (SYSisSame<POD_T, fpreal32>())
222  return reinterpret_cast<const fpreal32 *>(data());
223  return GT_DataArray::getF32Array(buffer);
224  }
226  {
227  if (SYSisSame<POD_T, fpreal64>())
228  return reinterpret_cast<const fpreal64 *>(data());
229  return GT_DataArray::getF64Array(buffer);
230  }
231 
232  void doImport(GT_Offset idx, uint8 *data, GT_Size size) const override
233  { importTuple<uint8>(idx, data, size); }
234  void doImport(GT_Offset idx, int8 *data, GT_Size size) const override
235  { importTuple<int8>(idx, data, size); }
236  void doImport(GT_Offset idx, int16 *data, GT_Size size) const override
237  { importTuple<int16>(idx, data, size); }
238  void doImport(GT_Offset idx, int32 *data, GT_Size size) const override
239  { importTuple<int32>(idx, data, size); }
240  void doImport(GT_Offset idx, int64 *data, GT_Size size) const override
241  { importTuple<int64>(idx, data, size); }
242  void doImport(GT_Offset idx, fpreal16 *data, GT_Size size) const override
243  { importTuple<fpreal16>(idx, data, size); }
244  void doImport(GT_Offset idx, fpreal32 *data, GT_Size size) const override
245  { importTuple<fpreal32>(idx, data, size); }
246  void doImport(GT_Offset idx, fpreal64 *data, GT_Size size) const override
247  { importTuple<fpreal64>(idx, data, size); }
248 
250  int tsize, int stride) const override
251  { t_ABCFill(data, start, length, tsize, stride); }
253  int tsize, int stride) const override
254  { t_ABCFill(data, start, length, tsize, stride); }
256  int tsize, int stride) const override
257  { t_ABCFill(data, start, length, tsize, stride); }
259  int tsize, int stride) const override
260  { t_ABCFill(data, start, length, tsize, stride); }
262  int tsize, int stride) const override
263  { t_ABCFill(data, start, length, tsize, stride); }
265  int tsize, int stride) const override
266  { t_ABCFill(data, start, length, tsize, stride); }
268  int tsize, int stride) const override
269  { t_ABCFill(data, start, length, tsize, stride); }
271  int tsize, int stride) const override
272  { t_ABCFill(data, start, length, tsize, stride); }
273  /// @}
274 
275 private:
276  template <typename DEST_POD_T> inline void
277  importTuple(GT_Offset idx, DEST_POD_T *data, GT_Size tsize) const
278  {
279  if (tsize < 1)
280  tsize = getTupleSize();
281  else
282  tsize = SYSmin(tsize, getTupleSize());
283  const POD_T *src = myData + idx*getTupleSize();
284  for (int i = 0; i < tsize; ++i)
285  data[i] = src[i];
286  }
287 
288  inline void
289  t_ABCFill(POD_T *dest, GT_Offset start, GT_Size length,
290  int tsize, int stride) const
291  {
292  if (tsize < 1)
293  tsize = getTupleSize();
294  stride = SYSmax(stride, tsize);
295  int n = SYSmin(tsize, getTupleSize());
296  if (n == getTupleSize() && stride == getTupleSize())
297  {
298  memcpy(dest, myData+start*getTupleSize(),
299  length*n*sizeof(POD_T));
300  }
301  else
302  {
303  const POD_T *src = myData+start*getTupleSize();
305  [&](const UT_BlockedRange<exint> &r)
306  {
307  exint rstart = r.begin();
308  exint rend = r.end();
309  POD_T *d = dest + rstart * stride;
310  const POD_T *s = src + rstart * getTupleSize();
311  for (exint i = rstart;
312  i < rend;
313  ++i, s += getTupleSize(), d += stride)
314  {
315  for (int j = 0; j < n; ++j)
316  d[j] = s[j];
317  }
318  });
319  }
320  }
321 
322  template <typename DEST_POD_T> inline void
323  t_ABCFill(DEST_POD_T *dest, GT_Offset start, GT_Size length,
324  int tsize, int stride) const
325  {
326  if (tsize < 1)
327  tsize = getTupleSize();
328  stride = SYSmax(stride, tsize);
329  int n = SYSmin(tsize, getTupleSize());
330  const POD_T *src = myData+start*getTupleSize();
332  [&](const UT_BlockedRange<exint> &r)
333  {
334  exint rstart = r.begin();
335  exint rend = r.end();
336  DEST_POD_T *d = dest + rstart * stride;
337  const POD_T *s = src + rstart * getTupleSize();
338  for (exint i = rstart;
339  i < rend;
340  ++i, s += getTupleSize(), d += stride)
341  {
342  for (int j = 0; j < n; ++j)
343  d[j] = s[j];
344  }
345  });
346  }
347 
348  GABC_IArray myArray; // Shared pointer to TypedArraySample
349  const POD_T *myData; // Actual sample data
350 };
351 
353 {
354 public:
355  GABC_IGTStringArray(const GABC_IArray &array);
357  {
358  }
359 private:
360 };
361 
370 
371 GABC_API extern GT_DataArrayHandle GABCarray(const GABC_IArray &iarray);
372 }
373 
374 #endif
const void * getBackingData() const override
Provide virtual access to the underlying backing data.
Definition: GABC_IGTArray.h:59
#define SYSmax(a, b)
Definition: SYS_Math.h:1570
GT_Size entries() const override
Definition: GABC_IGTArray.h:71
GT_Storage
Definition: GT_Types.h:19
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glcorearb.h:2540
fpreal64 getF64(GT_Offset offset, int index=0) const override
void doImport(GT_Offset idx, uint8 *data, GT_Size size) const override
void doImport(GT_Offset idx, int16 *data, GT_Size size) const override
int64 getI64(GT_Offset offset, int index=0) const override
GABC_API GT_DataArrayHandle GABCarray(const GABC_IArray &iarray)
int int32
Definition: SYS_Types.h:39
void doFillArray(int8 *data, GT_Offset start, GT_Size length, int tsize, int stride) const override
void doFillArray(fpreal32 *data, GT_Offset start, GT_Size length, int tsize, int stride) const override
const int64 * getI64Array(GT_DataArrayHandle &buffer) const override
void doImport(GT_Offset idx, fpreal32 *data, GT_Size size) const override
const fpreal32 * getF32Array(GT_DataArrayHandle &buffer) const override
GABC_IGTArray(const GABC_IArray &array)
Definition: GABC_IGTArray.h:43
GT_String getS(GT_Offset, int) const override
GLboolean * data
Definition: glcorearb.h:131
GLuint start
Definition: glcorearb.h:475
virtual const fpreal32 * getF32Array(GT_DataArrayHandle &buffer) const
int64 exint
Definition: SYS_Types.h:125
GT_Type getTypeInfo() const override
Definition: GABC_IGTArray.h:67
GT_Type
Definition: GT_Types.h:36
GLdouble s
Definition: glad.h:3009
const uint8 * getU8Array(GT_DataArrayHandle &buffer) const override
GLuint GLsizei GLsizei * length
Definition: glcorearb.h:795
int64 getMemoryUsage() const override
Definition: GABC_IGTArray.h:73
void UTparallelForLightItems(const Range &range, const Body &body, const bool force_use_task_scope=true)
void doImport(GT_Offset idx, fpreal16 *data, GT_Size size) const override
virtual const fpreal64 * getF64Array(GT_DataArrayHandle &buffer) const
float fpreal32
Definition: SYS_Types.h:200
const char * className() const override
Definition: GABC_IGTArray.h:63
#define GABC_NAMESPACE
Definition: GABC_API.h:42
uint8 getU8(GT_Offset offset, int index=0) const override
double fpreal64
Definition: SYS_Types.h:201
unsigned char uint8
Definition: SYS_Types.h:36
void doFillArray(fpreal64 *data, GT_Offset start, GT_Size length, int tsize, int stride) const override
void doImport(GT_Offset idx, int8 *data, GT_Size size) const override
virtual const fpreal16 * getF16Array(GT_DataArrayHandle &buffer) const
GLdouble n
Definition: glcorearb.h:2008
void doFillArray(uint8 *data, GT_Offset start, GT_Size length, int tsize, int stride) const override
GLintptr offset
Definition: glcorearb.h:665
Definition: core.h:760
Abstract data class for an array of float, int or string data.
Definition: GT_DataArray.h:40
GT_Size getStringIndexCount() const override
const fpreal64 * getF64Array(GT_DataArrayHandle &buffer) const override
void doFillArray(fpreal16 *data, GT_Offset start, GT_Size length, int tsize, int stride) const override
#define UT_ASSERT_P(ZZ)
Definition: UT_Assert.h:155
static const UT_StringHolder theEmptyString
GLint GLenum GLboolean GLsizei stride
Definition: glcorearb.h:872
void doImport(GT_Offset idx, int32 *data, GT_Size size) const override
int64 GT_Offset
Definition: GT_Types.h:129
long long int64
Definition: SYS_Types.h:116
signed char int8
Definition: SYS_Types.h:35
GT_Offset getDictIndex(GT_Offset, int) const override
const POD_T * data() const
Raw access to the data array.
Definition: GABC_IGTArray.h:56
void getIndexedDicts(UT_Array< UT_OptionsHolder > &, UT_IntArray &) const override
void getIndexedStrings(UT_StringArray &, UT_IntArray &) const override
GLint j
Definition: glad.h:2733
int64 GT_Size
Definition: GT_Types.h:128
GLsizeiptr size
Definition: glcorearb.h:664
fpreal16 getF16(GT_Offset offset, int index=0) const override
GABC_IGTStringArray(const GABC_IArray &array)
void doImport(GT_Offset idx, int64 *data, GT_Size size) const override
short int16
Definition: SYS_Types.h:37
void doFillArray(int64 *data, GT_Offset start, GT_Size length, int tsize, int stride) const override
GLuint index
Definition: glcorearb.h:786
#define GABC_API
Definition: GABC_API.h:37
virtual const int64 * getI64Array(GT_DataArrayHandle &buffer) const
GT_Offset getStringIndex(GT_Offset, int) const override
void doFillArray(int32 *data, GT_Offset start, GT_Size length, int tsize, int stride) const override
fpreal32 getF32(GT_Offset offset, int index=0) const override
GT_Size getTupleSize() const override
Definition: GABC_IGTArray.h:69
const fpreal16 * getF16Array(GT_DataArrayHandle &buffer) const override
GT_Storage getStorage() const override
Definition: GABC_IGTArray.h:65
virtual const uint8 * getU8Array(GT_DataArrayHandle &buffer) const
void doImport(GT_Offset idx, fpreal64 *data, GT_Size size) const override
GLboolean r
Definition: glcorearb.h:1222
int32 getI32(GT_Offset offset, int index=0) const override
GT_Size getDictIndexCount() const override
#define SYSmin(a, b)
Definition: SYS_Math.h:1571
Declare prior to use.
void doFillArray(int16 *data, GT_Offset start, GT_Size length, int tsize, int stride) const override
const int32 * getI32Array(GT_DataArrayHandle &buffer) const override
Definition: format.h:895
virtual const int32 * getI32Array(GT_DataArrayHandle &buffer) const
GLenum src
Definition: glcorearb.h:1793