HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GAS_SeedMarkers.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: GAS_SeedMarkers.h ( GAS Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __GAS_SeedMarkers__
12 #define __GAS_SeedMarkers__
13 
14 #include "GAS_API.h"
15 
16 #include "GAS_SubSolver.h"
17 #include "GAS_Utils.h"
18 
19 #include <GU/GU_Detail.h>
20 
21 #include <GA/GA_SplittableRange.h>
22 #include <GA/GA_PageHandle.h>
23 #include <GA/GA_PageIterator.h>
24 
25 #include <SIM/SIM_VectorField.h>
26 #include <SIM/SIM_IndexField.h>
27 
29 #include <UT/UT_ParallelUtil.h>
30 #include <UT/UT_UniquePtr.h>
31 
33 
34 class GU_Detail;
35 class SIM_ScalarField;
36 class GU_PrimParticle;
37 
39 {
40 public:
41  GET_DATA_FUNC_S(GAS_NAME_SURFACE, SurfaceName);
42  GET_DATA_FUNC_S(GAS_NAME_GEOMETRY, GeometryName);
43  GET_DATA_FUNC_S(GAS_NAME_SOURCE, SourceName);
44  GET_DATA_FUNC_S("sourcevelocityfield", SourceVelocityName);
45  GET_DATA_FUNC_B("applynewsourceonly", ApplyNewSourceOnly);
46 
47  GET_DATA_FUNC_B("usesourceattrib", UseSourceAttribute);
48  GET_DATA_FUNC_S("sourceattrib", SourceAttribute);
49 
50  GET_DATA_FUNC_S(GAS_NAME_SINK, SinkName);
51  GET_DATA_FUNC_S("velocityfield", BoundaryVelocityName);
52  GET_DATA_FUNC_S("boundaryfield", BoundaryName);
53 
54  GETSET_DATA_FUNCS_I("surfelpervoxel", SurfelPerVoxel);
55  GETSET_DATA_FUNCS_F("birththreshold", BirthThreshold);
56  GETSET_DATA_FUNCS_F("deaththreshold", DeathThreshold);
57  GETSET_DATA_FUNCS_F("oversampling", Oversampling);
58  GETSET_DATA_FUNCS_F("oversamplingbandwidth", OversamplingBandwidth);
59  GETSET_DATA_FUNCS_B("oversamplebounds", OversampleBounds);
60  GETSET_DATA_FUNCS_B("movetoiso", MoveToIso);
61 
62  GETSET_DATA_FUNCS_B("outsidesurfels", OutsideSurfels);
63  GETSET_DATA_FUNCS_B("insidesurfels", InsideSurfels);
64 
65  GETSET_DATA_FUNCS_B("addparticlesystem", AddParticleSystem);
66  GETSET_DATA_FUNCS_B("killoutside", KillOutside);
67  GETSET_DATA_FUNCS_B("copynearest", CopyNearest);
68 
69  GETSET_DATA_FUNCS_B("useboundary", UseBoundary);
70  GETSET_DATA_FUNCS_V3("lowerboundarythickness", LowerBoundaryThickness);
71  GETSET_DATA_FUNCS_V3("upperboundarythickness", UpperBoundaryThickness);
72 
73  GETSET_DATA_FUNCS_V3("volumesize", VolumeSize);
74  GETSET_DATA_FUNCS_V3("volumecenter", VolumeCenter);
75 
76  GET_DATA_FUNC_B("useinterpvel", UseInterpVel);
77 
78  GETSET_DATA_FUNCS_B("usewaterline", UseWaterline);
79  GETSET_DATA_FUNCS_F("waterline", Waterline);
80  GETSET_DATA_FUNCS_V3("waterlinedirection", WaterlineDirection);
81 
82  GETSET_DATA_FUNCS_B("pscaletoggle",PscaleToggle);
83  GETSET_DATA_FUNCS_F("particleradius", ParticleRadius);
84 
85  GET_DATA_FUNC_S("interpattribs", InterpolateAttributes);
86 
87  GETSET_DATA_FUNCS_F("minrad", MinRad);
88  GETSET_DATA_FUNCS_F("maxrad", MaxRad);
89 
90  GETSET_DATA_FUNCS_B("usebandwidth", UseBandwidth);
91  GETSET_DATA_FUNCS_F("birthbandwidth", BirthBandwidth);
92  GETSET_DATA_FUNCS_F("deathbandwidth", DeathBandwidth);
93  GETSET_DATA_FUNCS_F("tol", Tolerance);
95 
96  GETSET_DATA_FUNCS_I("slice", Slice);
97 
98 protected:
99  explicit GAS_SeedMarkers(const SIM_DataFactory *factory);
100  ~GAS_SeedMarkers() override;
101 
102  /// Moves the fields given by FieldName by the given velocity
103  /// field. Moves the points given by GeometryName likewise.
104  bool solveGasSubclass(SIM_Engine &engine,
105  SIM_Object *obj,
106  SIM_Time time,
107  SIM_Time timestep) override;
108 
109  /// Creates new marker particles so that there are sufficient
110  /// near the iso contour. Deletes any particles that are now
111  /// too far away.
112  void seedMarkers(SIM_Object *obj,
113  GU_Detail *gdp,
114  const GA_PointGroup *ptgrp,
115  const SIM_RawField *surface,
116  const SIM_RawField *source,
117  const SIM_RawField *sink,
118  const SIM_RawField *collisionmask,
119  const SIM_RawField *boundarylayer,
120  const SIM_RawIndexField *indexfield,
121  const SIM_VectorField *sourcevelocity,
122  const SIM_VectorField *boundaryvelocity,
123  bool usewaterline);
124 
126  {
127  fpreal rmin, rmax, deathcutoff, birthcutoff;
128  fpreal birththreshold, deaththreshold;
129  fpreal oversampling, oversamplingcutoff, isotol;
130  fpreal seed, particleradius;
131  bool oversampleatbounds, movetoiso;
132  const SIM_RawField *surface, *source, *sink, *collision;
135  const GU_Detail *gdp;
137  bool outsidesurfels, insidesurfels;
138  bool copynearest, usebandwidth;
139  int slice;
142 
144 
152 
154  };
155 
156  THREADED_METHOD1_CONST(GAS_SeedMarkers, parms.surface->shouldMultiThread(),
157  reseedParticles,
158  const gas_SeedMarkersParms &, parms)
159  void reseedParticlesPartial(const gas_SeedMarkersParms &parms,
160  const UT_JobInfo &info) const;
162  updateRadius,
163  const SIM_RawField *, surface,
164  GU_Detail *, gdp,
165  fpreal, rmin,
166  fpreal, rmax)
167  void updateRadiusPartial(const SIM_RawField *surface,
168  GU_Detail *gdp,
169  fpreal rmin, fpreal rmax,
170  const UT_JobInfo &info) const;
171 
172  THREADED_METHOD5_CONST(GAS_SeedMarkers, range.canMultiThread(),
173  interpolateAttributes,
174  const GU_Detail *, gdp,
175  const GA_SplittableRange &, range,
176  const GA_AttributeRefMap&, map,
177  const GA_RWHandleF &, rad_h,
178  const openvdb::tools::PointIndexGrid *, grid)
179  void interpolateAttributesPartial(const GU_Detail *gdp,
181  const GA_AttributeRefMap& map,
182  const GA_RWHandleF &rad_h,
183  const openvdb::tools::PointIndexGrid *grid,
184  const UT_JobInfo &info) const;
185 
186 private:
187 
188  static const SIM_DopDescription *getDopDescription();
189 
193  "Gas Seed Markers",
194  getDopDescription());
195 };
196 
197 
198 //
199 //
200 // Shared operations between GAS_SeedMarkers and GAS_SeedVolume
201 //
202 //
203 
204 // Return whether a sample at this position should be oversampled. Also
205 // returns the miniminum distance to an oversampling boundary (either the
206 // surface or volume boundary) for computing percentage of voxel that
207 // should be oversampled.
208 static bool
209 gas_needsOversampling(const UT_Vector3 &pos,
210  fpreal absdistvalue, fpreal cutoff,
211  const UT_Vector3 &surforig, const UT_Vector3 &surfend,
212  bool oversampleatbounds)
213 {
214  bool needsoversample = false;
215  if (absdistvalue < cutoff)
216  {
217  needsoversample = true;
218  }
219  if (oversampleatbounds)
220  {
221  UT_Vector3 offlo = pos - surforig;
222  UT_Vector3 offhi = surfend - pos;
223  fpreal bounddist = SYSmin(offlo.minComponent(), offhi.minComponent());
224  // Reject sample if outside the boundaries.
225  if (bounddist < 0)
226  return false;
227  if (bounddist < cutoff)
228  needsoversample = true;
229  }
230  return needsoversample;
231 }
232 
233 
234 // Create a new array of type T if the local one is not empty, then
235 // swap in the local one's content, replacing the localarray with an emty
236 // array of the same capacity.
237 template <typename T>
238 static void
239 gas_swapLocal(T &localarray, int curtile, UT_ValArray<UT_UniquePtr<T>> &tilearrays)
240 {
241  if (localarray.entries())
242  {
243  tilearrays(curtile) = UTmakeUnique<T>(localarray.capacity());
244  tilearrays(curtile)->swap(localarray);
245  }
246 }
247 
249 {
251  const GA_RWHandleV3 &vel_h,
252  const SIM_VectorField &velocity,
254  : gdp(gdp)
255  , velhandle(vel_h)
256  , surffield(NULL)
257  , velfield(velocity)
258  , boss(boss)
259  , usebound(false)
260  , lowerbound(UT_Vector3(0,0,0))
261  , upperbound(UT_Vector3(0,0,0))
262  {}
263 
265  const GA_RWHandleV3 &vel_h,
266  const SIM_RawField *surface,
267  const SIM_VectorField &velocity,
269  : gdp(gdp)
270  , velhandle(vel_h)
271  , surffield(surface)
272  , velfield(velocity)
273  , boss(boss)
274  , usebound(false)
275  , lowerbound(UT_Vector3(0,0,0))
276  , upperbound(UT_Vector3(0,0,0))
277  {}
278 
280  const GA_RWHandleV3 &vel_h,
281  const SIM_VectorField &velocity,
283  const UT_Vector3 lowerbound,
284  const UT_Vector3 upperbound)
285  : gdp(gdp)
286  , velhandle(vel_h)
287  , surffield(NULL)
288  , velfield(velocity)
289  , boss(boss)
290  , usebound(true)
291  , lowerbound(lowerbound)
292  , upperbound(upperbound)
293  {}
294 
295  void operator()(const GA_SplittableRange &r) const
296  {
298 
299  if(boss->opInterrupt())
300  return;
301 
303 
304  for (GA_Iterator it(r); it.blockAdvance(start, end); )
305  {
306  vel_ph.setPage(start);
307 
308  for (GA_Offset ptoff = start; ptoff < end; ++ptoff)
309  {
310  UT_Vector3 pos = gdp.getPos3(ptoff);
311 
312  // If we're enforcing the boundary velocity to points
313  // in the boundary, we can early exit on particles
314  // not inside the boundary layer.
315  if(usebound && !(pos.x() <= lowerbound.x() ||
316  pos.y() <= lowerbound.y() ||
317  pos.z() <= lowerbound.z() ||
318  pos.x() >= upperbound.x() ||
319  pos.y() >= upperbound.y() ||
320  pos.z() >= upperbound.z()))
321  continue;
322 
323  // If we're overwriting velocity inside of a surface
324  // volume, we can early exit on points not inside
325  // the surface volume
326  if (surffield && surffield->getValue(pos) > 0)
327  continue;
328 
329  vel_ph.set(ptoff, velfield.getValue(pos));
330  }
331  }
332  }
333 
334  const GU_Detail &gdp;
339 
342  bool usebound;
343 };
344 
346 {
347 public:
349  {
350  myHashVec[0] = seed;
351  myHashVec[1] = pos.x();
352  myHashVec[2] = pos.y();
353  myHashVec[3] = pos.z();
354  myHashVec[4] = 0;
355  }
356 
357 protected:
359 };
360 
362 {
363 public:
364  gas_randInt(fpreal32 seed, const UT_Vector3 &pos, fpreal32 increment = 1)
365  : gas_randHelper(seed,pos), myIncrement(increment){}
366 
367  int operator()(int n)
368  {
369  uint seed = SYSvector_hash(myHashVec, 5);
370  int r = SYSfloor(SYSrandom(seed) * n);
371  myHashVec[4] += myIncrement;
372  return r;
373  }
374 private:
375  fpreal32 myIncrement;
376 };
377 
379 {
380 public:
381  gas_randVec(fpreal32 seed, const UT_Vector3 &pos)
382  : gas_randHelper(seed,pos){}
383 
385  {
386  myHashVec[4] = n;
387  uint seed = SYSvector_hash(myHashVec, 5);
388  UT_Vector3 randvec;
389  randvec.x() = SYSrandomZero(seed);
390  randvec.y() = SYSrandomZero(seed);
391  randvec.z() = SYSrandomZero(seed);
392  return randvec;
393  }
394 };
395 
396 
397 
398 
399 #endif
400 
const UT_Vector3 upperbound
#define DECLARE_STANDARD_GETCASTTOTYPE()
Definition: SIM_DataUtils.h:50
gas_randHelper(fpreal32 seed, const UT_Vector3 &pos)
#define THREADED_METHOD4_CONST(CLASSNAME, DOMULTI, METHOD, PARMTYPE1, PARMNAME1, PARMTYPE2, PARMNAME2, PARMTYPE3, PARMNAME3, PARMTYPE4, PARMNAME4)
GLenum GLint * range
Definition: glcorearb.h:1925
gas_setVelocityHelper(const GU_Detail &gdp, const GA_RWHandleV3 &vel_h, const SIM_VectorField &velocity, UT_Interrupt *boss)
Iteration over a range of elements.
Definition: GA_Iterator.h:29
#define GAS_NAME_GEOMETRY
Definition: GAS_Utils.h:30
gas_randInt(fpreal32 seed, const UT_Vector3 &pos, fpreal32 increment=1)
#define GETSET_DATA_FUNCS_B(DataName, FuncName)
GT_API const UT_StringHolder time
#define GAS_API
Definition: GAS_API.h:10
bool blockAdvance(GA_Offset &start, GA_Offset &end)
GLuint start
Definition: glcorearb.h:475
constexpr SYS_FORCE_INLINE T & z() noexcept
Definition: UT_Vector3.h:667
fpreal32 myHashVec[5]
virtual bool solveGasSubclass(SIM_Engine &engine, SIM_Object *obj, SIM_Time time, SIM_Time timestep)=0
const GU_Detail & gdp
const UT_Vector3 lowerbound
fpreal getValue(UT_Vector3 pos) const
Functions to resolve quantities about the field.
SYS_FORCE_INLINE UT_Vector3 getPos3(GA_Offset ptoff) const
The ptoff passed is the point offset.
Definition: GA_Detail.h:185
#define GETSET_DATA_FUNCS_F(DataName, FuncName)
float fpreal32
Definition: SYS_Types.h:200
#define THREADED_METHOD5_CONST(CLASSNAME, DOMULTI, METHOD, PARMTYPE1, PARMNAME1, PARMTYPE2, PARMNAME2, PARMTYPE3, PARMNAME3, PARMTYPE4, PARMNAME4, PARMTYPE5, PARMNAME5)
GA_ATINumeric * getAttribute() const
Definition: GA_Handle.h:339
#define GETSET_DATA_FUNCS_V3(DataName, FuncName)
UT_ValArray< UT_UniquePtr< UT_Vector3Array > > * boundptslist
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
#define DECLARE_DATAFACTORY(DataClass, SuperClass, Description, DopParms)
Definition: SIM_DataUtils.h:63
gas_randVec(fpreal32 seed, const UT_Vector3 &pos)
GA_Size GA_Offset
Definition: GA_Types.h:646
constexpr SYS_FORCE_INLINE T minComponent() const noexcept
Definition: UT_Vector3.h:413
int opInterrupt(int percent=-1)
GLdouble n
Definition: glcorearb.h:2008
UT_ValArray< UT_UniquePtr< GA_OffsetArray > > * delptslist
GLuint GLuint end
Definition: glcorearb.h:475
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
const SIM_RawField * surffield
GLsizei GLsizei GLchar * source
Definition: glcorearb.h:803
#define GETSET_DATA_FUNCS_I(DataName, FuncName)
A handle to simplify manipulation of multiple attributes.
SYS_API fpreal32 SYSfloor(fpreal32 val)
int operator()(int n)
UT_ValArray< UT_UniquePtr< UT_FprealArray > > * radii
const SIM_VectorField & velfield
gas_setVelocityHelper(const GU_Detail &gdp, const GA_RWHandleV3 &vel_h, const SIM_RawField *surface, const SIM_VectorField &velocity, UT_Interrupt *boss)
#define GAS_NAME_SINK
Definition: GAS_Utils.h:35
#define THREADED_METHOD1_CONST(CLASSNAME, DOMULTI, METHOD, PARMTYPE1, PARMNAME1)
gas_setVelocityHelper(const GU_Detail &gdp, const GA_RWHandleV3 &vel_h, const SIM_VectorField &velocity, UT_Interrupt *boss, const UT_Vector3 lowerbound, const UT_Vector3 upperbound)
Grid< PointIndexTree > PointIndexGrid
Point index grid.
UT_ValArray< UT_UniquePtr< UT_Vector3Array > > * newptslist
fpreal64 fpreal
Definition: SYS_Types.h:277
const GA_RWHandleV3 & velhandle
UT_ValArray< UT_UniquePtr< UT_Vector3Array > > * sourceptslist
Space-partitioning acceleration structure for points. Partitions the points into voxels to accelerate...
#define GET_DATA_FUNC_B(DataName, FuncName)
UT_Vector3 getValue(const UT_Vector3 &pos) const
#define SIM_NAME_SEED
Definition: SIM_Names.h:185
This class holds a three dimensional scalar field.
const SIM_RawIndexField * indexfield
const openvdb::tools::PointIndexGrid * ptgridvdb
GLboolean r
Definition: glcorearb.h:1222
constexpr SYS_FORCE_INLINE T & y() noexcept
Definition: UT_Vector3.h:665
#define GAS_NAME_SOURCE
Definition: GAS_Utils.h:36
#define SYSmin(a, b)
Definition: SYS_Math.h:1571
#define GAS_NAME_SURFACE
Definition: GAS_Utils.h:38
This class holds a three dimensional vector field.
UT_ValArray< UT_UniquePtr< UT_FprealArray > > * distances
#define GET_DATA_FUNC_S(DataName, FuncName)
unsigned int uint
Definition: SYS_Types.h:45
SYS_FORCE_INLINE UT_Vector3 operator()(int n)
UT_ValArray< UT_UniquePtr< GA_OffsetArray > > * closeptslist
void operator()(const GA_SplittableRange &r) const
SYS_FORCE_INLINE GA_Size getNumPoints() const
Return the number of points.
Definition: GA_Detail.h:334
constexpr SYS_FORCE_INLINE T & x() noexcept
Definition: UT_Vector3.h:663