HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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 int32 *get(GT_Offset off, int32 *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 int64 *get(GT_Offset off, int64 *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 fpreal16 *get(GT_Offset off, fpreal16 *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 fpreal64 *get(GT_Offset off, fpreal64 *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 fpreal32 *get(GT_Offset off, fpreal32 *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 
113  virtual uint8 getU8(GT_Offset offset, int index=0) const
114  {
115  offset = offset * getTupleSize() + index;
116  UT_ASSERT_P(offset>=0
117  && offset<entries()*getTupleSize());
118  return myData[offset];
119  }
120  virtual int32 getI32(GT_Offset offset, int index=0) const
121  {
122  offset = offset * getTupleSize() + index;
123  UT_ASSERT_P(offset>=0
124  && offset<entries()*getTupleSize());
125  return myData[offset];
126  }
127  virtual int64 getI64(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 fpreal16 getF16(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 fpreal32 getF32(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 fpreal64 getF64(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 GT_String getS(GT_Offset, int) const { return NULL; }
156  virtual GT_Size getStringIndexCount() const { return -1; }
157  virtual GT_Offset getStringIndex(GT_Offset, int) const { return -1; }
159  UT_IntArray &) const {}
160 
161  virtual const uint8 *getU8Array(GT_DataArrayHandle &buffer) const
162  {
163  if (SYSisSame<POD_T, uint8>())
164  return reinterpret_cast<const uint8 *>(data());
165  return GT_DataArray::getU8Array(buffer);
166  }
168  {
169  if (SYSisSame<POD_T, int32>())
170  return reinterpret_cast<const int32 *>(data());
171  return GT_DataArray::getI32Array(buffer);
172  }
174  {
175  if (SYSisSame<POD_T, int64>())
176  return reinterpret_cast<const int64 *>(data());
177  return GT_DataArray::getI64Array(buffer);
178  }
180  {
181  if (SYSisSame<POD_T, fpreal16>())
182  return reinterpret_cast<const fpreal16 *>(data());
183  return GT_DataArray::getF16Array(buffer);
184  }
186  {
187  if (SYSisSame<POD_T, fpreal32>())
188  return reinterpret_cast<const fpreal32 *>(data());
189  return GT_DataArray::getF32Array(buffer);
190  }
192  {
193  if (SYSisSame<POD_T, fpreal64>())
194  return reinterpret_cast<const fpreal64 *>(data());
195  return GT_DataArray::getF64Array(buffer);
196  }
197 
198  virtual void doImport(GT_Offset idx, uint8 *data, GT_Size size) const
199  { importTuple<uint8>(idx, data, size); }
200  virtual void doImport(GT_Offset idx, int32 *data, GT_Size size) const
201  { importTuple<int32>(idx, data, size); }
202  virtual void doImport(GT_Offset idx, int64 *data, GT_Size size) const
203  { importTuple<int64>(idx, data, size); }
204  virtual void doImport(GT_Offset idx, fpreal16 *data, GT_Size size) const
205  { importTuple<fpreal16>(idx, data, size); }
206  virtual void doImport(GT_Offset idx, fpreal32 *data, GT_Size size) const
207  { importTuple<fpreal32>(idx, data, size); }
208  virtual void doImport(GT_Offset idx, fpreal64 *data, GT_Size size) const
209  { importTuple<fpreal64>(idx, data, size); }
210 
212  int tsize, int stride) const
213  {
214  t_ABCFill(data, getStorage() == GT_STORE_UINT8,
215  start, length, tsize, 1, stride);
216  }
218  int tsize, int stride) const
219  {
220  t_ABCFill(data, getStorage() == GT_STORE_INT32,
221  start, length, tsize, 1, stride);
222  }
224  int tsize, int stride) const
225  {
226  t_ABCFill(data, getStorage() == GT_STORE_INT64,
227  start, length, tsize, 1, stride);
228  }
230  int tsize, int stride) const
231  {
232  t_ABCFill(data, getStorage() == GT_STORE_REAL16,
233  start, length, tsize, 1, stride);
234  }
236  int tsize, int stride) const
237  {
238  t_ABCFill(data, getStorage() == GT_STORE_REAL32,
239  start, length, tsize, 1, stride);
240  }
242  int tsize, int stride) const
243  {
244  t_ABCFill(data, getStorage() == GT_STORE_REAL64,
245  start, length, tsize, 1, stride);
246  }
247  /// @}
248 
249 private:
250  template <typename DEST_POD_T> inline void
251  importTuple(GT_Offset idx, DEST_POD_T *data, GT_Size tsize) const
252  {
253  if (tsize < 1)
254  tsize = getTupleSize();
255  else
256  tsize = SYSmin(tsize, getTupleSize());
257  const POD_T *src = myData + idx*getTupleSize();
258  for (int i = 0; i < tsize; ++i)
259  data[i] = src[i];
260  }
261 
262  template <typename DEST_POD_T> inline void
263  t_ABCFill(DEST_POD_T *dest, bool typematch, GT_Offset start, GT_Size length,
264  int tsize, int nrepeats, int stride) const
265  {
266  if (tsize < 1)
267  tsize = getTupleSize();
268  stride = SYSmax(stride, tsize);
269  int n = SYSmin(tsize, getTupleSize());
270  if (typematch && n == getTupleSize()
271  && stride == getTupleSize() && nrepeats==1)
272  {
273  memcpy(dest, myData+start*getTupleSize(),
274  length*n*sizeof(POD_T));
275  }
276  else
277  {
278  const POD_T *src = myData+start*getTupleSize();
279  for (GT_Offset i = 0; i < length; ++i,
280  src += getTupleSize())
281  {
282  for (GT_Offset r=0; r<nrepeats; ++r, dest += stride)
283  {
284  for (int j = 0; j < n; ++j)
285  dest[j] = src[j];
286  }
287  }
288  }
289  }
290  GABC_IArray myArray; // Shared pointer to TypedArraySample
291  const POD_T *myData; // Actual sample data
292 };
293 
295 {
296 public:
297  GABC_IGTStringArray(const GABC_IArray &array);
299  {
300  }
301 private:
302 };
303 
310 
311 GABC_API extern GT_DataArrayHandle GABCarray(const GABC_IArray &iarray);
312 }
313 
314 #endif
#define SYSmax(a, b)
Definition: SYS_Math.h:1365
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:108
virtual const fpreal32 * getF32Array(GT_DataArrayHandle &buffer) const
GT_Type
Definition: GT_Types.h:31
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 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
#define UT_ASSERT_P(ZZ)
Definition: UT_Assert.h:101
virtual void getIndexedStrings(UT_StringArray &, UT_IntArray &) const
long long int64
Definition: SYS_Types.h:100
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
double fpreal64
Definition: SYS_Types.h:185
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
GLboolean * data
Definition: glcorearb.h:130
int int32
Definition: SYS_Types.h:28
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
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:25
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
GLboolean r
Definition: glcorearb.h:1221
#define const
Definition: zconf.h:214
int64 GT_Offset
Definition: GT_Types.h:110
int64 GT_Size
Definition: GT_Types.h:109
virtual int64 getI64(GT_Offset offset, int index=0) const
#define SYSmin(a, b)
Definition: SYS_Math.h:1366
virtual int64 getMemoryUsage() const
Definition: GABC_IGTArray.h:64
float fpreal32
Definition: SYS_Types.h:184
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