-
Notifications
You must be signed in to change notification settings - Fork 765
added vdb option to -soup2ls action and improved error handeling #2266
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kmuseth
wants to merge
1
commit into
AcademySoftwareFoundation:master
Choose a base branch
from
kmuseth:improve_shrinkwrap
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+70
−4
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -756,6 +756,7 @@ void Tool::init() | |
| {"geo", "0", "0", "age (i.e. stack index) of the geometry to be processed. Defaults to 0, i.e. most recently inserted geometry."}, | ||
| {"erode", "8", "2", "number of iterations of constrained erosion. Defaults to 8."}, | ||
| {"thres", "0", "0.01", "closing (or engineering) threshold. Defaults to 0, i.e. it\'s diabled."}, | ||
| {"vdb", "0", "0|0,1,2|*", "selects which of the level-set grids generated by the hierarchical shrink-wrap algorithm to output, by resolution level: 0 is the finest (highest-resolution) grid, 1 the next-finest, and so on. Accepts a single index (default 0, i.e. only the finest grid), a comma-separated list (e.g. \"0,1,2\" outputs the three finest grids), or \"*\" to output every generated grid. A runtime error is thrown if a requested level does not exist. Note: unlike other actions, here \"vdb\" selects outputs (not inputs)."}, | ||
| {"keep", "", "1|0|true|false", "toggle wether the input geometry is preserved or deleted after the conversion"}, | ||
| {"name", "", "soup2ls_input", "specify the name of the resulting vdb (by default it's derived from the input geometry)"}}, | ||
| [&](){mParser.setDefaults();}, [&](){this->soupToLevelSet();}); | ||
|
|
@@ -2180,6 +2181,9 @@ void Tool::soupToLevelSet() | |
| const float thres = mParser.get<float>("thres"); | ||
| const bool keep = mParser.get<bool>("keep"); | ||
| std::string grid_name = mParser.get<std::string>("name"); | ||
| // Output selector (NB: selects outputs, not inputs): "*" for all generated | ||
| // grids, otherwise a list of resolution levels (0 = finest). Defaults to "0". | ||
| const std::string vdb_sel = mParser.get<std::string>("vdb"); | ||
|
|
||
| auto it = this->getGeom(geo_age); | ||
| Geometry::Ptr mesh = *it; | ||
|
|
@@ -2193,13 +2197,48 @@ void Tool::soupToLevelSet() | |
| Spinner spin, *progress = mParser.verbose ? &spin : nullptr; | ||
| const tools::ShrinkWrapLimit D(nErode, thres); | ||
| tools::PolySoup poly{std::move(mesh->vtx()), std::move(mesh->tri()), std::move(mesh->quad()), mesh->bbox()}; | ||
| auto grid = tools::polySoupToLevelSet<GridT>(std::move(poly), dim, voxel, D, width, progress, offset_mode); | ||
|
|
||
| // Build the LOD hierarchy directly (rather than the single-grid free function) | ||
| // so we can output more than just the finest level. grids() is ordered | ||
| // finest(0) -> coarsest(size-1), matching the "vdb" level indices below. | ||
| using SW = tools::PolySoupToLevelSet<GridT>; | ||
| auto sw = voxel > 0.0f ? std::make_unique<SW>(std::move(poly), voxel, width) | ||
| : std::make_unique<SW>(std::move(poly), dim, width); | ||
| sw->process(D, progress, offset_mode); | ||
|
|
||
| if (mParser.verbose) mTimer.stop(); | ||
|
|
||
| const std::vector<GridT::Ptr> grids = sw->grids();// finest(0) -> coarsest | ||
| const int count = static_cast<int>(grids.size()); | ||
|
|
||
| // Resolve the selector into a list of level indices. "*" -> every level. | ||
| std::vector<int> levels; | ||
| if (vdb_sel == "*") { | ||
| for (int i = 0; i < count; ++i) levels.push_back(i); | ||
| } else { | ||
| levels = mParser.getVec<int>("vdb"); | ||
| if (levels.empty()) levels.push_back(0); | ||
| } | ||
|
|
||
| // Validate every requested level BEFORE pushing any grid, so an out-of-range | ||
| // index produces a clean error with no partial output on the stack. | ||
| for (const int lvl : levels) { | ||
| if (lvl < 0 || lvl >= count) { | ||
| throw std::invalid_argument("soup2ls: requested output grid vdb=" + std::to_string(lvl) + | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 suggestion: Use |
||
| " does not exist; the shrink-wrap hierarchy generated " + std::to_string(count) + | ||
| " grid(s), so valid levels are 0 (finest) .. " + std::to_string(count - 1) + " (coarsest)"); | ||
| } | ||
| } | ||
|
|
||
| if (grid_name.empty()) grid_name = "soup2ls_" + mesh->getName(); | ||
| grid->setName(grid_name); | ||
| mGrid.push_back(grid); | ||
| const bool multi = levels.size() > 1; | ||
| for (const int lvl : levels) { | ||
| GridT::Ptr g = grids[lvl]; | ||
| // Disambiguate names only when several grids are output; a single output | ||
| // keeps the plain name (preserving the historical vdb=0 behavior). | ||
| g->setName(multi ? grid_name + "_" + std::to_string(lvl) : grid_name); | ||
| mGrid.push_back(g); | ||
| } | ||
| if (!keep) mGeom.erase(std::next(it).base()); | ||
| }// Tool::soupToLevelSet | ||
| #endif// VDB_TOOL_USE_SHRINKWRAP | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
☑️ todo: We should have a test for this case now that it's fixed.