39 #ifndef OPENVDB_TOOLS_TOPOLOGY_TO_LEVELSET_HAS_BEEN_INCLUDED 40 #define OPENVDB_TOOLS_TOPOLOGY_TO_LEVELSET_HAS_BEEN_INCLUDED 50 #include <tbb/task_group.h> 73 template<
typename Gr
idT>
74 inline typename GridT::template ValueConverter<float>::Type::Ptr
75 topologyToLevelSet(
const GridT& grid,
int halfWidth = 3,
int closingSteps = 1,
int dilation = 0,
76 int smoothingSteps = 0);
92 template<
typename Gr
idT,
typename InterrupterT>
93 inline typename GridT::template ValueConverter<float>::Type::Ptr
94 topologyToLevelSet(
const GridT& grid,
int halfWidth = 3,
int closingSteps = 1,
int dilation = 0,
95 int smoothingSteps = 0, InterrupterT* interrupt =
nullptr);
101 namespace ttls_internal {
104 template<
typename TreeT>
116 template<
typename TreeT>
119 ErodeOp(TreeT& t,
int n) : tree(&t), size(n) {}
126 template<
typename TreeType>
133 const TreeType& rhsTree,
ValueType offset)
134 : mLhsNodes(lhsNodes.empty() ? nullptr : &lhsNodes[0]), mRhsTree(&rhsTree), mOffset(offset)
138 void operator()(
const tbb::blocked_range<size_t>& range)
const 140 using Iterator =
typename LeafNodeType::ValueOnIter;
145 for (
size_t n = range.begin(), N = range.end(); n < N; ++n) {
149 if (!rhsNodePt)
continue;
151 for (Iterator it = lhsNode.beginValueOn(); it; ++it) {
153 val =
std::min(val, offset + rhsNodePt->getValue(it.pos()));
160 TreeType
const *
const mRhsTree;
165 template<
typename Gr
idType,
typename InterrupterType>
167 normalizeLevelSet(GridType& grid,
const int halfWidthInVoxels, InterrupterType* interrupt =
nullptr)
177 template<
typename Gr
idType,
typename InterrupterType>
180 InterrupterType* interrupt =
nullptr)
182 using ValueType =
typename GridType::ValueType;
183 using TreeType =
typename GridType::TreeType;
184 using LeafNodeType =
typename TreeType::LeafNodeType;
186 GridType filterGrid(grid);
191 for (
int n = 0; n < iterations; ++n) {
192 if (interrupt && interrupt->wasInterrupted())
break;
196 std::vector<LeafNodeType*> nodes;
197 grid.tree().getNodes(nodes);
199 const ValueType offset = ValueType(
double(0.5) * grid.transform().voxelSize()[0]);
201 tbb::parallel_for(tbb::blocked_range<size_t>(0, nodes.size()),
213 template<
typename Gr
idT,
typename InterrupterT>
214 inline typename GridT::template ValueConverter<float>::Type::Ptr
216 int smoothingSteps, InterrupterT* interrupt)
218 using MaskTreeT =
typename GridT::TreeType::template ValueConverter<ValueMask>::Type;
219 using FloatTreeT =
typename GridT::TreeType::template ValueConverter<float>::Type;
225 closingSteps =
std::max(closingSteps, 0);
228 if (!grid.hasUniformVoxels()) {
241 const float background = float(grid.voxelSize()[0]) *
float(halfWidth);
242 typename FloatTreeT::Ptr lsTree(
245 tbb::task_group pool;
250 lsTree->topologyDifference( maskTree );
254 typename FloatGridT::Ptr lsGrid = FloatGridT::create( lsTree );
255 lsGrid->setTransform( grid.transform().copy() );
263 if (smoothingSteps > 0) {
271 template<
typename Gr
idT>
272 inline typename GridT::template ValueConverter<float>::Type::Ptr
273 topologyToLevelSet(
const GridT& grid,
int halfWidth,
int closingSteps,
int dilation,
int smoothingSteps)
276 return topologyToLevelSet(grid, halfWidth, closingSteps, dilation, smoothingSteps, &interrupt);
284 #endif // OPENVDB_TOOLS_TOPOLOGY_TO_LEVELSET_HAS_BEEN_INCLUDED
const LeafNodeT * probeConstLeaf(const Coord &xyz) const
Return a pointer to the leaf node that contains voxel (x, y, z), or nullptr if no such node exists...
Definition: ValueAccessor.h:422
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:109
Container class that associates a tree with a transform and metadata.
Definition: Grid.h:55
Definition: FiniteDifference.h:194
Tag dispatch class that distinguishes topology copy constructors from deep copy constructors.
Definition: Types.h:750
Performs various types of level set deformations with interface tracking. These unrestricted deformat...
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:128
Propagate the signs of distance values from the active voxels in the narrow band to the inactive valu...
Implementation of morphological dilation and erosion.
Definition: Exceptions.h:40
Dummy NOOP interrupter class defining interface.
Definition: NullInterrupter.h:52
Definition: Exceptions.h:92
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:180