HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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_S(GAS_NAME_SINK, SinkName);
48  GET_DATA_FUNC_S("velocityfield", BoundaryVelocityName);
49  GET_DATA_FUNC_S("boundaryfield", BoundaryName);
50 
51  GETSET_DATA_FUNCS_I("surfelpervoxel", SurfelPerVoxel);
52  GETSET_DATA_FUNCS_F("birththreshold", BirthThreshold);
53  GETSET_DATA_FUNCS_F("deaththreshold", DeathThreshold);
54  GETSET_DATA_FUNCS_F("oversampling", Oversampling);
55  GETSET_DATA_FUNCS_F("oversamplingbandwidth", OversamplingBandwidth);
56  GETSET_DATA_FUNCS_B("oversamplebounds", OversampleBounds);
57  GETSET_DATA_FUNCS_B("movetoiso", MoveToIso);
58 
59  GETSET_DATA_FUNCS_B("outsidesurfels", OutsideSurfels);
60  GETSET_DATA_FUNCS_B("insidesurfels", InsideSurfels);
61 
62  GETSET_DATA_FUNCS_B("addparticlesystem", AddParticleSystem);
63  GETSET_DATA_FUNCS_B("killoutside", KillOutside);
64  GETSET_DATA_FUNCS_B("copynearest", CopyNearest);
65 
66  GETSET_DATA_FUNCS_B("useboundary", UseBoundary);
67  GETSET_DATA_FUNCS_V3("lowerboundarythickness", LowerBoundaryThickness);
68  GETSET_DATA_FUNCS_V3("upperboundarythickness", UpperBoundaryThickness);
69 
70  GETSET_DATA_FUNCS_V3("volumesize", VolumeSize);
71  GETSET_DATA_FUNCS_V3("volumecenter", VolumeCenter);
72 
73  GET_DATA_FUNC_B("useinterpvel", UseInterpVel);
74 
75  GETSET_DATA_FUNCS_B("usewaterline", UseWaterline);
76  GETSET_DATA_FUNCS_F("waterline", Waterline);
77  GETSET_DATA_FUNCS_V3("waterlinedirection", WaterlineDirection);
78 
79  GETSET_DATA_FUNCS_B("pscaletoggle",PscaleToggle);
80  GETSET_DATA_FUNCS_F("particleradius", ParticleRadius);
81 
82  GET_DATA_FUNC_S("interpattribs", InterpolateAttributes);
83 
84  GETSET_DATA_FUNCS_F("minrad", MinRad);
85  GETSET_DATA_FUNCS_F("maxrad", MaxRad);
86 
87  GETSET_DATA_FUNCS_B("usebandwidth", UseBandwidth);
88  GETSET_DATA_FUNCS_F("birthbandwidth", BirthBandwidth);
89  GETSET_DATA_FUNCS_F("deathbandwidth", DeathBandwidth);
90  GETSET_DATA_FUNCS_F("tol", Tolerance);
92 
93  GETSET_DATA_FUNCS_I("slice", Slice);
94 
95 protected:
96  explicit GAS_SeedMarkers(const SIM_DataFactory *factory);
97  virtual ~GAS_SeedMarkers();
98 
99  /// Moves the fields given by FieldName by the given velocity
100  /// field. Moves the points given by GeometryName likewise.
101  virtual bool solveGasSubclass(SIM_Engine &engine,
102  SIM_Object *obj,
103  SIM_Time time,
104  SIM_Time timestep);
105 
106  /// Creates new marker particles so that there are sufficient
107  /// near the iso contour. Deletes any particles that are now
108  /// too far away.
109  void seedMarkers(SIM_Object *obj,
110  GU_Detail *gdp,
111  const GA_PointGroup *ptgrp,
112  const SIM_RawField *surface,
113  const SIM_RawField *source,
114  const SIM_RawField *sink,
115  const SIM_RawField *collisionmask,
116  const SIM_RawField *boundarylayer,
117  const SIM_RawIndexField *indexfield,
118  const SIM_VectorField *sourcevelocity,
119  const SIM_VectorField *boundaryvelocity,
120  bool usewaterline);
121 
123  {
124  fpreal rmin, rmax, deathcutoff, birthcutoff;
125  fpreal birththreshold, deaththreshold;
126  fpreal oversampling, oversamplingcutoff, isotol;
127  fpreal seed, particleradius;
128  bool oversampleatbounds, movetoiso;
129  const SIM_RawField *surface, *source, *sink, *collision;
132  const GU_Detail *gdp;
134  bool outsidesurfels, insidesurfels;
135  bool copynearest, usebandwidth;
136  int slice;
139 
141 
149 
151  };
152 
153  THREADED_METHOD1_CONST(GAS_SeedMarkers, parms.surface->shouldMultiThread(),
154  reseedParticles,
155  const gas_SeedMarkersParms &, parms)
156  void reseedParticlesPartial(const gas_SeedMarkersParms &parms,
157  const UT_JobInfo &info) const;
159  updateRadius,
160  const SIM_RawField *, surface,
161  GU_Detail *, gdp,
162  fpreal, rmin,
163  fpreal, rmax)
164  void updateRadiusPartial(const SIM_RawField *surface,
165  GU_Detail *gdp,
166  fpreal rmin, fpreal rmax,
167  const UT_JobInfo &info) const;
168 
169  THREADED_METHOD5_CONST(GAS_SeedMarkers, range.canMultiThread(),
170  interpolateAttributes,
171  const GU_Detail *, gdp,
172  const GA_SplittableRange &, range,
173  const GA_AttributeRefMap&, map,
174  const GA_RWHandleF &, rad_h,
175  const openvdb::tools::PointIndexGrid *, grid)
176  void interpolateAttributesPartial(const GU_Detail *gdp,
178  const GA_AttributeRefMap& map,
179  const GA_RWHandleF &rad_h,
180  const openvdb::tools::PointIndexGrid *grid,
181  const UT_JobInfo &info) const;
182 
183 private:
184 
185  static const SIM_DopDescription *getDopDescription();
186 
190  "Gas Seed Markers",
191  getDopDescription());
192 };
193 
194 
195 //
196 //
197 // Shared operations between GAS_SeedMarkers and GAS_SeedVolume
198 //
199 //
200 
201 // Return whether a sample at this position should be oversampled. Also
202 // returns the miniminum distance to an oversampling boundary (either the
203 // surface or volume boundary) for computing percentage of voxel that
204 // should be oversampled.
205 static bool
206 gas_needsOversampling(const UT_Vector3 &pos,
207  fpreal absdistvalue, fpreal cutoff,
208  const UT_Vector3 &surforig, const UT_Vector3 &surfend,
209  bool oversampleatbounds)
210 {
211  bool needsoversample = false;
212  if (absdistvalue < cutoff)
213  {
214  needsoversample = true;
215  }
216  if (oversampleatbounds)
217  {
218  UT_Vector3 offlo = pos - surforig;
219  UT_Vector3 offhi = surfend - pos;
220  fpreal bounddist = SYSmin(offlo.minComponent(), offhi.minComponent());
221  // Reject sample if outside the boundaries.
222  if (bounddist < 0)
223  return false;
224  if (bounddist < cutoff)
225  needsoversample = true;
226  }
227  return needsoversample;
228 }
229 
230 
231 // Create a new array of type T if the local one is not empty, then
232 // swap in the local one's content, replacing the localarray with an emty
233 // array of the same capacity.
234 template <typename T>
235 static void
236 gas_swapLocal(T &localarray, int curtile, UT_ValArray<UT_UniquePtr<T>> &tilearrays)
237 {
238  if (localarray.entries())
239  {
240  tilearrays(curtile) = UTmakeUnique<T>(localarray.capacity());
241  tilearrays(curtile)->swap(localarray);
242  }
243 }
244 
246 {
248  const GA_RWHandleV3 &vel_h,
249  const SIM_VectorField &velocity,
251  : gdp(gdp)
252  , velhandle(vel_h)
253  , surffield(NULL)
254  , velfield(velocity)
255  , boss(boss)
256  , usebound(false)
257  , lowerbound(UT_Vector3(0,0,0))
258  , upperbound(UT_Vector3(0,0,0))
259  {}
260 
262  const GA_RWHandleV3 &vel_h,
263  const SIM_RawField *surface,
264  const SIM_VectorField &velocity,
266  : gdp(gdp)
267  , velhandle(vel_h)
268  , surffield(surface)
269  , velfield(velocity)
270  , boss(boss)
271  , usebound(false)
272  , lowerbound(UT_Vector3(0,0,0))
273  , upperbound(UT_Vector3(0,0,0))
274  {}
275 
277  const GA_RWHandleV3 &vel_h,
278  const SIM_VectorField &velocity,
280  const UT_Vector3 lowerbound,
281  const UT_Vector3 upperbound)
282  : gdp(gdp)
283  , velhandle(vel_h)
284  , surffield(NULL)
285  , velfield(velocity)
286  , boss(boss)
287  , usebound(true)
288  , lowerbound(lowerbound)
289  , upperbound(upperbound)
290  {}
291 
292  void operator()(const GA_SplittableRange &r) const
293  {
295 
296  if(boss->opInterrupt())
297  return;
298 
300 
301  for (GA_Iterator it(r); it.blockAdvance(start, end); )
302  {
303  vel_ph.setPage(start);
304 
305  for (GA_Offset ptoff = start; ptoff < end; ++ptoff)
306  {
307  UT_Vector3 pos = gdp.getPos3(ptoff);
308 
309  // If we're enforcing the boundary velocity to points
310  // in the boundary, we can early exit on particles
311  // not inside the boundary layer.
312  if(usebound && !(pos.x() <= lowerbound.x() ||
313  pos.y() <= lowerbound.y() ||
314  pos.z() <= lowerbound.z() ||
315  pos.x() >= upperbound.x() ||
316  pos.y() >= upperbound.y() ||
317  pos.z() >= upperbound.z()))
318  continue;
319 
320  // If we're overwriting velocity inside of a surface
321  // volume, we can early exit on points not inside
322  // the surface volume
323  if (surffield && surffield->getValue(pos) > 0)
324  continue;
325 
326  vel_ph.set(ptoff, velfield.getValue(pos));
327  }
328  }
329  }
330 
331  const GU_Detail &gdp;
336 
339  bool usebound;
340 };
341 
343 {
344 public:
346  {
347  myHashVec[0] = seed;
348  myHashVec[1] = pos.x();
349  myHashVec[2] = pos.y();
350  myHashVec[3] = pos.z();
351  myHashVec[4] = 0;
352  }
353 
354 protected:
356 };
357 
359 {
360 public:
361  gas_randInt(fpreal32 seed, const UT_Vector3 &pos, fpreal32 increment = 1)
362  : gas_randHelper(seed,pos), myIncrement(increment){}
363 
364  int operator()(int n)
365  {
366  uint seed = SYSvector_hash(myHashVec, 5);
367  int r = SYSfloor(SYSrandom(seed) * n);
368  myHashVec[4] += myIncrement;
369  return r;
370  }
371 private:
372  fpreal32 myIncrement;
373 };
374 
376 {
377 public:
378  gas_randVec(fpreal32 seed, const UT_Vector3 &pos)
379  : gas_randHelper(seed,pos){}
380 
382  {
383  myHashVec[4] = n;
384  uint seed = SYSvector_hash(myHashVec, 5);
385  UT_Vector3 randvec;
386  randvec.x() = SYSrandomZero(seed);
387  randvec.y() = SYSrandomZero(seed);
388  randvec.z() = SYSrandomZero(seed);
389  return randvec;
390  }
391 };
392 
393 
394 
395 
396 #endif
397 
const UT_Vector3 upperbound
SYS_FORCE_INLINE T minComponent() const
#define DECLARE_STANDARD_GETCASTTOTYPE()
Definition: SIM_DataUtils.h:45
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:1924
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:28
#define GAS_NAME_GEOMETRY
Definition: GAS_Utils.h:28
gas_randInt(fpreal32 seed, const UT_Vector3 &pos, fpreal32 increment=1)
#define GETSET_DATA_FUNCS_B(DataName, FuncName)
#define GAS_API
Definition: GAS_API.h:10
bool blockAdvance(GA_Offset &start, GA_Offset &end)
GLuint start
Definition: glcorearb.h:474
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:170
#define GETSET_DATA_FUNCS_F(DataName, FuncName)
SYS_FORCE_INLINE T & x(void)
Definition: UT_Vector3.h:581
#define THREADED_METHOD5_CONST(CLASSNAME, DOMULTI, METHOD, PARMTYPE1, PARMNAME1, PARMTYPE2, PARMNAME2, PARMTYPE3, PARMNAME3, PARMTYPE4, PARMNAME4, PARMTYPE5, PARMNAME5)
#define GETSET_DATA_FUNCS_V3(DataName, FuncName)
UT_ValArray< UT_UniquePtr< UT_Vector3Array > > * boundptslist
#define DECLARE_DATAFACTORY(DataClass, SuperClass, Description, DopParms)
Definition: SIM_DataUtils.h:58
gas_randVec(fpreal32 seed, const UT_Vector3 &pos)
GA_Size GA_Offset
Definition: GA_Types.h:617
GA_Attribute * getAttribute() const
Definition: GA_Handle.h:343
SYS_FORCE_INLINE T & z(void)
Definition: UT_Vector3.h:585
int opInterrupt(int percent=-1)
GLdouble n
Definition: glcorearb.h:2007
UT_ValArray< UT_UniquePtr< GA_OffsetArray > > * delptslist
GLuint GLuint end
Definition: glcorearb.h:474
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
const SIM_RawField * surffield
GLsizei GLsizei GLchar * source
Definition: glcorearb.h:802
#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
unsigned int uint
Definition: SYS_Types.h:33
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:33
#define THREADED_METHOD1_CONST(CLASSNAME, DOMULTI, METHOD, PARMTYPE1, PARMNAME1)
SYS_FORCE_INLINE T & y(void)
Definition: UT_Vector3.h:583
double fpreal
Definition: SYS_Types.h:263
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
const GA_RWHandleV3 & velhandle
UT_ValArray< UT_UniquePtr< UT_Vector3Array > > * sourceptslist
Space-partitioning acceleration structure for points. Partitions the points into voxels to accelerate...
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:47
#define GET_DATA_FUNC_B(DataName, FuncName)
UT_Vector3 getValue(const UT_Vector3 &pos) const
#define SIM_NAME_SEED
Definition: SIM_Names.h:184
This class holds a three dimensional scalar field.
const SIM_RawIndexField * indexfield
const openvdb::tools::PointIndexGrid * ptgridvdb
GLboolean r
Definition: glcorearb.h:1221
#define GAS_NAME_SOURCE
Definition: GAS_Utils.h:34
#define SYSmin(a, b)
Definition: SYS_Math.h:1366
#define GAS_NAME_SURFACE
Definition: GAS_Utils.h:36
This class holds a three dimensional vector field.
UT_ValArray< UT_UniquePtr< UT_FprealArray > > * distances
#define GET_DATA_FUNC_S(DataName, FuncName)
float fpreal32
Definition: SYS_Types.h:184
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:281