12 #ifndef OPENVDB_TOOLS_TOPOLOGY_TO_LEVELSET_HAS_BEEN_INCLUDED
13 #define OPENVDB_TOOLS_TOPOLOGY_TO_LEVELSET_HAS_BEEN_INCLUDED
23 #include <tbb/task_group.h>
46 template<
typename Gr
idT>
47 inline typename GridT::template ValueConverter<float>::Type::Ptr
48 topologyToLevelSet(
const GridT& grid,
int halfWidth = 3,
int closingSteps = 1,
int dilation = 0,
49 int smoothingSteps = 0);
65 template<
typename Gr
idT,
typename InterrupterT>
66 inline typename GridT::template ValueConverter<float>::Type::Ptr
67 topologyToLevelSet(
const GridT& grid,
int halfWidth = 3,
int closingSteps = 1,
int dilation = 0,
68 int smoothingSteps = 0, InterrupterT* interrupt =
nullptr);
74 namespace ttls_internal {
77 template<
typename TreeT>
80 DilateOp(TreeT& t,
int n) : tree(&t), size(n) {}
89 template<
typename TreeT>
92 ErodeOp(TreeT& t,
int n) : tree(&t), size(n) {}
99 template<
typename TreeType>
106 const TreeType& rhsTree,
ValueType offset)
107 : mLhsNodes(lhsNodes.empty() ? nullptr : &lhsNodes[0]), mRhsTree(&rhsTree), mOffset(offset)
111 void operator()(
const tbb::blocked_range<size_t>& range)
const
113 using Iterator =
typename LeafNodeType::ValueOnIter;
118 for (
size_t n = range.begin(), N = range.end(); n < N; ++n) {
122 if (!rhsNodePt)
continue;
124 for (Iterator it = lhsNode.beginValueOn(); it; ++it) {
126 val =
std::min(val, offset + rhsNodePt->getValue(it.pos()));
132 LeafNodeType * *
const mLhsNodes;
133 TreeType
const *
const mRhsTree;
134 ValueType
const mOffset;
138 template<
typename Gr
idType,
typename InterrupterType>
140 normalizeLevelSet(GridType& grid,
const int halfWidthInVoxels, InterrupterType* interrupt =
nullptr)
150 template<
typename Gr
idType,
typename InterrupterType>
153 InterrupterType* interrupt =
nullptr)
155 using ValueType =
typename GridType::ValueType;
156 using TreeType =
typename GridType::TreeType;
157 using LeafNodeType =
typename TreeType::LeafNodeType;
159 GridType filterGrid(grid);
164 for (
int n = 0; n < iterations; ++n) {
165 if (interrupt && interrupt->wasInterrupted())
break;
169 std::vector<LeafNodeType*> nodes;
170 grid.tree().getNodes(nodes);
172 const ValueType offset = ValueType(
double(0.5) * grid.transform().voxelSize()[0]);
174 tbb::parallel_for(tbb::blocked_range<size_t>(0, nodes.size()),
186 template<
typename Gr
idT,
typename InterrupterT>
187 inline typename GridT::template ValueConverter<float>::Type::Ptr
189 int smoothingSteps, InterrupterT* interrupt)
191 using MaskTreeT =
typename GridT::TreeType::template ValueConverter<ValueMask>::Type;
192 using FloatTreeT =
typename GridT::TreeType::template ValueConverter<float>::Type;
198 closingSteps =
std::max(closingSteps, 0);
201 if (!grid.hasUniformVoxels()) {
214 const float background = float(grid.voxelSize()[0]) * float(halfWidth);
215 typename FloatTreeT::Ptr lsTree(
218 tbb::task_group pool;
223 lsTree->topologyDifference( maskTree );
227 typename FloatGridT::Ptr lsGrid = FloatGridT::create( lsTree );
228 lsGrid->setTransform( grid.transform().copy() );
236 if (smoothingSteps > 0) {
244 template<
typename Gr
idT>
245 inline typename GridT::template ValueConverter<float>::Type::Ptr
246 topologyToLevelSet(
const GridT& grid,
int halfWidth,
int closingSteps,
int dilation,
int smoothingSteps)
249 return topologyToLevelSet(grid, halfWidth, closingSteps, dilation, smoothingSteps, &interrupt);
Performs various types of level set deformations with interface tracking. These unrestricted deformat...
Implementation of morphological dilation and erosion.
Propagate the signs of distance values from the active voxels in the narrow band to the inactive valu...
Container class that associates a tree with a transform and metadata.
Definition: Grid.h:577
Tag dispatch class that distinguishes topology copy constructors from deep copy constructors.
Definition: openvdb/Types.h:542
Definition: openvdb/Exceptions.h:65
Definition: ValueAccessor.h:183
const LeafNodeT * probeConstLeaf(const Coord &xyz) const
Definition: ValueAccessor.h:384
@ FIRST_BIAS
Definition: FiniteDifference.h:167
@ GRID_LEVEL_SET
Definition: openvdb/Types.h:315
Definition: openvdb/Exceptions.h:13
#define OPENVDB_THROW(exception, message)
Definition: openvdb/Exceptions.h:74
Dummy NOOP interrupter class defining interface.
Definition: NullInterrupter.h:26
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:101
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:153