HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SIM_PhysicalParms.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_PhysicalParms_h__
9 #define __SIM_PhysicalParms_h__
10 
11 #include "SIM_API.h"
12 #include "SIM_Data.h"
13 #include "SIM_DataUtils.h"
14 #include "SIM_OptionsUser.h"
15 #include <UT/UT_KDTree.h>
16 #include <utility>
17 
18 class SIM_Object;
19 class SIM_Solver;
20 class GEO_PointTree;
21 class SIM_PointTree;
22 class SIM_Geometry;
23 class SIM_RawField;
24 class SIM_VectorField;
25 
27 #include <GU/GU_Detail.h>
28 #include <GU/GU_DetailHandle.h>
29 
30 
31 /// This enumeration lists all the properties that can be accessed using
32 /// the getPropertyAtPosition() and getPropertyAtPoint() functions.
33 typedef enum {
39  // If you add any, you have to update Gas Calculate which
40  // hard codes PROPERTY COUNT
41  SIM_PROPERTY_COUNT // Tracks number of properties.
42 } SIM_Property;
43 
44 /// This simple verb class is designed to create a fast and
45 /// usually threadsafe way to lookup lots of property value queries.
46 /// For threadsafety it is important you act on a resolver local
47 /// to your thread, you can create such a thing with the copy() function.
49 {
50 public:
52  virtual ~SIM_PropertyResolver() {}
53 
54  /// Duplicates this.
55  virtual SIM_PropertyResolver *copy() const = 0;
56 
57  virtual fpreal getF(const UT_Vector3 &pos) = 0;
58  virtual UT_Vector3 getV3(const UT_Vector3 &pos) = 0;
59 
60  /// Sometimes despite our best efforts the lookup isn't threadsafe.
61  virtual bool threadsafe() const { return true; }
62 };
63 
65 {
66 public:
69 
70  SIM_PropertyResolver *copy() const override
71  {
72  return new SIM_PropertyResolverConstant(*this);
73  }
74 
75  fpreal getF(const UT_Vector3 &pos) override { return myValue.x(); }
76  UT_Vector3 getV3(const UT_Vector3 &pos) override { return myValue; }
77 protected:
79 };
80 
81 // Helper class which makes ut_KDPQueuePtr clonable by just making new objects
82 namespace SIM_Detail
83 {
85 {
86 public:
88  : myQueue(UT_KDTree::createQueue())
89  {
90  }
92  : myQueue(UT_KDTree::createQueue())
93  {
94  }
95  KDPQueuePtr &operator=(const KDPQueuePtr &copy) = delete;
96 
97  ut_KDPQueue &operator*() const
98  {
99  return *myQueue;
100  }
101  ut_KDPQueue *operator->() const noexcept
102  {
103  return myQueue.get();
104  }
105 private:
106  ut_KDPQueuePtr myQueue;
107 };
108 } // namespace SIM_Detail
109 
111 {
112 public:
114  const SIM_Geometry *geo,
115  const char *attribname,
116  const UT_DMatrix4 &worldtogdp);
118 
119  SIM_PropertyResolver *copy() const override;
120 
121  fpreal getF(const UT_Vector3 &pos) override;
122  UT_Vector3 getV3(const UT_Vector3 &pos) override;
123  GA_Offset getPtOff(const UT_Vector3 &pos);
124 protected:
125 
127  const GU_Detail *myGdp;
133 };
134 
136 {
137 public:
138  SIM_PropertyResolverVelNearestPoint(const SIM_Engine &engine, const SIM_Object *object);
140 
141  SIM_PropertyResolver *copy() const override;
142 
143  UT_Vector3 getV3(const UT_Vector3 &pos) override;
144  fpreal getF(const UT_Vector3 &pos) override { return getV3(pos).x(); }
145 protected:
146 
148  const GU_Detail *myGdp;
153 
154  UT_Vector3 myPivot, myLinVel, myAngVel;
156 
157  bool myHasOld;
164 };
165 
167 {
168 public:
171 
172  SIM_PropertyResolver *copy() const override
173  {
174  return new SIM_PropertyResolverField(*this);
175  }
176 
177 
178  fpreal getF(const UT_Vector3 &pos) override;
179  UT_Vector3 getV3(const UT_Vector3 &pos) override;
180 protected:
181  const SIM_RawField *myField[3];
182 };
183 
185 {
186 public:
188  const UT_Vector3 &pivot,
189  const UT_Vector3 &angvel);
190 
191  SIM_PropertyResolver *copy() const override
192  {
193  return new SIM_PropertyResolverMotion(*this);
194  }
195 
196  fpreal getF(const UT_Vector3 &pos) override { return getV3(pos).x(); }
197  UT_Vector3 getV3(const UT_Vector3 &pos) override;
198 
199 protected:
200  UT_Vector3 myPivot, myLinVel, myAngVel;
201 };
202 
204 {
205 public:
207  bool usesdfhistory,
208  bool usegeohistory,
209  fpreal integrateovertime)
210  {
211  myObject = obj;
212  myUseSDF = usesdfhistory;
213  myUseGeo = usegeohistory;
214  myIntegrate = integrateovertime;
215  }
216 
217  SIM_PropertyResolver *copy() const override
218  {
219  return new SIM_PropertyResolverVelAtPosition(*this);
220  }
221 
222  fpreal getF(const UT_Vector3 &pos) override { return getV3(pos).x(); }
223  UT_Vector3 getV3(const UT_Vector3 &pos) override;
224 
225  bool threadsafe() const override { return false; }
226 protected:
228  bool myUseSDF, myUseGeo;
230 };
231 
232 /// This simple verb class is designed to create a fast and
233 /// usually threadsafe way to lookup lots of property value queries.
234 /// For threadsafety it is important you act on a resolver local
235 /// to your thread, you can create such a thing with the copy() function.
237 {
238 public:
240  const SIM_Object *obj)
241  {
242  mySolver = solver;
243  myObject = obj;
244  }
246 
247  virtual void get(GA_Index ptnum, UT_DMatrix3 &immatrix) const;
248 
249  /// The default implementation just calls
250  /// SIM_Solver::getPointImpulseMassMatrix and is not threadsafe.
251  virtual bool threadsafe() const { return false; }
252 
253 protected:
256 };
257 
258 
259 /// A simple, threadsafe mass matrix resolver that just looks up the mass point
260 /// attribute and returns 1/mass if exists else 1.
263 {
264 public:
266  const SIM_Object *obj);
268 
269  void get(GA_Index ptnum, UT_DMatrix3 &immatrix) const override;
270 
271  bool threadsafe() const override { return true; }
272 
273 protected:
275  const GU_Detail *myGdp;
277 };
278 
279 /// This class contains physical attributes that apply to all objects.
281  public SIM_OptionsUser
282 {
283 public:
284  /// Coefficient of friction.
286  /// Dynamic friction multiplier.
288  /// Bounce coefficient.
290  /// Temperature coefficient
292  /// Forward bounce coefficient
294 
295  fpreal getProperty(const SIM_Property &property) const;
296 
297 protected:
298  explicit SIM_PhysicalParms(const SIM_DataFactory *factory);
299  ~SIM_PhysicalParms() override;
300 
301 private:
302  static const SIM_DopDescription *getPhysicalParmsDopDescription();
303 
306  SIM_Data,
307  "Physical Parameters",
308  getPhysicalParmsDopDescription());
309 };
310 
311 #endif
fpreal getF(const UT_Vector3 &pos) override
#define DECLARE_STANDARD_GETCASTTOTYPE()
Definition: SIM_DataUtils.h:50
KDPQueuePtr & operator=(const KDPQueuePtr &copy)=delete
OIIO_UTIL_API bool copy(string_view from, string_view to, std::string &err)
const GLdouble * v
Definition: glcorearb.h:837
KDPQueuePtr(const KDPQueuePtr &)
This class contains physical attributes that apply to all objects.
virtual UT_Vector3 getV3(const UT_Vector3 &pos)=0
SIM_PropertyResolverConstant(UT_Vector3 v)
#define SIM_NAME_TEMPERATURE
Definition: SIM_Names.h:200
#define GETSET_DATA_FUNCS_F(DataName, FuncName)
SIM_PropertyResolver * copy() const override
Duplicates this.
SIM_PropertyResolver * copy() const override
Duplicates this.
SIM_PropertyResolver * copy() const override
Duplicates this.
#define DECLARE_DATAFACTORY(DataClass, SuperClass, Description, DopParms)
Definition: SIM_DataUtils.h:63
GA_Size GA_Offset
Definition: GA_Types.h:646
SIM_Detail::KDPQueuePtr myQueue
fpreal getF(const UT_Vector3 &pos) override
SIM_PropertyResolverVelAtPosition(const SIM_Object *obj, bool usesdfhistory, bool usegeohistory, fpreal integrateovertime)
bool threadsafe() const override
Sometimes despite our best efforts the lookup isn't threadsafe.
virtual bool threadsafe() const
Sometimes despite our best efforts the lookup isn't threadsafe.
SIM_PropertyResolver * copy() const override
Duplicates this.
ut_KDPQueue * operator->() const noexcept
UT_UniquePtr< ut_KDPQueue, ut_KDPQueueDeleter > ut_KDPQueuePtr
Definition: UT_KDTree.h:42
virtual SIM_PropertyResolver * copy() const =0
Duplicates this.
fpreal getF(const UT_Vector3 &pos) override
GA_Size GA_Index
Define the strictness of GA_Offset/GA_Index.
Definition: GA_Types.h:640
#define SIM_NAME_FRICTION
Definition: SIM_Names.h:132
#define SIM_NAME_DYNAMICFRICTION
Definition: SIM_Names.h:112
UT_Vector3 getV3(const UT_Vector3 &pos) override
fpreal64 fpreal
Definition: SYS_Types.h:277
virtual fpreal getF(const UT_Vector3 &pos)=0
#define SIM_API
Definition: SIM_API.h:12
GA_API const UT_StringHolder pivot
SIM_PointImpulseMassMatrixResolver(const SIM_Solver *solver, const SIM_Object *obj)
ut_KDPQueue & operator*() const
This class holds a three dimensional vector field.
#define SIM_NAME_BOUNCEFORWARD
Definition: SIM_Names.h:110
#define SIM_NAME_BOUNCE
Definition: SIM_Names.h:80
SIM_Property
fpreal getF(const UT_Vector3 &pos) override
constexpr SYS_FORCE_INLINE T & x() noexcept
Definition: UT_Vector3.h:663