From 964bca6fb0b131a2cfee28f72835e6c6a3cc9e56 Mon Sep 17 00:00:00 2001 From: bwangxxx <390297188@qq.com> Date: Sat, 7 Oct 2023 17:33:02 +0800 Subject: [PATCH] newHeatMap --- zeno/src/nodes/prim/PrimitiveHeatmap.cpp | 48 ++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/zeno/src/nodes/prim/PrimitiveHeatmap.cpp b/zeno/src/nodes/prim/PrimitiveHeatmap.cpp index e46240ccfb..c1ce22c5ee 100644 --- a/zeno/src/nodes/prim/PrimitiveHeatmap.cpp +++ b/zeno/src/nodes/prim/PrimitiveHeatmap.cpp @@ -93,6 +93,54 @@ ZENDEFNODE(HeatmapFromImage, "visualize", }}); +struct HeatmapFromImage2 : zeno::INode { + virtual void apply() override { + auto image = get_input("image"); + int w = image->userData().get2("w"); + auto heatmap = std::make_shared(); + + auto spos = get_input2("startPos"); + auto epos = get_input2("endPos"); + int start = zeno::clamp(spos, 0.0f, 1.0f) * w; + int end = zeno::clamp(epos, 0.0f, 1.0f) * w; + std::vector temp; + for (auto i = start; i < end; i++) { + temp.push_back(image->verts[i]); + } + + auto resample = get_input2("resample"); + if (0 < resample && resample < w) { + for (auto i = 0; i < resample; i++) { + float x = i / float(resample); + x = zeno::clamp(x, 0, 1) * temp.size(); + int j = (int) zeno::floor(x); + j = zeno::clamp(j, 0, temp.size() - 2); + float f = x - j; + auto c = (1 - f) * temp.at(j) + f * temp.at(j + 1); + heatmap->colors.push_back(c); + } + } + else { + heatmap->colors = temp; + } + + set_output("heatmap", std::move(heatmap)); + } +}; + +ZENDEFNODE(HeatmapFromImage2, + { /* inputs: */ { + "image", + {"float", "startPos", "0"}, + {"float", "endPos", "1"}, + {"int", "resample", "0"}, + }, /* outputs: */ { + "heatmap", + }, /* params: */ { + }, /* category: */ { + "visualize", + }}); + struct PrimitiveColorByHeatmap : zeno::INode { virtual void apply() override { auto prim = get_input("prim");