12 #ifndef OPENVDB_TOOLS_TOPOLOGY_TO_LEVELSET_HAS_BEEN_INCLUDED
13 #define OPENVDB_TOOLS_TOPOLOGY_TO_LEVELSET_HAS_BEEN_INCLUDED
25 #include <tbb/task_group.h>
49 template<
typename Gr
idT>
50 typename GridT::template ValueConverter<float>::Type::Ptr
55 int smoothingSteps = 0);
71 template<
typename Gr
idT,
typename InterrupterT>
72 typename GridT::template ValueConverter<float>::Type::Ptr
77 int smoothingSteps = 0,
78 InterrupterT* interrupt =
nullptr);
85 namespace ttls_internal {
88 template<
typename TreeType>
89 struct OffsetAndMinComp
91 using LeafNodeType =
typename TreeType::LeafNodeType;
94 OffsetAndMinComp(std::vector<LeafNodeType*>& lhsNodes,
95 const TreeType& rhsTree,
101 void operator()(
const tbb::blocked_range<size_t>&
range)
const
103 using Iterator =
typename LeafNodeType::ValueOnIter;
105 tree::ValueAccessor<const TreeType> rhsAcc(mRhsTree);
108 for (
size_t n = range.begin(),
N = range.
end();
n <
N; ++
n) {
110 LeafNodeType& lhsNode = *mLhsNodes[
n];
111 const LeafNodeType* rhsNodePt = rhsAcc.probeConstLeaf(lhsNode.origin());
112 if (!rhsNodePt)
continue;
114 auto*
const data = lhsNode.buffer().data();
115 for (Iterator it = lhsNode.beginValueOn(); it; ++it) {
117 val =
std::min(val, offset + rhsNodePt->getValue(it.pos()));
123 std::vector<LeafNodeType*>& mLhsNodes;
124 const TreeType& mRhsTree;
129 template<
typename Gr
idType,
typename InterrupterType>
131 normalizeLevelSet(
GridType& grid,
const int halfWidthInVoxels, InterrupterType* interrupt =
nullptr)
133 LevelSetFilter<GridType, GridType, InterrupterType>
filter(grid, interrupt);
135 filter.setNormCount(halfWidthInVoxels);
141 template<
typename Gr
idType,
typename InterrupterType>
143 smoothLevelSet(
GridType& grid,
int iterations,
int halfBandWidthInVoxels,
144 InterrupterType* interrupt =
nullptr)
147 using TreeType =
typename GridType::TreeType;
148 using LeafNodeType =
typename TreeType::LeafNodeType;
152 LevelSetFilter<GridType, GridType, InterrupterType>
filter(filterGrid, interrupt);
155 for (
int n = 0;
n < iterations; ++
n) {
156 if (interrupt && interrupt->wasInterrupted())
break;
160 std::vector<LeafNodeType*> nodes;
161 grid.tree().getNodes(nodes);
166 OffsetAndMinComp<TreeType>(nodes, filterGrid.tree(), -
offset));
169 normalizeLevelSet(grid, halfBandWidthInVoxels, interrupt);
176 template<
typename Gr
idT,
typename InterrupterT>
177 typename GridT::template ValueConverter<float>::Type::Ptr
179 int smoothingSteps, InterrupterT* interrupt)
188 closingSteps =
std::max(closingSteps, 0);
191 if (!grid.hasUniformVoxels()) {
192 OPENVDB_THROW(ValueError,
"Non-uniform voxels are not supported!");
196 MaskTreeT maskTree(grid.tree(),
false, openvdb::TopologyCopy());
205 const float background =
float(grid.voxelSize()[0]) *
float(halfWidth);
206 typename FloatTreeT::Ptr lsTree(
207 new FloatTreeT(maskTree, background, -background, openvdb::TopologyCopy()));
209 tbb::task_group
pool;
219 lsTree->topologyDifference(maskTree);
222 lsTree->voxelizeActiveTiles();
226 typename FloatGridT::Ptr lsGrid = FloatGridT::create(lsTree);
227 lsGrid->setTransform(grid.transform().copy());
232 ttls_internal::normalizeLevelSet(*lsGrid, 3*halfWidth, interrupt);
235 if (smoothingSteps > 0) {
236 ttls_internal::smoothLevelSet(*lsGrid, smoothingSteps, halfWidth, interrupt);
243 template<
typename Gr
idT>
244 typename GridT::template ValueConverter<float>::Type::Ptr
245 topologyToLevelSet(
const GridT& grid,
int halfWidth,
int closingSteps,
int dilation,
int smoothingSteps)
248 return topologyToLevelSet(grid, halfWidth, closingSteps, dilation, smoothingSteps, &interrupt);
257 #ifdef OPENVDB_USE_EXPLICIT_INSTANTIATION
259 #ifdef OPENVDB_INSTANTIATE_TOPOLOGYTOLEVELSET
263 #define _FUNCTION(TreeT) \
264 Grid<TreeT>::ValueConverter<float>::Type::Ptr topologyToLevelSet(const Grid<TreeT>&, int, int, int, int, \
265 util::NullInterrupter*)
269 #endif // OPENVDB_USE_EXPLICIT_INSTANTIATION
276 #endif // OPENVDB_TOOLS_TOPOLOGY_TO_LEVELSET_HAS_BEEN_INCLUDED
void parallel_for(int64_t start, int64_t end, std::function< void(int64_t index)> &&task, parallel_options opt=parallel_options(0, Split_Y, 1))
GridType
List of types that are currently supported by NanoVDB.
#define OPENVDB_USE_VERSION_NAMESPACE
ImageBuf OIIO_API min(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
Base class for interrupters.
#define OPENVDB_ALL_TREE_INSTANTIATE(Function)
SYS_FORCE_INLINE const_iterator end() const
IMATH_NAMESPACE::V2f float
Container class that associates a tree with a transform and metadata.
ImageBuf OIIO_API max(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
GA_API const UT_StringHolder N
Implementation of morphological dilation and erosion.
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.
Attribute-owned data structure for points. Point attributes are stored in leaf nodes and ordered by v...
#define OPENVDB_THROW(exception, message)
**Note that the tasks the is the thread number *for the pool
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter