Medical image analysis toolkit providing algorithms for segmentation, registration, and processing of medical images
—
ITK provides comprehensive support for mesh data structures and geometric processing operations. The mesh framework includes general meshes, advanced QuadEdge mesh topology, point sets, and various mesh processing algorithms.
General mesh structure supporting vertices, edges, and faces.
template<typename TPixelType, unsigned int VDimension>
class Mesh : public PointSet<TPixelType, VDimension>
{
public:
typedef Mesh Self;
typedef PointSet<TPixelType, VDimension> Superclass;
typedef SmartPointer<Self> Pointer;
typedef SmartPointer<const Self> ConstPointer;
static Pointer New();
// Cell management
void SetCell(CellIdentifier cellId, CellAutoPointer & cellPointer);
bool GetCell(CellIdentifier cellId, CellAutoPointer & cellPointer) const;
void SetCellData(CellIdentifier cellId, CellPixelType cellData);
bool GetCellData(CellIdentifier cellId, CellPixelType * cellData) const;
// Cell containers
void SetCells(CellsContainer * cells);
CellsContainer * GetCells();
const CellsContainer * GetCells() const;
void SetCellData(CellDataContainer * cellData);
CellDataContainer * GetCellData();
const CellDataContainer * GetCellData() const;
// Boundaries
void SetBoundaryAssignments(BoundaryAssignmentsContainer * boundaryAssignments);
BoundaryAssignmentsContainer * GetBoundaryAssignments();
const BoundaryAssignmentsContainer * GetBoundaryAssignments() const;
// Cell links
void SetCellLinks(CellLinksContainer * cellLinks);
CellLinksContainer * GetCellLinks();
const CellLinksContainer * GetCellLinks() const;
// Mesh queries
unsigned long GetNumberOfCells() const;
bool GetAssignedCellBoundaryIfOneExists(int dimension,
CellIdentifier cellId,
CellFeatureIdentifier featureId,
CellAutoPointer & boundaryPtr) const;
// Cell iteration
void SetCellsAllocationMethod(CellsAllocationMethodType cellsAllocationMethod);
CellsAllocationMethodType GetCellsAllocationMethod() const;
protected:
virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
virtual void ReleaseCellsMemory();
};Advanced mesh topology using QuadEdge data structure.
template<typename TPixel, unsigned int VDimension>
class QuadEdgeMesh : public Mesh<TPixel, VDimension>
{
public:
typedef QuadEdgeMesh Self;
typedef Mesh<TPixel, VDimension> Superclass;
typedef SmartPointer<Self> Pointer;
typedef SmartPointer<const Self> ConstPointer;
static Pointer New();
// Edge operations
QEPrimal * AddEdge(const PointIdentifier & orgPid, const PointIdentifier & destPid);
QEPrimal * AddEdgeWithSecurePointList(const PointIdentifier & orgPid, const PointIdentifier & destPid);
virtual QEPrimal * AddEdge(const PointType & orgPt, const PointType & destPt);
virtual void DeleteEdge(QEPrimal * e);
virtual void LightWeightDeleteEdge(EdgeCellType * edgeCell);
virtual void LightWeightDeleteEdge(QEPrimal * e);
// Face operations
QEPrimal * AddFace(const PointIdList & PointIdList);
QEPrimal * AddFaceWithSecurePointList(const PointIdList & PointIdList);
QEPrimal * AddFaceTriangle(const PointIdentifier & aPid,
const PointIdentifier & bPid,
const PointIdentifier & cPid);
void DeleteFace(FaceCellType * faceCell);
void LightWeightDeleteFace(FaceCellType * faceCell);
// Topology queries
bool FindEdge(const PointIdentifier & pid0, const PointIdentifier & pid1) const;
QEPrimal * FindEdge(const PointIdentifier & pid0, const PointIdentifier & pid1);
unsigned long GetNumberOfFaces() const;
unsigned long GetNumberOfEdges() const;
// Euler operations
PointIdentifier Splice(QEPrimal * a, QEPrimal * b);
void EulerOperatorJoinVertexInFaceSplitEdge(QEPrimal * e, QEPrimal * f);
void EulerOperatorSplitVertexInEdgeJoinFace(QEPrimal * e, QEPrimal * f);
void EulerOperatorDeleteCenterVertexInTriangularFaceSplitEdge(QEPrimal * e);
// Mesh validation
bool CheckEdge(QEPrimal * e) const;
virtual void DeletePoint(const PointIdentifier & pid);
virtual void DeleteEdge(const PointIdentifier & orgPid, const PointIdentifier & destPid);
protected:
virtual void CopyInformation(const DataObject * data) ITK_OVERRIDE;
virtual void Graft(const DataObject * data) ITK_OVERRIDE;
};Base class for point cloud data structures.
template<typename TPixelType, unsigned int VDimension>
class PointSet : public DataObject
{
public:
typedef PointSet Self;
typedef DataObject Superclass;
typedef SmartPointer<Self> Pointer;
typedef SmartPointer<const Self> ConstPointer;
static Pointer New();
// Point management
void SetPoint(PointIdentifier pointId, PointType point);
bool GetPoint(PointIdentifier pointId, PointType * point) const;
PointType GetPoint(PointIdentifier pointId) const;
// Point data
void SetPointData(PointIdentifier pointId, PixelType data);
bool GetPointData(PointIdentifier pointId, PixelType * data) const;
PixelType GetPointData(PointIdentifier pointId) const;
// Container access
void SetPoints(PointsContainer * points);
PointsContainer * GetPoints();
const PointsContainer * GetPoints() const;
void SetPointData(PointDataContainer * pointData);
PointDataContainer * GetPointData();
const PointDataContainer * GetPointData() const;
// Point queries
PointIdentifier GetNumberOfPoints() const;
bool RequestedRegionIsOutsideOfTheBufferedRegion() ITK_OVERRIDE;
void Initialize() ITK_OVERRIDE;
// Bounding box
const BoundingBoxType * GetBoundingBox() const;
protected:
virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
virtual void PassThroughInformation(const DataObject * inputPointSet);
virtual void DeepCopy(const DataObject * inputPointSet);
};Base interface for mesh cells (vertices, edges, faces).
template<typename TPixelType, typename TCellTraits>
class CellInterface
{
public:
typedef CellInterface Self;
typedef TPixelType PixelType;
typedef TCellTraits CellTraits;
// Cell type information
virtual CellGeometry GetType() const = 0;
virtual void MakeCopy(CellAutoPointer & cell) const = 0;
virtual unsigned int GetDimension() const = 0;
virtual unsigned int GetInterpolationOrder() const;
virtual unsigned int GetNumberOfPoints() const = 0;
virtual unsigned int GetNumberOfBoundaryFeatures(int dimension) const = 0;
virtual bool GetBoundaryFeature(int dimension, CellFeatureIdentifier featureId,
CellAutoPointer & cell) = 0;
// Point list access
virtual void SetPointIds(PointIdConstIterator first) = 0;
virtual void SetPointIds(PointIdConstIterator first, PointIdConstIterator last) = 0;
virtual void SetPointId(int localId, PointIdentifier ptId) = 0;
virtual PointIdIterator PointIdsBegin() = 0;
virtual PointIdConstIterator PointIdsBegin() const = 0;
virtual PointIdIterator PointIdsEnd() = 0;
virtual PointIdConstIterator PointIdsEnd() const = 0;
// Visiting and evaluation
virtual bool EvaluatePosition(CoordRepType * position,
PointsContainer * points,
CoordRepType * closestPoint,
CoordRepType pcoords[],
double * dist2,
InterpolationWeightType * weights) = 0;
virtual void EvaluateShapeFunctions(const ParametricCoordArrayType & parametricCoordinates,
ShapeFunctionsArrayType & weights) const = 0;
// Destruction
virtual ~CellInterface() {}
};Triangle cell for 2D mesh faces.
template<typename TCellInterface>
class TriangleCell : public TCellInterface
{
public:
typedef TriangleCell Self;
typedef TCellInterface Superclass;
typedef typename Superclass::PixelType PixelType;
typedef typename Superclass::CellType CellType;
typedef typename Superclass::CellAutoPointer CellAutoPointer;
typedef typename Superclass::CellConstAutoPointer CellConstAutoPointer;
typedef typename Superclass::CellRawPointer CellRawPointer;
typedef typename Superclass::CellConstRawPointer CellConstRawPointer;
// Cell type information
itkCellCommonTypedefs(TriangleCell);
itkCellInheritedTypedefs(TCellInterface);
itkTypeMacro(TriangleCell, CellInterface);
// Overridden methods
virtual CellGeometry GetType() const ITK_OVERRIDE { return Superclass::TRIANGLE_CELL; }
virtual void MakeCopy(CellAutoPointer & cell) const ITK_OVERRIDE;
virtual unsigned int GetDimension() const ITK_OVERRIDE { return 2; }
virtual unsigned int GetNumberOfPoints() const ITK_OVERRIDE { return 3; }
virtual unsigned int GetNumberOfBoundaryFeatures(int dimension) const ITK_OVERRIDE;
virtual bool GetBoundaryFeature(int dimension, CellFeatureIdentifier featureId,
CellAutoPointer & cell) ITK_OVERRIDE;
// Point management
virtual void SetPointIds(PointIdConstIterator first) ITK_OVERRIDE;
virtual void SetPointIds(PointIdConstIterator first, PointIdConstIterator last) ITK_OVERRIDE;
virtual void SetPointId(int localId, PointIdentifier ptId) ITK_OVERRIDE;
// Shape functions
virtual void EvaluateShapeFunctions(const ParametricCoordArrayType & parametricCoordinates,
ShapeFunctionsArrayType & weights) const ITK_OVERRIDE;
// Area computation
virtual CoordRepType ComputeArea(PointsContainer * points);
// Constructors
TriangleCell();
~TriangleCell() {}
protected:
PointIdentifier m_PointIds[3];
};Tetrahedron cell for 3D mesh elements.
template<typename TCellInterface>
class TetrahedronCell : public TCellInterface
{
public:
typedef TetrahedronCell Self;
typedef TCellInterface Superclass;
// Cell type information
itkCellCommonTypedefs(TetrahedronCell);
itkCellInheritedTypedefs(TCellInterface);
itkTypeMacro(TetrahedronCell, CellInterface);
// Overridden methods
virtual CellGeometry GetType() const ITK_OVERRIDE { return Superclass::TETRAHEDRON_CELL; }
virtual void MakeCopy(CellAutoPointer & cell) const ITK_OVERRIDE;
virtual unsigned int GetDimension() const ITK_OVERRIDE { return 3; }
virtual unsigned int GetNumberOfPoints() const ITK_OVERRIDE { return 4; }
virtual unsigned int GetNumberOfBoundaryFeatures(int dimension) const ITK_OVERRIDE;
virtual bool GetBoundaryFeature(int dimension, CellFeatureIdentifier featureId,
CellAutoPointer & cell) ITK_OVERRIDE;
// Point management
virtual void SetPointIds(PointIdConstIterator first) ITK_OVERRIDE;
virtual void SetPointIds(PointIdConstIterator first, PointIdConstIterator last) ITK_OVERRIDE;
virtual void SetPointId(int localId, PointIdentifier ptId) ITK_OVERRIDE;
// Shape functions
virtual void EvaluateShapeFunctions(const ParametricCoordArrayType & parametricCoordinates,
ShapeFunctionsArrayType & weights) const ITK_OVERRIDE;
// Volume computation
virtual CoordRepType ComputeVolume(PointsContainer * points);
// Constructors
TetrahedronCell();
~TetrahedronCell() {}
protected:
PointIdentifier m_PointIds[4];
};Converts binary masks to narrow band point sets.
template<typename TInputImage, typename TOutputMesh>
class BinaryMaskToNarrowBandPointSetFilter : public ImageToMeshFilter<TInputImage, TOutputMesh>
{
public:
typedef BinaryMaskToNarrowBandPointSetFilter Self;
typedef ImageToMeshFilter<TInputImage, TOutputMesh> Superclass;
typedef SmartPointer<Self> Pointer;
typedef SmartPointer<const Self> ConstPointer;
static Pointer New();
// Band width control
void SetBandWidth(float bandWidth);
itkGetConstMacro(BandWidth, float);
// Distance computation
void SetDistanceFromObject(float distanceFromObject);
itkGetConstMacro(DistanceFromObject, float);
protected:
virtual void GenerateData() ITK_OVERRIDE;
virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
};Base class for mesh-to-mesh processing filters.
template<typename TInputMesh, typename TOutputMesh>
class MeshToMeshFilter : public MeshSource<TOutputMesh>
{
public:
typedef MeshToMeshFilter Self;
typedef MeshSource<TOutputMesh> Superclass;
typedef SmartPointer<Self> Pointer;
typedef SmartPointer<const Self> ConstPointer;
// Input handling
using Superclass::SetInput;
void SetInput(const InputMeshType * input);
const InputMeshType * GetInput() const;
const InputMeshType * GetInput(unsigned int idx) const;
protected:
virtual void GenerateInputRequestedRegion() ITK_OVERRIDE;
virtual void CopyInputMeshToOutputMeshPoints();
virtual void CopyInputMeshToOutputMeshPointData();
virtual void CopyInputMeshToOutputMeshCells();
virtual void CopyInputMeshToOutputMeshCellData();
};Converts triangle meshes to simplex meshes.
template<typename TInputMesh, typename TOutputMesh>
class TriangleMeshToSimplexMeshFilter : public MeshToMeshFilter<TInputMesh, TOutputMesh>
{
public:
typedef TriangleMeshToSimplexMeshFilter Self;
typedef MeshToMeshFilter<TInputMesh, TOutputMesh> Superclass;
typedef SmartPointer<Self> Pointer;
typedef SmartPointer<const Self> ConstPointer;
static Pointer New();
protected:
virtual void GenerateData() ITK_OVERRIDE;
virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
void Initialize();
void CreateSimplexPoints();
void CreateEdgeForTrianglePair(CellIdentifier pointIndex, CellIdentifier boundaryId);
void CreateSimplexNeighbors();
void CreateCells();
};Spatial object representation of meshes.
template<typename TMesh>
class MeshSpatialObject : public SpatialObject<TMesh::PointDimension>
{
public:
typedef MeshSpatialObject Self;
typedef SpatialObject<TMesh::PointDimension> Superclass;
typedef SmartPointer<Self> Pointer;
typedef SmartPointer<const Self> ConstPointer;
static Pointer New();
// Mesh access
void SetMesh(MeshType * mesh);
MeshType * GetMesh();
const MeshType * GetMesh() const;
// Bounding box computation
virtual bool ComputeLocalBoundingBox() const ITK_OVERRIDE;
// Spatial object queries
virtual bool IsEvaluableAt(const PointType & point,
unsigned int depth = 0,
char * name = ITK_NULLPTR) const ITK_OVERRIDE;
virtual bool ValueAt(const PointType & point, double & value,
unsigned int depth = 0,
char * name = ITK_NULLPTR) const ITK_OVERRIDE;
virtual bool IsInside(const PointType & point,
unsigned int depth,
char * name) const ITK_OVERRIDE;
protected:
virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
};Extended traits for QuadEdge meshes with additional data.
template<typename TPixelType, unsigned int VPointDimension, typename TPData, typename TDData,
typename TCoordRep, typename TInterpolationWeightType>
class QuadEdgeMeshExtendedTraits
{
public:
typedef TPixelType PixelType;
typedef TCoordRep CoordRepType;
typedef TInterpolationWeightType InterpolationWeightType;
itkStaticConstMacro(PointDimension, unsigned int, VPointDimension);
itkStaticConstMacro(MaxTopologicalDimension, unsigned int, VPointDimension);
typedef TPData PrimalDataType;
typedef TDData DualDataType;
typedef GeometricalQuadEdge<PrimalDataType, DualDataType, true, true> QEPrimal;
typedef typename QEPrimal::DualType QEDual;
typedef typename QEPrimal::OriginRefType QEOriginRefType;
// Points
typedef Point<CoordRepType, VPointDimension> PointType;
typedef MapContainer<PointIdentifier, PointType> PointsContainer;
typedef PointsContainer::Iterator PointsContainerIterator;
typedef PointsContainer::ConstIterator PointsContainerConstIterator;
// Cells
typedef QuadEdgeMeshLineCell<CellType> LineCellType;
typedef QuadEdgeMeshPolygonCell<CellType> PolygonCellType;
typedef MapContainer<CellIdentifier, CellType *> CellsContainer;
typedef CellsContainer::Iterator CellsContainerIterator;
typedef CellsContainer::ConstIterator CellsContainerConstIterator;
// Cell data
typedef MapContainer<CellIdentifier, PixelType> CellDataContainer;
typedef CellDataContainer::Iterator CellDataContainerIterator;
typedef CellDataContainer::ConstIterator CellDataContainerConstIterator;
};// Define mesh type
typedef itk::Mesh<float, 3> MeshType;
MeshType::Pointer mesh = MeshType::New();
// Add points
MeshType::PointType point;
point[0] = 0.0; point[1] = 0.0; point[2] = 0.0;
mesh->SetPoint(0, point);
point[0] = 1.0; point[1] = 0.0; point[2] = 0.0;
mesh->SetPoint(1, point);
point[0] = 0.5; point[1] = 1.0; point[2] = 0.0;
mesh->SetPoint(2, point);
// Create triangle cell
typedef MeshType::CellType CellType;
typedef itk::TriangleCell<CellType> TriangleCellType;
CellType::CellAutoPointer triangle;
triangle.TakeOwnership(new TriangleCellType);
// Set triangle vertices
triangle->SetPointId(0, 0);
triangle->SetPointId(1, 1);
triangle->SetPointId(2, 2);
// Add triangle to mesh
mesh->SetCell(0, triangle);
std::cout << "Number of points: " << mesh->GetNumberOfPoints() << std::endl;
std::cout << "Number of cells: " << mesh->GetNumberOfCells() << std::endl;// Define QuadEdge mesh type
typedef itk::QuadEdgeMesh<float, 3> QEMeshType;
QEMeshType::Pointer qeMesh = QEMeshType::New();
// Add points
QEMeshType::PointType p0, p1, p2, p3;
p0[0] = 0.0; p0[1] = 0.0; p0[2] = 0.0;
p1[0] = 1.0; p1[1] = 0.0; p1[2] = 0.0;
p2[0] = 1.0; p2[1] = 1.0; p2[2] = 0.0;
p3[0] = 0.0; p3[1] = 1.0; p3[2] = 0.0;
QEMeshType::PointIdentifier pid0 = qeMesh->AddPoint(p0);
QEMeshType::PointIdentifier pid1 = qeMesh->AddPoint(p1);
QEMeshType::PointIdentifier pid2 = qeMesh->AddPoint(p2);
QEMeshType::PointIdentifier pid3 = qeMesh->AddPoint(p3);
// Add triangular faces
qeMesh->AddFaceTriangle(pid0, pid1, pid2);
qeMesh->AddFaceTriangle(pid0, pid2, pid3);
std::cout << "Number of points: " << qeMesh->GetNumberOfPoints() << std::endl;
std::cout << "Number of faces: " << qeMesh->GetNumberOfFaces() << std::endl;
std::cout << "Number of edges: " << qeMesh->GetNumberOfEdges() << std::endl;// Common mesh instantiations
typedef Mesh<float, 2> Mesh2D;
typedef Mesh<float, 3> Mesh3D;
typedef Mesh<double, 2> DoubleMesh2D;
typedef Mesh<double, 3> DoubleMesh3D;
typedef QuadEdgeMesh<float, 2> QEMesh2D;
typedef QuadEdgeMesh<float, 3> QEMesh3D;
typedef QuadEdgeMesh<double, 2> QEDoubleMesh2D;
typedef QuadEdgeMesh<double, 3> QEDoubleMesh3D;
typedef PointSet<float, 2> PointSet2D;
typedef PointSet<float, 3> PointSet3D;
// Cell types
typedef TriangleCell<CellInterface<float, CellTraitsInfo<2>>> TriangleCell2D;
typedef TriangleCell<CellInterface<float, CellTraitsInfo<3>>> TriangleCell3D;
typedef TetrahedronCell<CellInterface<float, CellTraitsInfo<3>>> TetrahedronCell3D;
typedef LineCell<CellInterface<float, CellTraitsInfo<2>>> LineCell2D;
typedef LineCell<CellInterface<float, CellTraitsInfo<3>>> LineCell3D;
// Container types
typedef MapContainer<PointIdentifier, Point<float, 2>> PointsContainer2D;
typedef MapContainer<PointIdentifier, Point<float, 3>> PointsContainer3D;
typedef MapContainer<CellIdentifier, CellInterface<float, CellTraitsInfo<2>> *> CellsContainer2D;
typedef MapContainer<CellIdentifier, CellInterface<float, CellTraitsInfo<3>> *> CellsContainer3D;
// Identifiers
typedef unsigned long PointIdentifier;
typedef unsigned long CellIdentifier;
typedef unsigned long CellFeatureIdentifier;
// Cell geometry types
enum CellGeometry {
VERTEX_CELL = 0,
LINE_CELL = 1,
TRIANGLE_CELL = 2,
QUADRILATERAL_CELL = 3,
POLYGON_CELL = 4,
TETRAHEDRON_CELL = 5,
HEXAHEDRON_CELL = 6,
QUADRATIC_EDGE_CELL = 7,
QUADRATIC_TRIANGLE_CELL = 8,
LAST_ITK_CELL,
MAX_ITK_CELLS = 255
};ITK's mesh processing framework provides comprehensive support for geometric data structures and processing operations, enabling sophisticated mesh-based analysis and modeling in medical imaging applications.
Install with Tessl CLI
npx tessl i tessl/cmake-itk