HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PoissonSolver.h File Reference

Solve Poisson's equation ∇2x = b for x, where b is a vector comprising the values of all of the active voxels in a grid. More...

#include <openvdb/Types.h>
#include <openvdb/math/ConjGradient.h>
#include <openvdb/tree/LeafManager.h>
#include <openvdb/tree/Tree.h>
#include <openvdb/util/NullInterrupter.h>
#include "Morphology.h"
#include <hboost/scoped_array.hpp>
+ Include dependency graph for PoissonSolver.h:

Go to the source code of this file.

Classes

struct  openvdb::OPENVDB_VERSION_NAME::tools::poisson::internal::LeafCountOp< LeafType >
 Functor for use with LeafManager::foreach() to populate an array with per-leaf active voxel counts. More...
 
struct  openvdb::OPENVDB_VERSION_NAME::tools::poisson::internal::LeafIndexOp< LeafType >
 Functor for use with LeafManager::foreach() to populate active leaf voxels with sequential indices. More...
 
struct  openvdb::OPENVDB_VERSION_NAME::tools::poisson::internal::CopyToVecOp< VectorValueType, SourceTreeType >
 Functor for use with LeafManager::foreach() to populate a vector with the values of a tree's active voxels. More...
 
struct  openvdb::OPENVDB_VERSION_NAME::tools::poisson::internal::CopyFromVecOp< TreeValueType, VIndexTreeType, VectorValueType >
 Functor for use with LeafManager::foreach() to populate a tree with values from a vector. More...
 
struct  openvdb::OPENVDB_VERSION_NAME::tools::poisson::internal::DirichletOp< ValueType >
 Constant boundary condition functor. More...
 
struct  openvdb::OPENVDB_VERSION_NAME::tools::poisson::internal::ISLaplacianOp< BoolTreeType, BoundaryOp >
 Functor for use with LeafManager::foreach() to populate a sparse Laplacian matrix. More...
 

Namespaces

 openvdb
 
 openvdb::OPENVDB_VERSION_NAME
 
 openvdb::OPENVDB_VERSION_NAME::tools
 
 openvdb::OPENVDB_VERSION_NAME::tools::poisson
 
 openvdb::OPENVDB_VERSION_NAME::tools::poisson::internal
 

Typedefs

typedef Int32 openvdb::OPENVDB_VERSION_NAME::tools::poisson::VIndex
 
typedef
math::pcg::SparseStencilMatrix
< double, 7 > 
openvdb::OPENVDB_VERSION_NAME::tools::poisson::LaplacianMatrix
 The type of a matrix used to represent a three-dimensional Laplacian operator. More...
 

Functions

template<typename TreeType >
TreeType::Ptr openvdb::OPENVDB_VERSION_NAME::tools::poisson::solve (const TreeType &, math::pcg::State &)
 Solve ∇2x = b for x, where b is a vector comprising the values of all of the active voxels in the input tree. More...
 
template<typename TreeType , typename Interrupter >
TreeType::Ptr openvdb::OPENVDB_VERSION_NAME::tools::poisson::solve (const TreeType &, math::pcg::State &, Interrupter &)
 Solve ∇2x = b for x, where b is a vector comprising the values of all of the active voxels in the input tree. More...
 
template<typename TreeType , typename BoundaryOp , typename Interrupter >
TreeType::Ptr openvdb::OPENVDB_VERSION_NAME::tools::poisson::solveWithBoundaryConditions (const TreeType &, const BoundaryOp &, math::pcg::State &, Interrupter &)
 Solve ∇2x = b for x with user-specified boundary conditions, where b is a vector comprising the values of all of the active voxels in the input tree or domain mask if provided. More...
 
template<typename PreconditionerType , typename TreeType , typename BoundaryOp , typename Interrupter >
TreeType::Ptr openvdb::OPENVDB_VERSION_NAME::tools::poisson::solveWithBoundaryConditionsAndPreconditioner (const TreeType &, const BoundaryOp &, math::pcg::State &, Interrupter &)
 Solve ∇2x = b for x with user-specified boundary conditions, where b is a vector comprising the values of all of the active voxels in the input tree or domain mask if provided. More...
 
template<typename PreconditionerType , typename TreeType , typename DomainTreeType , typename BoundaryOp , typename Interrupter >
TreeType::Ptr openvdb::OPENVDB_VERSION_NAME::tools::poisson::solveWithBoundaryConditionsAndPreconditioner (const TreeType &, const DomainTreeType &, const BoundaryOp &, math::pcg::State &, Interrupter &)
 
Low-level functions
template<typename VIndexTreeType >
void openvdb::OPENVDB_VERSION_NAME::tools::poisson::populateIndexTree (VIndexTreeType &)
 Overwrite each active voxel in the given scalar tree with a sequential index, starting from zero. More...
 
template<typename TreeType >
TreeType::template
ValueConverter< VIndex >
::Type::Ptr 
openvdb::OPENVDB_VERSION_NAME::tools::poisson::createIndexTree (const TreeType &)
 Iterate over the active voxels of the input tree and for each one assign its index in the iteration sequence to the corresponding voxel of an integer-valued output tree. More...
 
template<typename VectorValueType , typename SourceTreeType >
math::pcg::Vector
< VectorValueType >::Ptr 
openvdb::OPENVDB_VERSION_NAME::tools::poisson::createVectorFromTree (const SourceTreeType &source, const typename SourceTreeType::template ValueConverter< VIndex >::Type &index)
 Return a vector of the active voxel values of the scalar-valued source tree. More...
 
template<typename TreeValueType , typename VIndexTreeType , typename VectorValueType >
VIndexTreeType::template
ValueConverter< TreeValueType >
::Type::Ptr 
openvdb::OPENVDB_VERSION_NAME::tools::poisson::createTreeFromVector (const math::pcg::Vector< VectorValueType > &values, const VIndexTreeType &index, const TreeValueType &background)
 Return a tree with the same active voxel topology as the index tree but whose voxel values are taken from the the given vector. More...
 
template<typename BoolTreeType >
LaplacianMatrix::Ptr openvdb::OPENVDB_VERSION_NAME::tools::poisson::createISLaplacian (const typename BoolTreeType::template ValueConverter< VIndex >::Type &vectorIndexTree, const BoolTreeType &interiorMask)
 Generate a sparse matrix of the index-space (Δx = 1) Laplacian operator using second-order finite differences. More...
 
template<typename BoolTreeType , typename BoundaryOp >
LaplacianMatrix::Ptr openvdb::OPENVDB_VERSION_NAME::tools::poisson::createISLaplacianWithBoundaryConditions (const typename BoolTreeType::template ValueConverter< VIndex >::Type &vectorIndexTree, const BoolTreeType &interiorMask, const BoundaryOp &boundaryOp, typename math::pcg::Vector< LaplacianMatrix::ValueType > &source)
 Generate a sparse matrix of the index-space (Δx = 1) Laplacian operator with user-specified boundary conditions using second-order finite differences. More...
 

Detailed Description

Solve Poisson's equation ∇2x = b for x, where b is a vector comprising the values of all of the active voxels in a grid.

Authors
D.J. Hill, Peter Cucka
Example:
Solve for the pressure in a cubic tank of liquid, assuming uniform boundary conditions:
FloatTree source(/*background=*/0.0f);
// Activate voxels to indicate that they contain liquid.
source.fill(CoordBBox(Coord(0, -10, 0), Coord(10, 0, 10)), /*value=*/0.0f);
math::pcg::State state = math::pcg::terminationDefaults<float>();
FloatTree::Ptr solution = tools::poisson::solve(source, state);
Example:
Solve for the pressure, P, in a cubic tank of liquid that is open at the top. Boundary conditions are P = 0 at the top, ∂P/∂y = −1 at the bottom and ∂P/∂x = 0 at the sides:
               P = 0
            +--------+ (N,0,N)
           /|       /|
  (0,0,0) +--------+ |
          | |      | | dP/dx = 0
dP/dx = 0 | +------|-+
          |/       |/
 (0,-N,0) +--------+ (N,-N,N)
          dP/dy = -1
const int N = 10;
DoubleTree source(/*background=*/0.0);
// Activate voxels to indicate that they contain liquid.
source.fill(CoordBBox(Coord(0, -N, 0), Coord(N, 0, N)), /*value=*/0.0);
// C++11
auto boundary = [](const openvdb::Coord& ijk, const openvdb::Coord& neighbor,
double& source, double& diagonal)
{
if (neighbor.x() == ijk.x() && neighbor.z() == ijk.z()) {
if (neighbor.y() < ijk.y()) source -= 1.0;
else diagonal -= 1.0;
}
};
math::pcg::State state = math::pcg::terminationDefaults<double>();
util::NullInterrupter interrupter;
source, boundary, state, interrupter);

Definition in file PoissonSolver.h.