HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
POP_AttribMap.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  */
7 
8 #ifndef __POP_AttribMap_h__
9 #define __POP_AttribMap_h__
10 
11 #include "POP_API.h"
12 #include <UT/UT_LinkList.h>
13 #include <GA/GA_AttributeRef.h>
14 #include <GA/GA_AttributeRefMap.h>
15 #include <GEO/GEO_Point.h>
16 #include <GEO/GEO_Vertex.h>
17 #include <GU/GU_Detail.h>
18 
19 class UT_String;
20 class POP_AttribMap;
21 class POP_ContextData;
22 class GA_GBElement;
23 class GA_AttributeDict;
25 
26 /// The POP_AttribMap is a class used to manage attributes during particle
27 /// birthing. Its primary role is tracking the attributes which are to be
28 /// inherited from the birth source, but it also manages the temporary
29 /// storage needed to evaluate attribute values from the source geometry.
30 
32 {
33 public:
35  : myName(0)
36  {
37  }
38 
40  {
41  if (myName)
42  free(myName);
43  }
44 
45  GA_StorageClass getType() const { return myType; }
46 
47  const GA_ROAttributeRef &getSourceOffset() const { return sourceOffset; }
48  const GA_ROAttributeRef &getEvalOffset() const { return evalOffset; }
49  const GA_RWAttributeRef &getDestOffset() const { return destOffset; }
50  int getTupleSize() const { return myTupleSize; }
51 
52  /// @{
53  /// Use POP_AttribMap::isEvalPoint() to determine which copy method to
54  /// call.
55  void copySourceData(GA_GBElement &dest,
56  const GA_GBElement &src) const;
57  void copyEvalData(GA_GBElement &dest,
58  const GA_GBElement &eval) const;
59  /// @}
60 
61 private:
62  void setName(const char *name) { myName = strdup(name); }
63  void refreshSource(const GA_AttributeDict &point_dict);
64 
65  GA_ROAttributeRef sourceOffset;
66  GA_ROAttributeRef evalOffset;
67  GA_RWAttributeRef destOffset;
68  int myTupleSize;
69  GA_StorageClass myType;
70  char *myName;
71 
72  friend class POP_AttribMap;
73 };
74 
76 {
77 public:
78  POP_AttribMap (void);
79  virtual ~POP_AttribMap (void);
80 
81  /// Build the mapping between the source and destination details. Note
82  /// that no evaluation storage is allocated here. We allocate this temp
83  /// storage when needed to avoid paying the overhead when we don't need
84  /// it and to give the caller an opportunity to request to specify any
85  /// additional attributes that should be included (for local variable
86  /// evaluation).
87  void build (POP_ContextData* map, const GU_Detail* source,
88  GU_Detail* dest, const UT_String &pattern,
89  int addLocalVar = 0, bool refreshable = false);
90 
91  /// refreshSource() should only be called if the map was built to be
92  /// refreshable by build(). Any extra source attributes registered
93  /// for evaluation via registerExtraSrcEvalAttributeForEval() will
94  /// have to be registered again.
95  void refreshSource(const GU_Detail *source);
96 
97  /// prepareForPossibleSourceDeletion() should be called before any action
98  /// that may result in deleting our source detail. A re-build or refresh
99  /// is not a replacement for this call as the original source detail will
100  /// often already be deleted by that point. This method should typically
101  /// be followed by a build(), refreshSource(), or
102  /// recoverAfterSourceNotDeleted() call.
103  void prepareForPossibleSourceDeletion();
104 
105  /// This method should be called after prepareForPossibleSourceDeletion()
106  /// if the source was not in fact deleted.
107  void recoverAfterSourceNotDeleted();
108 
109  /// @{
110  /// AttributeRefMaps mapping attributes in the evaluation detail to the
111  /// corresponding attributes in the source detail. This is a subset of
112  /// the source attributes consisting of those to be inherited by newly
113  /// birthed particles and also those needed by the generator to evaluate
114  /// attribute-based local variables.
115  ///
116  /// These methods will allocate the eval storage (detail) if it is not
117  /// already available.
119  {
120  ensureEvalStorageIsAvailable();
121  return myHandles;
122  }
124  {
125  ensureEvalStorageIsAvailable();
126  return myVectorHandles;
127  }
128  /// @}
129 
130  /// @{
131  /// Methods to query the maximum number of entries in the various
132  /// evaluation maps without forcing an allocation. Because these
133  /// methods don't account for the overlap between the attributes
134  /// we evaluate for inheritence and those we evaluate for local
135  /// variables, the returned value may be greater than the actual
136  /// entry counts of the evaluation maps would be after allocation.
138  {
139  if (myEvalDetail)
140  return myHandles.entries();
141  else
142  {
143  // myHandles will contain all the mapped
144  // attributes, all the extra evaluation
145  // attributes, and P.
146  return length()
147  + mySrcExtraEvalAttributes.entries()
148  + 1;
149  }
150  }
152  {
153  if (myEvalDetail)
154  return myVectorHandles.entries();
155  else
156  {
157  return myMappedVectorEntries +
158  myExtraVectorEntries;
159  }
160  }
161  /// @}
162 
164  { return (myEvalNormalOffset); }
165  bool hasSrcVelocity() const
166  { return(mySrcVelocityOffset.isValid()); }
167 
168  void getSrcOrEvalNormal(UT_Vector3 &N,
169  GEO_PointP src);
170  void setSrcNormal(const UT_Vector3& N) { mySourceNml = N; }
171 
172  /// Will allocate the eval storage (detail) if it is not already available.
174  {
175  ensureEvalStorageIsAvailable();
176  return myEvalVertex;
177  }
178  /// Will allocate the eval storage (detail) if it is not already available.
180  {
181  ensureEvalStorageIsAvailable();
182  return myEvalPoint;
183  }
184  bool isEvalPoint(GEO_PointP elem) const
185  {
186  if (!elem)
187  return !myEvalPoint;
188  if (!myEvalPoint)
189  return false;
190  return &elem->getIndexMap() == &myEvalPoint->getIndexMap() &&
191  elem->getMapOffset() == myEvalPoint->getMapOffset();
192  }
193  const GU_Detail *getSrcDetail() const
194  { return mySrcDetail; }
195  const GU_Detail *peekEvalDetail() const
196  { return myEvalDetail; }
197 
198  /// Any extra attributes should be registered before the first call
199  /// needing evaluation storage. Any such attributes will need to be
200  /// registered again after any build() or refreshSource() call.
201  void registerExtraSrcAttributeForEval(
202  const GA_Attribute *attrib);
203 
205  {
206  if (!myEvalDetail) // already initialized
207  initializeEvalStorage();
208  }
209 
210 private:
211  void initializeEvalStorage();
212 
213  const GU_Detail *mySrcDetail;
214  GU_Detail *myEvalDetail;
215  GA_AttributeRefMap myHandles;
216  GA_AttributeRefMap myVectorHandles;
217  // Special instance used to manage a vertex pool bound to myEvalDetail.
218  // Necessary to preserve temporary vertex/point across refreshSource().
219  GA_AttributeRefMap myVertexPoolWrapper;
220 
221  int myMappedVectorEntries;
222  int myExtraVectorEntries;
223 
224  GA_ROAttributeRef mySrcNormalOffset;
225  GA_ROAttributeRef mySrcVelocityOffset;
226 
227  GA_RWAttributeRef myEvalNormalOffset;
228 
229  /// A list of additional attributes from the source detail requiring
230  /// evaluation during birthing.
231  UT_ValArray<const GA_Attribute *> mySrcExtraEvalAttributes;
232 
233  GEO_WorkVertexBuffer *myVertexBuffer;
234  GEO_Vertex *myEvalVertex;
235  GEO_PointP myEvalPoint;
236  UT_Vector3 mySourceNml;
237 };
238 
239 #endif
bool hasSrcVelocity() const
Definition of a geometry attribute.
Definition: GA_Attribute.h:190
const GU_Detail * getSrcDetail() const
int peekEvalVectorMapMaxEntries() const
GA_Offset getMapOffset() const
Definition: GA_GBElement.h:103
void ensureEvalStorageIsAvailable()
#define POP_API
Definition: POP_API.h:10
GA_StorageClass
Definition: GA_Types.h:68
int peekEvalMapMaxEntries() const
3D Vector class.
GA_AttributeRefMap & getEvalVectorMap()
A string map of attributes to ease backward compatibility In the GB/GEO/GU library code would often p...
This class provides a way to manage a reference to an attribute permitting Read-Write access...
GEO_Vertex * getEvalVertex()
Will allocate the eval storage (detail) if it is not already available.
This class provides a way to manage a reference to an attribute permitting Read-Only access...
GLsizei GLsizei GLchar * source
Definition: glcorearb.h:802
bool isEvalPoint(GEO_PointP elem) const
A handle to simplify manipulation of multiple attributes.
GLuint const GLchar * name
Definition: glcorearb.h:785
const GA_ROAttributeRef & getSourceOffset() const
Definition: POP_AttribMap.h:47
const GA_RWAttributeRef & getEvalNormalOffset()
const GA_ROAttributeRef & getEvalOffset() const
Definition: POP_AttribMap.h:48
const GA_RWAttributeRef & getDestOffset() const
Definition: POP_AttribMap.h:49
GA_StorageClass getType() const
Definition: POP_AttribMap.h:45
GEO_PointP getEvalPoint()
Will allocate the eval storage (detail) if it is not already available.
GA_API const UT_StringHolder N
GA_AttributeRefMap & getEvalMap()
DO NOT USE THIS CLASS!!!
Definition: GEO_Point.h:389
void setSrcNormal(const UT_Vector3 &N)
const GU_Detail * peekEvalDetail() const
int getTupleSize() const
Definition: POP_AttribMap.h:50
GLenum src
Definition: glcorearb.h:1792
const GA_IndexMap & getIndexMap() const
Provide access to the GA_IndexMap containing this element.
Definition: GA_GBElement.h:99