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 = NULL)
137 Filter f(
this, mask); f.gaussian(width);
143 void offset(ValueType offset,
const MaskType* mask = NULL)
145 Filter f(
this, mask); f.offset(offset);
154 void median(
int width = 1,
const MaskType* mask = NULL)
156 Filter f(
this, mask); f.median(width);
164 void mean(
int width = 1,
const MaskType* mask = NULL)
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) {}
189 void median(
int width);
190 void mean(
int width);
191 void gaussian(
int width);
194 void offset(ValueType value);
195 void operator()(
const LeafRange& r)
const 197 if (mTask) mTask(const_cast<Filter*>(
this), r);
202 const int n = mParent->getGrainSize();
204 tbb::parallel_for(mParent->leafs().leafRange(n), *
this);
206 (*this)(mParent->leafs().leafRange());
208 if (swap) mParent->leafs().swapLeafBuffer(1, n==0);
211 template <
size_t Axis>
214 acc(grid.tree()), width(w), frac(1/ValueType(2*w+1)) {}
217 ValueType sum = zeroVal<ValueType>();
219 for (i -= width; i <= j; ++i) sum += acc.getValue(xyz);
222 typename GridT::ConstAccessor
acc;
227 template <
typename AvgT>
228 void box(
const LeafRange& r,
Int32 w);
230 void boxX(
const LeafRange& r,
Int32 w) { this->box<Avg<0> >(r,w); }
231 void boxZ(
const LeafRange& r,
Int32 w) { this->box<Avg<1> >(r,w); }
232 void boxY(
const LeafRange& r,
Int32 w) { this->box<Avg<2> >(r,w); }
234 void median(
const LeafRange&,
int);
237 void offset(
const LeafRange&, ValueType);
240 const MaskType* mMask;
241 typename boost::function<void (Filter*, const LeafRange&)> mTask;
244 AlphaType mMinMask, mMaxMask;
252 template<
typename Gr
idT,
typename MaskT,
typename InterruptT>
259 mParent->leafs().rebuildAuxBuffers(1, mParent->getGrainSize()==0);
261 mTask = boost::bind(&Filter::median, _1, _2,
std::max(1, width));
266 mParent->endInterrupter();
269 template<
typename Gr
idT,
typename MaskT,
typename InterruptT>
278 mParent->endInterrupter();
281 template<
typename Gr
idT,
typename MaskT,
typename InterruptT>
288 for (
int n=0; n<4; ++n) this->box(width);
290 mParent->endInterrupter();
293 template<
typename Gr
idT,
typename MaskT,
typename InterruptT>
302 mTask = boost::bind(&Filter::boxX, _1, _2, width);
305 mTask = boost::bind(&Filter::boxY, _1, _2, width);
308 mTask = boost::bind(&Filter::boxZ, _1, _2, width);
314 template<
typename Gr
idT,
typename MaskT,
typename InterruptT>
319 mParent->startInterrupter(
"Mean-curvature flow of level set");
321 mParent->leafs().rebuildAuxBuffers(1, mParent->getGrainSize()==0);
328 mParent->endInterrupter();
331 template<
typename Gr
idT,
typename MaskT,
typename InterruptT>
336 mParent->startInterrupter(
"Laplacian flow of level set");
338 mParent->leafs().rebuildAuxBuffers(1, mParent->getGrainSize()==0);
345 mParent->endInterrupter();
348 template<
typename Gr
idT,
typename MaskT,
typename InterruptT>
355 mParent->leafs().removeAuxBuffers();
359 while (offset-dist >
ValueType(0.001)*CFL && mParent->checkInterrupter()) {
363 mTask = boost::bind(&Filter::offset, _1, _2, copysign(delta, value));
369 mParent->endInterrupter();
376 template<
typename Gr
idT,
typename MaskT,
typename InterruptT>
381 mParent->checkInterrupter();
387 AlphaMaskT alpha(mParent->grid(), *mMask, mParent->minMask(),
388 mParent->maxMask(), mParent->isMaskInverted());
390 ValueType* buffer = leafIter.buffer(1).data();
391 for (VoxelCIterT iter = leafIter->cbeginValueOn(); iter; ++iter) {
392 if (alpha(iter.getCoord(), a, b)) {
393 stencil.moveTo(iter);
394 const ValueType phi0 = *iter, phi1 = phi0 + dt*stencil.meanCurvatureNormGrad();
395 buffer[iter.pos()] = b * phi0 + a * phi1;
401 ValueType* buffer = leafIter.buffer(1).data();
402 for (VoxelCIterT iter = leafIter->cbeginValueOn(); iter; ++iter) {
403 stencil.moveTo(iter);
404 buffer[iter.pos()] = *iter + dt*stencil.meanCurvatureNormGrad();
417 template<
typename Gr
idT,
typename MaskT,
typename InterruptT>
422 mParent->checkInterrupter();
428 AlphaMaskT alpha(mParent->grid(), *mMask, mParent->minMask(),
429 mParent->maxMask(), mParent->isMaskInverted());
431 ValueType* buffer = leafIter.buffer(1).data();
432 for (VoxelCIterT iter = leafIter->cbeginValueOn(); iter; ++iter) {
433 if (alpha(iter.getCoord(), a, b)) {
434 stencil.moveTo(iter);
435 const ValueType phi0 = *iter, phi1 = phi0 + dt*stencil.laplacian();
436 buffer[iter.pos()] = b * phi0 + a * phi1;
442 ValueType* buffer = leafIter.buffer(1).data();
443 for (VoxelCIterT iter = leafIter->cbeginValueOn(); iter; ++iter) {
444 stencil.moveTo(iter);
445 buffer[iter.pos()] = *iter + dt*stencil.laplacian();
452 template<
typename Gr
idT,
typename MaskT,
typename InterruptT>
460 AlphaMaskT alpha(mParent->grid(), *mMask, mParent->minMask(),
461 mParent->maxMask(), mParent->isMaskInverted());
463 for (VoxelIterT iter = leafIter->beginValueOn(); iter; ++iter) {
464 if (alpha(iter.getCoord(), a, b)) iter.setValue(*iter + a*offset);
469 for (VoxelIterT iter = leafIter->beginValueOn(); iter; ++iter) {
470 iter.setValue(*iter + offset);
477 template<
typename Gr
idT,
typename MaskT,
typename InterruptT>
486 AlphaMaskT alpha(mParent->grid(), *mMask, mParent->minMask(),
487 mParent->maxMask(), mParent->isMaskInverted());
489 ValueType* buffer = leafIter.buffer(1).data();
490 for (VoxelCIterT iter = leafIter->cbeginValueOn(); iter; ++iter) {
491 if (alpha(iter.getCoord(), a, b)) {
492 stencil.moveTo(iter);
493 buffer[iter.pos()] = b * (*iter) + a * stencil.median();
499 ValueType* buffer = leafIter.buffer(1).data();
500 for (VoxelCIterT iter = leafIter->cbeginValueOn(); iter; ++iter) {
501 stencil.moveTo(iter);
502 buffer[iter.pos()] = stencil.median();
509 template<
typename Gr
idT,
typename MaskT,
typename InterruptT>
510 template <
typename AvgT>
516 AvgT avg(mParent->grid(), w);
519 AlphaMaskT alpha(mParent->grid(), *mMask, mParent->minMask(),
520 mParent->maxMask(), mParent->isMaskInverted());
522 ValueType* buffer = leafIter.buffer(1).data();
523 for (VoxelCIterT iter = leafIter->cbeginValueOn(); iter; ++iter) {
524 const Coord xyz = iter.getCoord();
525 if (alpha(xyz, a, b)) buffer[iter.pos()] = b * (*iter)+ a * avg(xyz);
530 ValueType* buffer = leafIter.buffer(1).data();
531 for (VoxelCIterT iter = leafIter->cbeginValueOn(); iter; ++iter) {
532 buffer[iter.pos()] = avg(iter.getCoord());
542 #endif // OPENVDB_TOOLS_LEVELSETFILTER_HAS_BEEN_INCLUDED
Performs multi-threaded interface tracking of narrow band level sets. This is the building-block for ...
Definition: Stencils.h:1204
int32_t Abs(int32_t i)
Return the absolute value of the given quantity.
Definition: Math.h:293
Definition: Exceptions.h:88
Definition: Stencils.h:1478
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:97
Iterator begin() const
Definition: LeafManager.h:181
#define OPENVDB_VERSION_NAME
Definition: version.h:43
void rebuildAuxBuffers(size_t auxBuffersPerLeaf, bool serial=false)
Change the number of auxiliary buffers.
Definition: LeafManager.h:283
Definition: Exceptions.h:39
CopyConstness< TreeType, NonConstBufferType >::Type BufferType
Definition: LeafManager.h:125
Axis
Definition: Math.h:838
Type Pow2(Type x)
Return .
Definition: Math.h:514
int32_t Int32
Definition: Types.h:60
Definition: LeafManager.h:134
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:71
Dense stencil of a given width.
Definition: Stencils.h:1616
const Type & Min(const Type &a, const Type &b)
Return the minimum of two values.
Definition: Math.h:622
Definition: LeafManager.h:131