HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SIM_SolverPop.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 __SIM_SolverPop_h__
9 #define __SIM_SolverPop_h__
10 
11 #include "SIMZ_API.h"
12 #include <SIM/SIM_OptionsUser.h>
13 #include <SIM/SIM_SingleSolver.h>
14 #include <POPNET/POPNET_Node.h>
15 #include "SIMZ_Utils.h"
16 
17 class GU_Detail;
18 class SIM_Impacts;
19 class SIM_DataFilter;
20 class SIM_PopGeometry;
21 class POP_ContextData;
22 
23 #define SIM_NAME_INITIALSTATE PN_INITIALSTATE
24 #define SIM_NAME_RANDOMSEED PN_RANDOMSEED
25 #define SIM_NAME_OVERSAMPLE PN_OVERSAMPLE
26 #define SIM_NAME_MAXPARTICLES PN_MAXPARTICLES
27 #define SIM_NAME_REMOVEUNUSED PN_REMOVEUNUSED
28 #define SIM_NAME_PATH1 PN_PATH1
29 #define SIM_NAME_PATH2 PN_PATH2
30 #define SIM_NAME_PATH3 PN_PATH3
31 #define SIM_NAME_PATH4 PN_PATH4
32 
33 #define SIM_NAME_COLLIDESTOP "collidestop"
34 #define SIM_NAME_COLLIDEKILL "collidekill"
35 #define SIM_NAME_COLLIDECONTINUE "collidecontinue"
36 #define SIM_NAME_COLLIDESTICK "collidestick"
37 #define SIM_NAME_COLLIDEBOUNCE "collidebounce"
38 
39 // This class implemented a computational fluid dynamics solver.
41  public SIM_OptionsUser
42 {
43 public:
44  // Access functions for our specific data.
45  GETSET_DATA_FUNCS_B("usepoppath", UsePopPath);
56 
57  GETSET_DATA_FUNCS_I("rehome", RehomeParticles);
58  GETSET_DATA_FUNCS_S("homepath", RehomeParticlePath);
59 
60  // Access functions for all out POPNET information.
66 
67  // SOP style paths
72 
73  // DOP style paths
74  GETSET_DATA_FUNCS_S("datapath1", DataPath1);
75  GETSET_DATA_FUNCS_S("datapath2", DataPath2);
76  GETSET_DATA_FUNCS_S("datapath3", DataPath3);
77  GETSET_DATA_FUNCS_S("datapath4", DataPath4);
78 
79  // Access our general solver information
80  GETSET_DATA_FUNCS_S("geo", GeometryName);
81  GETSET_DATA_FUNCS_I("solvemode", SolveMode);
82 
83  GETSET_DATA_FUNCS_B("doreapparticles", DoReapParticles);
84  GETSET_DATA_FUNCS_B("doapplyrules", DoApplyRules);
85  GETSET_DATA_FUNCS_B("suppresspos", SuppressPos);
86  GETSET_DATA_FUNCS_B("suppressvel", SuppressVel);
87  GETSET_DATA_FUNCS_B("suppressup", SuppressUp);
88  GETSET_DATA_FUNCS_B("suppressage", SuppressAge);
89  GETSET_DATA_FUNCS_B("suppressrot", SuppressRot);
90  GETSET_DATA_FUNCS_B("suppressangvel", SuppressAngVel);
91  GETSET_DATA_FUNCS_B("doprepparticles", DoPrepParticles);
92  GETSET_DATA_FUNCS_B("docookpop", DoCookPOP);
93  GETSET_DATA_FUNCS_B("docookfirst", DoCookFirst);
94  GETSET_DATA_FUNCS_B("doimpacts", DoImpacts);
95  GETSET_DATA_FUNCS_B("dodopforces", DoDopForces);
96  GETSET_DATA_FUNCS_B("convertacceltoforce", ConvertAccelToForce);
97 
98 protected:
99  explicit SIM_SolverPop(const SIM_DataFactory *factory);
100  virtual ~SIM_SolverPop();
101 
103  SIM_Object &object,
104  SIM_ObjectArray &feedbacktoobjects,
105  const SIM_Time &timestep,
106  bool newobject);
107  virtual int getRequestedCacheSubclass() const;
108  virtual void getImpulseMassMatrixSubclass(
109  const SIM_Object &object,
110  const UT_Vector3 &impulseworldpos,
111  UT_DMatrix3 &immatrix) const;
113  const SIM_Object &object,
114  int ptnum, UT_DMatrix3 &immatrix) const;
115  virtual void getDefaultColliderLabelSubclass(
116  const SIM_Object &object,
117  UT_String &label) const;
118  virtual void getDefaultColliderSubclass(
119  const SIM_Object &object,
120  const UT_String &colliderlabel,
121  UT_String &collidertype,
122  bool &colliderreverseobjectroles) const;
123 
124  virtual SIM_Guide *createGuideObjectSubclass() const;
125  virtual void buildGuideGeometrySubclass(const SIM_RootData &root,
126  const SIM_Options &options,
127  const GU_DetailHandle &gdh,
128  UT_DMatrix4 *xform,
129  const SIM_Time &t) const;
130 
131 private:
132  SIM_PopGeometry *getGeometry(SIM_Object &obj,
133  UT_StringArray &oldhomes);
134  static const SIM_DopDescription *getSolverPopDopDescription();
135 
136  void applySoftConstraintForces(SIM_Object &object,
137  POP_ContextData &contextdata) const;
138  void applyHardConstraintPositions(SIM_Object &object,
139  POP_ContextData &contextdata,
140  const UT_DMatrix4 &ixform) const;
141  void applyShapeMatchForces(SIM_Object &object,
142  POP_ContextData &contextdata,
143  SIM_Time timeinc) const;
144 
145  void respondToCollision(SIM_Engine &engine,
146  SIM_Object &object,
147  SIM_PopGeometry &popgeo,
148  const SIM_ObjectArray &affectors,
149  const UT_DMatrix4 &xform,
150  const UT_DMatrix4 &ixform,
151  const SIM_Impacts *impacts,
152  int impactidx,
153  int impactflags,
154  GA_Index ptnum,
155  bool hasidattribute) const;
156  bool respondToCollisions(SIM_Engine &engine,
157  SIM_Object &object,
158  SIM_PopGeometry &popgeo,
159  const SIM_ObjectArray &affectors,
160  const UT_DMatrix4 &xform,
161  const UT_DMatrix4 &ixform,
162  const UT_DMatrix4 &posixform,
163  const char *impactdataname,
164  const SIM_DataFilter &fstop,
165  const SIM_DataFilter &fkill,
166  const SIM_DataFilter &fcont,
167  const SIM_DataFilter &fstick,
168  const SIM_DataFilter &fbounce,
169  bool doinglastpopsubstep,
170  bool checkforduplicates) const;
171 
172  // This function ensures that the geometry has the attributes
173  // that are mandatory for POPs.
174  void createRequiredAttributes(GU_Detail *gdp) const;
175 
176  // This function ensures that any points in the geometry are part
177  // or at least one particle system.
178  void makePointsParticles(GU_Detail *gdp,
179  const char *generator,
180  fpreal lifespan) const;
181  // This function takes all particle primitives with the same generator
182  // attribute value and combines them into a single primitive. This is
183  // necessary when combining geometries to ensure that all particles
184  // that should be processed by a particular POP node are all processed
185  // by that node.
186  void combineParticlePrimitives(GU_Detail &gdp);
187 
188  // Rehomes all of the particle primitive generators to our
189  // home settings. Invokes combineParticlePrimtives if any
190  // rehoming occured.
191  void rehomeParticles(GU_Detail *gdp,
192  UT_StringArray &oldhomes) const;
193  void restoreHomes(GU_Detail *gdp,
194  const UT_StringArray &oldhomes) const;
195 
196  // Converts the accel attribute into a force attribute,
197  // multiplying by either mass or density depending on what
198  // is present.
199  void convertAccelToForce(GU_Detail *gdp) const;
200 
201  // These functions respond to impact information attached to the
202  // particles.
203  void changeParticleStateFromImpacts(
204  POP_ContextData &contextdata,
205  const SIM_Impacts *impacts,
206  int impactidx,
207  int statechange,
208  GA_Index ptnum) const;
209  void createConstraintsFromImpacts(
210  SIM_Engine &engine,
211  SIM_Object &object,
212  const SIM_ObjectArray &affectors,
213  const SIM_Impacts *impacts,
214  int impactidx,
215  GA_Index ptnum,
216  bool hasidattribute) const;
217  void bounceParticlesFromImpacts(
218  POP_ContextData &contextdata,
219  const UT_DMatrix4 &xform,
220  const UT_DMatrix4 &ixform,
221  const SIM_Impacts *impacts,
222  int impactidx,
223  GA_Index ptnum) const;
224 
228  "POP Solver",
229  getSolverPopDopDescription());
230 };
231 
232 #endif
233 
#define SIM_NAME_PATH1
Definition: SIM_SolverPop.h:28
#define SIMZ_API
Definition: SIMZ_API.h:10
#define DECLARE_STANDARD_GETCASTTOTYPE()
Definition: SIM_DataUtils.h:45
#define SIM_NAME_COLLIDESTOP
Definition: SIM_SolverPop.h:33
GLuint GLsizei const GLchar * label
Definition: glcorearb.h:2544
#define SIM_NAME_PATH2
Definition: SIM_SolverPop.h:29
#define SIM_NAME_MAXPARTICLES
Definition: SIM_SolverPop.h:26
#define GETSET_DATA_FUNCS_B(DataName, FuncName)
#define SIM_NAME_COLLIDEKILL
Definition: SIM_SolverPop.h:34
#define GETSET_DATA_FUNCS_S(DataName, FuncName)
virtual void getDefaultColliderSubclass(const SIM_Object &object, const UT_String &colliderlabel, UT_String &collidertype, bool &colliderreverseobjectroles) const
#define SIM_NAME_POPPATH
Definition: SIMZ_Utils.h:27
virtual int getRequestedCacheSubclass() const
#define GETSET_DATA_FUNCS_F(DataName, FuncName)
#define SIM_NAME_RANDOMSEED
Definition: SIM_SolverPop.h:24
virtual void buildGuideGeometrySubclass(const SIM_RootData &root, const SIM_Options &options, const GU_DetailHandle &gdh, UT_DMatrix4 *xform, const SIM_Time &t) const
#define DECLARE_DATAFACTORY(DataClass, SuperClass, Description, DopParms)
Definition: SIM_DataUtils.h:58
#define SIM_NAME_COLLIDEBOUNCE
Definition: SIM_SolverPop.h:37
#define SIM_NAME_MAKEPOINTSPARTICLES
Definition: SIMZ_Utils.h:22
Holds pointers to a number of SIM_Object objects.
#define SIM_NAME_COLLIDESTICK
Definition: SIM_SolverPop.h:36
#define SIM_NAME_COLLIDECONTINUE
Definition: SIM_SolverPop.h:35
virtual void getImpulseMassMatrixSubclass(const SIM_Object &object, const UT_Vector3 &impulseworldpos, UT_DMatrix3 &immatrix) const
#define GETSET_DATA_FUNCS_I(DataName, FuncName)
#define SIM_NAME_OVERSAMPLE
Definition: SIM_SolverPop.h:25
GA_Size GA_Index
Define the strictness of GA_Offset/GA_Index.
Definition: GA_Types.h:611
#define SIM_NAME_REMOVEUNUSED
Definition: SIM_SolverPop.h:27
#define SIM_NAME_GENERATOR
Definition: SIMZ_Utils.h:18
virtual void getDefaultColliderLabelSubclass(const SIM_Object &object, UT_String &label) const
Gets the default collider label for an object using this solver.
double fpreal
Definition: SYS_Types.h:263
#define SIM_NAME_INHERITVELOCITY
Definition: SIMZ_Utils.h:20
virtual SIM_Result solveSingleObjectSubclass(SIM_Engine &engine, SIM_Object &object, SIM_ObjectArray &feedbacktoobjects, const SIM_Time &timestep, bool newobject)=0
#define SIM_NAME_LIFESPAN
Definition: SIMZ_Utils.h:21
virtual void getPointImpulseMassMatrixSubclass(const SIM_Object &object, int ptnum, UT_DMatrix3 &immatrix) const
#define SIM_NAME_PATH4
Definition: SIM_SolverPop.h:31
#define SIM_NAME_PATH3
Definition: SIM_SolverPop.h:30
#define SIM_NAME_INITIALSTATE
Definition: SIM_SolverPop.h:23
virtual SIM_Guide * createGuideObjectSubclass() const