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) {}
102 template<
typename TreeType>
109 const TreeType& rhsTree,
ValueType offset)
110 : mLhsNodes(lhsNodes.empty() ? nullptr : &lhsNodes[0]), mRhsTree(&rhsTree), mOffset(offset)
114 void operator()(
const tbb::blocked_range<size_t>& range)
const
116 using Iterator =
typename LeafNodeType::ValueOnIter;
121 for (
size_t n = range.begin(), N = range.end(); n < N; ++n) {
125 if (!rhsNodePt)
continue;
127 for (Iterator it = lhsNode.beginValueOn(); it; ++it) {
129 val =
std::min(val, offset + rhsNodePt->getValue(it.pos()));
135 LeafNodeType * *
const mLhsNodes;
136 TreeType
const *
const mRhsTree;
137 ValueType
const mOffset;
141 template<
typename Gr
idType,
typename InterrupterType>
143 normalizeLevelSet(GridType& grid,
const int halfWidthInVoxels, InterrupterType* interrupt =
nullptr)
153 template<
typename Gr
idType,
typename InterrupterType>
156 InterrupterType* interrupt =
nullptr)
158 using ValueType =
typename GridType::ValueType;
159 using TreeType =
typename GridType::TreeType;
160 using LeafNodeType =
typename TreeType::LeafNodeType;
162 GridType filterGrid(grid);
167 for (
int n = 0; n < iterations; ++n) {
168 if (interrupt && interrupt->wasInterrupted())
break;
172 std::vector<LeafNodeType*> nodes;
173 grid.tree().getNodes(nodes);
175 const ValueType offset = ValueType(
double(0.5) * grid.transform().voxelSize()[0]);
177 tbb::parallel_for(tbb::blocked_range<size_t>(0, nodes.size()),
189 template<
typename Gr
idT,
typename InterrupterT>
190 inline typename GridT::template ValueConverter<float>::Type::Ptr
192 int smoothingSteps, InterrupterT* interrupt)
194 using MaskTreeT =
typename GridT::TreeType::template ValueConverter<ValueMask>::Type;
195 using FloatTreeT =
typename GridT::TreeType::template ValueConverter<float>::Type;
201 closingSteps =
std::max(closingSteps, 0);
204 if (!grid.hasUniformVoxels()) {
218 const float background = float(grid.voxelSize()[0]) * float(halfWidth);
219 typename FloatTreeT::Ptr lsTree(
222 tbb::task_group pool;
227 lsTree->topologyDifference( maskTree );
231 typename FloatGridT::Ptr lsGrid = FloatGridT::create( lsTree );
232 lsGrid->setTransform( grid.transform().copy() );
240 if (smoothingSteps > 0) {
248 template<
typename Gr
idT>
249 inline typename GridT::template ValueConverter<float>::Type::Ptr
250 topologyToLevelSet(
const GridT& grid,
int halfWidth,
int closingSteps,
int dilation,
int smoothingSteps)
253 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:560
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:333
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.in:116
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h.in:178