void GridForwardEulerDiffusionSolver3::solve( const ScalarGrid3& source, double diffusionCoefficient, double timeIntervalInSeconds, ScalarGrid3* dest, const ScalarField3& boundarySdf, const ScalarField3& fluidSdf) { auto src = source.constDataAccessor(); Vector3D h = source.gridSpacing(); auto pos = source.dataPosition(); buildMarkers(source.resolution(), pos, boundarySdf, fluidSdf); source.parallelForEachDataPointIndex( [&](size_t i, size_t j, size_t k) { if (_markers(i, j, k) == kFluid) { (*dest)(i, j, k) = source(i, j, k) + diffusionCoefficient * timeIntervalInSeconds * laplacian(src, _markers, h, i, j, k); } else { (*dest)(i, j, k) = source(i, j, k); } }); }
std::function<double(const Vector3D&)> CubicSemiLagrangian3::getScalarSamplerFunc(const ScalarGrid3& source) const { auto sourceSampler = CubicArraySampler3<double, double>( source.constDataAccessor(), source.gridSpacing(), source.dataOrigin()); return sourceSampler.functor(); }
void triangulateAndSave(const ScalarGrid3& sdf, const std::string& objFilename) { TriangleMesh3 mesh; marchingCubes(sdf.constDataAccessor(), sdf.gridSpacing(), sdf.dataOrigin(), &mesh, 0.0, kDirectionAll); std::ofstream file(objFilename.c_str()); if (file) { printf("Writing %s...\n", objFilename.c_str()); mesh.writeObj(&file); file.close(); } else { printf("Cannot write file %s.\n", objFilename.c_str()); exit(EXIT_FAILURE); } }