11 #ifndef GU_VDBFROMPARTICLEFLUID_H_
12 #define GU_VDBFROMPARTICLEFLUID_H_
25 #define USE_W2SUM_MASS 0
27 #define USE_WEIGHTED_DIST 0
28 #define USE_VELOCITY 0
41 PHANTOM_PARTICLES = 0,
42 REFINED_AVERAGE_POSITION
55 sampling_method(SMOOTH_SAMPLE),
56 surfacing_method(PHANTOM_PARTICLES),
57 particle_separation(0.1),
61 resampling_iterations(-1),
64 additional_padding(0.5),
69 smoothing_iterations(0),
70 feature_preservation(0.0),
72 feature_enhancement(0.3),
73 tile_grid_orig(
Vector3R(0.0, 0.0, 0.0))
140 surfacing_method(PHANTOM_PARTICLES),
141 sampling_method(SMOOTH_SAMPLE),
142 world_orig(0.0, 0.0, 0.0),
143 world_orig_voxel(0, 0, 0),
146 padding_voxels(-1.0),
147 influence_voxels(-1.0),
148 surface_distance(-1.0),
149 sampling_frequency(-1.0),
150 sampling_iterations(0),
152 smoothing_iterations(0),
153 feature_preservation(0.0),
155 feature_enhancement(0.3)
158 SurfacingMethod surfacing_method;
159 SamplingMethod sampling_method;
161 CoordT world_orig_voxel;
164 exint padding_voxels;
165 RealT influence_voxels;
166 RealT surface_distance;
167 RealT particle_separation;
168 RealT sampling_frequency;
169 int sampling_iterations;
171 int smoothing_iterations;
172 RealT feature_preservation;
173 RealT sheeting_scale;
174 RealT feature_enhancement;
201 #if USE_WEIGHTED_DIST
206 center() {
return pos / wsum; }
208 density() {
return (pos.length() - rad) / wsum; }
210 height() {
return pos.length() / wsum; }
212 radius() {
return rad / wsum; }
216 struct SamplingGridPoint
233 typedef typename openvdb::math::Vec2<int> Vec2T;
235 typedef typename TileTreeT::LeafNodeType TileLeafT;
236 typedef typename openvdb::Grid<TileTreeT> TileGridT;
237 typedef typename TileGridT::Ptr TileGridPtr;
238 typedef typename TileGridT::Accessor TileAccessorT;
239 typedef typename TileGridT::ConstAccessor TileConstAccessorT;
240 typedef typename openvdb::tree::LeafManager<TileTreeT> TileLeafManagerT;
241 typedef typename TileLeafManagerT::LeafRange TileRangeT;
265 return myErrorMessage.str();
268 int evaluate(RealGridPtr result_grid,
bool threaded =
true);
269 void drawGuide(
GU_Detail *gdp, RealT padding);
286 class ut_isGridIdxLess
289 inline bool operator()(
const GridIdxKey &
a,
290 const GridIdxKey &
b)
const
292 if (a.grididx == b.grididx)
293 return a.key < b.key;
294 return a.grididx < b.grididx;
299 struct SentinelVoxelsCleaner
301 void run(RealGridPtr grid);
302 void operator()(
const RealRangeT&
r)
const;
307 RealT bytesPerVoxel(RealT sampling_frequency_in_voxels);
313 return i * myMaxJK + j * myMaxK + k;
328 struct ParticleInstancer;
329 struct InstanceMerger;
337 inline bool operator()(
const TileLeafT::ValueOnIter &
a,
338 const TileLeafT::ValueOnIter &
b)
const
340 Vec2T vala = a.getValue();
341 Vec2T valb = b.getValue();
342 return vala(1) - vala(0) < valb(1) - valb(0);
348 inline Vector3R vecFloor(
const Vector3R
v)
353 inline Vector3R vecCeil(
const Vector3R v)
358 inline Vector3R vecRound(
const Vector3R v)
363 inline RealT maxComp(
const Vector3R v)
368 inline RealT minComp(
const Vector3R v)
377 void position(
exint start_idx,
exint stop_idx, Vector3R tile_orig, CoordT tile_orig_voxel);
378 void run(
bool resample_input,
int band_voxels);
384 coordToIndex(CoordT v,
exint grid_side_points,
exint grid_side_points_sqr)
386 return grid_side_points_sqr *
v(0) +
387 grid_side_points *
v(1) +
v(2);
392 exint grid_side_points_sqr)
394 return grid_side_points_sqr * i + grid_side_points * j + k;
400 exint i = index / grid_side_points_sqr;
401 index -= i * grid_side_points_sqr;
402 exint j = index / grid_side_points;
403 index -= j * grid_side_points;
404 return CoordT(i, j, index);
410 pasteParticle(
const Vector3R &pos, RealT rad,
411 RealT
mass, RealT squeeze = RealT(1.0));
414 pasteParticleToSamplingGrid(
const Vector3R &pos, RealT rad,
415 RealT mass, RealT squeeze = RealT(1.0));
419 inline RealT evalDensity(Vector3R xyz);
420 inline RealT evalIsoDensity(Vector3R xyz, RealT *
dist = NULL);
422 inline RealT adjustedHeight(
exint voxel_index, RealT srad);
424 void expandIndexList(
UT_IntArray &idx_list,
int num_voxels,
exint grid_side_points);
426 void markBandVoxels(
int band_radius,
bool mark_all =
false);
428 #if CLIP_DEEP_PARTICLES
429 void separateDeepAndShallowSamples();
430 void floodIndexList(
UT_IntArray &idx_list,
bool ascending);
431 void floodDeepVoxels();
434 void finalizeDensities();
435 void writeToVDB(
int band_voxels);
437 void collectNewSamples();
440 inline void recordSample(
const Vector3R &pos, RealT rad, RealT mass = RealT(1.0),
441 RealT vel = RealT(0.0),
bool clean_voxel_only =
true);
443 inline int findSamplingVoxelCorners(
const Vector3R &pos,
exint *
offsets, RealT *weights);
445 void resampleInputParticles();
446 exint addAllParticles();
447 exint pasteNewSamples();
451 void buildPointTree();
452 int nearestParticle(Vector3R &xyz);
456 inline RealT softClipAbove(RealT
min, RealT
max, RealT
clip, RealT
x)
462 return ((max - x) * x + (x - min) * clip)/(max -
min);
465 inline RealT softClipBelow(RealT min, RealT max, RealT clip, RealT x)
471 return ((max - x) * clip + (x - min) * x) / (max -
min);
474 void boxFilter(RealT rwidth,
int iterations, RealT bias);
475 void boxFilterV2(
int width,
int iterations, RealT bias);
483 exint myStartIdx, myStopIdx;
488 RealT myBufferVoxelSize;
489 exint myBufferGridSidePoints;
490 exint myBufferGridSidePointsSqr;
491 exint myBufferGridSize;
496 RealT mySamplingVoxelSize;
497 exint mySamplingGridSidePoints;
498 exint mySamplingGridSidePointsSqr;
499 exint mySamplingGridSize;
503 #if CLIP_DEEP_PARTICLES
510 Vector3R mySamplingOrig;
515 CoordT myTileOrigVoxel;
516 Vector3R myWorldOrig;
517 CoordT myWorldOrigVoxel;
518 Vector3R myBufferOrig;
519 CoordT myBufferOrigVoxel;
521 exint myPaddingVoxels;
522 RealT mySamplingFrequency;
523 int mySamplingIterations;
524 RealT mySurfaceDistance;
525 RealT myParticleSeparation;
526 RealT myInfluenceVoxels;
527 RealT myInfluenceVoxelsSqr;
529 int mySmoothingIterations;
530 RealT myFeaturePreservation;
537 int16 myCurrentIteration;
539 RealT mySheetingScale;
540 RealT myFeatureEnhancement;
542 SamplingMethod mySamplingMethod;
543 SurfacingMethod mySurfacingMethod;
553 RealT myInfluenceRadius;
554 RealT myInfluenceVoxels;
555 RealT mySamplingFrequency;
556 int mySamplingIterations;
561 exint myMaxJK, myMaxI, myMaxJ, myMaxK;
562 Vector3R myBoundingBoxOrig;
563 CoordT myBoundingBoxOrigVoxel;
566 exint myTilePaddingVoxels;
567 exint myTileSideVoxels;
569 RealT myTileSideLength;
570 Vector3R myTileGridOrig;
573 TileGridPtr myTileIdxGrid;
576 RealGridPtr myOutputVDBGrid;
578 bool myResampleInput;
580 RealT mySurfaceDistance;
581 RealT myParticleSeparation;
583 TaskArrayT myHardTasks;
588 std::stringstream myErrorMessage;
591 int mySmoothingIterations;
592 RealT myFeaturePreservation;
594 SamplingMethod mySamplingMethod;
595 SurfacingMethod mySurfacingMethod;
601 RealT mySheetingScale;
602 RealT myFeatureEnhancement;
GA_API const UT_StringHolder dist
#define SYS_PACKED_STRUCT_HINT_END
openvdb::tree::Tree4< RealT, 5, 4, 3 >::Type RealTreeT
RealGridT::Accessor RealAccessorT
#define SYS_PACKED_STRUCT_HINT_BEGIN(name, n)
GLsizei const GLchar *const * string
RealTreeT::LeafNodeType RealLeafT
GLboolean GLboolean GLboolean GLboolean a
int resampling_iterations
ImageBuf OIIO_API min(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
RealGridT::ConstAccessor ConstRealAccessorT
openvdb::tree::LeafManager< RealTreeT > RealLeafManagerT
const std::string getErrorMessage()
GLuint GLsizei const GLuint const GLintptr * offsets
GLint GLsizei GLsizei height
UT_Vector3T< RealT > Vector3R
RealT feature_enhancement
openvdb::Grid< RealTreeT > RealGridT
SYS_API fpreal32 SYSfloor(fpreal32 val)
RealT feature_preservation
GLboolean GLboolean GLboolean b
GA_API const UT_StringHolder mass
UT_Vector3T< exint > CoordT
RealT particle_separation
RealLeafManagerT::LeafRange RealRangeT
SIM_API const UT_StringHolder position
ImageBuf OIIO_API max(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
RealGridT::Ptr RealGridPtr
A LeafManager manages a linear array of pointers to a given tree's leaf nodes, as well as optional au...
void OIIO_UTIL_API split(string_view str, std::vector< string_view > &result, string_view sep=string_view(), int maxsplit=-1)
IMATH_INTERNAL_NAMESPACE_HEADER_ENTER IMATH_HOSTDEVICE IMATH_CONSTEXPR14 T clip(const T &p, const Box< T > &box) IMATH_NOEXCEPT
SurfacingMethod surfacing_method
SYS_API fpreal32 SYSceil(fpreal32 val)
SamplingMethod sampling_method