36 #ifndef OPENVDB_TOOLS_LEVELSETUTIL_HAS_BEEN_INCLUDED
37 #define OPENVDB_TOOLS_LEVELSETUTIL_HAS_BEEN_INCLUDED
39 #include <openvdb/Grid.h>
40 #include <openvdb/tree/LeafManager.h>
41 #include <tbb/blocked_range.h>
42 #include <tbb/parallel_reduce.h>
55 template<
typename Gr
idType>
56 inline typename GridType::ValueType lsutilGridMax()
61 template<
typename Gr
idType>
62 inline typename GridType::ValueType lsutilGridZero()
64 return zeroVal<typename GridType::ValueType>();
87 template<
class Gr
idType>
91 typename GridType::ValueType cutoffDistance = lsutilGridMax<GridType>());
106 template<
class Gr
idType>
107 inline typename Grid<typename GridType::TreeType::template ValueConverter<bool>::Type>::Ptr
109 const GridType& grid,
110 typename GridType::ValueType iso = lsutilGridZero<GridType>());
120 template<
class TreeType>
137 inline void operator()(
const tbb::blocked_range<size_t>&);
141 LeafArray& mLeafArray;
142 ValueType mMin, mMax;
152 template<
typename ValueType>
157 : mWeight(ValueType(1.0) / cutoffDistance)
162 template <
typename LeafNodeType>
165 const ValueType zero = zeroVal<ValueType>();
167 for (
typename LeafNodeType::ValueAllIter iter = leaf.beginValueAll(); iter; ++iter) {
168 ValueType& value =
const_cast<ValueType&
>(iter.getValue());
173 value =
std::min(ValueType(1.0), value * mWeight);
174 iter.setValueOn(value > zero);
184 template<
typename TreeType>
194 template <
typename LeafNodeType>
197 const Coord origin = leaf.origin();
198 const typename TreeType::LeafNodeType* refLeafPt = mTree.probeConstLeaf(origin);
200 if (refLeafPt != NULL) {
202 const typename TreeType::LeafNodeType& refLeaf = *refLeafPt;
203 typename LeafNodeType::ValueAllIter iter = leaf.beginValueAll();
205 for (; iter; ++iter) {
206 if (refLeaf.getValue(iter.pos()) < mIso) {
216 const TreeType& mTree;
217 typename TreeType::ValueType mIso;
226 template <
class TreeType>
235 template <
class TreeType>
238 : mLeafArray(rhs.mLeafArray)
245 template <
class TreeType>
249 tbb::parallel_reduce(mLeafArray.getRange(), *
this);
253 template <
class TreeType>
257 (*this)(mLeafArray.getRange());
261 template <
class TreeType>
265 typename TreeType::LeafNodeType::ValueOnCIter iter;
267 for (
size_t n = range.begin(); n < range.end(); ++n) {
268 iter = mLeafArray.leaf(n).cbeginValueOn();
269 for (; iter; ++iter) {
278 template <
class TreeType>
291 template <
class Gr
idType>
295 typedef typename GridType::TreeType TreeType;
296 typedef typename GridType::ValueType ValueType;
298 cutoffDistance = -std::abs(cutoffDistance);
300 TreeType& tree =
const_cast<TreeType&
>(grid.tree());
309 if (minmax.
minVoxel() > cutoffDistance) {
318 const ValueType zero = zeroVal<ValueType>();
319 typename TreeType::ValueAllIter iter(tree);
320 iter.setMaxDepth(TreeType::ValueAllIter::LEAF_DEPTH - 1);
322 for ( ; iter; ++iter) {
323 ValueType& value =
const_cast<ValueType&
>(iter.getValue());
329 value = ValueType(1.0);
330 iter.setActiveState(
true);
336 typename TreeType::Ptr newTree(
new TreeType(zero));
337 newTree->merge(tree);
346 grid.setTree(newTree);
355 template <
class Gr
idType>
359 typedef typename GridType::TreeType::template ValueConverter<bool>::Type BoolTreeType;
362 typename BoolGridType::Ptr maskGrid(BoolGridType::create(
false));
363 maskGrid->setTransform(grid.transform().copy());
364 BoolTreeType& maskTree = maskGrid->tree();
366 maskTree.topologyUnion(grid.tree());
379 typename BoolTreeType::ValueAllIter iter(maskTree);
380 iter.setMaxDepth(BoolTreeType::ValueAllIter::LEAF_DEPTH - 1);
382 for ( ; iter; ++iter) {
386 maskTree.pruneInactive();
395 #endif // OPENVDB_TOOLS_LEVELSETUTIL_HAS_BEEN_INCLUDED
OPENVDB_API Hermite max(const Hermite &, const Hermite &)
min and max operations done directly on the compressed data.
void foreach(const LeafOp &op, bool threaded=true)
Threaded method that applies a user-supplied functor to each leaf node in the LeafManager.
Definition: LeafManager.h:461
void setActiveState(const Coord &xyz, bool on=true)
Set the active state of the voxel at the given coordinates but don't change its value.
Definition: ValueAccessor.h:291
#define OPENVDB_VERSION_NAME
Definition: version.h:45
OPENVDB_API Hermite min(const Hermite &, const Hermite &)
min and max operations done directly on the compressed data.
Definition: ValueAccessor.h:173
Container class that associates a tree with a transform and metadata.
Definition: Grid.h:54
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:56
This class manages a linear array of pointers to a given tree's leaf nodes, as well as optional auxil...
Definition: LeafManager.h:109