61 #ifndef OPENVDB_TOOLS_POISSONSOLVER_HAS_BEEN_INCLUDED 62 #define OPENVDB_TOOLS_POISSONSOLVER_HAS_BEEN_INCLUDED 86 template<
typename TreeType>
99 inline typename TreeType::Ptr
102 template<
typename TreeType,
typename Interrupter>
103 inline typename TreeType::Ptr
109 template<
typename TreeType,
typename BoundaryOp,
typename Interrupter>
140 inline typename TreeType::Ptr
146 bool staggered =
false);
149 typename PreconditionerType,
152 typename Interrupter>
153 inline typename TreeType::Ptr
159 bool staggered =
false);
162 typename PreconditionerType,
164 typename DomainTreeType,
166 typename Interrupter>
167 inline typename TreeType::Ptr
170 const DomainTreeType&,
174 bool staggered =
false);
184 template<
typename VIndexTreeType>
190 template<
typename TreeType>
191 inline typename TreeType::template ValueConverter<VIndex>::Type::Ptr
201 template<
typename VectorValueType,
typename SourceTreeType>
204 const SourceTreeType& source,
205 const typename SourceTreeType::template ValueConverter<VIndex>::Type& index);
215 template<
typename TreeValueType,
typename VIndexTreeType,
typename VectorValueType>
216 inline typename VIndexTreeType::template ValueConverter<TreeValueType>::Type::Ptr
219 const VIndexTreeType& index,
220 const TreeValueType& background);
227 template<
typename BoolTreeType>
230 const typename BoolTreeType::template ValueConverter<VIndex>::Type& vectorIndexTree,
232 bool staggered =
false);
254 template<
typename BoolTreeType,
typename BoundaryOp>
257 const typename BoolTreeType::template ValueConverter<VIndex>::Type& vectorIndexTree,
259 const BoundaryOp& boundaryOp,
261 bool staggered =
false);
267 template<
typename ValueType>
286 template<
typename LeafType>
291 void operator()(
const LeafType& leaf,
size_t leafIdx)
const {
292 count[leafIdx] = static_cast<VIndex>(leaf.onVoxelCount());
299 template<
typename LeafType>
305 VIndex idx = (leafIdx == 0) ? 0 : count[leafIdx - 1];
306 for (
typename LeafType::ValueOnIter it = leaf.beginValueOn(); it; ++it) {
315 template<
typename VIndexTreeType>
319 using LeafT =
typename VIndexTreeType::LeafNodeType;
323 LeafMgrT leafManager(result);
324 const size_t leafCount = leafManager.leafCount();
326 if (leafCount == 0)
return;
329 std::unique_ptr<VIndex[]> perLeafCount(
new VIndex[leafCount]);
330 VIndex* perLeafCountPtr = perLeafCount.get();
335 for (
size_t i = 1; i < leafCount; ++i) {
336 perLeafCount[i] += perLeafCount[i - 1];
340 assert(
Index64(perLeafCount[leafCount-1]) == result.activeVoxelCount());
348 template<
typename TreeType>
349 inline typename TreeType::template ValueConverter<VIndex>::Type::Ptr
352 using VIdxTreeT =
typename TreeType::template ValueConverter<VIndex>::Type;
355 const VIndex invalidIdx = -1;
356 typename VIdxTreeT::Ptr result(
360 result->voxelizeActiveTiles();
375 template<
typename VectorValueType,
typename SourceTreeType>
378 using VIdxTreeT =
typename SourceTreeType::template ValueConverter<VIndex>::Type;
380 using LeafT =
typename SourceTreeType::LeafNodeType;
392 if (
const LeafT* leaf = tree->probeLeaf(idxLeaf.origin())) {
395 for (
typename VIdxLeafT::ValueOnCIter it = idxLeaf.cbeginValueOn(); it; ++it) {
396 vec[*it] = leaf->getValue(it.pos());
401 const TreeValueT& value = tree->getValue(idxLeaf.origin());
402 for (
typename VIdxLeafT::ValueOnCIter it = idxLeaf.cbeginValueOn(); it; ++it) {
412 template<
typename VectorValueType,
typename SourceTreeType>
415 const typename SourceTreeType::template ValueConverter<VIndex>::Type& idxTree)
417 using VIdxTreeT =
typename SourceTreeType::template ValueConverter<VIndex>::Type;
422 const size_t numVoxels = idxTree.activeVoxelCount();
423 typename VectorT::Ptr result(
new VectorT(static_cast<math::pcg::SizeType>(numVoxels)));
427 VIdxLeafMgrT leafManager(idxTree);
441 template<
typename TreeValueType,
typename VIndexTreeType,
typename VectorValueType>
444 using OutTreeT =
typename VIndexTreeType::template ValueConverter<TreeValueType>::Type;
446 using VIdxLeafT =
typename VIndexTreeType::LeafNodeType;
457 OutLeafT* leaf = tree->probeLeaf(idxLeaf.origin());
458 assert(leaf !=
nullptr);
459 for (
typename VIdxLeafT::ValueOnCIter it = idxLeaf.cbeginValueOn(); it; ++it) {
460 leaf->setValueOnly(it.pos(), static_cast<TreeValueType>(vec[*it]));
468 template<
typename TreeValueType,
typename VIndexTreeType,
typename VectorValueType>
469 inline typename VIndexTreeType::template ValueConverter<TreeValueType>::Type::Ptr
472 const VIndexTreeType& idxTree,
473 const TreeValueType& background)
475 using OutTreeT =
typename VIndexTreeType::template ValueConverter<TreeValueType>::Type;
479 typename OutTreeT::Ptr result(
new OutTreeT(idxTree, background,
TopologyCopy()));
480 OutTreeT& tree = *result;
484 VIdxLeafMgrT leafManager(idxTree);
498 template<
typename BoolTreeType,
typename BoundaryOp>
501 using VIdxTreeT =
typename BoolTreeType::template ValueConverter<VIndex>::Type;
513 const BoolTreeType& mask,
const BoundaryOp& op,
VectorT& src):
524 const ValueT diagonal = -6.f, offDiagonal = 1.f;
527 for (
typename VIdxLeafT::ValueOnCIter it = idxLeaf.cbeginValueOn(); it; ++it) {
528 assert(it.getValue() > -1);
545 row.setValue(rowNum, diagonal);
557 ValueT modifiedDiagonal = 0.f;
561 row.setValue(column, offDiagonal);
562 modifiedDiagonal -= 1;
564 boundaryOp(ijk, ijk.
offsetBy(-1, 0, 0), source->at(rowNum), modifiedDiagonal);
568 row.setValue(column, offDiagonal);
569 modifiedDiagonal -= 1;
571 boundaryOp(ijk, ijk.
offsetBy(0, -1, 0), source->at(rowNum), modifiedDiagonal);
575 row.setValue(column, offDiagonal);
576 modifiedDiagonal -= 1;
578 boundaryOp(ijk, ijk.
offsetBy(0, 0, -1), source->at(rowNum), modifiedDiagonal);
582 row.setValue(column, offDiagonal);
583 modifiedDiagonal -= 1;
585 boundaryOp(ijk, ijk.
offsetBy(0, 0, 1), source->at(rowNum), modifiedDiagonal);
589 row.setValue(column, offDiagonal);
590 modifiedDiagonal -= 1;
592 boundaryOp(ijk, ijk.
offsetBy(0, 1, 0), source->at(rowNum), modifiedDiagonal);
596 row.setValue(column, offDiagonal);
597 modifiedDiagonal -= 1;
599 boundaryOp(ijk, ijk.
offsetBy(1, 0, 0), source->at(rowNum), modifiedDiagonal);
602 row.setValue(rowNum, modifiedDiagonal);
612 #define OPENVDB_TOOLS_POISSON_LAPLACIAN_STENCIL 2 615 template<
typename VIdxTreeT,
typename BoundaryOp>
628 laplacian(&m), idxTree(&idx), boundaryOp(op), source(&src) {}
634 const int kNumOffsets = 6;
635 const Coord ijkOffset[kNumOffsets] = {
636 #if OPENVDB_TOOLS_POISSON_LAPLACIAN_STENCIL == 1 637 Coord(-1,0,0),
Coord(1,0,0),
Coord(0,-1,0),
Coord(0,1,0),
Coord(0,0,-1),
Coord(0,0,1)
639 Coord(-2,0,0),
Coord(2,0,0),
Coord(0,-2,0),
Coord(0,2,0),
Coord(0,0,-2),
Coord(0,0,2)
644 for (
typename VIdxLeafT::ValueOnCIter it = idxLeaf.cbeginValueOn(); it; ++it) {
645 assert(it.getValue() > -1);
647 const Coord ijk = it.getCoord();
652 ValueT modifiedDiagonal = 0.f;
655 for (
int dir = 0; dir < kNumOffsets; ++dir) {
656 const Coord neighbor = ijk + ijkOffset[dir];
661 #if OPENVDB_TOOLS_POISSON_LAPLACIAN_STENCIL == 1 662 const bool ijkIsInterior = (vectorIdx.
probeValue(neighbor + ijkOffset[dir], column)
665 const bool ijkIsInterior = vectorIdx.
probeValue(neighbor, column);
670 row.setValue(column, 1.f);
671 modifiedDiagonal -= 1.f;
675 boundaryOp(ijk, neighbor, source->at(rowNum), modifiedDiagonal);
679 row.setValue(rowNum, modifiedDiagonal);
687 template<
typename BoolTreeType>
688 inline LaplacianMatrix::Ptr
694 static_cast<math::pcg::SizeType>(idxTree.activeVoxelCount()));
700 template<
typename BoolTreeType,
typename BoundaryOp>
701 inline LaplacianMatrix::Ptr
703 const typename BoolTreeType::template ValueConverter<VIndex>::Type& idxTree,
705 const BoundaryOp& boundaryOp,
709 using VIdxTreeT =
typename BoolTreeType::template ValueConverter<VIndex>::Type;
713 const Index64 numDoF = idxTree.activeVoxelCount();
721 VIdxLeafMgrT idxLeafManager(idxTree);
727 laplacian, idxTree, boundaryOp, source));
737 template<
typename TreeType>
738 inline typename TreeType::Ptr
742 return solve(inTree, state, interrupter, staggered);
746 template<
typename TreeType,
typename Interrupter>
747 inline typename TreeType::Ptr
755 template<
typename TreeType,
typename BoundaryOp,
typename Interrupter>
756 inline typename TreeType::Ptr
761 return solveWithBoundaryConditionsAndPreconditioner<DefaultPrecondT>(
762 inTree, boundaryOp, state, interrupter, staggered);
767 typename PreconditionerType,
770 typename Interrupter>
771 inline typename TreeType::Ptr
773 const TreeType& inTree,
774 const BoundaryOp& boundaryOp,
776 Interrupter& interrupter,
779 return solveWithBoundaryConditionsAndPreconditioner<PreconditionerType>(
780 inTree, inTree, boundaryOp, state, interrupter, staggered);
784 typename PreconditionerType,
786 typename DomainTreeType,
788 typename Interrupter>
789 inline typename TreeType::Ptr
791 const TreeType& inTree,
792 const DomainTreeType& domainMask,
793 const BoundaryOp& boundaryOp,
795 Interrupter& interrupter,
798 using TreeValueT =
typename TreeType::ValueType;
801 using VIdxTreeT =
typename TreeType::template ValueConverter<VIndex>::Type;
802 using MaskTreeT =
typename TreeType::template ValueConverter<bool>::Type;
808 typename VectorT::Ptr b = createVectorFromTree<VecValueT>(inTree, *idxTree);
823 typename VectorT::Ptr x(
new VectorT(b->size(), zeroVal<VecValueT>()));
834 return createTreeFromVector<TreeValueT>(*x, *idxTree, zeroVal<TreeValueT>());
842 #endif // OPENVDB_TOOLS_POISSONSOLVER_HAS_BEEN_INCLUDED
Definition: ValueAccessor.h:193
Diagonal preconditioner.
Definition: ConjGradient.h:42
bool isValueOn(const Coord &xyz) const
Return the active state of the voxel at the given coordinates.
Definition: ValueAccessor.h:237
bool probeValue(const Coord &xyz, ValueType &value) const
Return the active state of the voxel as well as its value.
Definition: ValueAccessor.h:240
Sparse, square matrix representing a 3D stencil operator of size STENCIL_SIZE.
Definition: ConjGradient.h:39
Read/write accessor to a row of this matrix.
Definition: ConjGradient.h:419
Preconditioned conjugate gradient solver (solves Ax = b using the conjugate gradient method with one ...
Signed (x, y, z) 32-bit integer coordinates.
Definition: Coord.h:25
Index32 SizeType
Definition: ConjGradient.h:33
Coord offsetBy(Int32 dx, Int32 dy, Int32 dz) const
Definition: Coord.h:92
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:102
int32_t Int32
Definition: Types.h:33
Implementation of morphological dilation and erosion.
const ValueType & getValue(const Coord &xyz) const
Return the value of the voxel at the given coordinates.
Definition: ValueAccessor.h:230
Definition: Exceptions.h:13
Dummy NOOP interrupter class defining interface.
Definition: NullInterrupter.h:25
Preconditioner using incomplete Cholesky factorization.
Definition: ConjGradient.h:43
This class manages a linear array of pointers to a given tree's leaf nodes, as well as optional auxil...
Definition: LeafManager.h:82
ValueType_ ValueType
Definition: ConjGradient.h:240
Tag dispatch class that distinguishes topology copy constructors from deep copy constructors.
Definition: Types.h:681
Information about the state of a conjugate gradient solution.
Definition: ConjGradient.h:46
SharedPtr< SparseStencilMatrix > Ptr
Definition: ConjGradient.h:242
Lightweight, variable-length vector.
Definition: ConjGradient.h:37
uint64_t Index64
Definition: Types.h:30
SharedPtr< Preconditioner > Ptr
Definition: ConjGradient.h:468
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:154
A LeafManager manages a linear array of pointers to a given tree's leaf nodes, as well as optional au...
SharedPtr< Vector > Ptr
Definition: ConjGradient.h:142
virtual bool isValid() const
Definition: ConjGradient.h:473