HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
POP_GenVar.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_GenVar_h__
9 #define __POP_GenVar_h__
10 
11 #include "POP_API.h"
12 #include "POP_Node.h"
13 
14 
15 class UT_String;
16 
17 
18 /// A subclass of POP_Node that handles many functions common to generators
19 /// including some common generator variables. Many generator POPs will
20 /// derive from this subclass instead of POP_Node.
21 
22 class POP_API POP_GenVar : public POP_Node
23 {
24 public:
25 
26  static CH_LocalVariable myVariables[];
28 
30 
32  {
33  PRIMITIVE_EDGE = 0,
34  PRIMITIVE_SURFACE = 1,
35  PRIMITIVE_CENTER = 2
36  };
37 
38 protected:
39  POP_GenVar (OP_Network* net, const char* name,
40  OP_Operator* entry);
41  virtual ~POP_GenVar (void);
42 
43  // the birthFrom___ functions birth particles from certain types of
44  // source geometry.
45  // Points = birth from points
46  // Primitives = birth from primitives
47  // MetaPrim = birth from metaprimitives
48  // Detail = birth from detail's volume
49  //
50  // data POP_ContextData being used
51  // doVar update local variables for source point
52  // gdp detail to retrieve geometry from
53  // group point or primitive group to use (or NULL)
54  // xform transform to apply to birthed particle position
55  // (or NULL)
56  // xformv transform to apply to vector attributes
57  // (or NULL)
58  // map mapping for inheriting attributes.
59  // The map should correspond to the inherit
60  // attribute data if it is set, otherwise, it
61  // should be built for the source gdp.
62  // (or NULL to do no inheriting).
63  // inherit attribute data to inherit general attributes
64  // from. if NULL, then general attributes are
65  // inherited from the source geo.
66  // split attributes from source particle when
67  // splitting (or NULL when not splitting).
68  // originIndex origin index value.
69  // originUse how to set origin id. Bit mask
70  // POP_ORIGIN_INDEX: add passed in index
71  // POP_ORIGIN_GEO: add source geometry number
72  // POP_ORIGIN_PARENT: add split origin
73  // source geo number:
74  // point - pt num
75  // primitives - primitive num
76  // metaprim - 0
77  // detail - 0
78  // born number of points to birth
79  // part particle primitive to birth into
80  // birthGroup group to add birthed points to (or NULL)
81  // lifetime function that generates a particle lifetime
82  // probability function that generates a random number
83  // representing the number of particles to birth
84  // per point/primitive.
85  // birthAttrib function to set attributes after particle
86  // is birthed
87  // doRandom if 1, birth from randomized points. if 0,
88  // birth from points in order
89  // whereFrom PRIMITIVE_EDGE, PRIMITIVE_SURFACE,
90  // or PRIMITIVE_CENTER
91  // checkTrim if 1, birth from trimmed area only.
92  // if 0, birth from entire surface.
93  // threshold for metaprim birthing, points are sampled
94  // and added. Birthin of a particle will occur
95  // when this threshold is passed.
96  // densityMin for metaprim birthing, particle will not be
97  // birthed unless the density is at least this
98  // intersector a GU_RayIntersect to perform ray intersections
99  // with the detail. It is the caller's
100  // responsibility to make sure that the
101  // intersector is initialized.
102  // useDensityProb use metaball density as a probability
103  // distribution for particle births. Causes
104  // threshold parameter to be ignored.
105  // jitter function to do jitter births
106  // maxAttempts failure threshold to tolerate before giving up
107 
108  void birthFromPoints (int doVar, POP_ContextData* data,
109  GU_Detail* gdp, GA_PointGroup* group,
110  const UT_Matrix4* xform,
111  const UT_Matrix3* xformv,
112  POP_AttribMap* map,
113  GEO_PointP split,
114  POP_IntFunc originIndex, int originUse,
115  float* born, GEO_PrimParticle* part,
116  GA_PointGroup* birthGroup,
117  POP_FloatFunc lifetime,
118  POP_FloatFunc probability,
119  POP_BirthAttribFunc birthAttrib,
120  int doRandom,
121  POP_JitterFunc jitter = 0,
122  int maxAttempts=100);
123 
124  void birthFromPointVelocity (int doVar, POP_ContextData *data,
125  GU_Detail *gdp, GA_PointGroup *group,
126  const UT_Matrix4 *xform,
127  const UT_Matrix3 *xformv,
128  POP_AttribMap *map,
129  POP_IntFunc originIndex, int originUse,
130  float *born, GEO_PrimParticle *part,
131  GA_PointGroup *birthGroup,
132  POP_FloatFunc lifetime,
133  POP_BirthAttribFunc birthAttrib,
134  UT_Vector3 birthVelocity,
135  UT_Vector3 birthAcceleration,
136  fpreal velocityScale,
137  fpreal particleSpacing);
138 
139  void birthFromPrimitives (int doVar, POP_ContextData* data,
140  GU_Detail* gdp, GA_PrimitiveGroup* group,
141  const UT_Matrix4* xform,
142  const UT_Matrix3* xformv,
143  POP_AttribMap* map,
144  GEO_PointP split,
145  POP_IntFunc originIndex, int originUse,
146  float* born, GEO_PrimParticle* part,
147  GA_PointGroup* birthGroup,
148  POP_FloatFunc lifetime,
149  POP_FloatFunc probability,
150  POP_BirthAttribFunc birthAttrib,
151  PrimitiveOrigin whereFrom, int checkTrim,
152  POP_JitterFunc jitter = 0,
153  int doRandom = 0, int maxAttempts = 100);
154 
155  void birthFromMetaPrim (int doVar, POP_ContextData* data,
156  GU_Detail* gdp, GA_PrimitiveGroup* group,
157  const UT_Matrix4* xform,
158  const UT_Matrix3* xformv,
159  POP_AttribMap* map,
160  GEO_PointP split,
161  POP_IntFunc originIndex, int originUse,
162  float* born, GEO_PrimParticle* part,
163  GA_PointGroup* birthGroup,
164  POP_FloatFunc lifetime,
165  POP_BirthAttribFunc birthAttrib,
166  float threshold, float densityMin,
167  int useDensityProb,
168  POP_JitterFunc jitter = 0,
169  int maxAttempts = 100);
170 
171  void birthFromDetail (int doVar, POP_ContextData* data,
172  GU_Detail* gdp,
173  const UT_Matrix4* xform,
174  const UT_Matrix3* xformv,
175  POP_AttribMap* map,
176  GEO_PointP split,
177  POP_IntFunc originIndex, int originUse,
178  float* born, GEO_PrimParticle* part,
179  GA_PointGroup* birthGroup,
180  POP_FloatFunc lifetime,
181  POP_BirthAttribFunc birthAttrib,
182  GU_RayIntersect* intersector,
183  POP_JitterFunc jitter = 0,
184  int maxAttempts = 100);
185 
186  // the birthNonUniformlyFromRandomPrimitives function births particles
187  // from certain types of source geometry in a non-uniform random manner.
188  //
189  // All parameters common with the birthFrom__ functions have the same
190  // meaning. In addition, this method supports the following additional
191  // parameters.
192  //
193  // distribAttrib - name of the primitive attribute which specifies
194  // the probability distribution for each primitive.
195  // The values are normalized and then used as the
196  // probability that this is the random primitive
197  // selected to birth from.
198  // If attribute does not exist, a uniform distribution
199  // is used by default.
200  // NOTE: if the value of the attribute for a
201  // primitive is <= 0, then particles will
202  // not birth off of that primitive.
203  //
204  void birthNonUniformlyFromRandomPrimitives (int doVar,
206  GU_Detail* gdp, GA_PrimitiveGroup* group,
207  const UT_Matrix4* xform,
208  const UT_Matrix3* xformv,
209  POP_AttribMap* map,
210  POP_IntFunc originIndex, int originUse,
211  float* born, GEO_PrimParticle* part,
212  GA_PointGroup* birthGroup,
213  POP_FloatFunc lifetime,
214  POP_FloatFunc probability,
215  POP_BirthAttribFunc birthAttrib,
216  PrimitiveOrigin whereFrom, int checkTrim,
217  POP_JitterFunc jitter,
218  const UT_String &distribAttrib,
219  int maxAttempts);
220 
221 
222  // buildVectorTransform() builds a matrix that transforms vectors.
223  // If xform is used to transform points, then xformv can be
224  // applied to transform vectors.
225  void buildVectorTransform (UT_Matrix3& xformv,
226  const UT_Matrix4& xform);
227 
228  virtual bool evalVariableValue(fpreal &v, int index, int thread);
229  virtual bool evalVariableValue(UT_String &v, int i, int thr)
230  { return POP_Node::evalVariableValue(v, i, thr); }
231 
232  void setupVars (POP_ContextData* data,
233  GU_Detail* gdp,
234  const GA_ElementGroup* source = 0);
235 
236  // Jitter births can change the detail being birthed from, consequently
237  // obsoleting the underlying attribute data set up with the setupVars()
238  // call. The hasAttributeVars() and refreshAttributeVars() methods below
239  // can be used to keep this data updated.
240  bool hasSourceAttributeVars() const;
241  void refreshSourceAttributeVars(GU_Detail *gdp);
242 
243  /// Local variables may require evaluating attributes that would not
244  /// otherwise need to be evaluated for birthing purposes. Call this
245  /// method to register those attributes for evaluation with the map.
246  void registerSourceAttributesForEval(POP_AttribMap &map)
247  const;
248 
249  virtual int isVarDependent (GU_Detail* gdp, POP_FParam param,
250  float t, int thread);
251  virtual int isVarDependent (GU_Detail* gdp, POP_IParam param,
252  float t, int thread);
253  virtual int isVarDependent (GU_Detail* gdp, POP_SParam param,
254  float t, int thread);
255  virtual int isVarDependent (GU_Detail* gdp, EV_EXPRESSION* expr,
256  int thread);
257 
258  virtual void allowVar (int val) { myAllowGeneratorVar = val; };
259  int isAllowVar() const { return myAllowGeneratorVar; }
260 
261  int isVarTest() const { return myVarTest; }
262  void setVarDependent(int val) { myVarDependent = val; }
263 
264  float getLastEmissionTime(const GEO_Detail *gdp) const;
265  void getLastEmissionAttrName(UT_String &name) const;
266  void setLastEmissionTime(GEO_Detail *gdp, float time) const;
267 
268 private:
269  class POP_API SourceAttribOffsets
270  {
271  public:
272  void refresh(const GU_Detail *gdp);
273  void clear();
274  bool areAnyValid() const;
275  void registerForEval(POP_AttribMap &map) const;
276 
277  GA_ROAttributeRef myAlphaOffset;
278  GA_ROAttributeRef myDiffuseOffset;
279  GA_ROAttributeRef myDistanceOffset;
280  GA_ROAttributeRef myDragOffset;
281  GA_ROAttributeRef myMassOffset;
282  GA_ROAttributeRef myNormalOffset;
283  GA_ROAttributeRef myScaleOffset;
284  GA_ROAttributeRef mySpringKOffset;
285  GA_ROAttributeRef myTensionOffset;
286  GA_ROAttributeRef myTextureOffset;
287  GA_ROAttributeRef myUpOffset;
288  GA_ROAttributeRef myVelocityOffset;
289  };
290 
291 protected:
292  const UT_Vector4 *mySourcePos; // source position
293  const GA_GBElement *mySourceAttElem; // Source attributes
296  const SourceAttribOffsets *mySourceAttOffsets;
297  const GA_GBElement *mySourceElem; // source element
299  int mySourceIter; // iteration number
300  float mySourceU; // source parametric u
301  float mySourceV; // source parametric v
302  UT_Vector3 *mySourceNml; // source normal
303 
304  /// A given candidate for mySourceAttElem can be from the source detail
305  /// or from the map's evaluation detail. This method returns the right
306  /// attribute offsets to use for mySourceAttOffsets.
307  ///
308  /// This method will initialize myEvalOffsetCache prior to returning it
309  /// when necessary.
310  const SourceAttribOffsets *getSourceOffsets(
311  const POP_AttribMap *map,
312  GEO_PointP source_att_elem);
313 
314 private:
315  void computeBBox();
316 
317  int myNumParticles;
318  int myNumPoints;
319  int myNumPrims;
320  int myNumGroupEntries;
321  GU_Detail *myBBGdp;
322  UT_Vector3 myBBOrigin;
323  UT_Vector3 myBBScale;
324  float myTimeInc;
325 
326  int myAllowGeneratorVar;
327  int myVarDependent;
328  int myVarTest;
329 
330  /// mySourceAttOffsets will either be NULL or will be pointing to one
331  /// of the following two caches. The first caches attribute info for
332  /// the source detail. The second caches the same for the evaluation
333  /// detail in the local POP_AttribMap instance.
334  SourceAttribOffsets mySourceOffsetCache;
335  SourceAttribOffsets myEvalOffsetCache;
336  bool myEvalOffsetCacheInit;
337 };
338 
339 #endif
virtual bool evalVariableValue(UT_String &v, int i, int thr)
Definition: POP_GenVar.h:229
virtual void allowVar(int val)
Control whether parameter evalutions are allowed to reference local variables.
Definition: POP_GenVar.h:258
virtual int isVarDependent(GU_Detail *gdp, POP_FParam param, float t, int thread)
const GA_GBElement * mySourceAttElem
Definition: POP_GenVar.h:293
#define POP_API
Definition: POP_API.h:10
const GLdouble * v
Definition: glcorearb.h:836
GA_GBPrimWrap mySourceTmpPrim
Definition: POP_GenVar.h:295
float(POP_Node::* POP_FParam)(float t)
Definition: POP_Node.h:403
void(POP_Node::* POP_SParam)(UT_String &s, float t)
Definition: POP_Node.h:405
3D Vector class.
static OP_TemplatePair myTemplatePair
Definition: POP_GenVar.h:29
png_uint_32 i
Definition: png.h:2877
int isVarTest() const
Definition: POP_GenVar.h:261
void(POP_Node::* POP_JitterFunc)(GU_Detail **gdp, GA_PointGroup **pointGroup, GA_PrimitiveGroup **primGroup, GU_RayIntersect **rayIntersect, POP_AttribMap **map, float timeIncFraction)
Definition: POP_Node.h:389
void(POP_Node::* POP_BirthAttribFunc)(POP_ContextData *data, GEO_PointP ppt, UT_Vector3 *vel, void *userdata)
Definition: POP_Node.h:367
int(POP_Node::* POP_IParam)(float t)
Definition: POP_Node.h:404
static OP_VariablePair myVariablePair
Definition: POP_GenVar.h:27
This class provides a way to manage a reference to an attribute permitting Read-Only access...
GLsizei GLsizei GLchar * source
Definition: glcorearb.h:802
float(POP_Node::* POP_FloatFunc)(POP_ContextData *data)
Definition: POP_Node.h:374
UT_Vector3 * mySourceNml
Definition: POP_GenVar.h:302
int mySourceIter
Definition: POP_GenVar.h:299
GLboolean * data
Definition: glcorearb.h:130
GLuint const GLchar * name
Definition: glcorearb.h:785
GEO_Point mySourceAttTmpPt
Definition: POP_GenVar.h:294
int(POP_Node::* POP_IntFunc)(POP_ContextData *data)
Definition: POP_Node.h:380
double fpreal
Definition: SYS_Types.h:269
GLenum GLfloat param
Definition: glcorearb.h:103
const GA_GBElement * mySourceElem
Definition: POP_GenVar.h:297
void setVarDependent(int val)
Definition: POP_GenVar.h:262
float mySourceV
Definition: POP_GenVar.h:301
GLuint index
Definition: glcorearb.h:785
GLuint GLfloat * val
Definition: glcorearb.h:1607
const UT_Vector4 * mySourcePos
Definition: POP_GenVar.h:292
virtual bool evalVariableValue(UT_String &val, int index, int thread)
int isAllowVar() const
Definition: POP_GenVar.h:259
GEO_Point mySourceTmpPt
Definition: POP_GenVar.h:298
DO NOT USE THIS CLASS!!!
Definition: GEO_Point.h:389
const SourceAttribOffsets * mySourceAttOffsets
Definition: POP_GenVar.h:296
float mySourceU
Definition: POP_GenVar.h:300