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);
257 #endif // OPENVDB_TOOLS_TOPOLOGY_TO_LEVELSET_HAS_BEEN_INCLUDED
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:82
Performs various types of level set deformations with interface tracking. These unrestricted deformat...
Definition: Exceptions.h:65
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:102
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:13
Dummy NOOP interrupter class defining interface.
Definition: NullInterrupter.h:25
Tag dispatch class that distinguishes topology copy constructors from deep copy constructors.
Definition: Types.h:681
Container class that associates a tree with a transform and metadata.
Definition: Grid.h:28
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:395
Definition: FiniteDifference.h:167
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:154