HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GA_AIFMath.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_AIFMath.h ( GA Library, C++)
7  *
8  * COMMENTS: Attribute Interface class for math methods
9  */
10 
11 #ifndef __GA_AIFMath__
12 #define __GA_AIFMath__
13 
14 #include "GA_API.h"
15 #include "GA_Types.h"
16 
17 #include <UT/UT_VectorTypes.h>
18 
19 #include <SYS/SYS_Types.h>
20 
21 
22 class GA_Attribute;
23 
24 
25 /// @brief Attribute Interface class to perform numeric operations on attributes
26 ///
27 /// This class provides the interface to perform numerical operations on
28 /// attribute data. Each attribute type may provide this interface if it
29 /// makes sense.@n
30 /// <b>Basic mathematicl operations.</b>
31 /// - madd(d, a, b) @code d = d + a*b @endcode
32 /// - scaleoffset(d, s, o) @code d = d*s + o @endcode
33 /// - add(d, a, b) @code d = a + b @endcode
34 /// - mul(d, a, b) @code d = a * b @endcode
35 /// - sub(d, a, b) @code d = a - b @endcode
36 /// - div(d, a, b) @code d = a / b @endcode
37 ///
38 /// <b>Common mathematical operations</b>
39 /// - normalize(d, a) @code d = normalize(a) @endcode
40 ///
41 /// <b>Matrix Operations</b>
42 /// - rowVecMult
43 /// - rowVecMult
44 /// - rowVecMult3
45 /// - colVecMult
46 /// - colVecMult
47 /// - colVecMult3
48 ///
49 /// @b Signatures @n
50 /// When performing operations on attributes, there are different variable
51 /// types.
52 /// - A constant value (scalar or tuple)
53 /// - A single element of the attribute array (specified by an offset)
54 /// - A selection of the attribute array (specified by an iterator)
55 /// Operations are defined as the permutations of all these different variable
56 /// types. The destination (LHS) must always be writable (i.e. an attribute,
57 /// not a constant).
58 ///
59 /// Many operations may also be performed on one or more components of the
60 /// tuple of values. The methods which take a @b component parameter will
61 /// use the component to work only on a single component of the tuple. If
62 /// the component parameter is less than zero, the operation will be applied
63 /// to all components.
64 ///
65 /// For example, the add() operation has the following signatures
66 /// @code
67 /// add(GA_Attribute &d, GA_Offset di, const GA_Attribute &a, GA_Offset ai, fpreal b, int component);
68 /// add(GA_Attribute &d, GA_Offset di, const GA_Attribute &a, GA_Offset ai, const fpreal32 *b, int tuple_size, int component);
69 /// add(GA_Attribute &d, GA_Offset di, const GA_Attribute &a, GA_Offset ai, const fpreal64 *b, int tuple_size, int component);
70 /// add(GA_Attribute &d, GA_Offset di, const GA_Attribute &a, GA_Offset ai, const GA_Attribute &b, GA_Offset bi, int component);
71 /// add(GA_Attribute &d, const GA_Range &di, const GA_Attribute &a, const GA_Range &ai, fpreal b, int component);
72 /// add(GA_Attribute &d, const GA_Range &di, const GA_Attribute &a, const GA_Range &ai, const fpreal32 *b, int tuple_size, int component);
73 /// add(GA_Attribute &d, const GA_Range &di, const GA_Attribute &a, const GA_Range &ai, const fpreal64 *b, int tuple_size, int component);
74 /// add(GA_Attribute &d, const GA_Range &di, const GA_Attribute &a, const GA_Range &ai, const GA_Attribute &b, GA_Offset bi, int component);
75 /// add(GA_Attribute &d, const GA_Range &di, const GA_Attribute &a, const GA_Range &ai, const GA_Attribute &b, const GA_Range &bi, int component);
76 /// @endcode
77 ///
78 /// To assist with being able to implement all these operations with minimal
79 /// effort, please see the GA_AttributeOperand class. All of the specialized
80 /// methods will simply call into the method which handles the operand. If you
81 /// wish to specialize the methods to be more efficient, you can do that by
82 /// overriding the specific method. In the case of add(), the generic
83 /// operation is.
84 /// @code
85 /// add(GA_AttributeOperantd &dest, GA_AttributeOperand &a, GA_AttributeOperand &b);
86 /// @endcode
87 ///
89 {
90 public:
92  virtual ~GA_AIFMath();
93 
94  /// Create an AIFMath which performs no arithmetic on any objects. This is
95  /// different than not having an AIFMath.
96  static const GA_AIFMath *getNoMath();
97 
98  /// Specialization macro for binary operations. This macro provides 9
99  /// specializations for various combinations of parameters. In the base
100  /// class, these methods simply call the generic implementations of the
101  /// operations, returning false if the attribute doesn't support required
102  /// elements.
103  #define GA_MATH_SPEC_BINARY_PURE(NAME) \
104  virtual bool NAME(GA_Attribute &d, GA_Offset di, \
105  const GA_Attribute &a, GA_Offset ai, \
106  fpreal b, int component=-1) const = 0; \
107  virtual bool NAME(GA_Attribute &d, GA_Offset di, \
108  const GA_Attribute &a, GA_Offset ai, \
109  const fpreal32 *b, int tuple_size, \
110  int component=-1) const = 0; \
111  virtual bool NAME(GA_Attribute &d, GA_Offset di, \
112  const GA_Attribute &a, GA_Offset ai, \
113  const fpreal64 *b, int tuple_size, \
114  int component=-1) const = 0; \
115  virtual bool NAME(GA_Attribute &d, GA_Offset di, \
116  const GA_Attribute &a, GA_Offset ai, \
117  const GA_Attribute &b, GA_Offset bi, \
118  int component=-1) const = 0;
119 
120  /// Convenience define for sub-class implementations
121  #define GA_MATH_SPEC_BINARY(NAME) \
122  bool NAME(GA_Attribute &d, GA_Offset di, \
123  const GA_Attribute &a, GA_Offset ai, \
124  fpreal b, int component=-1) const override; \
125  bool NAME(GA_Attribute &d, GA_Offset di, \
126  const GA_Attribute &a, GA_Offset ai, \
127  const fpreal32 *b, int tuple_size, \
128  int component=-1) const override; \
129  bool NAME(GA_Attribute &d, GA_Offset di, \
130  const GA_Attribute &a, GA_Offset ai, \
131  const fpreal64 *b, int tuple_size, \
132  int component=-1) const override; \
133  bool NAME(GA_Attribute &d, GA_Offset di, \
134  const GA_Attribute &a, GA_Offset ai, \
135  const GA_Attribute &b, GA_Offset bi, \
136  int component=-1) const override;
137 
138 
143 
144  // DTYPE is the double precision type (i.e. UT_DMatrix4). FTYPE is the
145  // single precision type (i.e. UT_Matrix4). NAME is the name of the
146  // method.
147  #define GA_MATH_SPEC_TRANSFORM_PURE(DTYPE, FTYPE, NAME) \
148  virtual bool NAME(const DTYPE &xform, \
149  GA_Attribute &d, GA_Offset di, \
150  const GA_Attribute &s, GA_Offset si) const=0; \
151  virtual bool NAME(const FTYPE &xform, \
152  GA_Attribute &d, GA_Offset di, \
153  const GA_Attribute &s, GA_Offset si) const=0;
154 
155  #define GA_MATH_SPEC_TRANSFORM(DTYPE, FTYPE, NAME) \
156  bool NAME(const DTYPE &xform, \
157  GA_Attribute &d, GA_Offset di, \
158  const GA_Attribute &s, \
159  GA_Offset si) const override; \
160  bool NAME(const FTYPE &xform, \
161  GA_Attribute &d, GA_Offset di, \
162  const GA_Attribute &s, GA_Offset si) const override;
163 
164  // Specializations for transform
168  GA_MATH_SPEC_TRANSFORM_PURE(UT_DMatrix4, UT_Matrix4, colVecMult)
169  GA_MATH_SPEC_TRANSFORM_PURE(UT_DMatrix3, UT_Matrix3, colVecMult)
170  GA_MATH_SPEC_TRANSFORM_PURE(UT_DMatrix4, UT_Matrix4, colVecMult3)
171 };
172 
173 #endif
UT_Vector3T< T > rowVecMult(const UT_Vector3T< T > &v, const UT_Matrix3T< S > &m)
Definition: UT_Matrix3.h:1516
Definition of a geometry attribute.
Definition: GA_Attribute.h:198
#define GA_MATH_SPEC_TRANSFORM_PURE(DTYPE, FTYPE, NAME)
Definition: GA_AIFMath.h:147
Attribute Interface class to perform numeric operations on attributes.
Definition: GA_AIFMath.h:88
#define GA_API
Definition: GA_API.h:14
ImageBuf OIIO_API sub(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
OIIO_FORCEINLINE OIIO_HOSTDEVICE float madd(float a, float b, float c)
Fused multiply and add: (a*b + c)
Definition: fmath.h:413
UT_Vector3T< T > colVecMult3(const UT_Matrix4T< S > &m, const UT_Vector3T< T > &v)
Definition: UT_Matrix4.h:1948
#define GA_MATH_SPEC_BINARY_PURE(NAME)
Definition: GA_AIFMath.h:103
UT_Vector3T< T > rowVecMult3(const UT_Vector3T< T > &v, const UT_Matrix4T< S > &m)
Definition: UT_Matrix4.h:1926
UT_Vector3T< T > colVecMult(const UT_Matrix3T< S > &m, const UT_Vector3T< T > &v)
Definition: UT_Matrix3.h:1534
ImageBuf OIIO_API add(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
ImageBuf OIIO_API mul(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)