Skip to content

Commit

Permalink
added patch from Jonathan S
Browse files Browse the repository at this point in the history
Signed-off-by: Ken Museth <[email protected]>
  • Loading branch information
kmuseth committed Nov 21, 2024
1 parent 06bb33e commit 02ddc88
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 31 deletions.
1 change: 1 addition & 0 deletions ci/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ cmake \
-DOPENVDB_BUILD_VDB_PRINT=ON \
-DOPENVDB_BUILD_VDB_LOD=ON \
-DOPENVDB_BUILD_VDB_TOOL=ON \
-DBUILD_TEST=ON \
-DOPENVDB_TOOL_USE_NANO=OFF \
-DOPENVDB_BUILD_PYTHON_UNITTESTS=ON \
-DMSVC_MP_THREAD_COUNT=${PARMS[-j]} \
Expand Down
1 change: 1 addition & 0 deletions openvdb_cmd/vdb_tool/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,5 @@ if(BUILD_TEST)
add_executable(vdb_tool_test src/unittest.cpp)
target_include_directories(vdb_tool_test PRIVATE vdb_tool_common)
target_link_libraries(vdb_tool_test PRIVATE vdb_tool_common GTest::gmock GTest::gtest GTest::gmock_main GTest::gtest_main)
add_test(vdb_tool_unit_test vdb_tool_test)
endif()
2 changes: 1 addition & 1 deletion openvdb_cmd/vdb_tool/include/Geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

#ifdef VDB_TOOL_USE_NANO
#include <nanovdb/NanoVDB.h>
#include <nanovdb/util/IO.h>
#include <nanovdb/io/IO.h>
#endif

#ifdef VDB_TOOL_USE_ABC
Expand Down
38 changes: 19 additions & 19 deletions openvdb_cmd/vdb_tool/include/Tool.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@

#ifdef VDB_TOOL_USE_NANO
#include <nanovdb/NanoVDB.h>
#include <nanovdb/util/IO.h>
#include <nanovdb/util/CreateNanoGrid.h>
#include <nanovdb/util/NanoToOpenVDB.h>
#include <nanovdb/io/IO.h>
#include <nanovdb/tools/CreateNanoGrid.h>
#include <nanovdb/tools/NanoToOpenVDB.h>
#endif

#ifdef VDB_TOOL_USE_EXR
Expand Down Expand Up @@ -1062,7 +1062,7 @@ void Tool::readNVDB(const std::string &fileName)
const size_t count = mGrid.size();
if (grids.size()) {
for (const auto& gridHandle : grids) {
if (gridNames[0]=="*" || findMatch(gridHandle.gridMetaData()->shortGridName(), gridNames)) mGrid.push_back(nanovdb::nanoToOpenVDB(gridHandle));
if (gridNames[0]=="*" || findMatch(gridHandle.gridMetaData()->shortGridName(), gridNames)) mGrid.push_back(nanovdb::tools::nanoToOpenVDB(gridHandle));
}
} else if (mParser.verbose>0) {
std::cerr << "readVDB: no vdb grids in \"" << fileName << "\"";
Expand Down Expand Up @@ -1262,26 +1262,26 @@ void Tool::writeNVDB(const std::string &fileName)
throw std::invalid_argument("writeNVDB: unsupported bits \""+bits+"\"");
}

nanovdb::StatsMode sMode = nanovdb::StatsMode::Default;
nanovdb::tools::StatsMode sMode = nanovdb::tools::StatsMode::Default;
if (stats == "none") {
sMode = nanovdb::StatsMode::Disable;
sMode = nanovdb::tools::StatsMode::Disable;
} else if (stats == "bbox") {
sMode = nanovdb::StatsMode::BBox;
sMode = nanovdb::tools::StatsMode::BBox;
} else if (stats == "extrema") {
sMode = nanovdb::StatsMode::MinMax;
sMode = nanovdb::tools::StatsMode::MinMax;
} else if (stats == "all") {
sMode = nanovdb::StatsMode::All;
sMode = nanovdb::tools::StatsMode::All;
} else if (stats != "") {
throw std::invalid_argument("writeNVDB: unsupported stats \""+stats+"\"");
}

nanovdb::ChecksumMode cMode = nanovdb::ChecksumMode::Default;
nanovdb::CheckMode cMode = nanovdb::CheckMode::Default;
if (checksum == "none") {
cMode = nanovdb::ChecksumMode::Disable;
cMode = nanovdb::CheckMode::Disable;
} else if (checksum == "partial") {
cMode = nanovdb::ChecksumMode::Partial;
cMode = nanovdb::CheckMode::Partial;
} else if (checksum == "full") {
cMode = nanovdb::ChecksumMode::Full;
cMode = nanovdb::CheckMode::Full;
} else if (checksum != "") {
throw std::invalid_argument("writeNVDB: unsupported checksum \""+checksum+"\"");
}
Expand All @@ -1302,21 +1302,21 @@ void Tool::writeNVDB(const std::string &fileName)
using SrcGridT = openvdb::FloatGrid;
switch (qMode){
case nanovdb::GridType::Fp4:
return nanovdb::createNanoGrid<SrcGridT, nanovdb::Fp4>(*floatGrid, sMode, cMode, dither, verbose);
return nanovdb::tools::createNanoGrid<SrcGridT, nanovdb::Fp4>(*floatGrid, sMode, cMode, dither, verbose);
case nanovdb::GridType::Fp8:
return nanovdb::createNanoGrid<SrcGridT, nanovdb::Fp8>(*floatGrid, sMode, cMode, dither, verbose);
return nanovdb::tools::createNanoGrid<SrcGridT, nanovdb::Fp8>(*floatGrid, sMode, cMode, dither, verbose);
case nanovdb::GridType::Fp16:
return nanovdb::createNanoGrid<SrcGridT, nanovdb::Fp16>(*floatGrid, sMode, cMode, dither, verbose);
return nanovdb::tools::createNanoGrid<SrcGridT, nanovdb::Fp16>(*floatGrid, sMode, cMode, dither, verbose);
case nanovdb::GridType::FpN:
if (absolute) {
return nanovdb::createNanoGrid<SrcGridT, nanovdb::FpN>(*floatGrid, sMode, cMode, dither, verbose, nanovdb::AbsDiff(tolerance));
return nanovdb::tools::createNanoGrid<SrcGridT, nanovdb::FpN>(*floatGrid, sMode, cMode, dither, verbose, nanovdb::tools::AbsDiff(tolerance));
} else {
return nanovdb::createNanoGrid<SrcGridT, nanovdb::FpN>(*floatGrid, sMode, cMode, dither, verbose, nanovdb::RelDiff(tolerance));
return nanovdb::tools::createNanoGrid<SrcGridT, nanovdb::FpN>(*floatGrid, sMode, cMode, dither, verbose, nanovdb::tools::RelDiff(tolerance));
}
default: break;// 32 bit float grids are handled below
}// end of switch
}
return nanovdb::openToNanoVDB(base, sMode, cMode, verbose);// float and other grids
return nanovdb::tools::openToNanoVDB(base, sMode, cMode, verbose);// float and other grids
};// openToNano

if (fileName=="stdout.nvdb") {
Expand Down
22 changes: 11 additions & 11 deletions openvdb_cmd/vdb_tool/src/unittest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ TEST_F(Test_vdb_tool, Geometry)
{// test readOFF and writeOFF
geo.write("data/test.off");
openvdb::vdb_tool::Geometry geo2;
EXPECT_TRUE(geo2.read("data/test.off"));
geo2.read("data/test.off");
EXPECT_EQ(4, geo2.vtxCount());
EXPECT_EQ(2, geo2.triCount());
EXPECT_EQ(1, geo2.quadCount());
Expand Down Expand Up @@ -820,7 +820,7 @@ TEST_F(Test_vdb_tool, ToolParser)
float beta = 0.0f, beta_sum = 0.0f;
std::string path, base, ext;

Parser p({{"alpha", "64"}, {"beta", "4.56"}});
Parser p({{"alpha", "64", "", ""}, {"beta", "4.56", "", ""}});
p.addAction("process_a", "a", "docs",
{{"alpha", "", "", ""},{"beta", "", "", ""}},
[&](){p.setDefaults();},
Expand All @@ -843,7 +843,7 @@ TEST_F(Test_vdb_tool, ToolParser)
p.finalize();

auto args = getArgs("vdb_tool -quiet -process_a alpha=128 -for v=0.1,0.4,0.1 -b alpha={$#v:++} beta={$v} -end");
p.parse(args.size(), args.data());
p.parse(int(args.size()), args.data());
EXPECT_EQ(0, alpha);
EXPECT_EQ(0.0f, beta);
EXPECT_EQ(0, alpha_sum);
Expand All @@ -855,7 +855,7 @@ TEST_F(Test_vdb_tool, ToolParser)
EXPECT_EQ(0.1f + 0.2f + 0.3f, beta_sum);// derived from loop

args = getArgs("vdb_tool -quiet -each file=path1/base1.ext1,path2/base2.ext2 -c alpha={$file:path} beta={$file:name} gamma={$file:ext} -end");
p.parse(args.size(), args.data());
p.parse(int(args.size()), args.data());
p.run();
EXPECT_EQ(path, "path1,path2");
EXPECT_EQ(base, "base1,base2");
Expand All @@ -875,7 +875,7 @@ TEST_F(Test_vdb_tool, ToolBasic)

EXPECT_NO_THROW({
auto args = getArgs("vdb_tool -quiet -sphere r=1.1 -ls2mesh -write data/sphere.ply data/config.txt");
Tool vdb_tool(args.size(), args.data());
Tool vdb_tool(int(args.size()), args.data());
vdb_tool.run();
});

Expand All @@ -896,7 +896,7 @@ TEST_F(Test_vdb_tool, Counter)

EXPECT_NO_THROW({
auto args = getArgs("vdb_tool -quiet -eval {1:@G} -sphere r=1.1 -ls2mesh -write data/sphere_{$G}.ply data/config_{$G:++}.txt");
Tool vdb_tool(args.size(), args.data());
Tool vdb_tool(int(args.size()), args.data());
vdb_tool.run();
});

Expand All @@ -919,7 +919,7 @@ TEST_F(Test_vdb_tool, ToolForLoop)
// test single for-loop
EXPECT_NO_THROW({
auto args = getArgs("vdb_tool -quiet -for i=0,3 -sphere r=1.{$i} dim=128 name=sphere_{$i} -ls2mesh -write data/sphere_{$#i:++}.ply -end");
Tool vdb_tool(args.size(), args.data());
Tool vdb_tool(int(args.size()), args.data());
vdb_tool.run();
});

Expand All @@ -928,7 +928,7 @@ TEST_F(Test_vdb_tool, ToolForLoop)
// test two nested for-loops
EXPECT_NO_THROW({
auto args = getArgs("vdb_tool -quiet -for v=0.1,0.3,0.1 -each s=sphere_1,sphere_3 -read ./data/{$s}.ply -mesh2ls voxel={$v} -end -end -write data/test.vdb");
Tool vdb_tool(args.size(), args.data());
Tool vdb_tool(int(args.size()), args.data());
vdb_tool.run();
});

Expand All @@ -948,7 +948,7 @@ TEST_F(Test_vdb_tool, ToolError)

EXPECT_THROW({
auto args = getArgs("vdb_tool -sphere bla=3 -ls2mesh -write data/sphere.ply data/config.txt -quiet");
Tool vdb_tool(args.size(), args.data());
Tool vdb_tool(int(args.size()), args.data());
vdb_tool.run();
}, std::invalid_argument);

Expand All @@ -971,7 +971,7 @@ TEST_F(Test_vdb_tool, ToolKeep)

EXPECT_NO_THROW({
auto args = getArgs("vdb_tool -quiet -default keep=1 -sphere r=2 -ls2mesh vdb=0 -write vdb=0 geo=0 data/sphere.vdb data/sphere.ply data/config.txt");
Tool vdb_tool(args.size(), args.data());
Tool vdb_tool(int(args.size()), args.data());
vdb_tool.run();
});

Expand All @@ -994,7 +994,7 @@ TEST_F(Test_vdb_tool, ToolConfig)

EXPECT_NO_THROW({
auto args = getArgs("vdb_tool -quiet -config data/config.txt");
Tool vdb_tool(args.size(), args.data());
Tool vdb_tool(int(args.size()), args.data());
vdb_tool.run();
});

Expand Down

0 comments on commit 02ddc88

Please sign in to comment.