HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GA_AIFInterp.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_AIFInterp.h ( GA Library, C++)
7  *
8  * COMMENTS: Attribute Interface for Interpolation
9  */
10 
11 #ifndef __GA_AIFInterp__
12 #define __GA_AIFInterp__
13 
14 #include "GA_API.h"
15 
16 #include "GA_Types.h"
17 
18 #include <SYS/SYS_Types.h>
19 
20 
21 class GA_Range;
22 class GA_Attribute;
24 class GA_WeightedSum;
25 
26 
27 /// @brief Attribute Interface class to perform interpolation operations on
28 /// attributes.
29 ///
30 /// This class provides an interface to perform interpolation operations on
31 /// attribute data.@n
32 /// - lerp(d, a, b, t)
33 /// @code d = SYSlerp(a, b, t) = (t-1)*a + t*b @endcode
34 /// - smooth(d, min, max, t)
35 /// @code d = SYSsmooth(min, max, t) @endcode
36 /// - fit(d, t, omin, omax, nmin, nmax)
37 /// @code d = SYSfit(t, omin, omax, nmin, nmax) @endcode
38 /// - fit01(d, t, nmin, nmax)
39 /// @code d = SYSfit(t, 0, 1, nmin, nmax) @endcode
40 /// - Weighted sum
41 /// - startSum(d, sum)@n
42 /// Initializes the weighted sum for a given attribute
43 /// - addSum(d, sum, a, w)@n
44 /// Add @b a*w to the sum.
45 /// - addSquare(d, sum, a, w)@n
46 /// Add @b a*a*w to the sum
47 /// - endSum(d, sum, scale_factor)@n
48 /// Complete the sum, scaling the value. If @b scale_factor is 1, then
49 /// no scaling is performed.
50 /// - endSquare(d, sum, scale_factor)@n
51 /// Complete the sum by scaling, then taking the square root of the
52 /// result. If @b scale_factor is 1, then no scaling is
53 /// performed.
54 /// For example, the lerp function can be implemented as: @code
55 /// lerp(d, a, b, t) {
56 /// GA_AIFInterp *i = d.getAIFInterp();
57 /// i->startSum(d, sum);
58 /// i->addSum(d, sum, a, 1-t);
59 /// i->addSum(d, sum, b, t);
60 /// i->finishSum(d, sum);
61 /// }
62 /// // To compute the RMS of an attribute: @code
63 /// rms(d, a, b, t) {
64 /// GA_AIFInterp *i = d.getAIFInterp();
65 /// i->startSum(d, sum);
66 /// i->addSquare(d, sum, a, 1);
67 /// i->addSquare(d, sum, b, 1);
68 /// i->finishSquare(d, sum, 1/sum.getTotalWeight());
69 /// }
70 /// // Compute the sum of the squares of the input
71 /// sumSquares(d, a, b, t) {
72 /// GA_AIFInterp *i = d.getAIFInterp();
73 /// i->startSum(d, sum);
74 /// i->addSquare(d, sum, a, 1);
75 /// i->addSquare(d, sum, b, 1);
76 /// i->finishSum(d, sum, 1.0);
77 /// }
78 ///
79 class GA_API GA_AIFInterp
80 {
81 public:
82  GA_AIFInterp() {}
83  virtual ~GA_AIFInterp();
84 
85  /// Return whether this interpolator is a conditional interpolation or
86  /// whether values are actually interpolated.
87  virtual bool isConditionalInterpolation() const { return false; }
88 
89  /// Note: Weighted sums can only be performed on a single element, and thus
90  /// don't have a generic GA_AttributeOperand method.
91  /// @param d The destination attribute
92  /// @param di The index in the destination attribute used to store results
93  /// @param sum Weighted sum to keep track of partial sums
94  virtual bool startSum(GA_Attribute &d, GA_Offset di,
95  const GA_WeightedSum &sum) const = 0;
96  /// Add an element into the weighted sum
97  /// @param d Destination attribute
98  /// @param di Destination offset
99  /// @param sum Storage for state of weighted sum
100  /// @param a Attribute to add into the sum
101  /// @param ai Index of the attribute to add into the sum
102  virtual bool addSum(GA_Attribute &d, GA_Offset di,
103  const GA_WeightedSum &sum,
104  const GA_Attribute &a, GA_Offset ai) const = 0;
105 
106  /// Add the square of an element to the weighted sum
107  /// @param d Destination attribute
108  /// @param di Destination offset
109  /// @param sum Storage for state of weighted sum
110  /// @param a Attribute to add into the sum
111  /// @param ai Index of the attribute to add into the sum
112  virtual bool addSquare(GA_Attribute &d, GA_Offset di,
113  const GA_WeightedSum &sum,
114  const GA_Attribute &a, GA_Offset ai) const = 0;
115 
116  /// Finish a weighted sum. The scale_factor can be used to normalize
117  /// weighting. For example: @code
118  /// endSum(d, di, sum, 1./sum.getTotalWeight());
119  /// @endcode
120  virtual bool endSum(GA_Attribute &d, GA_Offset di,
121  const GA_WeightedSum &sum,
122  fpreal scale_factor = 1) const = 0;
123 
124  /// Finish a weighted sum by scaling then taking the square root of the
125  /// sum. The scale_factor can be used to normalize weighting. For
126  /// example: @code
127  /// endSquare(d, di, sum, 1./sum.getTotalWeight());
128  /// @endcode
129  /// A scale of 1 will result in the result being the square root of the sum.
130  virtual bool endSquare(GA_Attribute &d, GA_Offset di,
131  const GA_WeightedSum &sum,
132  fpreal scale_factor = 1) const = 0;
133 
134  /// Add an element into the weighted sum where the element refers to
135  /// homogeneous coordinates.
136  ///
137  /// The @c wsum should be used in the endSum() to correct the
138  /// normalization. That is, the endSum() code should look like: @code
139  /// endSum(d, di, sum, scale_factor / wsum, ...);
140  /// @endcode
141  /// where the scale_factor is the non-homogeneous scale factor.
142  ///
143  /// @param d Destination attribute
144  /// @param di Destination offset
145  /// @param sum Storage for state of weighted sum
146  /// @param a Attribute to add into the sum
147  /// @param ai Index of the attribute to add into the sum
148  /// @note The default behaviour of this method is to call addSum()
149  virtual bool addHSum(GA_Attribute &d, GA_Offset di,
150  const GA_WeightedSum &sum,
151  const GA_Attribute &a, GA_Offset ai) const;
152 
153  /// Add the square of the homogeneous input to the sum
154  virtual bool addHSquare(GA_Attribute &d, GA_Offset di,
155  const GA_WeightedSum &sum,
156  const GA_Attribute &a, GA_Offset ai) const;
157 
158  /// Finish a weighted sum for homogeneous coordinates. The scale_factor
159  /// can be used to normalize weighting. For example: @code
160  /// endHSum(d, di, sum, 1./sum.getTotalWeight());
161  /// @endcode
162  virtual bool endHSum(GA_Attribute &d, GA_Offset di,
163  const GA_WeightedSum &sum,
164  fpreal scale_factor = 1) const;
165  /// Finish a weighted sum for homogeneous coordinates by scaling then
166  /// taking the square root.
167  /// For example: @code
168  /// endHSquare(d, di, sum, 1./sum.getTotalWeight());
169  /// @endcode
170  virtual bool endHSquare(GA_Attribute &d, GA_Offset di,
171  const GA_WeightedSum &sum,
172  fpreal scale_factor = 1) const;
173 
174  /// d = SYSlerp(a, b, t);
175  virtual bool lerp(GA_AttributeOperand &d,
178  GA_AttributeOperand &t) const;
179  /// d = SYSsmooth(min, max, t);
180  virtual bool smooth(GA_AttributeOperand &d,
183  GA_AttributeOperand &t) const;
184 
185  /// d = SYSfit(a, omin, omax, nmin, nmax);
186  virtual bool fit(GA_AttributeOperand &d,
188  GA_AttributeOperand &omin,
189  GA_AttributeOperand &omax,
190  GA_AttributeOperand &nmin,
191  GA_AttributeOperand &nmax) const;
192 
193  /// d = SYSfit(a, 0, 1, nmin, nmax);
194  virtual bool fit01(GA_AttributeOperand &d,
196  GA_AttributeOperand &nmin,
197  GA_AttributeOperand &nmax) const;
198 
199 
200  /// @{
201  /// Specializations of common method
202  virtual bool lerp(GA_Attribute &d, GA_Offset di,
203  const GA_Attribute &a, GA_Offset ai,
204  const GA_Attribute &b, GA_Offset bi,
205  fpreal t) const = 0;
206  virtual bool lerp(GA_Attribute &d, const GA_Range &di,
207  const GA_Attribute &a, const GA_Range &ai,
208  const GA_Attribute &b, const GA_Range &bi,
209  fpreal t) const = 0;
210  virtual bool lerp(GA_Attribute &d, const GA_Range &di,
211  const GA_Attribute &a, const GA_Range &ai,
212  const GA_Attribute &b, const GA_Range &bi,
213  const GA_Attribute &t, const GA_Range &ti
214  ) const = 0;
215 
216  virtual bool smooth(GA_Attribute &d, GA_Offset di,
217  fpreal min, fpreal max,
218  const GA_Attribute &a, GA_Offset ai) const = 0;
219  virtual bool smooth(GA_Attribute &d, const GA_Range &di,
220  fpreal min, fpreal max,
221  const GA_Attribute &a, const GA_Range &ai
222  ) const = 0;
223 
224  virtual bool fit(GA_Attribute &d, GA_Offset di,
225  const GA_Attribute &a, GA_Offset ai,
226  fpreal omin, fpreal omax,
227  fpreal nmin, fpreal nmax) const = 0;
228  virtual bool fit(GA_Attribute &d, const GA_Range &di,
229  const GA_Attribute &a, const GA_Range &ai,
230  fpreal omin, fpreal omax,
231  fpreal nmin, fpreal nmax) const = 0;
232  /// @}
233 
234  // The fit01() methods simply pass in 0 & 1 as omin/omax
235  virtual bool fit01(GA_Attribute &d, const GA_Range &di,
236  const GA_Attribute &a, const GA_Range &ai,
237  fpreal nmin, fpreal nmax) const;
238  virtual bool fit01(GA_Attribute &d, GA_Offset di,
239  const GA_Attribute &a, GA_Offset ai,
240  fpreal nmin, fpreal nmax) const;
241 
242  /// @{
243  /// This macro can be used to implement the non-pure virtual attribute
244  /// operand methods by calling the baseclass given (usually GA_AIFMath).
245  /// For example, it might be used as: @code
246  /// class MyTupleInterface : public GA_AIFTuple
247  /// {
248  /// public:
249  /// GA_AIFMATH_OPERAND_METHODS(GA_AIFTuple)
250  /// ... implement rest of class
251  /// }
252  /// @endcode
253  #define GA_AIFINTERP_OPERAND_METHODS(BASECLASS) \
254  virtual bool lerp(GA_AttributeOperand &d, \
255  GA_AttributeOperand &a, \
256  GA_AttributeOperand &b, \
257  GA_AttributeOperand &t) const \
258  { return BASECLASS::lerp(d, a, b, t); } \
259  virtual bool smooth(GA_AttributeOperand &d, \
260  GA_AttributeOperand &min, \
261  GA_AttributeOperand &max, \
262  GA_AttributeOperand &t) const \
263  { return BASECLASS::smooth(d, min, max, t); } \
264  virtual bool fit(GA_AttributeOperand &d, \
265  GA_AttributeOperand &a, \
266  GA_AttributeOperand &omin, \
267  GA_AttributeOperand &omax, \
268  GA_AttributeOperand &nmin, \
269  GA_AttributeOperand &nmax) const \
270  { return BASECLASS::fit(d, a, omin, omax, nmin, nmax); }
271  /// @}
272 };
273 
274 #endif
Definition of a geometry attribute.
Definition: GA_Attribute.h:189
virtual bool endHSum(GA_Attribute &d, GA_Offset di, const GA_WeightedSum &sum, fpreal scale_factor=1) const
virtual bool addHSum(GA_Attribute &d, GA_Offset di, const GA_WeightedSum &sum, const GA_Attribute &a, GA_Offset ai) const
const hboost::disable_if_c< VecTraits< T >::IsVec, T >::type & min(const T &a, const T &b)
Definition: Composite.h:128
virtual bool lerp(GA_AttributeOperand &d, GA_AttributeOperand &a, GA_AttributeOperand &b, GA_AttributeOperand &t) const
d = SYSlerp(a, b, t);
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1221
Context to keep track of weighted sums.
#define GA_API
Definition: GA_API.h:12
virtual bool endSquare(GA_Attribute &d, GA_Offset di, const GA_WeightedSum &sum, fpreal scale_factor=1) const =0
virtual bool fit(GA_AttributeOperand &d, GA_AttributeOperand &a, GA_AttributeOperand &omin, GA_AttributeOperand &omax, GA_AttributeOperand &nmin, GA_AttributeOperand &nmax) const
d = SYSfit(a, omin, omax, nmin, nmax);
A range of elements in an index-map.
Definition: GA_Range.h:42
virtual bool fit01(GA_AttributeOperand &d, GA_AttributeOperand &a, GA_AttributeOperand &nmin, GA_AttributeOperand &nmax) const
d = SYSfit(a, 0, 1, nmin, nmax);
const hboost::disable_if_c< VecTraits< T >::IsVec, T >::type & max(const T &a, const T &b)
Definition: Composite.h:132
GA_Size GA_Offset
Definition: GA_Types.h:617
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1221
double fpreal
Definition: SYS_Types.h:269
virtual bool smooth(GA_AttributeOperand &d, GA_AttributeOperand &min, GA_AttributeOperand &max, GA_AttributeOperand &t) const
d = SYSsmooth(min, max, t);
virtual bool addHSquare(GA_Attribute &d, GA_Offset di, const GA_WeightedSum &sum, const GA_Attribute &a, GA_Offset ai) const
Add the square of the homogeneous input to the sum.
virtual bool endSum(GA_Attribute &d, GA_Offset di, const GA_WeightedSum &sum, fpreal scale_factor=1) const =0
Attribute Interface class to perform interpolation operations on attributes.
virtual bool endHSquare(GA_Attribute &d, GA_Offset di, const GA_WeightedSum &sum, fpreal scale_factor=1) const