37 #ifndef OPENVDB_TOOLS_COMPOSITE_HAS_BEEN_INCLUDED
38 #define OPENVDB_TOOLS_COMPOSITE_HAS_BEEN_INCLUDED
40 #include <openvdb/Platform.h>
41 #include <openvdb/Exceptions.h>
42 #include <openvdb/Types.h>
43 #include <openvdb/Grid.h>
44 #include <openvdb/math/Math.h>
46 #include <boost/utility/enable_if.hpp>
58 inline void csgUnion(GridOrTreeT& a, GridOrTreeT& b,
bool prune =
true);
63 inline void csgIntersection(GridOrTreeT& a, GridOrTreeT& b,
bool prune =
true);
68 inline void csgDifference(GridOrTreeT& a, GridOrTreeT& b,
bool prune =
true);
73 inline void compMax(GridOrTreeT& a, GridOrTreeT& b);
77 inline void compMin(GridOrTreeT& a, GridOrTreeT& b);
81 inline void compSum(GridOrTreeT& a, GridOrTreeT& b);
85 inline void compMul(GridOrTreeT& a, GridOrTreeT& b);
89 inline void compDiv(GridOrTreeT& a, GridOrTreeT& b);
93 inline void compReplace(GridOrTreeT& a,
const GridOrTreeT& b);
102 template<
typename T>
inline
103 const typename boost::disable_if_c<VecTraits<T>::IsVec, T>::type&
106 template<
typename T>
inline
107 const typename boost::disable_if_c<VecTraits<T>::IsVec, T>::type&
112 template<
typename T>
inline
113 const typename boost::enable_if_c<VecTraits<T>::IsVec, T>::type&
114 min(
const T& a,
const T& b)
116 const typename T::ValueType aMag = a.lengthSqr(), bMag = b.lengthSqr();
117 return (aMag < bMag ? a : (bMag < aMag ? b :
std::min(a, b)));
120 template<
typename T>
inline
121 const typename boost::enable_if_c<VecTraits<T>::IsVec, T>::type&
122 max(
const T& a,
const T& b)
124 const typename T::ValueType aMag = a.lengthSqr(), bMag = b.lengthSqr();
125 return (aMag < bMag ? b : (bMag < aMag ? a :
std::max(a, b)));
131 template<
typename Gr
idOrTreeT>
133 compMax(GridOrTreeT& aTree, GridOrTreeT& bTree)
136 typedef typename Adapter::TreeType TreeT;
137 typedef typename TreeT::ValueType ValueT;
143 Adapter::tree(aTree).combineExtended(Adapter::tree(bTree), Local::op,
false);
147 template<
typename Gr
idOrTreeT>
149 compMin(GridOrTreeT& aTree, GridOrTreeT& bTree)
152 typedef typename Adapter::TreeType TreeT;
153 typedef typename TreeT::ValueType ValueT;
159 Adapter::tree(aTree).combineExtended(Adapter::tree(bTree), Local::op,
false);
163 template<
typename Gr
idOrTreeT>
165 compSum(GridOrTreeT& aTree, GridOrTreeT& bTree)
168 typedef typename Adapter::TreeType TreeT;
174 Adapter::tree(aTree).combineExtended(Adapter::tree(bTree), Local::op,
false);
178 template<
typename Gr
idOrTreeT>
180 compMul(GridOrTreeT& aTree, GridOrTreeT& bTree)
183 typedef typename Adapter::TreeType TreeT;
189 Adapter::tree(aTree).combineExtended(Adapter::tree(bTree), Local::op,
false);
193 template<
typename Gr
idOrTreeT>
195 compDiv(GridOrTreeT& aTree, GridOrTreeT& bTree)
198 typedef typename Adapter::TreeType TreeT;
204 Adapter::tree(aTree).combineExtended(Adapter::tree(bTree), Local::op,
false);
211 template<
typename TreeT>
218 void operator()(
const typename TreeT::ValueOnCIter& iter)
const
221 iter.getBoundingBox(bbox);
222 aTree->fill(bbox, *iter);
225 void operator()(
const typename TreeT::LeafCIter& leafIter)
const
228 for (
typename TreeT::LeafCIter::LeafNodeT::ValueOnCIter iter =
229 leafIter->cbeginValueOn(); iter; ++iter)
231 acc.
setValue(iter.getCoord(), *iter);
237 template<
typename Gr
idOrTreeT>
242 typedef typename Adapter::TreeType TreeT;
243 typedef typename TreeT::ValueOnCIter ValueOnCIterT;
246 Adapter::tree(aTree).topologyUnion(Adapter::tree(bTree));
251 ValueOnCIterT iter = bTree.cbeginValueOn();
252 iter.setMaxDepth(iter.getLeafDepth() - 1);
256 foreach(Adapter::tree(bTree).cbeginLeaf(), op);
265 template<
typename TreeType>
270 typedef typename TreeT::ValueType
ValueT;
271 typedef typename TreeT::LeafNodeType::ChildAllIter
ChildIterT;
276 mAOutside(aTree.background()),
277 mAInside(math::
negative(mAOutside)),
278 mBOutside(bTree.background()),
281 const ValueT zero = zeroVal<ValueT>();
282 if (!(mAOutside > zero)) {
284 "expected grid A outside value > 0, got " << mAOutside);
286 if (!(mAInside < zero)) {
288 "expected grid A inside value < 0, got " << mAInside);
290 if (!(mBOutside > zero)) {
292 "expected grid B outside value > 0, got " << mBOutside);
294 if (!(mBInside < zero)) {
296 "expected grid B outside value < 0, got " << mBOutside);
308 template<
typename TreeType>
312 typedef typename TreeT::ValueType
ValueT;
313 typedef typename TreeT::LeafNodeType::ChildAllIter
ChildIterT;
320 template<
typename AIterT,
typename BIterT>
324 template<
typename IterT>
327 ValueT aValue = zeroVal<ValueT>();
328 typename IterT::ChildNodeType* aChild = aIter.probeChild(aValue);
329 if (!aChild && aValue < zeroVal<ValueT>()) {
334 ValueT bValue = zeroVal<ValueT>();
335 typename IterT::ChildNodeType* bChild = bIter.probeChild(bValue);
336 if (!bChild && bValue < zeroVal<ValueT>()) {
338 aIter.setValue(this->mAInside);
339 aIter.setValueOn(bIter.isValueOn());
344 if (!aChild && aValue > zeroVal<ValueT>()) {
348 bIter.setValue(this->mBOutside);
350 bChild->resetBackground(this->mBOutside, this->mAOutside);
351 aIter.setChild(bChild);
359 return (aChild && bChild) ? 0 : STOP;
366 aIter.probeValue(aValue);
367 bIter.probeValue(bValue);
368 if (aValue > bValue) {
369 aIter.setValue(bValue);
370 aIter.setValueOn(bIter.isValueOn());
381 template<
typename TreeType>
385 typedef typename TreeT::ValueType
ValueT;
386 typedef typename TreeT::LeafNodeType::ChildAllIter
ChildIterT;
393 template<
typename AIterT,
typename BIterT>
397 template<
typename IterT>
400 ValueT aValue = zeroVal<ValueT>();
401 typename IterT::ChildNodeType* aChild = aIter.probeChild(aValue);
402 if (!aChild && !(aValue < zeroVal<ValueT>())) {
407 ValueT bValue = zeroVal<ValueT>();
408 typename IterT::ChildNodeType* bChild = bIter.probeChild(bValue);
409 if (!bChild && !(bValue < zeroVal<ValueT>())) {
411 aIter.setValue(this->mAOutside);
412 aIter.setValueOn(bIter.isValueOn());
417 if (!aChild && aValue < zeroVal<ValueT>()) {
421 bIter.setValue(this->mBOutside);
423 bChild->resetBackground(this->mBOutside, this->mAOutside);
424 aIter.setChild(bChild);
432 return (aChild && bChild) ? 0 : STOP;
439 aIter.probeValue(aValue);
440 bIter.probeValue(bValue);
441 if (aValue < bValue) {
442 aIter.setValue(bValue);
443 aIter.setValueOn(bIter.isValueOn());
453 template<
typename TreeType>
457 typedef typename TreeT::ValueType
ValueT;
458 typedef typename TreeT::LeafNodeType::ChildAllIter
ChildIterT;
465 template<
typename AIterT,
typename BIterT>
469 template<
typename IterT>
472 ValueT aValue = zeroVal<ValueT>();
473 typename IterT::ChildNodeType* aChild = aIter.probeChild(aValue);
474 if (!aChild && !(aValue < zeroVal<ValueT>())) {
479 ValueT bValue = zeroVal<ValueT>();
480 typename IterT::ChildNodeType* bChild = bIter.probeChild(bValue);
481 if (!bChild && bValue < zeroVal<ValueT>()) {
483 aIter.setValue(this->mAOutside);
484 aIter.setValueOn(bIter.isValueOn());
489 if (!aChild && aValue < zeroVal<ValueT>()) {
493 bIter.setValue(this->mBOutside);
495 bChild->resetBackground(this->mBOutside, this->mAOutside);
496 aIter.setChild(bChild);
505 return (aChild && bChild) ? 0 : STOP;
512 aIter.probeValue(aValue);
513 bIter.probeValue(bValue);
515 if (aValue < bValue) {
516 aIter.setValue(bValue);
517 aIter.setValueOn(bIter.isValueOn());
527 template<
typename Gr
idOrTreeT>
529 csgUnion(GridOrTreeT& a, GridOrTreeT& b,
bool prune)
532 typedef typename Adapter::TreeType TreeT;
533 TreeT &aTree = Adapter::tree(a), &bTree = Adapter::tree(b);
535 aTree.visit2(bTree, visitor);
536 if (prune) aTree.pruneLevelSet();
540 template<
typename Gr
idOrTreeT>
545 typedef typename Adapter::TreeType TreeT;
546 TreeT &aTree = Adapter::tree(a), &bTree = Adapter::tree(b);
548 aTree.visit2(bTree, visitor);
549 if (prune) aTree.pruneLevelSet();
553 template<
typename Gr
idOrTreeT>
558 typedef typename Adapter::TreeType TreeT;
559 TreeT &aTree = Adapter::tree(a), &bTree = Adapter::tree(b);
561 aTree.visit2(bTree, visitor);
562 if (prune) aTree.pruneLevelSet();
570 #endif // OPENVDB_TOOLS_COMPOSITE_HAS_BEEN_INCLUDED
void setValue(const Coord &xyz, const ValueType &value)
Set the value of the voxel at the given coordinates and mark the voxel as active. ...
Definition: ValueAccessor.h:241
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:97
CombineArgs & setResult(const AValueType &val)
Set the output value.
Definition: Types.h:300
Definition: Exceptions.h:88
This adapter allows code that is templated on a Tree type to accept either a Tree type or a Grid type...
Definition: Grid.h:837
This struct collects both input and output arguments to "grid combiner" functors used with the tree::...
Definition: Types.h:265
#define OPENVDB_VERSION_NAME
Definition: version.h:45
const AValueType & a() const
Get the A input value.
Definition: Types.h:290
const BValueType & b() const
Get the B input value.
Definition: Types.h:292
T negative(const T &val)
Return the unary negation of the given value.
Definition: Math.h:107
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:67