39 #ifndef OPENVDB_TOOLS_TOPOLOGY_TO_LEVELSET_HAS_BEEN_INCLUDED 40 #define OPENVDB_TOOLS_TOPOLOGY_TO_LEVELSET_HAS_BEEN_INCLUDED 46 #include <openvdb/Grid.h> 47 #include <openvdb/Types.h> 48 #include <openvdb/math/FiniteDifference.h> 49 #include <openvdb/util/NullInterrupter.h> 51 #include <tbb/task_group.h> 72 template<
typename Gr
idT>
73 inline typename GridT::template ValueConverter<float>::Type::Ptr
74 topologyToLevelSet(
const GridT& grid,
int halfWidth = 3,
int closingSteps = 1,
int dilation = 0,
75 int smoothingSteps = 0);
91 template<
typename Gr
idT,
typename InterrupterT>
92 inline typename GridT::template ValueConverter<float>::Type::Ptr
93 topologyToLevelSet(
const GridT& grid,
int halfWidth = 3,
int closingSteps = 1,
int dilation = 0,
94 int smoothingSteps = 0, InterrupterT* interrupt = NULL);
100 namespace ttls_internal {
103 template<
typename TreeT>
115 template<
typename TreeT>
118 ErodeOp(TreeT& t,
int n) : tree(&t), size(n) {}
125 template<
typename TreeType>
131 OffsetAndMinComp(std::vector<LeafNodeType*>& lhsNodes,
const TreeType& rhsTree, ValueType offset)
132 : mLhsNodes(lhsNodes.empty() ? NULL : &lhsNodes[0]), mRhsTree(&rhsTree), mOffset(offset)
136 void operator()(
const tbb::blocked_range<size_t>& range)
const 138 typedef typename LeafNodeType::ValueOnIter Iterator;
141 const ValueType offset = mOffset;
143 for (
size_t n = range.begin(), N = range.end(); n < N; ++n) {
145 LeafNodeType& lhsNode = *mLhsNodes[n];
146 const LeafNodeType * rhsNodePt = rhsAcc.
probeConstLeaf(lhsNode.origin());
147 if (!rhsNodePt)
continue;
149 for (Iterator it = lhsNode.beginValueOn(); it; ++it) {
150 ValueType& val =
const_cast<ValueType&
>(it.getValue());
151 val =
std::min(val, offset + rhsNodePt->getValue(it.pos()));
157 LeafNodeType * *
const mLhsNodes;
158 TreeType
const *
const mRhsTree;
159 ValueType
const mOffset;
163 template<
typename Gr
idType,
typename InterrupterType>
165 normalizeLevelSet(GridType& grid,
const int halfWidthInVoxels, InterrupterType* interrupt = NULL)
175 template<
typename Gr
idType,
typename InterrupterType>
177 smoothLevelSet(GridType& grid,
int iterations,
int halfBandWidthInVoxels, InterrupterType* interrupt = NULL)
179 typedef typename GridType::ValueType ValueType;
180 typedef typename GridType::TreeType TreeType;
181 typedef typename TreeType::LeafNodeType LeafNodeType;
183 GridType filterGrid(grid);
188 for (
int n = 0; n < iterations; ++n) {
189 if (interrupt && interrupt->wasInterrupted())
break;
193 std::vector<LeafNodeType*> nodes;
194 grid.tree().getNodes(nodes);
196 const ValueType offset = ValueType(
double(0.5) * grid.transform().voxelSize()[0]);
198 tbb::parallel_for(tbb::blocked_range<size_t>(0, nodes.size()),
210 template<
typename Gr
idT,
typename InterrupterT>
211 inline typename GridT::template ValueConverter<float>::Type::Ptr
213 int smoothingSteps, InterrupterT* interrupt)
215 typedef typename GridT::TreeType::template ValueConverter<ValueMask>::Type MaskTreeT;
216 typedef typename GridT::TreeType::template ValueConverter<float>::Type FloatTreeT;
222 closingSteps =
std::max(closingSteps, 0);
225 if ( !grid.hasUniformVoxels() ) {
238 const float background = float(grid.voxelSize()[0]) *
float(halfWidth);
239 typename FloatTreeT::Ptr lsTree(
242 tbb::task_group pool;
247 lsTree->topologyDifference( maskTree );
251 typename FloatGridT::Ptr lsGrid = FloatGridT::create( lsTree );
252 lsGrid->setTransform( grid.transform().copy() );
260 if (smoothingSteps > 0) {
268 template<
typename Gr
idT>
269 inline typename GridT::template ValueConverter<float>::Type::Ptr
270 topologyToLevelSet(
const GridT& grid,
int halfWidth,
int closingSteps,
int dilation,
int smoothingSteps)
273 return topologyToLevelSet(grid, halfWidth, closingSteps, dilation, smoothingSteps, &interrupt);
281 #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:430
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:109
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:136
Definition: Exceptions.h:92
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
Definition: FiniteDifference.h:194
Container class that associates a tree with a transform and metadata.
Definition: Grid.h:55
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:188
Tag dispatch class that distinguishes topology copy constructors from deep copy constructors.
Definition: Types.h:518
Dummy NOOP interrupter class defining interface.
Definition: NullInterrupter.h:52