HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GA_AttributeOperand.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_AttributeOperand.h ( GA Library, C++)
7  *
8  * COMMENTS: Wrapper class around different styles of operands for
9  * operations on attributes.
10  */
11 
12 #ifndef __GA_AttributeOperand__
13 #define __GA_AttributeOperand__
14 
15 #include "GA_API.h"
16 #include "GA_AttributeProxy.h"
17 #include "GA_Iterator.h"
18 #include "GA_Range.h"
19 #include "GA_Types.h"
20 
21 #include <SYS/SYS_Types.h>
22 
23 #include <stddef.h>
24 
25 
26 class GA_AIFTuple;
27 class GA_Attribute;
28 class GA_Range;
29 
30 
31 /// The GA_AttributeOperand class provides a simple interface to look at data
32 /// in operations performed on attributes. Accessing the data may be less
33 /// efficient than direct access. But it allows you to have a trade-off
34 /// between code complexity and efficiency.
36 {
37 public:
38  /// Constant value for all iterations/tuples
39  GA_AttributeOperand(fpreal, const GA_Attribute &attrib);
40 
41  /// Constant tuple of fpreal32 values for all iterations
42  GA_AttributeOperand(const fpreal32 *value, int tuple_size,
43  const GA_Attribute &attrib);
44 
45  /// Constant tuple of fpreal64 values for all iterations
46  GA_AttributeOperand(const fpreal64 *value, int tuple_size,
47  const GA_Attribute &attrib);
48 
49  /// Writable attribute for a single iteration
51 
52  /// Read-only attribute, single value for all iterations
53  GA_AttributeOperand(const GA_Attribute &attrib, GA_Offset offset);
54 
55  /// Writable attribute with a selection of offsets based on the iterator
56  GA_AttributeOperand(GA_Attribute &attrib, const GA_Range &it);
57 
58  /// Read-only attribute with a selection of offsets based on the iterator
59  GA_AttributeOperand(const GA_Attribute &attrib, const GA_Range &it);
60 
61  /// Destructor
63 
64  /// Rewind and start iterating.
65  void rewind();
66  /// Test whether the iterations are complete. This operation will return
67  /// false for all operands except.
68  /// - Operands with full iterators (dependent on iterator state)
69  /// - Writeable attributes with a single offset. These attributes will
70  /// return true after the first iteration.
71  /// @note Read-only attributes that have a single offset will keep
72  /// returning the same value and iterate for ever.
73  bool atEnd() const; // Advance to next element
74  /// Advance to the next iteration.
75  /// This operation is a no-op for operands which don't have an iterator.
76  /// The exception is the writable attribute with a single offset.
77  void advance();
78 
79  /// Query the tuple size. For constant scalar values, the tuplesize will
80  /// be 2**31-1.
81  int getTupleSize() const { return myTupleSize; }
82 
83  /// @{
84  /// Import/Store a value from the given tuple index. The function will
85  /// return false if the operation fails.
86  bool getI(GA_Offset off, int64 &v, int tuple_idx=0) const;
87  bool getF(GA_Offset off, fpreal &v, int tple_idx=0) const;
88  bool setF(GA_Offset off, fpreal v, int tuple_idx=0) const;
89  bool getI(const GA_Iterator &it, int64 &v, int tuple_idx=0) const
90  { return getI(it.getOffset(), v, tuple_idx); }
91  bool getF(const GA_Iterator &it, fpreal &v, int tuple_idx=0) const
92  { return getF(it.getOffset(), v, tuple_idx); }
93  bool setF(const GA_Iterator &it, fpreal v, int tuple_idx=0) const
94  { return setF(it.getOffset(), v, tuple_idx); }
95  /// @}
96 
97  /// @{
98  /// Extract a full tuple. This will succeed fail if the tuple size
99  /// of the attribute is smaller than the requested size. Otherwise, the
100  /// tuple of the attribute may be truncated to the requested size.
101  bool getF(GA_Offset off, fpreal32 *v, int tuple_size) const;
102  bool getF(GA_Offset off, fpreal64 *v, int tuple_size) const;
103  bool getF(const GA_Iterator &it, fpreal32 *v, int tuple_size) const
104  { return getF(it.getOffset(), v, tuple_size); }
105  bool getF(const GA_Iterator &it, fpreal64 *v, int tuple_size) const
106  { return getF(it.getOffset(), v, tuple_size); }
107  /// @}
108 
109  /// @{
110  /// Store a tuple of values. The tuple size passed in will be clamped to
111  /// the tuple size of the underlying attribute.
112  bool setF(GA_Offset off, const fpreal32 *v, int tuple_size) const;
113  bool setF(GA_Offset off, const fpreal64 *v, int tuple_size) const;
114  bool setF(const GA_Iterator &it, const fpreal32 *v, int size) const
115  { return setF(it.getOffset(), v, size); }
116  bool setF(const GA_Iterator &it, const fpreal64 *v, int size) const
117  { return setF(it.getOffset(), v, size); }
118  /// @}
119 
120  /// Raw access to the writable attribute
122  {
123  return myDestProxy
124  ? myDestProxy->getAttribute()
125  : NULL;
126  }
127 
128  /// Raw access to the read-only attribute
129  const GA_Attribute *getAttribute() const
130  {
131  return myDestProxy
132  ? myDestProxy->getAttribute()
133  : NULL;
134  }
135 
136  /// Query whether the underlying attribute, if any, uses integer storage.
137  bool getIsIntegral() const;
138 
139  /// Test to determine whether the operand is writable
140  bool getIsWritable() const;
141 
142  /// Test to determine whether the operand has a finite selection. That is,
143  /// whether it has a finite iterator (i.e. a constant has an infinite number
144  /// of iterations).
145  bool getIsFinite() const;
146 
147  /// Test whether the operand is responsible for iterating.
148  bool isIterator() const { return myRange != &myRepeater; }
149 
150  /// Get raw access to the iterator. This is used to prevent multiple
151  /// iterations of the same iterator.
152  const GA_Range &getRange() const { return *myRange; }
153 
154 private:
155 #if 1
156  GA_AttributeProxyHandle myDestProxy;
157 #else
158  union {
159  const GA_AttributeProxy *myConst;
160  GA_AttributeProxy *myNonConst;
161  } myAttribProxy;
162 #endif
163  GA_Range myRepeater; // Range for non-iterator operands
164  const GA_Range *myRange;
165  const GA_AIFTuple *myTuple; // To access attributes as floats
166  const fpreal32 *myReal32;
167  const fpreal64 *myReal64;
168  fpreal myValue;
169  GA_Offset myOffset;
170  int myTupleSize;
171  int myMode; // Mode of operation
172  bool myOffsetIteratorDone;
173 };
174 
175 #endif
Definition of a geometry attribute.
Definition: GA_Attribute.h:189
Iteration over a range of elements.
Definition: GA_Iterator.h:28
bool getF(const GA_Iterator &it, fpreal &v, int tuple_idx=0) const
const GLdouble * v
Definition: glcorearb.h:836
GA_Attribute * getAttribute()
Raw access to the writable attribute.
#define GA_API
Definition: GA_API.h:12
GA_Offset getOffset() const
Definition: GA_Iterator.h:66
bool setF(const GA_Iterator &it, fpreal v, int tuple_idx=0) const
GLsizeiptr size
Definition: glcorearb.h:663
bool setF(const GA_Iterator &it, const fpreal64 *v, int size) const
A range of elements in an index-map.
Definition: GA_Range.h:42
GA_Size GA_Offset
Definition: GA_Types.h:617
long long int64
Definition: SYS_Types.h:106
This class holds a reference to an attribute. Such an indirection level allows an easy way to invalid...
double fpreal64
Definition: SYS_Types.h:191
bool setF(const GA_Iterator &it, const fpreal32 *v, int size) const
const GA_Attribute * getAttribute() const
Raw access to the read-only attribute.
GLintptr offset
Definition: glcorearb.h:664
bool getF(const GA_Iterator &it, fpreal64 *v, int tuple_size) const
bool isIterator() const
Test whether the operand is responsible for iterating.
GLsizei const GLfloat * value
Definition: glcorearb.h:823
double fpreal
Definition: SYS_Types.h:269
bool getI(const GA_Iterator &it, int64 &v, int tuple_idx=0) const
Generic Attribute Interface class to access an attribute as a tuple.
Definition: GA_AIFTuple.h:32
bool getF(const GA_Iterator &it, fpreal32 *v, int tuple_size) const
float fpreal32
Definition: SYS_Types.h:190
const GA_Range & getRange() const