11 #ifndef __SIM_RawField__
12 #define __SIM_RawField__
126 int xres,
int yres,
int zres);
129 int xres,
int yres,
int zres,
151 return field()->numTiles() > 1;
161 void makeConstant(
float cval);
184 int &numsample,
int *ix,
int *iy,
int *iz,
225 sampleval(v), samplew(w), ptpos(p) {}
255 extrapolateFromIndexInternal,
279 void moveAlongCurvature(
fpreal amount,
281 int miniter,
int maxiter);
293 const SIM_RawField &, speed,
294 const SIM_RawField &, source,
297 void moveAlongNormalPartial(
const SIM_RawField &speed,
299 fpreal timestep, fpreal bandwidth,
304 void moveAlongNormalMidpoint(
const SIM_RawField &speed,
305 const SIM_RawField &source,
306 fpreal timestep, fpreal bandwidth);
317 void reinitializeSignedDistance(
int maxiter,
334 const SIM_RawField *, other)
338 const SIM_RawField *, other)
344 const SIM_RawField &, other)
354 void sumPerComponentPartial(UT_DoubleArray &result,
355 UT_Int64Array &activevoxels,
356 const SIM_RawIndexField *comp,
361 int64 &, activevoxels,
363 const SIM_RawIndexField *, comp,
364 const SIM_RawField *, pressureboundary)
365 void sumComponentPartial(
double &result,
368 const SIM_RawIndexField *comp,
369 const SIM_RawField *pressureboundary,
375 const UT_DoubleArray &, valuelist,
376 const SIM_RawIndexField *, comp)
377 void addValuePerComponentPartial(const UT_DoubleArray &valuelist,
378 const SIM_RawIndexField *comp,
384 const SIM_RawIndexField *, comp,
385 const SIM_RawField *, pressureboundary)
386 void addValueToComponentPartial(
double value,
388 const SIM_RawIndexField *comp,
389 const SIM_RawField *pressureboundary,
395 const SIM_RawField &,
A,
397 const SIM_RawField &,
B)
398 void setScaleAddPartial(const SIM_RawField &A,
406 const SIM_RawField &, sdf,
408 void smearedSignPartial(const SIM_RawField &sdf,
415 void convertToHeavisidePartial(const
UT_JobInfo &info);
418 static fpreal toHeaviside(fpreal
val, fpreal diam);
419 static fpreal fromHeaviside(fpreal val, fpreal diam);
421 fpreal toHeaviside(fpreal val) const;
422 fpreal fromHeaviside(fpreal val) const;
442 fpreal reduceOp(REDUCE_NAMES op)
const;
450 void localReduceOp(REDUCE_NAMES op,
const UT_Vector3 &radius);
457 localReduceOp(REDUCE_AVERAGE, r);
463 fpreal reduceMaskedOp(REDUCE_NAMES op,
497 bool hasNan()
const {
return field()->hasNan(); }
501 void testForNan()
const;
515 void clearGrid()
const;
521 void updateGridFromField()
const;
524 void updateFieldFromGrid()
const;
540 { myVoxelSize = voxelsize; myVoxelDiameter = voxelsize.
length(); }
543 {
return myVoxelSize.x()
549 int64 getMemoryUsage()
const;
554 void getVoxelRes(
int &xres,
int &yres,
int &zres)
const;
573 fpreal getCellValue(
int x,
int y,
int z)
const;
577 void addToCell(
int x,
int y,
int z,
fpreal v);
582 void setCellValue(
int x,
int y,
int z,
fpreal v);
598 fpreal64 getLaplacianAtIndex(
int x,
int y,
int z)
const;
608 fpreal64 getCurvatureAtIndex(
int x,
int y,
int z)
const;
617 fpreal64 getCurvatureTimesGradAtIndex(
int x,
int y,
int z)
const;
628 int axis,
bool positivegradient)
const;
644 bool posToIndex(
UT_Vector3 pos,
int &
x,
int &
y,
int &
z)
const;
657 bool cellIndexToPos(
int x,
int y,
int z,
UT_Vector3 &pos)
const;
658 bool posToCellIndex(
UT_Vector3 pos,
int &
x,
int &
y,
int &
z)
const;
672 float time,
float voxelsize,
686 float time,
float voxelsize,
767 void advectSingleMinMaxPartial(
const sim_advectParms &parms,
771 const SIM_RawField *, source,
772 const SIM_RawField *, velx,
773 const SIM_RawField *, vely,
774 const SIM_RawField *, velz,
776 const SIM_RawField *, collision,
779 void advectTracePartial(
const SIM_RawField *source,
780 const SIM_RawField *velx,
781 const SIM_RawField *vely,
782 const SIM_RawField *velz,
784 const SIM_RawField *collision,
789 const sim_advectParms &, parms)
790 void advectTraceMinMaxPartial(
const sim_advectParms &parms,
794 const SIM_RawField *, source,
795 const SIM_RawField *, velx,
796 const SIM_RawField *, vely,
797 const SIM_RawField *, velz,
799 const SIM_RawField *, collision,
803 void advectMultistepPartial(
const SIM_RawField *source,
805 const SIM_RawField *vely,
806 const SIM_RawField *velz,
808 const SIM_RawField *collision,
810 SIM_FieldAdvection advectmethod,
814 const sim_advectParms &, parms)
815 void advectMultistepMinMaxPartial(
const sim_advectParms &parms,
820 const SIM_RawField &, source,
821 const SIM_RawField *, velx,
822 const SIM_RawField *, vely,
823 const SIM_RawField *, velz,
826 void advectHJWENOPartial(
const SIM_RawField &source,
828 const SIM_RawField *vely,
829 const SIM_RawField *velz,
835 const SIM_RawField &, source,
836 const SIM_RawField *, velx,
837 const SIM_RawField *, vely,
838 const SIM_RawField *, velz,
841 void advectUpwindPartial(
const SIM_RawField &source,
842 const SIM_RawField *velx,
843 const SIM_RawField *vely,
844 const SIM_RawField *velz,
852 const SIM_RawField *, temperature,
856 void buoyancyPartial(
const SIM_RawField *stencil,
858 fpreal up, fpreal Tamb,
893 d = SYSsafediv(d, s);
943 dstval = mixValues(parms.
calctype, dstval, srcval);
955 sim_particleToFieldParms &, parms)
956 void applyParticlesPartial(
969 float,
time,
float, voxelsize,
970 const SIM_RawField *, collision,
972 void advect2Partial(
const SIM_RawField *source,
973 sim_PointVelocity getVelocity,
974 float time,
float voxelsize,
975 const SIM_RawField *collision,
981 void advectSelf(
const SIM_RawField *velx,
982 const SIM_RawField *vely,
983 const SIM_RawField *velz,
985 const SIM_RawField *collision,
988 void advectSelf(sim_PointVelocity getVelocity,
989 float time,
float voxelsize,
990 const SIM_RawField *collision,
994 void advectMinMaxSelf(SIM_RawField *minfield,
995 SIM_RawField *maxfield,
996 const SIM_RawField *velx,
997 const SIM_RawField *vely,
998 const SIM_RawField *velz,
1000 const SIM_RawField *collision,
1006 void diffuse(
fpreal diffrate,
1008 const SIM_RawField *collision=0);
1011 static
void diffuse(
float *dstdata,
const float *srcdata[3][3][3],
1012 float b,
float ivsx,
float ivsy,
float ivsz,
1014 int max_xtile,
int max_ytile,
1015 int max_xvox,
int max_yvox);
1028 const SIM_RawField *, surface,
1029 const SIM_RawField *,
stencil)
1030 void buildDivergenceFacePartial(const SIM_VectorField *vel,
1031 const SIM_RawField *surface,
1054 bool variational =
true,
1055 bool ghostfluid =
true,
1056 PCG_METHOD pcgmethod = PCG_MIC);
1064 gaussSeidelIteration,
1069 void gaussSeidelIterationPartial(
1080 gaussSeidelIterationFlat,
1083 fpreal32, sumweight,
1085 void gaussSeidelIterationFlatPartial(
1097 gaussSeidelIterationFlat2D,
1100 fpreal32, sumweight,
1102 void gaussSeidelIterationFlat2DPartial(
1113 const SIM_RawField *collision=0,
1114 const SIM_RawField *cvalue = 0,
1115 const SIM_RawField *boundary = 0,
1118 const SIM_RawField *collision,
1119 const SIM_RawField *cvalue = 0);
1120 void enforceSideBoundary(
int axis,
int side,
1123 const SIM_BoundaryLine &indexbline = SIM_BoundaryLine(),
1124 const SIM_RawField *boundaryfield = 0);
1127 enforceCollisionBoundaryInternal,
1129 const SIM_RawField *, collision,
1130 const SIM_RawField *, cvalue)
1131 void enforceCollisionBoundaryInternalPartial(
1132 SIM_FieldBoundary boundary,
1133 const SIM_RawField *collision,
1134 const SIM_RawField *cvalue,
1141 void enforceBoundaryFlat(fpreal32 *
values,
1144 enforceCollisionBoundaryFlat,
1148 void enforceCollisionBoundaryFlatPartial(fpreal32 *values,
1149 const SIM_RawIndexField *collision_lookup,
1151 void enforceSideBoundaryFlat(fpreal32 *values,
1153 SIM_FieldBoundary bound,
1163 void setBoundary(
int axis,
int side, SIM_FieldBoundary bound)
1164 { myBoundary[axis][side] = bound; }
1166 {
return myBoundary[axis][side]; }
1168 { myBoundaryValue[axis][side] =
v; }
1170 {
return myBoundaryValue[axis][side]; }
1182 float getBorderValue()
const;
1190 void setCompressionTolerance(
fpreal tol);
1191 fpreal getCompressionTolerance()
const;
1206 int maxpasses = -1);
1207 void waveletInverseTransform(
1210 int maxpasses = -1);
1217 void waveletExtractComponent(
const SIM_RawField *wavelet,
1246 computeSDFWeightsSampledInternal(sdf,samplesperaxis,invert,
1247 minweight, dilatedist);
1252 computeSDFWeightsSampledInternal,
1254 int, samplesperaxis,
1259 void computeSDFWeightsSampledInternalPartial(
const SIM_RawField *sdf,
1271 computeSDFWeightsFace,
1277 void computeSDFWeightsFacePartial(
const SIM_RawField *sdf,
1287 computeSDFWeightsVolumeFraction,
1292 void computeSDFWeightsVolumeFractionPartial(
const SIM_RawField *sdf,
1301 fpreal computeVoxelSDFWeightFace(
int x,
int y,
int z,
1308 setScaleDivideThreshold,
1320 void waveletRebuildFromVoxelArray(
1335 fpreal64 *, masktotal,
1337 const SIM_RawField *,
mask,
1339 void reduceMaskedOpInternalPartial(fpreal64 *sum, fpreal64 *masktotal, REDUCE_NAMES op, const SIM_RawField *maskfield,
bool maskissdf, const
UT_JobInfo &info) const;
1343 const SIM_RawField *maskfield,
1344 bool maskissdf) const;
1349 const SIM_RawField *, depths,
1350 const SIM_RawField *, valid,
1356 void buildExtrapListPartial(
1358 const SIM_RawField *depths,
1359 const SIM_RawField *valid,
1361 fpreal dir, fpreal maxdist,
1362 bool clamp, fpreal clampval,
1367 void localReduceByAxis(REDUCE_NAMES op,
1373 template <
int AXIS, REDUCE_NAMES OP>
1378 template <
int AXIS, REDUCE_NAMES OP>
1385 void localReduceAxisOp(REDUCE_NAMES op,
1392 field.getTileRes(1)*field.getTileRes(2) > 1,
1396 UT_VoxelArrayF &, field,
1398 void localReduceAxisXPartial(
1400 UT_VoxelArrayF &dst,
1401 UT_VoxelArrayF &field,
1404 { localReduceAxisOp<0>(op,
dst, field, radius, info); }
1407 field.getTileRes(0)*field.getTileRes(2) > 1,
1413 void localReduceAxisYPartial(
1419 { localReduceAxisOp<1>(op,
dst, field, radius, info); }
1422 field.getTileRes(0)*field.getTileRes(1) > 1,
1428 void localReduceAxisZPartial(
1434 { localReduceAxisOp<2>(op,
dst, field, radius, info); }
1450 void buildFromVDBSampledPartial(
const GEO_PrimVDB *vdb,
1452 const UT_DMatrix4 &xform,
1465 mutable
bool myFieldOutOfDate;
1475 fpreal myVoxelDiameter;
1478 fpreal myBoundaryValue[3][2];
1493 myRes[0] = myRes[1] = myRes[2] = 0;
1515 return myIdx[2] >= myRes[2];
1521 if (myIdx[0] >= myRes[0])
1525 if (myIdx[1] >= myRes[1])
1529 if (myIdx[2] >= myRes[2])
1532 myIdx[2] = myRes[2];
1538 int x()
const {
return myIdx[0]; }
1539 int y()
const {
return myIdx[1]; }
1540 int z()
const {
return myIdx[2]; }
1541 int idx(
int axis)
const {
return myIdx[axis]; }
1548 return myIdx[0] == 0;
1580 #define CALL_PROBEXY(XSTEP, YSTEP, src, dst, command) \
1582 if ((dstsample ^ srcsample) & 4) \
1584 if (dstsample & 4) \
1586 UT_VoxelProbeAverage<fpreal32, XSTEP, YSTEP, -1> theprobe; \
1587 theprobe.setArray(src->field()); \
1592 UT_VoxelProbeAverage<fpreal32, XSTEP, YSTEP, 1> theprobe; \
1593 theprobe.setArray(src->field()); \
1599 UT_VoxelProbeAverage<fpreal32, XSTEP, YSTEP, 0> theprobe; \
1600 theprobe.setArray(src->field()); \
1605 #define CALL_PROBEX(XSTEP, src, dst, command) \
1607 if ((dstsample ^ srcsample) & 2) \
1609 if (dstsample & 2) \
1611 CALL_PROBEXY(XSTEP, -1, src, dst, command); \
1615 CALL_PROBEXY(XSTEP, 1, src, dst, command); \
1620 CALL_PROBEXY(XSTEP, 0, src, dst, command); \
1624 #define CALL_VOXELPROBE(src, dst, defval, command) \
1628 UT_VoxelProbeConstant<fpreal32> theprobe; \
1629 theprobe.setValue(defval); \
1634 int dstsample, srcsample; \
1635 dstsample = dst->getSample(); \
1636 srcsample = src->getSample(); \
1637 if ((dstsample ^ srcsample) & 1) \
1639 if (dstsample & 1) \
1641 CALL_PROBEX(-1, src, dst, command); \
1645 CALL_PROBEX(1, src, dst, command); \
1650 CALL_PROBEX(0, src, dst, command); \
GLboolean GLboolean GLboolean b
#define THREADED_METHOD7(CLASSNAME, DOMULTI, METHOD, PARMTYPE1, PARMNAME1, PARMTYPE2, PARMNAME2, PARMTYPE3, PARMNAME3, PARMTYPE4, PARMNAME4, PARMTYPE5, PARMNAME5, PARMTYPE6, PARMNAME6, PARMTYPE7, PARMNAME7)
#define THREADED_METHOD4_CONST(CLASSNAME, DOMULTI, METHOD, PARMTYPE1, PARMNAME1, PARMTYPE2, PARMNAME2, PARMTYPE3, PARMNAME3, PARMTYPE4, PARMNAME4)
virtual ~SIM_RawFieldCellIterator()
GLint GLint GLsizei GLint border
GLenum GLenum GLenum GLenum GLenum scale
*get result *(waiting if necessary)*A common idiom is to fire a bunch of sub tasks at the and then *wait for them to all complete We provide a helper class
void getVoxelRes(int &xres, int &yres, int &zres) const
#define THREADED_METHOD8(CLASSNAME, DOMULTI, METHOD, PARMTYPE1, PARMNAME1, PARMTYPE2, PARMNAME2, PARMTYPE3, PARMNAME3, PARMTYPE4, PARMNAME4, PARMTYPE5, PARMNAME5, PARMTYPE6, PARMNAME6, PARMTYPE7, PARMNAME7, PARMTYPE8, PARMNAME8)
GT_API const UT_StringHolder time
const UT_Vector3 & getVoxelSize() const
#define THREADED_METHOD1(CLASSNAME, DOMULTI, METHOD, PARMTYPE1, PARMNAME1)
static fpreal applyParticleToFieldParms(fpreal srcval, fpreal dstval, const sim_particleToFieldParms &parms)
UT_Vector3T< float > UT_Vector3
static fpreal mixValues(MIX_NAMES mixtype, fpreal d, fpreal s)
Performs the requires mixing.
UT_VoxelArrayF * fieldNC() const
const SIM_RawField * velz
constexpr SYS_FORCE_INLINE T length() const noexcept
SIM_RawFieldCellIterator()
UT_Vector3(* sim_PointVelocityCB)(const UT_Vector3 &, int, void *)
bool shouldMultiThread() const
Returns true if this should be multithreaded.
#define THREADED_METHOD5_CONST(CLASSNAME, DOMULTI, METHOD, PARMTYPE1, PARMNAME1, PARMTYPE2, PARMNAME2, PARMTYPE3, PARMNAME3, PARMTYPE4, PARMNAME4, PARMTYPE5, PARMNAME5)
GLuint GLuint GLfloat weight
#define THREADED_METHOD3(CLASSNAME, DOMULTI, METHOD, PARMTYPE1, PARMNAME1, PARMTYPE2, PARMNAME2, PARMTYPE3, PARMNAME3)
bool gridIsAuthoritative() const
Returns true if the OpenCL grid has more up-to-date data than the voxel array.
GLenum GLsizei GLsizei GLint * values
GLubyte GLubyte GLubyte GLubyte w
fpreal getVoxelDiameter() const
void markGridAsChanged()
Mark the field as out of date, but only if we have a valid grid.
SIM_FieldSample getSample() const
sim_PointVelocity(sim_PointVelocityCB _cb, void *_data)
const UT_Vector3 & getBBoxOrig() const
GLfloat GLfloat GLfloat v2
const UT_Vector3 & getBBoxSize() const
GLsizei GLsizei GLchar * source
#define THREADED_METHOD2(CLASSNAME, DOMULTI, METHOD, PARMTYPE1, PARMNAME1, PARMTYPE2, PARMNAME2)
void computeSDFWeightsSampled(const SIM_RawField *sdf, int samplesperaxis, bool invert, fpreal minweight, fpreal dilatedist=0)
bool isStartOfTile() const
const SIM_RawField * collision
GLdouble GLdouble GLdouble z
void setBoundaryValue(int axis, int side, fpreal v)
typedef int(WINAPI *PFNWGLRELEASEPBUFFERDCARBPROC)(HPBUFFERARB hPbuffer
const UT_Vector3 & getSize() const
const SIM_RawField * source
#define THREADED_METHOD5(CLASSNAME, DOMULTI, METHOD, PARMTYPE1, PARMNAME1, PARMTYPE2, PARMNAME2, PARMTYPE3, PARMNAME3, PARMTYPE4, PARMNAME4, PARMTYPE5, PARMNAME5)
fpreal average() const
Prebuilt versions.
GLfloat GLfloat GLfloat GLfloat v3
#define THREADED_METHOD4(CLASSNAME, DOMULTI, METHOD, PARMTYPE1, PARMNAME1, PARMTYPE2, PARMNAME2, PARMTYPE3, PARMNAME3, PARMTYPE4, PARMNAME4)
void setArray(const SIM_RawField *field)
GEO_PrimVolumeXform * fieldxform
GLint GLsizei GLsizei height
fpreal getBoundaryValue(int axis, int side) const
const UT_VoxelArrayF * field() const
Fetches the raw field.
#define THREADED_METHOD2_CONST(CLASSNAME, DOMULTI, METHOD, PARMTYPE1, PARMNAME1, PARMTYPE2, PARMNAME2)
GA_API const UT_StringHolder up
void boxBlur(float radius)
#define THREADED_METHOD6(CLASSNAME, DOMULTI, METHOD, PARMTYPE1, PARMNAME1, PARMTYPE2, PARMNAME2, PARMTYPE3, PARMNAME3, PARMTYPE4, PARMNAME4, PARMTYPE5, PARMNAME5, PARMTYPE6, PARMNAME6)
fpreal getVoxelVolume() const
bool hasNan() const
Returns true if our field has any NANs.
SIM_FieldAdvection advectmethod
GLint GLfloat GLint stencil
REDUCE_NAMES
Types of reductions supported by reduceOp.
const UT_Vector3 & getOrig() const
#define THREADED_METHOD3_CONST(CLASSNAME, DOMULTI, METHOD, PARMTYPE1, PARMNAME1, PARMTYPE2, PARMNAME2, PARMTYPE3, PARMNAME3)
ImageBuf OIIO_API resample(const ImageBuf &src, bool interpolate=true, ROI roi={}, int nthreads=0)
This class holds a three dimensional vector field.
#define THREADED_METHOD(CLASSNAME, DOMULTI, METHOD)
SIM_FieldBoundary getBoundary(int axis, int side) const
void setVoxelSize(const UT_Vector3 &voxelsize)