42 #ifndef OPENVDB_TOOLS_LEVELSETFILTER_HAS_BEEN_INCLUDED 43 #define OPENVDB_TOOLS_LEVELSETFILTER_HAS_BEEN_INCLUDED 46 #include <boost/type_traits/is_floating_point.hpp> 61 template<
typename GridT,
62 typename MaskT =
typename GridT::template ValueConverter<float>::Type,
63 typename InterruptT = util::NullInterrupter>
73 BOOST_STATIC_ASSERT(boost::is_floating_point<AlphaType>::value);
79 : BaseType(grid, interrupt)
90 AlphaType
minMask()
const {
return mMinMask; }
93 AlphaType
maxMask()
const {
return mMaxMask; }
119 Filter f(
this, mask); f.meanCurvature();
126 Filter f(
this, mask); f.laplacian();
135 void gaussian(
int width = 1,
const MaskType* mask =
nullptr)
137 Filter f(
this, mask); f.gaussian(width);
143 void offset(ValueType offset,
const MaskType* mask =
nullptr)
145 Filter f(
this, mask); f.offset(offset);
154 void median(
int width = 1,
const MaskType* mask =
nullptr)
156 Filter f(
this, mask); f.median(width);
164 void mean(
int width = 1,
const MaskType* mask =
nullptr)
166 Filter f(
this, mask); f.mean(width);
177 typedef typename TreeType::LeafNodeType LeafT;
178 typedef typename LeafT::ValueOnIter VoxelIterT;
179 typedef typename LeafT::ValueOnCIter VoxelCIterT;
185 Filter(
LevelSetFilter* parent,
const MaskType* mask) : mParent(parent), mMask(mask) {}
186 Filter(
const Filter&) =
default;
190 void median(
int width);
191 void mean(
int width);
192 void gaussian(
int width);
195 void offset(ValueType value);
196 void operator()(
const LeafRange& r)
const 198 if (mTask) mTask(const_cast<Filter*>(
this), r);
203 const int n = mParent->getGrainSize();
205 tbb::parallel_for(mParent->leafs().leafRange(n), *
this);
207 (*this)(mParent->leafs().leafRange());
209 if (swap) mParent->leafs().swapLeafBuffer(1, n==0);
212 template <
size_t Axis>
215 acc(grid.tree()), width(w), frac(1/ValueType(2*w+1)) {}
218 ValueType sum = zeroVal<ValueType>();
220 for (i -= width; i <= j; ++
i) sum += acc.getValue(xyz);
223 typename GridT::ConstAccessor
acc;
228 template <
typename AvgT>
229 void box(
const LeafRange& r,
Int32 w);
231 void boxX(
const LeafRange& r,
Int32 w) { this->box<Avg<0> >(r,w); }
232 void boxZ(
const LeafRange& r,
Int32 w) { this->box<Avg<1> >(r,w); }
233 void boxY(
const LeafRange& r,
Int32 w) { this->box<Avg<2> >(r,w); }
235 void median(
const LeafRange&,
int);
238 void offset(
const LeafRange&, ValueType);
241 const MaskType* mMask;
242 typename boost::function<void (Filter*, const LeafRange&)> mTask;
245 AlphaType mMinMask, mMaxMask;
253 template<
typename Gr
idT,
typename MaskT,
typename InterruptT>
260 mParent->leafs().rebuildAuxBuffers(1, mParent->getGrainSize()==0);
262 mTask = boost::bind(&Filter::median, _1, _2,
std::max(1, width));
267 mParent->endInterrupter();
270 template<
typename Gr
idT,
typename MaskT,
typename InterruptT>
279 mParent->endInterrupter();
282 template<
typename Gr
idT,
typename MaskT,
typename InterruptT>
289 for (
int n=0; n<4; ++n) this->box(width);
291 mParent->endInterrupter();
294 template<
typename Gr
idT,
typename MaskT,
typename InterruptT>
303 mTask = boost::bind(&Filter::boxX, _1, _2, width);
306 mTask = boost::bind(&Filter::boxY, _1, _2, width);
309 mTask = boost::bind(&Filter::boxZ, _1, _2, width);
315 template<
typename Gr
idT,
typename MaskT,
typename InterruptT>
320 mParent->startInterrupter(
"Mean-curvature flow of level set");
322 mParent->leafs().rebuildAuxBuffers(1, mParent->getGrainSize()==0);
329 mParent->endInterrupter();
332 template<
typename Gr
idT,
typename MaskT,
typename InterruptT>
337 mParent->startInterrupter(
"Laplacian flow of level set");
339 mParent->leafs().rebuildAuxBuffers(1, mParent->getGrainSize()==0);
346 mParent->endInterrupter();
349 template<
typename Gr
idT,
typename MaskT,
typename InterruptT>
356 mParent->leafs().removeAuxBuffers();
360 while (offset-dist >
ValueType(0.001)*CFL && mParent->checkInterrupter()) {
364 mTask = boost::bind(&Filter::offset, _1, _2, copysign(delta, value));
370 mParent->endInterrupter();
377 template<
typename Gr
idT,
typename MaskT,
typename InterruptT>
382 mParent->checkInterrupter();
388 AlphaMaskT alpha(mParent->grid(), *mMask, mParent->minMask(),
389 mParent->maxMask(), mParent->isMaskInverted());
391 ValueType* buffer = leafIter.buffer(1).data();
392 for (VoxelCIterT iter = leafIter->cbeginValueOn(); iter; ++iter) {
393 if (alpha(iter.getCoord(), a, b)) {
394 stencil.moveTo(iter);
395 const ValueType phi0 = *iter, phi1 = phi0 + dt*stencil.meanCurvatureNormGrad();
396 buffer[iter.pos()] = b * phi0 + a * phi1;
402 ValueType* buffer = leafIter.buffer(1).data();
403 for (VoxelCIterT iter = leafIter->cbeginValueOn(); iter; ++iter) {
404 stencil.moveTo(iter);
405 buffer[iter.pos()] = *iter + dt*stencil.meanCurvatureNormGrad();
418 template<
typename Gr
idT,
typename MaskT,
typename InterruptT>
423 mParent->checkInterrupter();
429 AlphaMaskT alpha(mParent->grid(), *mMask, mParent->minMask(),
430 mParent->maxMask(), mParent->isMaskInverted());
432 ValueType* buffer = leafIter.buffer(1).data();
433 for (VoxelCIterT iter = leafIter->cbeginValueOn(); iter; ++iter) {
434 if (alpha(iter.getCoord(), a, b)) {
435 stencil.moveTo(iter);
436 const ValueType phi0 = *iter, phi1 = phi0 + dt*stencil.laplacian();
437 buffer[iter.pos()] = b * phi0 + a * phi1;
443 ValueType* buffer = leafIter.buffer(1).data();
444 for (VoxelCIterT iter = leafIter->cbeginValueOn(); iter; ++iter) {
445 stencil.moveTo(iter);
446 buffer[iter.pos()] = *iter + dt*stencil.laplacian();
453 template<
typename Gr
idT,
typename MaskT,
typename InterruptT>
461 AlphaMaskT alpha(mParent->grid(), *mMask, mParent->minMask(),
462 mParent->maxMask(), mParent->isMaskInverted());
464 for (VoxelIterT iter = leafIter->beginValueOn(); iter; ++iter) {
465 if (alpha(iter.getCoord(), a, b)) iter.setValue(*iter + a*offset);
470 for (VoxelIterT iter = leafIter->beginValueOn(); iter; ++iter) {
471 iter.setValue(*iter + offset);
478 template<
typename Gr
idT,
typename MaskT,
typename InterruptT>
487 AlphaMaskT alpha(mParent->grid(), *mMask, mParent->minMask(),
488 mParent->maxMask(), mParent->isMaskInverted());
490 ValueType* buffer = leafIter.buffer(1).data();
491 for (VoxelCIterT iter = leafIter->cbeginValueOn(); iter; ++iter) {
492 if (alpha(iter.getCoord(), a, b)) {
493 stencil.moveTo(iter);
494 buffer[iter.pos()] = b * (*iter) + a * stencil.median();
500 ValueType* buffer = leafIter.buffer(1).data();
501 for (VoxelCIterT iter = leafIter->cbeginValueOn(); iter; ++iter) {
502 stencil.moveTo(iter);
503 buffer[iter.pos()] = stencil.median();
510 template<
typename Gr
idT,
typename MaskT,
typename InterruptT>
511 template <
typename AvgT>
517 AvgT avg(mParent->grid(), w);
520 AlphaMaskT alpha(mParent->grid(), *mMask, mParent->minMask(),
521 mParent->maxMask(), mParent->isMaskInverted());
523 ValueType* buffer = leafIter.buffer(1).data();
524 for (VoxelCIterT iter = leafIter->cbeginValueOn(); iter; ++iter) {
525 const Coord xyz = iter.getCoord();
526 if (alpha(xyz, a, b)) buffer[iter.pos()] = b * (*iter)+ a * avg(xyz);
531 ValueType* buffer = leafIter.buffer(1).data();
532 for (VoxelCIterT iter = leafIter->cbeginValueOn(); iter; ++iter) {
533 buffer[iter.pos()] = avg(iter.getCoord());
543 #endif // OPENVDB_TOOLS_LEVELSETFILTER_HAS_BEEN_INCLUDED
Performs multi-threaded interface tracking of narrow band level sets. This is the building-block for ...
const Type & Min(const Type &a, const Type &b)
Return the minimum of two values.
Definition: Math.h:606
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:101
tbb::atomic< Index32 > i
Definition: LeafBuffer.h:71
Definition: LeafManager.h:127
#define OPENVDB_VERSION_NAME
Definition: version.h:43
Definition: Stencils.h:1217
Definition: Stencils.h:1495
Definition: LeafManager.h:130
Coord Abs(const Coord &xyz)
Definition: Coord.h:509
Dense stencil of a given width.
Definition: Stencils.h:1633
typename CopyConstness< TreeType, NonConstBufferType >::Type BufferType
Definition: LeafManager.h:121
Definition: Exceptions.h:39
void rebuildAuxBuffers(size_t auxBuffersPerLeaf, bool serial=false)
Change the number of auxiliary buffers.
Definition: LeafManager.h:307
Definition: Exceptions.h:92
Iterator begin() const
Definition: LeafManager.h:181
Signed (x, y, z) 32-bit integer coordinates.
Definition: Coord.h:48
Type Pow2(Type x)
Return .
Definition: Math.h:498
int32_t Int32
Definition: Types.h:59
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:71
Axis
Definition: Math.h:852