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 "GABC_IArray.h"
35 
36 namespace GABC_NAMESPACE
37 {
38 template <typename POD_T>
40 {
41 public:
43  : GT_DataArray()
44  , myArray(array)
45  , myData(static_cast<const POD_T *>(array.data()))
46  {
47  if (array.isConstant())
48  setDataId(1);
49  }
50  ~GABC_IGTArray() override
51  {
52  }
53 
54  /// Raw access to the data array
55  const POD_T *data() const { return myData; }
56 
57  /// Provide virtual access to the underlying backing data
58  const void *getBackingData() const override { return myData; }
59 
60  /// @{
61  /// Methods defined on GT_DataArray
62  const char *className() const override
63  { return "GABC_IGTArray"; }
64  GT_Storage getStorage() const override
65  { return GTstorage<POD_T>(); }
66  GT_Type getTypeInfo() const override
67  { return myArray.gtType(); }
68  GT_Size getTupleSize() const override
69  { return myArray.tupleSize(); }
70  GT_Size entries() const override
71  { return myArray.entries(); }
72  int64 getMemoryUsage() const override
73  {
74  return sizeof(*this)
75  + sizeof(POD_T)*entries()*getTupleSize();
76  }
77 
78  const uint8 *get(GT_Offset off, uint8 *buf, int sz) const override
79  {
80  off = off * getTupleSize();
81  for (int i = 0; i < sz; ++i)
82  buf[i] = myData[off+i];
83  return buf;
84  }
85  const int8 *get(GT_Offset off, int8 *buf, int sz) const override
86  {
87  off = off * getTupleSize();
88  for (int i = 0; i < sz; ++i)
89  buf[i] = myData[off+i];
90  return buf;
91  }
92  const int16 *get(GT_Offset off, int16 *buf, int sz) const override
93  {
94  off = off * getTupleSize();
95  for (int i = 0; i < sz; ++i)
96  buf[i] = myData[off+i];
97  return buf;
98  }
99  const int32 *get(GT_Offset off, int32 *buf, int sz) const override
100  {
101  off = off * getTupleSize();
102  for (int i = 0; i < sz; ++i)
103  buf[i] = myData[off+i];
104  return buf;
105  }
106  const int64 *get(GT_Offset off, int64 *buf, int sz) const override
107  {
108  off = off * getTupleSize();
109  for (int i = 0; i < sz; ++i)
110  buf[i] = myData[off+i];
111  return buf;
112  }
113  const fpreal16 *get(GT_Offset off, fpreal16 *buf, int sz) const override
114  {
115  off = off * getTupleSize();
116  for (int i = 0; i < sz; ++i)
117  buf[i] = myData[off+i];
118  return buf;
119  }
120  const fpreal64 *get(GT_Offset off, fpreal64 *buf, int sz) const override
121  {
122  off = off * getTupleSize();
123  for (int i = 0; i < sz; ++i)
124  buf[i] = myData[off+i];
125  return buf;
126  }
127  const fpreal32 *get(GT_Offset off,
128  fpreal32 *buf, int sz) const override
129  {
130  off = off * getTupleSize();
131  for (int i = 0; i < sz; ++i)
132  buf[i] = myData[off+i];
133  return buf;
134  }
135 
136  uint8 getU8(GT_Offset offset, int index=0) const override
137  {
138  offset = offset * getTupleSize() + index;
139  UT_ASSERT_P(offset>=0
140  && offset<entries()*getTupleSize());
141  return myData[offset];
142  }
143  int32 getI32(GT_Offset offset, int index=0) const override
144  {
145  offset = offset * getTupleSize() + index;
146  UT_ASSERT_P(offset>=0
147  && offset<entries()*getTupleSize());
148  return myData[offset];
149  }
150  int64 getI64(GT_Offset offset, int index=0) const override
151  {
152  offset = offset * getTupleSize() + index;
153  UT_ASSERT_P(offset>=0
154  && offset<entries()*getTupleSize());
155  return myData[offset];
156  }
157  fpreal16 getF16(GT_Offset offset, int index=0) const override
158  {
159  offset = offset * getTupleSize() + index;
160  UT_ASSERT_P(offset>=0
161  && offset<entries()*getTupleSize());
162  return myData[offset];
163  }
164  fpreal32 getF32(GT_Offset offset, int index=0) const override
165  {
166  offset = offset * getTupleSize() + index;
167  UT_ASSERT_P(offset>=0
168  && offset<entries()*getTupleSize());
169  return myData[offset];
170  }
171  fpreal64 getF64(GT_Offset offset, int index=0) const override
172  {
173  offset = offset * getTupleSize() + index;
174  UT_ASSERT_P(offset>=0
175  && offset<entries()*getTupleSize());
176  return myData[offset];
177  }
178  GT_String getS(GT_Offset, int) const override
180  GT_Size getStringIndexCount() const override
181  { return -1; }
182  GT_Offset getStringIndex(GT_Offset, int) const override
183  { return -1; }
185  UT_IntArray &) const override {}
186 
187  const uint8 *getU8Array(GT_DataArrayHandle &buffer) const override
188  {
189  if (SYSisSame<POD_T, uint8>())
190  return reinterpret_cast<const uint8 *>(data());
191  return GT_DataArray::getU8Array(buffer);
192  }
193  const int32 *getI32Array(GT_DataArrayHandle &buffer) const override
194  {
195  if (SYSisSame<POD_T, int32>())
196  return reinterpret_cast<const int32 *>(data());
197  return GT_DataArray::getI32Array(buffer);
198  }
199  const int64 *getI64Array(GT_DataArrayHandle &buffer) const override
200  {
201  if (SYSisSame<POD_T, int64>())
202  return reinterpret_cast<const int64 *>(data());
203  return GT_DataArray::getI64Array(buffer);
204  }
206  {
207  if (SYSisSame<POD_T, fpreal16>())
208  return reinterpret_cast<const fpreal16 *>(data());
209  return GT_DataArray::getF16Array(buffer);
210  }
212  {
213  if (SYSisSame<POD_T, fpreal32>())
214  return reinterpret_cast<const fpreal32 *>(data());
215  return GT_DataArray::getF32Array(buffer);
216  }
218  {
219  if (SYSisSame<POD_T, fpreal64>())
220  return reinterpret_cast<const fpreal64 *>(data());
221  return GT_DataArray::getF64Array(buffer);
222  }
223 
224  void doImport(GT_Offset idx, uint8 *data, GT_Size size) const override
225  { importTuple<uint8>(idx, data, size); }
226  void doImport(GT_Offset idx, int8 *data, GT_Size size) const override
227  { importTuple<int8>(idx, data, size); }
228  void doImport(GT_Offset idx, int16 *data, GT_Size size) const override
229  { importTuple<int16>(idx, data, size); }
230  void doImport(GT_Offset idx, int32 *data, GT_Size size) const override
231  { importTuple<int32>(idx, data, size); }
232  void doImport(GT_Offset idx, int64 *data, GT_Size size) const override
233  { importTuple<int64>(idx, data, size); }
234  void doImport(GT_Offset idx, fpreal16 *data, GT_Size size) const override
235  { importTuple<fpreal16>(idx, data, size); }
236  void doImport(GT_Offset idx, fpreal32 *data, GT_Size size) const override
237  { importTuple<fpreal32>(idx, data, size); }
238  void doImport(GT_Offset idx, fpreal64 *data, GT_Size size) const override
239  { importTuple<fpreal64>(idx, data, size); }
240 
242  int tsize, int stride) const override
243  { t_ABCFill(data, start, length, tsize, stride); }
245  int tsize, int stride) const override
246  { t_ABCFill(data, start, length, tsize, stride); }
248  int tsize, int stride) const override
249  { t_ABCFill(data, start, length, tsize, stride); }
251  int tsize, int stride) const override
252  { t_ABCFill(data, start, length, tsize, stride); }
254  int tsize, int stride) const override
255  { t_ABCFill(data, start, length, tsize, stride); }
257  int tsize, int stride) const override
258  { t_ABCFill(data, start, length, tsize, stride); }
260  int tsize, int stride) const override
261  { t_ABCFill(data, start, length, tsize, stride); }
263  int tsize, int stride) const override
264  { t_ABCFill(data, start, length, tsize, stride); }
265  /// @}
266 
267 private:
268  template <typename DEST_POD_T> inline void
269  importTuple(GT_Offset idx, DEST_POD_T *data, GT_Size tsize) const
270  {
271  if (tsize < 1)
272  tsize = getTupleSize();
273  else
274  tsize = SYSmin(tsize, getTupleSize());
275  const POD_T *src = myData + idx*getTupleSize();
276  for (int i = 0; i < tsize; ++i)
277  data[i] = src[i];
278  }
279 
280  inline void
281  t_ABCFill(POD_T *dest, GT_Offset start, GT_Size length,
282  int tsize, int stride) const
283  {
284  if (tsize < 1)
285  tsize = getTupleSize();
286  stride = SYSmax(stride, tsize);
287  int n = SYSmin(tsize, getTupleSize());
288  if (n == getTupleSize() && stride == getTupleSize())
289  {
290  memcpy(dest, myData+start*getTupleSize(),
291  length*n*sizeof(POD_T));
292  }
293  else
294  {
295  const POD_T *src = myData+start*getTupleSize();
296  for (GT_Offset i = 0; i < length; ++i,
297  src += getTupleSize(), dest += stride)
298  {
299  for (int j = 0; j < n; ++j)
300  dest[j] = src[j];
301  }
302  }
303  }
304 
305  template <typename DEST_POD_T> inline void
306  t_ABCFill(DEST_POD_T *dest, GT_Offset start, GT_Size length,
307  int tsize, int stride) const
308  {
309  if (tsize < 1)
310  tsize = getTupleSize();
311  stride = SYSmax(stride, tsize);
312  int n = SYSmin(tsize, getTupleSize());
313  const POD_T *src = myData+start*getTupleSize();
314  for (GT_Offset i = 0; i < length; ++i,
315  src += getTupleSize(), dest += stride)
316  {
317  for (int j = 0; j < n; ++j)
318  dest[j] = src[j];
319  }
320  }
321 
322  GABC_IArray myArray; // Shared pointer to TypedArraySample
323  const POD_T *myData; // Actual sample data
324 };
325 
327 {
328 public:
331  {
332  }
333 private:
334 };
335 
344 
345 GABC_API extern GT_DataArrayHandle GABCarray(const GABC_IArray &iarray);
346 }
347 
348 #endif
const void * getBackingData() const override
Provide virtual access to the underlying backing data.
Definition: GABC_IGTArray.h:58
#define SYSmax(a, b)
Definition: SYS_Math.h:1535
GT_Size entries() const override
Definition: GABC_IGTArray.h:70
GT_Storage
Definition: GT_Types.h:18
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:42
GT_String getS(GT_Offset, int) const override
GLuint start
Definition: glcorearb.h:474
virtual const fpreal32 * getF32Array(GT_DataArrayHandle &buffer) const
GT_Type getTypeInfo() const override
Definition: GABC_IGTArray.h:66
GT_Type
Definition: GT_Types.h:34
const uint8 * getU8Array(GT_DataArrayHandle &buffer) const override
int64 getMemoryUsage() const override
Definition: GABC_IGTArray.h:72
void doImport(GT_Offset idx, fpreal16 *data, GT_Size size) const override
GLenum src
Definition: glcorearb.h:1792
virtual const fpreal64 * getF64Array(GT_DataArrayHandle &buffer) const
float fpreal32
Definition: SYS_Types.h:200
GLuint buffer
Definition: glcorearb.h:659
const char * className() const override
Definition: GABC_IGTArray.h:62
#define GABC_NAMESPACE
Definition: GABC_API.h:42
uint8 getU8(GT_Offset offset, int index=0) const override
GLsizeiptr size
Definition: glcorearb.h:663
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
GLenum array
Definition: glew.h:9108
virtual const fpreal16 * getF16Array(GT_DataArrayHandle &buffer) const
void doFillArray(uint8 *data, GT_Offset start, GT_Size length, int tsize, int stride) const override
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:170
static const UT_StringHolder theEmptyString
void doImport(GT_Offset idx, int32 *data, GT_Size size) const override
int64 GT_Offset
Definition: GT_Types.h:124
long long int64
Definition: SYS_Types.h:116
signed char int8
Definition: SYS_Types.h:35
const POD_T * data() const
Raw access to the data array.
Definition: GABC_IGTArray.h:55
void getIndexedStrings(UT_StringArray &, UT_IntArray &) const override
GLdouble n
Definition: glcorearb.h:2007
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glcorearb.h:2539
GLboolean * data
Definition: glcorearb.h:130
int64 GT_Size
Definition: GT_Types.h:123
GLuint GLsizei GLsizei * length
Definition: glcorearb.h:794
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:785
#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:68
const fpreal16 * getF16Array(GT_DataArrayHandle &buffer) const override
GT_Storage getStorage() const override
Definition: GABC_IGTArray.h:64
virtual const uint8 * getU8Array(GT_DataArrayHandle &buffer) const
GLintptr offset
Definition: glcorearb.h:664
void doImport(GT_Offset idx, fpreal64 *data, GT_Size size) const override
#define const
Definition: zconf.h:214
GLint GLenum GLboolean GLsizei stride
Definition: glcorearb.h:871
int32 getI32(GT_Offset offset, int index=0) const override
#define SYSmin(a, b)
Definition: SYS_Math.h:1536
void doFillArray(int16 *data, GT_Offset start, GT_Size length, int tsize, int stride) const override
const int32 * getI32Array(GT_DataArrayHandle &buffer) const override
virtual const int32 * getI32Array(GT_DataArrayHandle &buffer) const