Skip to content

Commit 910e562

Browse files
committed
added placeholder for -slice action
Signed-off-by: Ken Museth <ken.museth@gmail.com>
1 parent 9ae7c7b commit 910e562

File tree

1 file changed

+85
-0
lines changed
  • openvdb_cmd/vdb_tool/include

1 file changed

+85
-0
lines changed

openvdb_cmd/vdb_tool/include/Tool.h

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,8 @@ class Tool
237237
/// @brief Scatters point into the active values of an input VDB grid
238238
void scatter();
239239

240+
void slice();
241+
240242
/// @brief apply affine transformations (uniform scale -> rotation -> translation) to a VDB grids and geometry
241243
void transform();
242244

@@ -742,6 +744,18 @@ void Tool::init()
742744
{"mask", "-1", "1", "age (i.e. stack index) of a mask VDB used for clipping. Defaults to -1, i.e. disabled"}},
743745
[&](){mParser.setDefaults();}, [&](){this->clip();});
744746

747+
mParser.addAction(
748+
{"slice"}, "Clip a VDB grid against another grid, a bbox or frustum",
749+
{{"vdb", "0", "0", "age (i.e. stack index) of the VDB grid to be processed. Defaults to 0, i.e. most recently inserted VDB."},
750+
{"keep", "", "1|0|true|false", "toggle wether the input VDB is preserved or deleted after the processing"},
751+
{"file", "slice.png", "(0,0,0),(1,1,1)", "min and max of the world-space bounding-box used for clipping. Defaults to empty, i.e. disabled"},
752+
{"x", "-1", "1", "taper of the frustum (requires bbox and depth to be specified). Defaults to -1, i.e. disabled"},
753+
{"Y", "-1", "1", "taper of the frustum (requires bbox and depth to be specified). Defaults to -1, i.e. disabled"},
754+
{"Z", "-1", "1", "taper of the frustum (requires bbox and depth to be specified). Defaults to -1, i.e. disabled"},
755+
{"color", "-1", "1", "depth in world units of the frustum (requires bbox and taper to be specified). Defaults to -1, i.e. disabled"},
756+
{"mask", "-1", "1", "age (i.e. stack index) of a mask VDB used for clipping. Defaults to -1, i.e. disabled"}},
757+
[&](){mParser.setDefaults();}, [&](){this->slice();});
758+
745759
mParser.addAction(
746760
{"prune"}, "prune away inactive values in a VDB grid",
747761
{{"vdb", "0", "0", "age (i.e. stack index) of the VDB grid to be processed. Defaults to 0, i.e. most recently inserted VDB"}},
@@ -2568,6 +2582,77 @@ void Tool::scatter()
25682582
}
25692583
}// Tool::scatter
25702584

2585+
// ==============================================================================================================
2586+
2587+
void Tool::slice()
2588+
{
2589+
const std::string &name = mParser.getAction().names[0];
2590+
OPENVDB_ASSERT(name == "slice");
2591+
std::string imageName("slice.ppm");
2592+
const size_t w = 1024, h= 1024;
2593+
2594+
std::unique_ptr<unsigned char>
2595+
auto turboLUT = [](uint8_t n)->tools::Film::RGBA{
2596+
// LUT from https://gist.github.com/mikhailov-work/6a308c20e494d9e0ccc29036b28faa7a (Apache-2.0)
2597+
static const unsigned char LUT[256][3] = {{48,18,59},{50,21,67},{51,24,74},{52,27,81},{53,30,88},{54,33,95},{55,36,102},{56,39,109},{57,42,115},{58,45,121},{59,47,128},{60,50,134},{61,53,139},{62,56,145},{63,59,151},{63,62,156},{64,64,162},{65,67,167},{65,70,172},{66,73,177},{66,75,181},{67,78,186},{68,81,191},{68,84,195},{68,86,199},{69,89,203},{69,92,207},{69,94,211},{70,97,214},{70,100,218},{70,102,221},{70,105,224},{70,107,227},{71,110,230},{71,113,233},{71,115,235},{71,118,238},{71,120,240},{71,123,242},{70,125,244},{70,128,246},{70,130,248},{70,133,250},{70,135,251},{69,138,252},{69,140,253},{68,143,254},{67,145,254},{66,148,255},{65,150,255},{64,153,255},{62,155,254},{61,158,254},{59,160,253},{58,163,252},{56,165,251},{55,168,250},{53,171,248},{51,173,247},{49,175,245},{47,178,244},{46,180,242},{44,183,240},{42,185,238},{40,188,235},{39,190,233},{37,192,231},{35,195,228},{34,197,226},{32,199,223},{31,201,221},{30,203,218},{28,205,216},{27,208,213},{26,210,210},{26,212,208},{25,213,205},{24,215,202},{24,217,200},{24,219,197},{24,221,194},{24,222,192},{24,224,189},{25,226,187},{25,227,185},{26,228,182},{28,230,180},{29,231,178},{31,233,175},{32,234,172},{34,235,170},{37,236,167},{39,238,164},{42,239,161},{44,240,158},{47,241,155},{50,242,152},{53,243,148},{56,244,145},{60,245,142},{63,246,138},{67,247,135},{70,248,132},{74,248,128},{78,249,125},{82,250,122},{85,250,118},{89,251,115},{93,252,111},{97,252,108},{101,253,105},{105,253,102},{109,254,98},{113,254,95},{117,254,92},{121,254,89},{125,255,86},{128,255,83},{132,255,81},{136,255,78},{139,255,75},{143,255,73},{146,255,71},{150,254,68},{153,254,66},{156,254,64},{159,253,63},{161,253,61},{164,252,60},{167,252,58},{169,251,57},{172,251,56},{175,250,55},{177,249,54},{180,248,54},{183,247,53},{185,246,53},{188,245,52},{190,244,52},{193,243,52},{195,241,52},{198,240,52},{200,239,52},{203,237,52},{205,236,52},{208,234,52},{210,233,53},{212,231,53},{215,229,53},{217,228,54},{219,226,54},{221,224,55},{223,223,55},{225,221,55},{227,219,56},{229,217,56},{231,215,57},{233,213,57},{235,211,57},{236,209,58},{238,207,58},{239,205,58},{241,203,58},{242,201,58},{244,199,58},{245,197,58},{246,195,58},{247,193,58},{248,190,57},{249,188,57},{250,186,57},{251,184,56},{251,182,55},{252,179,54},{252,177,54},{253,174,53},{253,172,52},{254,169,51},{254,167,50},{254,164,49},{254,161,48},{254,158,47},{254,155,45},{254,153,44},{254,150,43},{254,147,42},{254,144,41},{253,141,39},{253,138,38},{252,135,37},{252,132,35},{251,129,34},{251,126,33},{250,123,31},{249,120,30},{249,117,29},{248,114,28},{247,111,26},{246,108,25},{245,105,24},{244,102,23},{243,99,21},{242,96,20},{241,93,19},{240,91,18},{239,88,17},{237,85,16},{236,83,15},{235,80,14},{234,78,13},{232,75,12},{231,73,12},{229,71,11},{228,69,10},{226,67,10},{225,65,9},{223,63,8},{221,61,8},{220,59,7},{218,57,7},{216,55,6},{214,53,6},{212,51,5},{210,49,5},{208,47,5},{206,45,4},{204,43,4},{202,42,4},{200,40,3},{197,38,3},{195,37,3},{193,35,2},{190,33,2},{188,32,2},{185,30,2},{183,29,2},{180,27,1},{178,26,1},{175,24,1},{172,23,1},{169,22,1},{167,20,1},{164,19,1},{161,18,1},{158,16,1},{155,15,1},{152,14,1},{149,13,1},{146,11,1},{142,10,1},{139,9,2},{136,8,2},{133,7,2},{129,6,2},{126,5,2},{122,4,3}};
2598+
return tools::Film::RGBA(LUT[n][0]/255.0f, LUT[n][1]/255.0f, LUT[n][2]/255.0f);
2599+
};
2600+
2601+
tools::Film image(w, h);
2602+
for (size_t i=0; i<w; ++i) {
2603+
const uint8_t n = uint8_t((255.0f*i)/(w-1));
2604+
for (size_t j=0; j<h; ++j) {
2605+
image.pixel(i,j) = turboLUT(n);
2606+
}
2607+
}
2608+
image.savePPM(imageName);
2609+
std::cerr << "Tool::slice is not impemented yet\n";
2610+
return;
2611+
try {
2612+
mParser.printAction();
2613+
const Index64 count = mParser.get<int>("count");
2614+
const float density = mParser.get<float>("density");
2615+
const int pointsPerVoxel = mParser.get<int>("ppv");
2616+
const int age = mParser.get<int>("vdb");
2617+
const bool keep = mParser.get<bool>("keep");
2618+
std::string grid_name = mParser.get<std::string>("name");
2619+
auto it = this->getGrid(age);
2620+
GridT::Ptr grid = gridPtrCast<GridT>(*it);
2621+
if (!grid) throw std::invalid_argument("slice: no float grid with age "+std::to_string(age));
2622+
if (mParser.verbose) mTimer.start("SDF -> mesh");
2623+
Geometry::Ptr geom(new Geometry());
2624+
struct PointWrapper {
2625+
std::vector<Vec3f> &xyz;
2626+
PointWrapper(std::vector<Vec3f> &_xyz) : xyz(_xyz) {}
2627+
Index64 size() const { return Index64(xyz.size()); }
2628+
void add(const Vec3d &p) { xyz.emplace_back(float(p[0]), float(p[1]), float(p[2])); }
2629+
} points(geom->vtx());
2630+
using RandGenT = std::mersenne_twister_engine<uint32_t, 32, 351, 175, 19,
2631+
0xccab8ee7, 11, 0xffffffff, 7, 0x31b6ab00, 15, 0xffe50000, 17, 1812433253>; // mt11213b
2632+
RandGenT mtRand;
2633+
2634+
if (count>0) {// fixed point count scattering
2635+
tools::UniformPointScatter<PointWrapper, RandGenT> tmp(points, count, mtRand);
2636+
tmp(*grid);
2637+
} else if (density>0.0f) {// uniform density scattering
2638+
tools::UniformPointScatter<PointWrapper, RandGenT> tmp(points, density, mtRand);
2639+
tmp(*grid);
2640+
} else if (pointsPerVoxel>0) {// dense uniform scattering
2641+
tools::DenseUniformPointScatter<PointWrapper, RandGenT> tmp(points, static_cast<float>(pointsPerVoxel), mtRand);
2642+
tmp(*grid);
2643+
} else {
2644+
throw std::invalid_argument("scatter: internal error");
2645+
}
2646+
if (!keep) mGrid.erase(std::next(it).base());
2647+
if (grid_name.empty()) grid_name = "scatter_"+grid->getName();
2648+
geom->setName(grid_name);
2649+
mGeom.push_back(geom);
2650+
if (mParser.verbose) mTimer.stop();
2651+
} catch (const std::exception& e) {
2652+
throw std::invalid_argument(name+": "+e.what());
2653+
}
2654+
}// Tool::scatter
2655+
25712656
// ==============================================================================================================
25722657
// LeVeque, R., High-Resolution Conservative Algorithms For Advection In Incompressible Flow, SIAM J. Numer. Anal. 33, 627–665 (1996)
25732658
// https://faculty.washington.edu/rjl/pubs/hiresadv/0733033.pdf

0 commit comments

Comments
 (0)