HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GA_ElementWrangler.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_ElementWrangler.h ( GA Library, C++)
7  *
8  * COMMENTS: A utility class to abstract common preamble from GA_GBElement
9  * methods to a higher level.
10  */
11 
12 #ifndef __GA_ElementWrangler__
13 #define __GA_ElementWrangler__
14 
15 #include "GA_API.h"
16 #include "GA_AttributeFilter.h"
17 #include "GA_AttributeRefMap.h"
18 #include "GA_Types.h"
19 
20 #include <UT/UT_NonCopyable.h>
21 #include <SYS/SYS_Types.h>
22 
23 
24 class GA_Attribute;
25 class GA_Detail;
26 class GA_Range;
27 
28 
29 /// @brief A utility class to amortize overhead from GA_GBElement attribute
30 /// handling methods.
31 ///
32 /// The GA_ElementWrangler class provides a simplified interface for common
33 /// attribute operations as elements are added or removed.
34 ///
35 /// This class is not thread-safe, so each thread should have its own copy,
36 /// and any attributes added after its instantiation will not be processed.
37 
39 {
40 public:
42  {
43  myMap.copyValue(myOwner, dest, myOwner, src);
44  }
45  void copyAttributeValues(const GA_Range &dest, GA_Offset src);
47  {
48  myMap.multiply(myOwner, dest, scale);
49  }
51  fpreal scale=1)
52  {
53  myMap.addValue(myOwner, dest, myOwner, src, scale);
54  }
56  GA_Offset src1, fpreal bias)
57  {
58  myMap.lerpValue(myOwner, dest, myOwner, src0, src1, bias);
59  }
60 
61  bool isValid(GA_Detail &dest) const
62  {
63  return myMap.getDestDetail() == &dest &&
64  myMap.getSourceDetail() == &dest;
65  }
66  bool isValid(GA_Detail &dest, const GA_Detail &src) const
67  {
68  return myMap.getDestDetail() == &dest &&
69  myMap.getSourceDetail() == &src;
70  }
71  int getNumAttributes() const
72  { return myMap.entries(); }
74  {
75  myMap.bumpAllDestDataIds();
76  }
77 protected:
79  const GA_Attribute *exclude = 0);
81  const GA_Detail &src, const GA_Attribute *exclude = 0);
82 
84  const GA_AttributeFilter &filter);
86  const GA_Detail &src, const GA_AttributeFilter &filter);
87 
88  /// Protected destructor as we don't support polymorphic destruction.
90 
91  GA_AttributeRefMap &getMap() { return myMap; }
92 private:
93  GA_AttributeOwner myOwner;
94  GA_AttributeRefMap myMap;
95 };
96 
97 /// By default, operations on "P" are performed as with any other attribute.
98 /// However, it's possible to turn on the homogeneous flag which will ensure
99 /// that operations are done using homogeneous coordinates.
101 {
102 public:
103  enum IncludeP { EXCLUDE_P, INCLUDE_P };
104 
105  /// The GA_PointWrangler::IncludeP argument passed to the constructor
106  /// determines whether the base class operations include "P".
107  GA_PointWrangler(GA_Detail &dest, IncludeP p);
108  GA_PointWrangler(GA_Detail &dest, const GA_Detail &src, IncludeP p);
109 
111  GA_PointWrangler(GA_Detail &dest, const GA_Detail &src,
112  const GA_AttributeFilter &filter);
113 
115  {
116  delete myAlternateMap;
117  }
118 
119  bool includesP() const { return myBaseIncludeP == INCLUDE_P; }
120 
125 
127  IncludeP copy_p)
128  {
129  if (copy_p == myBaseIncludeP)
130  copyAttributeValues(dest, src);
131  else
132  {
133  initAlternateHandle();
134  myAlternateMap->copyValue(
135  GA_ATTRIB_POINT, dest,
136  GA_ATTRIB_POINT, src);
137  }
138  }
140  IncludeP scale_p)
141  {
142  if (scale_p == myBaseIncludeP)
143  scaleAttributeValues(dest, scale);
144  else
145  {
146  initAlternateHandle();
147  myAlternateMap->multiply(
148  GA_ATTRIB_POINT, dest, scale);
149  }
150  }
152  fpreal scale, IncludeP add_p)
153  {
154  if (add_p == myBaseIncludeP)
155  addAttributeValues(dest, src, scale);
156  else
157  {
158  initAlternateHandle();
159  myAlternateMap->addValue(
160  GA_ATTRIB_POINT, dest,
161  GA_ATTRIB_POINT, src, scale);
162  }
163  }
165  GA_Offset src1, fpreal bias,
166  IncludeP lerp_p)
167  {
168  if (lerp_p == myBaseIncludeP)
169  lerpAttributeValues(dest, src0, src1, bias);
170  else
171  {
172  initAlternateHandle();
173  myAlternateMap->lerpValue(
174  GA_ATTRIB_POINT, dest,
175  GA_ATTRIB_POINT, src0, src1, bias);
176  }
177  }
178 private:
179  void initAlternateHandle()
180  {
181  if (!myAlternateMap)
182  allocAlternateHandle();
183  }
184  void allocAlternateHandle();
185 
186  // We keep track of whether the base class handle includes "P" since we
187  // may need to allocate an alternate handle when an operation requests
188  // the opposite behavior.
189  IncludeP myBaseIncludeP;
190  GA_AttributeFilter myFilter;
191  GA_AttributeRefMap *myAlternateMap;
192 };
193 
195 {
196 public:
200  : GA_ElementWrangler(GA_ATTRIB_VERTEX, dest, src) {}
201 
203  : GA_ElementWrangler(GA_ATTRIB_VERTEX, dest, filter) {}
205  const GA_AttributeFilter &filter)
206  : GA_ElementWrangler(GA_ATTRIB_VERTEX, dest, src, filter) {}
207 private:
208 };
209 
211 {
212 public:
216  : GA_ElementWrangler(GA_ATTRIB_PRIMITIVE, dest, src) {}
217 
219  : GA_ElementWrangler(GA_ATTRIB_PRIMITIVE, dest, filter) {}
221  const GA_AttributeFilter &filter)
222  : GA_ElementWrangler(GA_ATTRIB_PRIMITIVE, dest, src, filter) {}
223 private:
224 };
225 
227 {
228 public:
232  : GA_ElementWrangler(GA_ATTRIB_GLOBAL, dest, src) {}
233 
235  : GA_ElementWrangler(GA_ATTRIB_GLOBAL, dest, filter) {}
237  const GA_AttributeFilter &filter)
238  : GA_ElementWrangler(GA_ATTRIB_GLOBAL, dest, src, filter) {}
239 private:
240 };
241 
243 {
244 public:
246  GA_PointWrangler::IncludeP include_p)
247  : myDestGdp(&dest), mySrcGdp(&dest), myPrimitiveWrangler(0),
248  myVertexWrangler(0), myPointWrangler(0), myIncludeP(include_p) {}
250  GA_PointWrangler::IncludeP include_p)
251  : myDestGdp(&dest), mySrcGdp(&src), myPrimitiveWrangler(0),
252  myVertexWrangler(0), myPointWrangler(0), myIncludeP(include_p) {}
253 
255  const GA_AttributeFilter &filter)
256  : myDestGdp(&dest), mySrcGdp(&dest), myPrimitiveWrangler(0),
257  myVertexWrangler(0), myPointWrangler(0), myFilter(filter) {}
259  const GA_AttributeFilter &filter)
260  : myDestGdp(&dest), mySrcGdp(&src), myPrimitiveWrangler(0),
261  myVertexWrangler(0), myPointWrangler(0), myFilter(filter) {}
262 
264  {
265  if (myPrimitiveWrangler)
266  delete myPrimitiveWrangler;
267  if (myVertexWrangler)
268  delete myVertexWrangler;
269  if (myPointWrangler)
270  delete myPointWrangler;
271  }
272 
273  void clear()
274  {
275  if (myPrimitiveWrangler)
276  {
277  delete myPrimitiveWrangler;
278  myPrimitiveWrangler = 0;
279  }
280  if (myVertexWrangler)
281  {
282  delete myVertexWrangler;
283  myVertexWrangler = 0;
284  }
285  if (myPointWrangler)
286  {
287  delete myPointWrangler;
288  myPointWrangler = 0;
289  }
290  }
291 
292  void reset(GA_Detail &dest)
293  {
294  myDestGdp = &dest;
295  mySrcGdp = &dest;
296  clear();
297  }
298  void reset(GA_Detail &dest, const GA_Detail &src)
299  {
300  myDestGdp = &dest;
301  mySrcGdp = &src;
302  clear();
303  }
304  bool isValid(const GA_Detail &dest) const
305  {
306  return myDestGdp == &dest &&
307  mySrcGdp == &dest;
308  }
309  bool isValid(const GA_Detail &dest,
310  const GA_Detail &src) const
311  {
312  return myDestGdp == &dest &&
313  mySrcGdp == &src;
314  }
315 
317  {
318  if (!myPrimitiveWrangler)
319  {
320  if (myFilter.isValid())
321  myPrimitiveWrangler = new GA_PrimitiveWrangler(*myDestGdp,
322  *mySrcGdp,
323  myFilter);
324  else
325  myPrimitiveWrangler = new GA_PrimitiveWrangler(*myDestGdp,
326  *mySrcGdp);
327  }
328  return *myPrimitiveWrangler;
329  }
331  {
332  if (!myVertexWrangler)
333  {
334  if (myFilter.isValid())
335  myVertexWrangler = new GA_VertexWrangler(*myDestGdp,
336  *mySrcGdp,
337  myFilter);
338  else
339  myVertexWrangler = new GA_VertexWrangler(*myDestGdp,
340  *mySrcGdp);
341  }
342  return *myVertexWrangler;
343  }
345  {
346  if (!myPointWrangler)
347  {
348  if (myFilter.isValid())
349  myPointWrangler = new GA_PointWrangler(*myDestGdp, *mySrcGdp,
350  myFilter);
351  else
352  myPointWrangler = new GA_PointWrangler(*myDestGdp, *mySrcGdp,
353  myIncludeP);
354  }
355  return *myPointWrangler;
356  }
357 
358 private:
359  GA_Detail *myDestGdp;
360  const GA_Detail *mySrcGdp;
361  GA_PrimitiveWrangler *myPrimitiveWrangler;
362  GA_VertexWrangler *myVertexWrangler;
363  GA_PointWrangler *myPointWrangler;
364  GA_PointWrangler::IncludeP myIncludeP;
365  GA_AttributeFilter myFilter;
366 };
367 
368 #endif
GA_DetailWrangler(GA_Detail &dest, const GA_Detail &src, const GA_AttributeFilter &filter)
void scaleAttributeValues(GA_Offset dest, fpreal scale)
GA_VertexWrangler & getVertex()
void addAttributeValues(GA_Offset dest, GA_Offset src, fpreal scale, IncludeP add_p)
Definition of a geometry attribute.
Definition: GA_Attribute.h:190
void copyAttributeValues(GA_Offset dest, GA_Offset src)
GA_PrimitiveWrangler(GA_Detail &dest, const GA_Detail &src, const GA_AttributeFilter &filter)
bool includesP() const
GA_DetailWrangler(GA_Detail &dest)
void addAttributeValues(GA_Offset dest, GA_Offset src, fpreal scale=1)
GA_ElementWranglerCache(GA_Detail &dest, const GA_AttributeFilter &filter)
bool isValid(GA_Detail &dest, const GA_Detail &src) const
~GA_ElementWrangler()
Protected destructor as we don't support polymorphic destruction.
bool isValid(GA_Detail &dest) const
A utility class to amortize overhead from GA_GBElement attribute handling methods.
#define GA_API
Definition: GA_API.h:12
GA_ElementWranglerCache(GA_Detail &dest, const GA_Detail &src, const GA_AttributeFilter &filter)
GA_VertexWrangler(GA_Detail &dest)
void reset(GA_Detail &dest)
A range of elements in an index-map.
Definition: GA_Range.h:42
GA_Size GA_Offset
Definition: GA_Types.h:617
GA_API const UT_StringHolder scale
GA_DetailWrangler(GA_Detail &dest, const GA_AttributeFilter &filter)
GA_DetailWrangler(GA_Detail &dest, const GA_Detail &src)
void lerpAttributeValues(GA_Offset dest, GA_Offset src0, GA_Offset src1, fpreal bias, IncludeP lerp_p)
void reset(GA_Detail &dest, const GA_Detail &src)
GA_ElementWranglerCache(GA_Detail &dest, GA_PointWrangler::IncludeP include_p)
A handle to simplify manipulation of multiple attributes.
bool isValid(const GA_Detail &dest, const GA_Detail &src) const
GA_VertexWrangler(GA_Detail &dest, const GA_Detail &src)
GA_PointWrangler & getPoint()
GA_PrimitiveWrangler(GA_Detail &dest, const GA_Detail &src)
GA_AttributeOwner
Definition: GA_Types.h:33
double fpreal
Definition: SYS_Types.h:270
GA_VertexWrangler(GA_Detail &dest, const GA_Detail &src, const GA_AttributeFilter &filter)
GA_ElementWranglerCache(GA_Detail &dest, const GA_Detail &src, GA_PointWrangler::IncludeP include_p)
GA_AttributeRefMap & getMap()
void scaleAttributeValues(GA_Offset dest, fpreal scale, IncludeP scale_p)
GA_PrimitiveWrangler(GA_Detail &dest)
void lerpAttributeValues(GA_Offset dest, GA_Offset src0, GA_Offset src1, fpreal bias)
GA_VertexWrangler(GA_Detail &dest, const GA_AttributeFilter &filter)
Container class for all geometry.
Definition: GA_Detail.h:95
void copyAttributeValues(GA_Offset dest, GA_Offset src, IncludeP copy_p)
GA_PrimitiveWrangler(GA_Detail &dest, const GA_AttributeFilter &filter)
GA_PrimitiveWrangler & getPrimitive()
int getNumAttributes() const
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition: glcorearb.h:1296
GLenum src
Definition: glcorearb.h:1792
bool isValid(const GA_Detail &dest) const