29 #ifndef OPENVDB_TOOLS_VALUETRANSFORMER_HAS_BEEN_INCLUDED 30 #define OPENVDB_TOOLS_VALUETRANSFORMER_HAS_BEEN_INCLUDED 33 #include <tbb/parallel_for.h> 34 #include <tbb/parallel_reduce.h> 88 template<
typename IterT,
typename XformOp>
89 inline void foreach(
const IterT& iter, XformOp& op,
90 bool threaded =
true,
bool shareOp =
true);
92 template<
typename IterT,
typename XformOp>
93 inline void foreach(
const IterT& iter,
const XformOp& op,
94 bool threaded =
true,
bool shareOp =
true);
137 template<
typename InIterT,
typename OutGr
idT,
typename XformOp>
139 XformOp& op,
bool threaded =
true,
bool shareOp =
true,
143 template<
typename InIterT,
typename OutGr
idT,
typename XformOp>
145 const XformOp& op,
bool threaded =
true,
bool shareOp =
true,
194 template<
typename IterT,
typename XformOp>
195 inline void accumulate(
const IterT& iter, XformOp& op,
bool threaded =
true);
203 template<
typename TreeT>
204 void setValueOnMin(TreeT& tree,
const Coord& xyz,
const typename TreeT::ValueType&
value);
211 template<
typename TreeT>
212 void setValueOnMax(TreeT& tree,
const Coord& xyz,
const typename TreeT::ValueType&
value);
219 template<
typename TreeT>
220 void setValueOnSum(TreeT& tree,
const Coord& xyz,
const typename TreeT::ValueType&
value);
227 template<
typename TreeT>
228 void setValueOnMult(TreeT& tree,
const Coord& xyz,
const typename TreeT::ValueType&
value);
236 template<
typename ValueType>
239 MinOp(
const ValueType& v): val(v) {}
240 inline void operator()(ValueType& v)
const { v = std::min<ValueType>(v, val); }
243 template<
typename ValueType>
246 MaxOp(
const ValueType& v): val(v) {}
247 inline void operator()(ValueType& v)
const { v = std::max<ValueType>(v, val); }
250 template<
typename ValueType>
253 SumOp(
const ValueType& v): val(v) {}
265 template<
typename ValueType>
283 template<
typename TreeT>
291 template<
typename TreeT>
299 template<
typename TreeT>
307 template<
typename TreeT>
320 template<
typename IterT,
typename OpT>
332 tbb::parallel_for(range, *
this);
346 template<
typename IterT,
typename OpT>
357 mIter(other.mIter), mOp(*other.mOrigOp), mOrigOp(other.mOrigOp) {}
363 tbb::parallel_for(range, *
this);
374 OpT
const *
const mOrigOp;
380 template<
typename IterT,
typename XformOp>
382 foreach(
const IterT& iter, XformOp& op,
bool threaded,
bool shared)
389 Processor proc(iter, op);
390 proc.process(threaded);
394 template<
typename IterT,
typename XformOp>
396 foreach(
const IterT& iter,
const XformOp& op,
bool threaded,
bool )
409 template<
typename InIterT,
typename OutTreeT,
typename OpT>
420 mInputTree(inIter.getTree()),
421 mOutputTree(&outTree),
425 if (static_cast<const void*>(mInputTree) == static_cast<void*>(mOutputTree)) {
427 " to transform a grid in place");
434 mInputIter(other.mInputIter),
435 mInputTree(other.mInputTree),
438 mMergePolicy(other.mMergePolicy)
447 mOutputTree =
nullptr;
453 if (!mInputTree || !mOutputTree)
return;
460 tbb::parallel_reduce(range, *
this);
469 if (!mOutputTree)
return;
471 for ( ; range; ++range) {
472 mOp(range.iterator(), outAccessor);
478 if (mOutputTree && other.mOutputTree) {
479 mOutputTree->merge(*other.mOutputTree, mMergePolicy);
487 OutTreeT* mOutputTree;
493 template<
typename InIterT,
typename OutTreeT,
typename OpT>
505 mInputTree(inIter.getTree()),
506 mOutputTree(&outTree),
511 if (static_cast<const void*>(mInputTree) == static_cast<void*>(mOutputTree)) {
513 " to transform a grid in place");
521 mInputIter(other.mInputIter),
522 mInputTree(other.mInputTree),
525 mOrigOp(other.mOrigOp),
526 mMergePolicy(other.mMergePolicy)
535 mOutputTree =
nullptr;
541 if (!mInputTree || !mOutputTree)
return;
548 tbb::parallel_reduce(range, *
this);
557 if (!mOutputTree)
return;
559 for ( ; range; ++range) {
560 mOp(range.iterator(), outAccessor);
566 if (mOutputTree && other.mOutputTree) {
567 mOutputTree->merge(*other.mOutputTree, mMergePolicy);
575 OutTreeT* mOutputTree;
577 OpT
const *
const mOrigOp;
587 template<
typename InIterT,
typename OutGr
idT,
typename XformOp>
593 using OutTreeT =
typename Adapter::TreeType;
596 Processor proc(inIter, Adapter::tree(outGrid), op, merge);
597 proc.process(threaded);
600 Processor proc(inIter, Adapter::tree(outGrid), op, merge);
601 proc.process(threaded);
606 template<
typename InIterT,
typename OutGr
idT,
typename XformOp>
612 using OutTreeT =
typename Adapter::TreeType;
615 Processor proc(inIter, Adapter::tree(outGrid), op, merge);
616 proc.process(threaded);
626 template<
typename IterT,
typename OpT>
648 mOp(new OpT(*other.mOrigOp)),
649 mOrigOp(other.mOrigOp)
658 tbb::parallel_reduce(range, *
this);
672 OpT
const *
const mOrigOp;
681 template<
typename IterT,
typename XformOp>
695 #ifdef OPENVDB_USE_EXPLICIT_INSTANTIATION 697 #ifdef OPENVDB_INSTANTIATE_VALUETRANSFORMER 701 #define _FUNCTION(TreeT) \ 702 void setValueOnMin(TreeT&, const Coord&, const TreeT::ValueType&) 706 #define _FUNCTION(TreeT) \ 707 void setValueOnMax(TreeT&, const Coord&, const TreeT::ValueType&) 711 #define _FUNCTION(TreeT) \ 712 void setValueOnSum(TreeT&, const Coord&, const TreeT::ValueType&) 716 #define _FUNCTION(TreeT) \ 717 void setValueOnMult(TreeT&, const Coord&, const TreeT::ValueType&) 721 #endif // OPENVDB_USE_EXPLICIT_INSTANTIATION 728 #endif // OPENVDB_TOOLS_VALUETRANSFORMER_HAS_BEEN_INCLUDED #define OPENVDB_LOG_INFO(message)
Log an info message of the form 'someVar << "some text" << ...'.
Definition: logging.h:254
#define OPENVDB_VOLUME_TREE_INSTANTIATE(Function)
Definition: version.h.in:150
T zeroVal()
Return the value of type T that corresponds to zero.
Definition: Math.h:69
MergePolicy
Definition: Types.h:467
Definition: Exceptions.h:13
ValueT value
Definition: GridBuilder.h:1287
Definition: TreeIterator.h:1302
Definition: ValueAccessor.h:182
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h.in:116
This adapter allows code that is templated on a Tree type to accept either a Tree type or a Grid type...
Definition: Grid.h:1070
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h.in:202