From 9559f1486066bfc3a4cf1a9f55e6416fc63d119c Mon Sep 17 00:00:00 2001 From: littlemine Date: Fri, 11 Oct 2024 17:00:26 +0800 Subject: [PATCH] help visualize zs spg sparsity as particles --- projects/CUDA/zpc | 2 +- projects/CuEulerian/hybrid/G2P.cu | 55 +++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/projects/CUDA/zpc b/projects/CUDA/zpc index a1b42adcae..2739e7b6a7 160000 --- a/projects/CUDA/zpc +++ b/projects/CUDA/zpc @@ -1 +1 @@ -Subproject commit a1b42adcaeedd7085ceebf5d0c6ad6315305f397 +Subproject commit 2739e7b6a71407be26dbc1a9b66ffcf597f031f8 diff --git a/projects/CuEulerian/hybrid/G2P.cu b/projects/CuEulerian/hybrid/G2P.cu index 470e10ca53..6af4ba176f 100644 --- a/projects/CuEulerian/hybrid/G2P.cu +++ b/projects/CuEulerian/hybrid/G2P.cu @@ -1,6 +1,7 @@ #include "Structures.hpp" #include "Utils.hpp" #include "zensim/cuda/execution/ExecutionPolicy.cuh" +#include "zensim/omp/execution/ExecutionPolicy.hpp" #include "zensim/geometry/SparseGrid.hpp" #include "zensim/geometry/VdbLevelSet.h" #include "zensim/profile/CppTimers.hpp" @@ -180,4 +181,58 @@ ZENDEFNODE(ZSSparseGridToPrimitive, {/* inputs: */ {}, /* category: */ {"Eulerian"}}); + +struct ZSSparseGridAsParticles : INode { + zs::Vector> transform_spgblock_to_particles(zs::CudaExecutionPolicy &pol, ZenoSparseGrid *zsSPG) { + using namespace zs; + constexpr auto space = RM_CVREF_T(pol)::exec_tag::value; + + auto &spg = zsSPG->getSparseGrid(); + auto nbs = spg.numBlocks(); + + zs::Vector> blockCenters(spg.get_allocator(), nbs); + + // fmt::print("spg memspace : {}\n", (int)spg.memspace()); + pol(range(nbs), + [spgv = proxy(spg), pars = proxy(blockCenters)]__device__(size_t bno) mutable { + auto bcoord = spgv.wCoord(bno, 0); + pars[bno] = bcoord + spgv.side_length * spgv.voxelSize() / 2; + }); + return blockCenters; + } + + void apply() override { + auto zsSPG = get_input("SparseGrid"); + auto &spg = zsSPG->getSparseGrid(); + + using namespace zs; + auto pol = cuda_exec(); + auto centers = transform_spgblock_to_particles(pol, zsSPG.get()); + centers = centers.clone({memsrc_e::host, -1}); + + auto prim = std::make_shared(); + + prim->resize(centers.size()); + std::memcpy(prim->verts.values.data(), centers.data(), sizeof(zeno::vec3f) * centers.size()); +#if 0 + pol(zip(prim->verts.values, centers), [](auto &dst, const auto& src) { + dst = zeno::vec3f{src[0], src[1], src[2]}; + }); +#endif + + set_output("prim", prim); + } +}; + +ZENDEFNODE(ZSSparseGridAsParticles, {/* inputs: */ + {"SparseGrid"}, + /* outputs: */ + {"prim"}, + /* params: */ + {}, + /* category: */ + {"Eulerian"}}); + + + } // namespace zeno \ No newline at end of file