MCPcopy Create free account
hub / github.com/AcademySoftwareFoundation/openvdb / offsetLevelSet

Method offsetLevelSet

openvdb_cmd/vdb_tool/include/Tool.h:1751–1790  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1749// ==============================================================================================================
1750
1751void Tool::offsetLevelSet()
1752{
1753 const std::string &name = mParser.getAction().name;
1754 OPENVDB_ASSERT(findMatch(name, {"dilate", "erode", "open", "close"}));
1755 try {
1756 mParser.printAction();
1757 float radius = mParser.get<float>("radius");
1758 const int space = mParser.get<int>("space");
1759 const int time = mParser.get<int>("time");
1760 const int age = mParser.get<int>("vdb");
1761 if (radius<0) throw std::invalid_argument("offsetLevelSet: invalid radius");
1762 if (radius==0) return;
1763 auto it = this->getGrid(age);
1764 GridT::Ptr grid = gridPtrCast<GridT>(*it);
1765 if (!grid || grid->getGridClass() != GRID_LEVEL_SET) throw std::invalid_argument("offsetLevelSet: no level set with age "+std::to_string(age));
1766 auto filter = this->createFilter(*grid, space, time);
1767 radius *= static_cast<float>((*it)->voxelSize()[0]);// voxel to world units
1768 if (name == "dilate") {
1769 if (mParser.verbose) mTimer.start("Dilate SDF");
1770 filter->offset(-radius);
1771 } else if (name == "erode") {
1772 if (mParser.verbose) mTimer.start("Erode SDF");
1773 filter->offset( radius);
1774 } else if (name == "open") {
1775 if (mParser.verbose) mTimer.start("Open SDF");
1776 filter->offset( radius);
1777 filter->offset(-radius);
1778 } else if (name == "close") {
1779 if (mParser.verbose) mTimer.start("Close SDF");
1780 filter->offset(-radius);
1781 filter->offset( radius);
1782 } else {
1783 throw std::invalid_argument("offsetLevelSet: invalid operation type");
1784 }
1785 grid->setName(name + "_" + grid->getName());
1786 if (mParser.verbose) mTimer.stop();
1787 } catch (const std::exception& e) {
1788 throw std::invalid_argument(name+": "+e.what());
1789 }
1790}// Tool::offsetLevelSet
1791
1792// ==============================================================================================================
1793

Callers 1

initMethod · 0.95

Calls 11

getGridMethod · 0.95
createFilterMethod · 0.95
findMatchFunction · 0.85
printActionMethod · 0.80
getGridClassMethod · 0.45
voxelSizeMethod · 0.45
startMethod · 0.45
offsetMethod · 0.45
setNameMethod · 0.45
getNameMethod · 0.45
stopMethod · 0.45

Tested by

no test coverage detected