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