| 1749 | // ============================================================================================================== |
| 1750 | |
| 1751 | void 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 |
no test coverage detected