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 <openvdb/tools/Prune.h>
42 #include <tbb/blocked_range.h>
43 #include <tbb/parallel_reduce.h>
56 template<
typename Gr
idType>
57 inline typename GridType::ValueType lsutilGridMax()
62 template<
typename Gr
idType>
63 inline typename GridType::ValueType lsutilGridZero()
65 return zeroVal<typename GridType::ValueType>();
88 template<
class Gr
idType>
92 typename GridType::ValueType cutoffDistance = lsutilGridMax<GridType>());
107 template<
class Gr
idType>
108 inline typename Grid<typename GridType::TreeType::template ValueConverter<bool>::Type>::Ptr
110 const GridType& grid,
111 typename GridType::ValueType iso = lsutilGridZero<GridType>());
121 template<
class TreeType>
138 inline void operator()(
const tbb::blocked_range<size_t>&);
142 LeafArray& mLeafArray;
143 ValueType mMin, mMax;
153 template<
typename ValueType>
158 : mWeight(ValueType(1.0) / cutoffDistance)
163 template <
typename LeafNodeType>
166 const ValueType zero = zeroVal<ValueType>();
168 for (
typename LeafNodeType::ValueAllIter iter = leaf.beginValueAll(); iter; ++iter) {
169 ValueType& value =
const_cast<ValueType&
>(iter.getValue());
174 value =
std::min(ValueType(1.0), value * mWeight);
175 iter.setValueOn(value > zero);
185 template<
typename TreeType>
195 template <
typename LeafNodeType>
198 const Coord origin = leaf.origin();
199 const typename TreeType::LeafNodeType* refLeafPt = mTree.probeConstLeaf(origin);
201 if (refLeafPt != NULL) {
203 const typename TreeType::LeafNodeType& refLeaf = *refLeafPt;
204 typename LeafNodeType::ValueAllIter iter = leaf.beginValueAll();
206 for (; iter; ++iter) {
207 if (refLeaf.getValue(iter.pos()) < mIso) {
217 const TreeType& mTree;
218 typename TreeType::ValueType mIso;
227 template <
class TreeType>
236 template <
class TreeType>
239 : mLeafArray(rhs.mLeafArray)
246 template <
class TreeType>
250 tbb::parallel_reduce(mLeafArray.getRange(), *
this);
254 template <
class TreeType>
258 (*this)(mLeafArray.getRange());
262 template <
class TreeType>
266 typename TreeType::LeafNodeType::ValueOnCIter iter;
268 for (
size_t n = range.begin(); n < range.end(); ++n) {
269 iter = mLeafArray.leaf(n).cbeginValueOn();
270 for (; iter; ++iter) {
279 template <
class TreeType>
292 template <
class Gr
idType>
296 typedef typename GridType::TreeType TreeType;
297 typedef typename GridType::ValueType ValueType;
299 cutoffDistance = -std::abs(cutoffDistance);
301 TreeType& tree =
const_cast<TreeType&
>(grid.tree());
310 if (minmax.
minVoxel() > cutoffDistance) {
319 const ValueType zero = zeroVal<ValueType>();
320 typename TreeType::ValueAllIter iter(tree);
321 iter.setMaxDepth(TreeType::ValueAllIter::LEAF_DEPTH - 1);
323 for ( ; iter; ++iter) {
324 ValueType& value =
const_cast<ValueType&
>(iter.getValue());
330 value = ValueType(1.0);
331 iter.setActiveState(
true);
337 typename TreeType::Ptr newTree(
new TreeType(zero));
338 newTree->merge(tree);
347 grid.setTree(newTree);
356 template <
class Gr
idType>
360 typedef typename GridType::TreeType::template ValueConverter<bool>::Type BoolTreeType;
363 typename BoolGridType::Ptr maskGrid(BoolGridType::create(
false));
364 maskGrid->setTransform(grid.transform().copy());
365 BoolTreeType& maskTree = maskGrid->tree();
367 maskTree.topologyUnion(grid.tree());
380 typename BoolTreeType::ValueAllIter iter(maskTree);
381 iter.setMaxDepth(BoolTreeType::ValueAllIter::LEAF_DEPTH - 1);
383 for ( ; iter; ++iter) {
396 #endif // OPENVDB_TOOLS_LEVELSETUTIL_HAS_BEEN_INCLUDED
Definition: ValueAccessor.h:173
This class manages a linear array of pointers to a given tree's leaf nodes, as well as optional auxil...
Definition: LeafManager.h:109
void foreach(const LeafOp &op, bool threaded=true, size_t grainSize=1)
Threaded method that applies a user-supplied functor to each leaf node in the LeafManager.
Definition: LeafManager.h:476
#define OPENVDB_VERSION_NAME
Definition: version.h:43
Definition: Exceptions.h:39
OPENVDB_API Hermite min(const Hermite &, const Hermite &)
min and max operations done directly on the compressed data.
OPENVDB_API Hermite max(const Hermite &, const Hermite &)
min and max operations done directly on the compressed data.
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
Container class that associates a tree with a transform and metadata.
Definition: Grid.h:54
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:71