Calculate Area and Volume of Simplex Mesh#

Synopsis#

Calculate the area and volume of an itk::SimplexMesh.

Results#

Output:

Ideal Volume: 523.599
Mesh Volume: 520.812
Ideal Surface Area: 314.159
Mesh Surface Area: 313.1

Code#

C++#

#define _USE_MATH_DEFINES // needed for Visual Studio (before #include <cmath>)
#include <itkSimplexMesh.h>
#include <itkRegularSphereMeshSource.h>
#include <itkTriangleMeshToSimplexMeshFilter.h>
#include <itkSimplexMeshVolumeCalculator.h>

using TMesh = itk::Mesh<float, 3>;
using TSimplex = itk::SimplexMesh<float, 3>;
using TSphere = itk::RegularSphereMeshSource<TMesh>;
using TConvert = itk::TriangleMeshToSimplexMeshFilter<TMesh, TSimplex>;
using TVolume = itk::SimplexMeshVolumeCalculator<TSimplex>;

int
main()
{

  // Create a spherical mesh with known radius and resolution.
  auto                source = TSphere::New();
  TSphere::VectorType scale;
  scale.Fill(5.0);
  source->SetScale(scale);
  source->SetResolution(5);
  source->Update();

  // Ensure that all cells of the mesh are triangles.
  for (TMesh::CellsContainerIterator it = source->GetOutput()->GetCells()->Begin();
       it != source->GetOutput()->GetCells()->End();
       ++it)
  {
    TMesh::CellAutoPointer cell;
    source->GetOutput()->GetCell(it->Index(), cell);
    if (3 != cell->GetNumberOfPoints())
    {
      std::cerr << "ERROR: All cells must be trianglar." << std::endl;
      return EXIT_FAILURE;
    }
  }

  // Convert the triangle mesh to a simplex mesh.
  auto convert = TConvert::New();
  convert->SetInput(source->GetOutput());
  convert->Update();

  // Calculate the volume and area of the simplex mesh.
  auto volume = TVolume::New();
  volume->SetSimplexMesh(convert->GetOutput());
  volume->Compute();

  // Compare with the volume and area of an ideal sphere.
  std::cout << "Ideal Volume: " << 4.0 / 3.0 * M_PI * pow(5.0, 3) << std::endl;
  std::cout << "Mesh Volume: " << volume->GetVolume() << std::endl;
  std::cout << "Ideal Surface Area: " << 4.0 * M_PI * pow(5.0, 2) << std::endl;
  std::cout << "Mesh Surface Area: " << volume->GetArea() << std::endl;

  return EXIT_SUCCESS;
}

Classes demonstrated#

template<typename TInputMesh>
class SimplexMeshVolumeCalculator : public itk::Object

Adapted from itkSimplexMeshToTriangleFilter to calculate the volume of a simplex mesh using the barycenters and normals. call Compute() to calculate the volume and GetVolume() to get the value. For an example see itkDeformableSimplexMesh3DFilter.cxx (Thomas Boettger. Division Medical and Biological Informatics, German Cancer Research Center, Heidelberg.)

The original implementation has been replaced with an algorithm based on the discrete form of the divergence theorem. The general assumption here is that the model is of closed surface. For more details see the following reference (Alyassin A.M. et al, “Evaluation of new algorithms for the interactive measurement of

surface area and volume”, Med Phys 21(6) 1994.).

Author

Leila Baghdadi MICe, Hospital for Sick Children, Toronto, Canada.

ITK Sphinx Examples:

See itk::SimplexMeshVolumeCalculator for additional documentation.