HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GA_AIFTuple.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: GA_AIFTuple.h ( GA Library, C++)
7  *
8  * COMMENTS: Tuple Attribute Interface
9  */
10 
11 #ifndef __GA_AIFTuple__
12 #define __GA_AIFTuple__
13 
14 #include "GA_API.h"
15 #include "GA_Types.h"
16 
17 #include <SYS/SYS_Types.h>
18 #include <SYS/SYS_TypeTraits.h>
19 
20 #include <vector>
21 
22 
23 class GA_Attribute;
24 class GA_Range;
25 class GA_Defaults;
26 
27 /// @brief Generic Attribute Interface class to access an attribute as a
28 /// tuple.
29 ///
30 /// This class provides the interface to access attribute data. Each
31 /// attribute type may provide this interface if it makes sense.
33 {
34 public:
35  GA_AIFTuple();
36  virtual ~GA_AIFTuple();
37 
38  /// @{
39  /// Query and set some tuple intrisics.
40  virtual int getTupleSize(const GA_Attribute *attrib) const = 0;
41  virtual bool setTupleSize(GA_Attribute *attrib, int size) const = 0;
42 
43  virtual GA_Storage getStorage(const GA_Attribute *attrib) const = 0;
44  virtual bool setStorage(GA_Attribute *attrib,
45  GA_Storage storage) const = 0;
46  /// @}
47 
48  /// @{
49  /// Make the attribute constant
50  virtual bool makeConstant(GA_Attribute *attrib,
51  int32 data, int index=0) const = 0;
52  virtual bool makeConstant(GA_Attribute *attrib,
53  int64 data, int index=0) const = 0;
54  virtual bool makeConstant(GA_Attribute *attrib,
55  fpreal32 data, int index=0) const = 0;
56  virtual bool makeConstant(GA_Attribute *attrib,
57  fpreal64 data, int index=0) const = 0;
58 
59  virtual bool makeConstant(GA_Attribute *attrib,
60  const int32 *data, int len, int index=0) const = 0;
61  virtual bool makeConstant(GA_Attribute *attrib,
62  const int64 *data, int len, int index=0) const = 0;
63  virtual bool makeConstant(GA_Attribute *attrib,
64  const fpreal32 *data, int len, int index=0) const = 0;
65  virtual bool makeConstant(GA_Attribute *attrib,
66  const fpreal64 *data, int len, int index=0) const = 0;
67  /// @}
68 
69  /// @{
70  /// Get a single value from a single offset in an attribute array.
71  virtual bool get(const GA_Attribute *attrib,
72  GA_Offset ai, int32 &data, int index=0) const = 0;
73  /// Get a single value from a single offset in an attribute array.
74  virtual bool get(const GA_Attribute *attrib,
75  GA_Offset ai, int64 &data, int index=0) const = 0;
76  /// Get a single value from a single offset in an attribute array.
77  virtual bool get(const GA_Attribute *attrib,
78  GA_Offset ai, fpreal32 &data, int index=0) const=0;
79  /// Get a single value from a single offset in an attribute array.
80  virtual bool get(const GA_Attribute *attrib,
81  GA_Offset ai, fpreal64 &data, int index=0) const=0;
82  /// @}
83 
84  /// @{
85  /// Get a tuple of values from a single array element, starting at the
86  /// (optionally) specified component.
87  virtual bool get(const GA_Attribute *attrib, GA_Offset ai,
88  int32 *data, int count, int start=0) const = 0;
89  /// Get a tuple of values from a single array element
90  virtual bool get(const GA_Attribute *attrib, GA_Offset ai,
91  int64 *data, int count, int start=0) const = 0;
92  /// Get a tuple of values from a single array element
93  virtual bool get(const GA_Attribute *attrib, GA_Offset ai,
94  fpreal32 *data, int count, int start=0) const = 0;
95  /// Get a tuple of values from a single array element
96  virtual bool get(const GA_Attribute *attrib, GA_Offset ai,
97  fpreal64 *data, int count, int start=0) const = 0;
98  /// @}
99 
100  // The default methods are not pure virtual and are implemented using the
101  // scalar methods above, but subclasses may override them to provide more
102  // efficient implementations.
103  /// @{
104  /// Get an array of values from a selection of elements from the attribute.
105  /// The result array must have been preallocated. If tuple_size is
106  /// not positive, the tuple size is assumed to be the attribute's tuple
107  /// size. If explicitly specified, 'tuple_size' values will be copied to
108  /// the result array for each element
109  virtual bool getRange(const GA_Attribute *attrib,
110  const GA_Range &range, int32 *result,
111  int start=0, int tuple_size=-1) const
112  { return templatedGetRange(attrib, range, result, start, tuple_size); }
113  /// Get an array of values from a selection of elements from the attribute.
114  /// The result array must have been preallocated.
115  virtual bool getRange(const GA_Attribute *attrib,
116  const GA_Range &range, int64 *result,
117  int start=0, int tuple_size=-1) const
118  { return templatedGetRange(attrib, range, result, start, tuple_size); }
119  /// Get an array of values from a selection of elements from the attribute.
120  /// The result array must have been preallocated.
121  virtual bool getRange(const GA_Attribute *attrib,
122  const GA_Range &range, fpreal32 *result,
123  int start=0, int tuple_size=-1) const
124  { return templatedGetRange(attrib, range, result, start, tuple_size); }
125  /// Get an array of values from a selection of elements from the attribute.
126  /// The result array must have been preallocated.
127  virtual bool getRange(const GA_Attribute *attrib,
128  const GA_Range &range, fpreal64 *result,
129  int start=0, int tuple_size=-1) const
130  { return templatedGetRange(attrib, range, result, start, tuple_size); }
131 
132  /// Templated version of getRange() which allows for both arithmetic types
133  /// as well as UT_Vector[234] UT_Matrix[234], UT_Quaternion[FD] types.
134  /// @{
135  template <typename T>
137  const GA_Attribute *attrib,
138  const GA_Range &range, T *result,
139  int start=0,
140  typename SYS_EnableIf< SYS_IsArithmetic_v<T> >::type *dummy = 0) const
141  {
142  // scalar fallback
143  return getRange(attrib, range, result, start, 1);
144  }
145  template <typename T>
147  const GA_Attribute *attrib,
148  const GA_Range &range, T *result,
149  int start=0,
150  typename SYS_DisableIf< SYS_IsArithmetic_v<T> >::type *dummy = 0) const
151  {
152  typedef typename T::value_type S;
153  return getRange(attrib, range, (S *)result, start, T::tuple_size);
154  }
155  /// @}
156 
157  /// Get an array of values from a selection of elements from the attribute
158  /// into a flattened std::vector of the appropriate type.
159  virtual bool getRangeInContainer(const GA_Attribute *attrib,
160  const GA_Range &range,
161  std::vector<int32> &data,
162  int start=0, int tuple_size=-1) const
163  { return templatedContainerGetRange(attrib, range, data, start, tuple_size); }
164  /// Get an array of values from a selection of elements from the attribute
165  /// into a flattened std::vector of the appropriate type.
166  virtual bool getRangeInContainer(const GA_Attribute *attrib,
167  const GA_Range &range,
168  std::vector<int64> &data,
169  int start=0, int tuple_size=-1) const
170  { return templatedContainerGetRange(attrib, range, data, start, tuple_size); }
171  /// Get an array of values from a selection of elements from the attribute
172  /// into a flattened std::vector of the appropriate type.
173  virtual bool getRangeInContainer(const GA_Attribute *attrib,
174  const GA_Range &range,
175  std::vector<fpreal32> &data,
176  int start=0, int tuple_size=-1) const
177  { return templatedContainerGetRange(attrib, range, data, start, tuple_size); }
178  /// Get an array of values from a selection of elements from the attribute
179  /// into a flattened std::vector of the appropriate type.
180  virtual bool getRangeInContainer(const GA_Attribute *attrib,
181  const GA_Range &range,
182  std::vector<fpreal64> &data,
183  int start=0, int tuple_size=-1) const
184  { return templatedContainerGetRange(attrib, range, data, start, tuple_size); }
185 
186 private:
187  template <typename T>
188  bool templatedGetRange(const GA_Attribute *attrib,
189  const GA_Range &range, T *result,
190  int start, int tuple_size) const;
191  template <typename T>
192  bool templatedContainerGetRange(const GA_Attribute *attrib,
193  const GA_Range &range, std::vector<T> &data,
194  int start, int tuple_size) const;
195 public:
196  /// @}
197 
198  /// @{
199  /// Test if any elements are NAN's
200  virtual bool isNan(const GA_Attribute *attrib, GA_Offset ai) const=0;
201  virtual bool isNan(const GA_Attribute *attrib,
202  const GA_Range &it) const = 0;
203  /// @}
204 
205  /// Return the default values for the attribute.
206  virtual const GA_Defaults getDefaults(const GA_Attribute *attrib) const = 0;
207 
208  // ----------------------------------------------------------------------
209 
210  /// @{
211  /// Set a component of a single element of the array.
212  /// If the component is -1, all elements of the tuple will be set to
213  /// the value.
214  virtual bool set(GA_Attribute *attrib, GA_Offset ai,
215  int32 data, int comp=-1) const = 0;
216  virtual bool set(GA_Attribute *attrib, GA_Offset ai,
217  int64 data, int comp=-1) const = 0;
218  virtual bool set(GA_Attribute *attrib, GA_Offset ai,
219  fpreal32 data, int comp=-1) const = 0;
220  virtual bool set(GA_Attribute *attrib, GA_Offset ai,
221  fpreal64 data, int comp=-1) const = 0;
222 
223  virtual bool set(GA_Attribute *attrib, const GA_Range &ai,
224  int32 data, int comp=-1) const = 0;
225  virtual bool set(GA_Attribute *attrib, const GA_Range &ai,
226  int64 data, int comp=-1) const = 0;
227  virtual bool set(GA_Attribute *attrib, const GA_Range &ai,
228  fpreal32 data, int comp=-1) const = 0;
229  virtual bool set(GA_Attribute *attrib, const GA_Range &ai,
230  fpreal64 data, int comp=-1) const = 0;
231  /// @}
232 
233  /// @{
234  /// Set a single element of the attribute to a tuple of values, starting
235  /// at the (optionally) specified component.
236  virtual bool set(GA_Attribute *attrib, GA_Offset ai,
237  const int32 *data, int count,
238  int start = 0) const = 0;
239  virtual bool set(GA_Attribute *attrib, GA_Offset ai,
240  const int64 *data, int count,
241  int start = 0) const = 0;
242  virtual bool set(GA_Attribute *attrib, GA_Offset ai,
243  const fpreal32 *data, int count,
244  int start = 0) const = 0;
245  virtual bool set(GA_Attribute *attrib, GA_Offset ai,
246  const fpreal64 *data, int count,
247  int start = 0) const = 0;
248 
249  virtual bool set(GA_Attribute *attrib, const GA_Range &ai,
250  const int32 *data, int count,
251  int start = 0) const = 0;
252  virtual bool set(GA_Attribute *attrib, const GA_Range &ai,
253  const int64 *data, int count,
254  int start = 0) const = 0;
255  virtual bool set(GA_Attribute *attrib, const GA_Range &ai,
256  const fpreal32 *data, int count,
257  int start = 0) const = 0;
258  virtual bool set(GA_Attribute *attrib, const GA_Range &ai,
259  const fpreal64 *data, int count,
260  int start = 0) const = 0;
261  /// @}
262 
263  // The default methods are not pure virtual and are implemented using the
264  // scalar methods above, but subclasses may override them to provide more
265  // efficient implementations.
266  /// @{
267  /// Set a selection of attributes to elements from an array of values.
268  /// If the tuple size is not positive, it is assumed to be the attribute's
269  /// tuple size. If explicitly specified, 'tuple_size' values will be
270  /// copied from the array for each element.
271  virtual bool setRange(GA_Attribute *attrib,
272  const GA_Range &it,
273  const int32 *data,
274  int start=0,
275  int tuple_size=-1) const
276  { return templatedSetRange(attrib, it, data, start, tuple_size); }
277  virtual bool setRange(GA_Attribute *attrib,
278  const GA_Range &it,
279  const int64 *data,
280  int start=0,
281  int tuple_size=-1) const
282  { return templatedSetRange(attrib, it, data, start, tuple_size); }
283  virtual bool setRange(GA_Attribute *attrib,
284  const GA_Range &it,
285  const fpreal32 *data,
286  int start=0,
287  int tuple_size=-1) const
288  { return templatedSetRange(attrib, it, data, start, tuple_size); }
289  virtual bool setRange(GA_Attribute *attrib,
290  const GA_Range &it,
291  const fpreal64 *data,
292  int start=0,
293  int tuple_size=-1) const
294  { return templatedSetRange(attrib, it, data, start, tuple_size); }
295 
296  /// Templated version of setRange() which allows for both arithmetic types
297  /// as well as UT_Vector[234] UT_Matrix[234], UT_Quaternion[FD] types.
298  /// @note Like setRange(), sets from an array of range.getEntries() values
299  /// @{
300  template <typename T>
302  GA_Attribute *attrib,
303  const GA_Range &range,
304  const T *data,
305  int start=0,
306  typename SYS_EnableIf< SYS_IsArithmetic_v<T> >::type *dummy = 0) const
307  {
308  // scalar fallback
309  return setRange(attrib, range, data, start, 1);
310  }
311  template <typename T>
313  GA_Attribute *attrib,
314  const GA_Range &range,
315  const T *data,
316  int start=0,
317  typename SYS_DisableIf< SYS_IsArithmetic_v<T> >::type *dummy = 0) const
318  {
319  typedef typename T::value_type S;
320  return setRange(attrib, range, (S *)data, start, T::tuple_size);
321  }
322  /// @}
323 
324 private:
325  template <typename T>
326  bool templatedSetRange(GA_Attribute *a,
327  const GA_Range &range, const T *data,
328  int start, int tuple_size) const;
329 public:
330  /// @}
331 
332  // ----------------------------------------------------------------------
333  /// Copy values from the source attribute to this attribute
334  virtual bool set(GA_Attribute &dest, GA_Offset di,
335  const GA_Attribute &src, GA_Offset si,
336  int component=-1) const = 0;
337  /// Copy values from the source attribute to this attribute
338  virtual bool set(GA_Attribute &dest, const GA_Range &di,
339  const GA_Attribute &src, const GA_Range &si,
340  int component=-1) const = 0;
341 
342  /// @{
343  /// Homogenize the tuple (i.e. multiply through by the last element of the
344  /// tuple).
345  virtual bool homogenize(GA_Attribute &dest, GA_Offset di) const;
346  /// @}
347 
348  /// @{
349  /// Dehomogenize (divide through by the last element of the tuple)
350  virtual bool dehomogenize(GA_Attribute &dest, GA_Offset di) const;
351  /// @}
352 };
353 
354 #endif
Definition of a geometry attribute.
Definition: GA_Attribute.h:198
int int32
Definition: SYS_Types.h:39
GLenum GLint * range
Definition: glcorearb.h:1925
virtual bool getRange(const GA_Attribute *attrib, const GA_Range &range, fpreal32 *result, int start=0, int tuple_size=-1) const
Definition: GA_AIFTuple.h:121
bool setRangeTuple(GA_Attribute *attrib, const GA_Range &range, const T *data, int start=0, typename SYS_DisableIf< SYS_IsArithmetic_v< T > >::type *dummy=0) const
Definition: GA_AIFTuple.h:312
virtual bool setRange(GA_Attribute *attrib, const GA_Range &it, const fpreal64 *data, int start=0, int tuple_size=-1) const
Definition: GA_AIFTuple.h:289
Class which stores the default values for a GA_Attribute.
Definition: GA_Defaults.h:35
getFileOption("OpenEXR:storage") storage
Definition: HDK_Image.dox:276
GLboolean * data
Definition: glcorearb.h:131
GLuint start
Definition: glcorearb.h:475
virtual bool setRange(GA_Attribute *attrib, const GA_Range &it, const fpreal32 *data, int start=0, int tuple_size=-1) const
Definition: GA_AIFTuple.h:283
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
#define GA_API
Definition: GA_API.h:14
**But if you need a result
Definition: thread.h:613
float fpreal32
Definition: SYS_Types.h:200
uint64 value_type
Definition: GA_PrimCompat.h:29
virtual bool getRange(const GA_Attribute *attrib, const GA_Range &range, int32 *result, int start=0, int tuple_size=-1) const
Definition: GA_AIFTuple.h:109
A range of elements in an index-map.
Definition: GA_Range.h:42
virtual bool getRange(const GA_Attribute *attrib, const GA_Range &range, int64 *result, int start=0, int tuple_size=-1) const
Definition: GA_AIFTuple.h:115
double fpreal64
Definition: SYS_Types.h:201
GA_Size GA_Offset
Definition: GA_Types.h:646
virtual bool setRange(GA_Attribute *attrib, const GA_Range &it, const int32 *data, int start=0, int tuple_size=-1) const
Definition: GA_AIFTuple.h:271
virtual bool getRange(const GA_Attribute *attrib, const GA_Range &range, fpreal64 *result, int start=0, int tuple_size=-1) const
Definition: GA_AIFTuple.h:127
constexpr enabler dummy
An instance to use in EnableIf.
Definition: CLI11.h:985
bool isNan(const float x)
Return true if x is a NaN (Not-A-Number) value.
Definition: Math.h:395
long long int64
Definition: SYS_Types.h:116
virtual bool getRangeInContainer(const GA_Attribute *attrib, const GA_Range &range, std::vector< fpreal64 > &data, int start=0, int tuple_size=-1) const
Definition: GA_AIFTuple.h:180
bool getRangeTuple(const GA_Attribute *attrib, const GA_Range &range, T *result, int start=0, typename SYS_EnableIf< SYS_IsArithmetic_v< T > >::type *dummy=0) const
Definition: GA_AIFTuple.h:136
GLsizeiptr size
Definition: glcorearb.h:664
bool getRangeTuple(const GA_Attribute *attrib, const GA_Range &range, T *result, int start=0, typename SYS_DisableIf< SYS_IsArithmetic_v< T > >::type *dummy=0) const
Definition: GA_AIFTuple.h:146
virtual bool setRange(GA_Attribute *attrib, const GA_Range &it, const int64 *data, int start=0, int tuple_size=-1) const
Definition: GA_AIFTuple.h:277
virtual bool getRangeInContainer(const GA_Attribute *attrib, const GA_Range &range, std::vector< fpreal32 > &data, int start=0, int tuple_size=-1) const
Definition: GA_AIFTuple.h:173
bool setRangeTuple(GA_Attribute *attrib, const GA_Range &range, const T *data, int start=0, typename SYS_EnableIf< SYS_IsArithmetic_v< T > >::type *dummy=0) const
Definition: GA_AIFTuple.h:301
GLuint index
Definition: glcorearb.h:786
virtual bool getRangeInContainer(const GA_Attribute *attrib, const GA_Range &range, std::vector< int32 > &data, int start=0, int tuple_size=-1) const
Definition: GA_AIFTuple.h:159
type
Definition: core.h:1059
Generic Attribute Interface class to access an attribute as a tuple.
Definition: GA_AIFTuple.h:32
GA_Storage
Definition: GA_Types.h:51
virtual bool getRangeInContainer(const GA_Attribute *attrib, const GA_Range &range, std::vector< int64 > &data, int start=0, int tuple_size=-1) const
Definition: GA_AIFTuple.h:166
GLint GLsizei count
Definition: glcorearb.h:405
Definition: format.h:895
GLenum src
Definition: glcorearb.h:1793