89 #ifndef OPENVDB_TOOLS_POISSONSOLVER_HAS_BEEN_INCLUDED 90 #define OPENVDB_TOOLS_POISSONSOLVER_HAS_BEEN_INCLUDED 100 #include <boost/scoped_array.hpp> 117 template<
typename TreeType>
130 inline typename TreeType::Ptr
133 template<
typename TreeType,
typename Interrupter>
134 inline typename TreeType::Ptr
140 template<
typename TreeType,
typename BoundaryOp,
typename Interrupter>
171 inline typename TreeType::Ptr
174 template<
typename PreconditionerType,
typename TreeType,
typename BoundaryOp,
typename Interrupter>
175 inline typename TreeType::Ptr
179 template<
typename PreconditionerType,
typename TreeType,
typename DomainTreeType,
typename BoundaryOp,
typename Interrupter>
180 inline typename TreeType::Ptr
192 template<
typename VIndexTreeType>
198 template<
typename TreeType>
199 inline typename TreeType::template ValueConverter<VIndex>::Type::Ptr
209 template<
typename VectorValueType,
typename SourceTreeType>
212 const SourceTreeType& source,
213 const typename SourceTreeType::template ValueConverter<VIndex>::Type& index);
223 template<
typename TreeValueType,
typename VIndexTreeType,
typename VectorValueType>
224 inline typename VIndexTreeType::template ValueConverter<TreeValueType>::Type::Ptr
227 const VIndexTreeType& index,
228 const TreeValueType& background);
235 template<
typename BoolTreeType>
238 const typename BoolTreeType::template ValueConverter<VIndex>::Type& vectorIndexTree,
239 const BoolTreeType& interiorMask);
261 template<
typename BoolTreeType,
typename BoundaryOp>
264 const typename BoolTreeType::template ValueConverter<VIndex>::Type& vectorIndexTree,
265 const BoolTreeType& interiorMask,
266 const BoundaryOp& boundaryOp,
279 template<
typename LeafType>
284 void operator()(
const LeafType& leaf,
size_t leafIdx)
const {
285 count[leafIdx] =
static_cast<VIndex
>(leaf.onVoxelCount());
292 template<
typename LeafType>
298 VIndex idx = (leafIdx == 0) ? 0 : count[leafIdx - 1];
299 for (
typename LeafType::ValueOnIter it = leaf.beginValueOn(); it; ++it) {
308 template<
typename VIndexTreeType>
312 typedef typename VIndexTreeType::LeafNodeType LeafT;
316 LeafMgrT leafManager(result);
317 const size_t leafCount = leafManager.leafCount();
319 if(leafCount == 0)
return;
322 boost::scoped_array<VIndex> perLeafCount(
new VIndex[leafCount]);
323 VIndex* perLeafCountPtr = perLeafCount.get();
328 for (
size_t i = 1; i < leafCount; ++i) {
329 perLeafCount[i] += perLeafCount[i - 1];
333 assert(
Index64(perLeafCount[leafCount-1]) == result.activeVoxelCount());
341 template<
typename TreeType>
342 inline typename TreeType::template ValueConverter<VIndex>::Type::Ptr
345 typedef typename TreeType::template ValueConverter<VIndex>::Type VIdxTreeT;
348 const VIndex invalidIdx = -1;
349 typename VIdxTreeT::Ptr result(
353 result->voxelizeActiveTiles();
368 template<
typename VectorValueType,
typename SourceTreeType>
371 typedef typename SourceTreeType::template ValueConverter<VIndex>::Type
VIdxTreeT;
373 typedef typename SourceTreeType::LeafNodeType
LeafT;
380 CopyToVecOp(
const SourceTreeType& t, VectorT& v): tree(&t), vector(&v) {}
384 VectorT& vec = *vector;
385 if (
const LeafT* leaf = tree->probeLeaf(idxLeaf.origin())) {
388 for (
typename VIdxLeafT::ValueOnCIter it = idxLeaf.cbeginValueOn(); it; ++it) {
389 vec[*it] = leaf->getValue(it.pos());
394 const TreeValueT& value = tree->getValue(idxLeaf.origin());
395 for (
typename VIdxLeafT::ValueOnCIter it = idxLeaf.cbeginValueOn(); it; ++it) {
405 template<
typename VectorValueType,
typename SourceTreeType>
408 const typename SourceTreeType::template ValueConverter<VIndex>::Type& idxTree)
410 typedef typename SourceTreeType::template ValueConverter<VIndex>::Type VIdxTreeT;
415 const size_t numVoxels = idxTree.activeVoxelCount();
416 typename VectorT::Ptr result(
new VectorT(static_cast<math::pcg::SizeType>(numVoxels)));
420 VIdxLeafMgrT leafManager(idxTree);
434 template<
typename TreeValueType,
typename VIndexTreeType,
typename VectorValueType>
437 typedef typename VIndexTreeType::template ValueConverter<TreeValueType>::Type
OutTreeT;
439 typedef typename VIndexTreeType::LeafNodeType
VIdxLeafT;
449 const VectorT& vec = *vector;
450 OutLeafT* leaf = tree->probeLeaf(idxLeaf.origin());
451 assert(leaf != NULL);
452 for (
typename VIdxLeafT::ValueOnCIter it = idxLeaf.cbeginValueOn(); it; ++it) {
453 leaf->setValueOnly(it.pos(),
static_cast<TreeValueType
>(vec[*it]));
461 template<
typename TreeValueType,
typename VIndexTreeType,
typename VectorValueType>
462 inline typename VIndexTreeType::template ValueConverter<TreeValueType>::Type::Ptr
465 const VIndexTreeType& idxTree,
466 const TreeValueType& background)
468 typedef typename VIndexTreeType::template ValueConverter<TreeValueType>::Type OutTreeT;
472 typename OutTreeT::Ptr result(
new OutTreeT(idxTree, background,
TopologyCopy()));
473 OutTreeT& tree = *result;
477 VIdxLeafMgrT leafManager(idxTree);
491 template<
typename ValueType>
494 const Coord&,
const Coord&, ValueType&, ValueType& diag)
const { diag -= 1; }
499 template<
typename BoolTreeType,
typename BoundaryOp>
502 typedef typename BoolTreeType::template ValueConverter<VIndex>::Type
VIdxTreeT;
514 const BoolTreeType& mask,
const BoundaryOp& op, VectorT& src):
515 laplacian(&m), idxTree(&idx), interiorMask(&mask), boundaryOp(op), source(&src) {}
525 const ValueT diagonal = -6.f, offDiagonal = 1.f;
528 for (
typename VIdxLeafT::ValueOnCIter it = idxLeaf.cbeginValueOn(); it; ++it) {
529 assert(it.getValue() > -1);
558 ValueT modifiedDiagonal = 0.f;
563 modifiedDiagonal -= 1;
565 boundaryOp(ijk, ijk.
offsetBy(-1, 0, 0), source->
at(rowNum), modifiedDiagonal);
570 modifiedDiagonal -= 1;
572 boundaryOp(ijk, ijk.
offsetBy(0, -1, 0), source->
at(rowNum), modifiedDiagonal);
577 modifiedDiagonal -= 1;
579 boundaryOp(ijk, ijk.
offsetBy(0, 0, -1), source->
at(rowNum), modifiedDiagonal);
584 modifiedDiagonal -= 1;
586 boundaryOp(ijk, ijk.
offsetBy(0, 0, 1), source->
at(rowNum), modifiedDiagonal);
591 modifiedDiagonal -= 1;
593 boundaryOp(ijk, ijk.
offsetBy(0, 1, 0), source->
at(rowNum), modifiedDiagonal);
598 modifiedDiagonal -= 1;
600 boundaryOp(ijk, ijk.
offsetBy(1, 0, 0), source->
at(rowNum), modifiedDiagonal);
603 row.
setValue(rowNum, modifiedDiagonal);
612 template<
typename BoolTreeType>
615 const BoolTreeType& interiorMask)
619 static_cast<math::pcg::SizeType>(idxTree.activeVoxelCount()));
625 template<
typename BoolTreeType,
typename BoundaryOp>
628 const typename BoolTreeType::template ValueConverter<VIndex>::Type& idxTree,
629 const BoolTreeType& interiorMask,
630 const BoundaryOp& boundaryOp,
633 typedef typename BoolTreeType::template ValueConverter<VIndex>::Type VIdxTreeT;
637 const Index64 numDoF = idxTree.activeVoxelCount();
642 LaplacianMatrix&
laplacian = *laplacianPtr;
645 VIdxLeafMgrT idxLeafManager(idxTree);
647 laplacian, idxTree, interiorMask, boundaryOp, source));
656 template<
typename TreeType>
657 inline typename TreeType::Ptr
661 return solve(inTree, state, interrupter);
665 template<
typename TreeType,
typename Interrupter>
666 inline typename TreeType::Ptr
674 template<
typename TreeType,
typename BoundaryOp,
typename Interrupter>
675 inline typename TreeType::Ptr
680 return solveWithBoundaryConditionsAndPreconditioner<DefaultPrecondT>(
681 inTree, boundaryOp, state, interrupter);
685 template<
typename PreconditionerType,
typename TreeType,
typename BoundaryOp,
typename Interrupter>
686 inline typename TreeType::Ptr
688 const BoundaryOp& boundaryOp,
math::pcg::State& state, Interrupter& interrupter)
691 return solveWithBoundaryConditionsAndPreconditioner<PreconditionerType>(inTree , inTree ,
692 boundaryOp, state, interrupter);
695 template<
typename PreconditionerType,
typename TreeType,
typename DomainTreeType,
typename BoundaryOp,
typename Interrupter>
696 inline typename TreeType::Ptr
698 const DomainTreeType& domainMask,
699 const BoundaryOp& boundaryOp,
703 typedef typename TreeType::ValueType TreeValueT;
706 typedef typename TreeType::template ValueConverter<VIndex>::Type VIdxTreeT;
707 typedef typename TreeType::template ValueConverter<bool>::Type MaskTreeT;
713 typename VectorT::Ptr b = createVectorFromTree<VecValueT>(inTree, *idxTree);
716 typename MaskTreeT::Ptr interiorMask(
722 *idxTree, *interiorMask, boundaryOp, *b);
725 laplacian->scale(-1.0);
727 typename VectorT::Ptr x(
new VectorT(b->size(), zeroVal<VecValueT>()));
729 new PreconditionerType(*laplacian));
730 if (!precond->isValid()) {
738 return createTreeFromVector<TreeValueT>(*x, *idxTree, zeroVal<TreeValueT>());
746 #endif // OPENVDB_TOOLS_POISSONSOLVER_HAS_BEEN_INCLUDED
boost::shared_ptr< Preconditioner > Ptr
Definition: ConjGradient.h:497
boost::shared_ptr< SparseStencilMatrix > Ptr
Definition: ConjGradient.h:271
Lightweight, variable-length vector.
Definition: ConjGradient.h:65
Dummy NOOP interrupter class defining interface.
Definition: NullInterrupter.h:52
SizeType setValue(SizeType column, const ValueType &value)
Set the value of the entry in the specified column.
Definition: ConjGradient.h:1265
bool probeValue(const Coord &xyz, ValueType &value) const
Return the active state of the voxel as well as its value.
Definition: ValueAccessor.h:266
Preconditioned conjugate gradient solver (solves Ax = b using the conjugate gradient method with one ...
This class manages a linear array of pointers to a given tree's leaf nodes, as well as optional auxil...
Definition: LeafManager.h:115
Signed (x, y, z) 32-bit integer coordinates.
Definition: Coord.h:47
ValueType_ ValueType
Definition: ConjGradient.h:269
Information about the state of a conjugate gradient solution.
Definition: ConjGradient.h:74
Definition: ValueAccessor.h:219
int32_t Int32
Definition: Types.h:60
uint64_t Index64
Definition: Types.h:57
#define OPENVDB_VERSION_NAME
Definition: version.h:43
Diagonal preconditioner.
Definition: ConjGradient.h:70
const ValueType & getValue(const Coord &xyz) const
Return the value of the voxel at the given coordinates.
Definition: ValueAccessor.h:256
RowEditor getRowEditor(SizeType row)
Return a read/write view onto the given row of this matrix.
Definition: ConjGradient.h:1109
Implementation of morphological dilation and erosion.
Coord offsetBy(Int32 dx, Int32 dy, Int32 dz) const
Definition: Coord.h:111
T & at(SizeType i)
Return the value of this vector's ith element.
Definition: ConjGradient.h:229
Definition: Exceptions.h:39
bool isValueOn(const Coord &xyz) const
Return the active state of the voxel at the given coordinates.
Definition: ValueAccessor.h:263
Index32 SizeType
Definition: ConjGradient.h:61
boost::shared_ptr< Vector > Ptr
Definition: ConjGradient.h:170
Sparse, square matrix representing a 3D stencil operator of size STENCIL_SIZE.
Definition: ConjGradient.h:67
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:71
A LeafManager manages a linear array of pointers to a given tree's leaf nodes, as well as optional au...
Read/write accessor to a row of this matrix.
Definition: ConjGradient.h:448
Preconditioner using incomplete Cholesky factorization.
Definition: ConjGradient.h:71