Introducing a new way to review your PRs.

Read the announcement

insightsoftwareconsortium / itk

Insight Toolkit (ITK) -- Official Repository. ITK builds on a proven, spatially-oriented architecture for processing, segmentation, and registration of scientific images in two, three, or more dimensions.

View on GitHub

19 documents · Updated Nov 23, 2026

docs / mesh-and-spatial-objects

Meshes and spatial objects

ITK represents geometric data as meshes, paths, and spatial objects. These data objects preserve shape, position, topology, and optional data while allowing filters to turn them into images, point sets, or other geometric objects in a processing pipeline.

Mesh representation

The mesh is an N-dimensional geometric model built from points and cells. Points hold locations and optional point data. Cells describe connectivity and can represent vertices, lines, polygons, triangles, tetrahedra, and other supported shapes. Cell data and boundary assignments can add information to the same geometric model. (Core data model)

Mesh structure

home/…/itkMesh.h defines the general mesh model. A mesh can keep links from points to the cells that use them. It can also derive neighboring features from cell-point use or store boundary links when explicit topology is needed.

The mesh model separates geometric points from cell connectivity. This lets a filter change point positions without changing the shape of the cells. It also lets filters preserve or copy point data, cell data, and links as separate parts of the mesh state.

The mesh topology child page covers the rules for cells, links, boundaries, and neighborhood access.

References: Modules/…/itkMesh.h• L57-83 Modules/…/itkMesh.h• L286-323 Modules/…/itkMesh.h• L326-367

Mesh pipeline operations

Mesh processing uses MeshSource as the common output interface. A mesh source produces a mesh data object that can connect to the next process. MeshToMeshFilter adds the matching input interface for filters that read one mesh and produce another. Its wrapped interface covers matching scalar mesh types across the supported image dimensions, so mesh-to-mesh processing can cross the language boundary for those types. (Modules/Core/Mesh/wrapping/itkMeshToMeshFilter.wrap#L4-L10)

Image-to-mesh filters provide the other common entry point. They turn image data into a geometric model. The reverse direction is also supported by filters that rasterize a mesh into an image, such as a binary image made from triangle geometry.

A transform mesh filter changes all mesh point locations and keeps the mesh connectivity and attached data unchanged. Data that describes direction or orientation, such as point normals, needs a separate matching update.

Wrapped mesh objects can also cross a Python persistence boundary without losing their geometry, cell connectivity, object name, or attached point and cell data. The same boundary supports exchange with VTK polygon meshes when the optional VTK package is available. (Modules/…/itkMeshSerializationTest.py• L81-129, Modules/…/itkMeshSerializationTest.py• L135-220)

References: Modules/…/itkMeshSource.h• L36-49 Modules/…/itkMeshSource.h• L73-123 Modules/…/itkMeshToMeshFilter.h• L35-47 Modules/…/itkMeshToMeshFilter.wrap• L4-10 Modules/…/itkImageToMeshFilter.h• L25-36 Modules/…/itkTriangleMeshToBinaryImageFilter.h• L63-72 Modules/…/itkTransformMeshFilter.h• L26-42 Modules/…/itkMeshSerializationTest.py• L81-129 Modules/…/itkMeshSerializationTest.py• L135-220

Quad-edge mesh topology

The quad-edge mesh is a mesh form for 2D manifolds embedded in N-dimensional space. It adds direct relationships between primal edges, their dual edges, vertices, and faces so that surface topology can be walked and changed.

Quad-edge structure

home/…/itkQuadEdgeMesh.h extends the general mesh with quad-edge storage. The base QuadEdge relation keeps an origin-edge ring and a rotation ring. Derived accessors use these rings to reach the symmetric edge and to move around an origin, destination, left face, right face, or dual edge. GeometricalQuadEdge adds the geometric identity of those relationships, so a quad-edge can carry its origin and face references as well as its topological links.

The geometric edge view distinguishes primal edges from their dual edges. It can identify wire edges, border edges, and internal edges from the face information on each side. These states give surface algorithms a common way to relate local topology to the geometry of the mesh.

This representation is useful when surface algorithms need direct adjacency. It supports boundary components as edge walks rather than requiring each neighborhood to be rebuilt from cell-point sets.

References: Modules/…/itkQuadEdgeMesh.h• L39-53 Modules/…/itkQuadEdgeMesh.h• L132-161 Modules/…/itkQuadEdge.h• L120-137 Modules/…/itkQuadEdge.h• L175-245 Modules/…/itkQuadEdge.h• L249-428 Modules/…/itkGeometricalQuadEdge.h• L25-47 Modules/…/itkGeometricalQuadEdge.h• L119-211

Topology operations

Quad-edge functions provide local changes to a surface. Their operations can flip, split, join, create, or delete edges, vertices, and faces. These changes update the relationships that make the surface walkable. The geometric edge layer keeps the corresponding origin, destination, and face references aligned with those relationships. QuadEdgeMeshFunctionBase provides a lightweight function-object path for these small edits, so repeated local changes do not require the full mesh-copy pattern used by large filter operations.

The base QuadEdge::Splice operation changes connectivity only and does not know the geometric state held by GeometricalQuadEdge. Surface edits should use the geometry-aware mesh operation when geometric references must stay aligned. (Modules/…/itkQuadEdge.h• L215-247)

Topology checks provide a gate before or after such changes. The checker looks for isolated vertices and edges and can validate the expected Euler characteristic, number of boundaries, and genus. Boundary-edge queries return one representative edge for each boundary component.

Detailed adjacency rules and local topology changes belong in the mesh topology child page.

References: Modules/…/itkQuadEdgeMeshFunctionBase.h• L27-49 Modules/…/itkQuadEdgeMeshFunctionBase.h• L69-99 Modules/…/itkQuadEdgeMeshEulerOperatorFlipEdgeFunction.h• L54-69 Modules/…/itkQuadEdgeMeshTopologyChecker.h• L25-42 Modules/…/itkQuadEdgeMeshTopologyChecker.h• L66-78 Modules/…/itkQuadEdgeMeshBoundaryEdgesMeshFunction.h• L25-34 Modules/…/itkGeometricalQuadEdge.h• L144-173 Modules/…/itkGeometricalQuadEdge.h• L275-304 Modules/…/itkQuadEdge.h• L215-247

Path representation

A path represents a one-dimensional route through an N-dimensional image or physical space. It maps a path parameter, such as a step number or arc length, to a location and can guide image traversal or carry a contour through a pipeline.

Path model

home/…/itkPath.h defines the common path contract. A path supplies a start and end parameter, evaluates a location, converts that location to an image index, and advances to the next connected index.

ParametricPath uses a floating-point parameter and returns a continuous image index. It supports open paths and closed loops. PolyLineParametricPath is a concrete form made from ordered vertices and line segments. Other path forms can use chain codes, Fourier descriptions, or other curve models while keeping the same path role.

References: Modules/…/itkPath.h• L27-45 Modules/…/itkPath.h• L81-116 Modules/…/itkParametricPath.h• L29-45 Modules/…/itkPolyLineParametricPath.h• L27-43

Path image exchange

Path filters connect geometric routes with image processing. An image-to-path filter extracts a path from an image. ContourExtractor2DImageFilter is a 2D example: it follows an intensity level or separate labels and returns one or more oriented polyline contours with sub-pixel positions. Contours that meet the image edge remain open, while other contours are closed. (Modules/…/itkContourExtractor2DImageFilter.h• L33-89)

Contour extraction also defines how ambiguous diagonal pixels connect and whether the output orientation follows or reverses the image gradient. The filter can process the full input region or a selected region, so the chosen image area affects which contour parts are produced. (Modules/…/itkContourExtractor2DImageFilter.h• L50-89, Modules/…/itkContourExtractor2DImageFilter.h• L163-199)

A path-to-image filter marks a path in a new image and can use the path bounds to choose a default output extent. The output image can also receive explicit size, spacing, origin, and path or background values.

Minimal path extraction uses a speed image and path information to find one or more routes between requested points. The resulting paths can then continue through ordinary path filters or return to image space.

This exchange is part of the wider spatial-data workflows child page. Image and transform file concerns are covered in Image and transform I/O.

References: Modules/…/itkImageToPathFilter.h• L26-43 Modules/…/itkContourExtractor2DImageFilter.h• L33-89 Modules/…/itkContourExtractor2DImageFilter.h• L163-217 Modules/…/itkPathToImageFilter.h• L26-37 Modules/…/itkPathToImageFilter.h• L81-128 Modules/…/itkSpeedFunctionToPathFilter.h• L27-45

Spatial-object representation

A spatial object represents a meaningful item in a scene. It combines a shape or value with a coordinate frame, properties, a bounding box, and optional parent-child relations. This makes a collection of related objects act as one spatial scene while still allowing each object to answer its own geometric queries.

Spatial-object hierarchy

home/…/itkSpatialObject.h is the common scene model. Each object has object-to-parent and object-to-world transforms. A group can contain any spatial-object children, and queries can include the object itself or descend through a selected depth of the hierarchy.

Objects expose common questions in object space and world space. They can report whether a point is inside, return a value at a point, report whether a value is meaningful there, and provide a bounding box. The base model also tracks properties and modification time across the object tree.

References: Modules/…/itkSpatialObject.h• L38-53 Modules/…/itkSpatialObject.h• L100-124 Modules/…/itkSpatialObject.h• L212-235 Modules/…/itkSpatialObject.h• L260-311 Modules/…/itkSpatialObject.h• L410-489

Spatial-object forms

Spatial-object types choose the data that best describes the item. Point-based objects store ordered spatial points and support point queries. Lines, contours, polygons, surfaces, tubes, and landmarks build on that model. Image objects use an image as their value source. Mesh spatial objects attach a mesh so it can also answer spatial-object queries.

The main forms have different roles:

FormMain role
MeshSpatialObjectGives a mesh a scene transform, bounds, and inside test.
ImageSpatialObjectGives an image a scene transform, interpolation, and value query.
ImageMaskSpatialObjectUses non-zero or selected image values to define inside space.
PointBasedSpatialObjectProvides shared point storage and point-based queries.
GroupSpatialObjectHolds child objects as one scene element.

References: Modules/…/itkMeshSpatialObject.h• L26-39 Modules/…/itkMeshSpatialObject.h• L65-119 Modules/…/itkImageSpatialObject.h• L29-40 Modules/…/itkImageSpatialObject.h• L74-103 Modules/…/itkImageMaskSpatialObject.h• L27-43 Modules/…/itkPointBasedSpatialObject.h• L27-37 Modules/…/itkGroupSpatialObject.h• L27-40

Spatial-object pipeline operations

Spatial objects enter image workflows through conversion filters. A spatial-object-to-image filter samples the object or its children into an image. It can preserve the object’s image geometry or create a mask with chosen inside and outside values. The output grid defines how the sampled object is represented. An ImageMaskSpatialObject then uses the selected pixels for world-space inside tests and bounds.

A spatial-object-to-point-set filter samples point-based objects in physical space and can include a selected depth of children. The same object can therefore serve as a scene model, a registration mask, or a sampled image input. This is the main bridge between scene-level geometry and the image-based processing system described in Filtering framework and Registration framework.

References: Modules/…/itkSpatialObjectToImageFilter.h• L26-39 Modules/…/itkSpatialObjectToImageFilter.h• L81-106 Modules/…/itkSpatialObjectToImageFilter.h• L135-155 Modules/…/itkSpatialObjectToImageFilter.h• L184-215 Modules/…/itkSpatialObjectToPointSetFilter.h• L29-37 Modules/…/itkSpatialObjectToPointSetFilter.h• L90-118 Modules/…/itkImageMaskSpatialObjectTest4.cxx• L82-167 Modules/…/itkImageMaskSpatialObjectTest4.cxx• L212-285

Spatial-object scene I/O

The spatial-object reader and writer move a scene hierarchy between ITK objects and MetaIO scene data. The reader can return the loaded root object or wrap it in a group so callers can traverse the loaded objects. Converters can be registered for additional spatial-object types.

Scene I/O keeps transforms, object type names, hierarchy links, and supported object data together. Image payloads can be written separately when the scene needs external image files.

References: Modules/…/itkSpatialObjectReader.h• L29-36 Modules/…/itkSpatialObjectReader.h• L62-105 Modules/…/itkSpatialObjectReader.h• L123-127 Modules/…/itkSpatialObjectWriter.h• L27-35 Modules/…/itkSpatialObjectWriter.h• L63-105

Representation relationships

These representations cover different views of the same spatial-data problem. A mesh emphasizes cells and surface topology. A path emphasizes an ordered one-dimensional route. A spatial object emphasizes scene meaning, coordinate frames, hierarchy, and point or value queries.

The usual pipeline choices are:

  1. Use a mesh when connectivity, surface geometry, or cell data is the main input to an operation.
  2. Use a quad-edge mesh when an algorithm needs fast surface adjacency or local topology edits.
  3. Use a path when an ordered route must guide image access or represent a contour.
  4. Use a spatial object when the item must live in a transformed scene or participate in a hierarchy.
  5. Convert between these forms and images or point sets at the pipeline boundary that matches the next operation.

The representations are complementary rather than interchangeable. A mesh can be wrapped as a MeshSpatialObject, and point-based spatial objects can become point sets, but each conversion changes which information is central to the next stage.

References: Modules/…/itkMeshSpatialObject.h• L26-39 Modules/…/itkSpatialObjectToPointSetFilter.h• L29-37 Modules/…/itkMeshToMeshFilter.h• L35-47 Modules/…/itkPath.h• L27-45

Change checklist

When these files or sections are changed, remember to consider these:

  • A change to mesh cell or point links must be checked against quad-edge conversions and any filter that expects neighborhood access.
  • A change to mesh point transforms must be checked against attached direction data and against MeshSpatialObject world-space queries.
  • A change to quad-edge primal or dual references must be checked against geometric origin and face state, including wire, border, and internal edge classification.
  • A change to direct quad-edge connectivity operations must be checked against the geometry-aware mesh operation so geometric references remain aligned.
  • A change to path parameter bounds or index stepping must be checked against path traversal and path-to-image output coverage.
  • A change to contour value, label mode, diagonal-pixel connectivity, or orientation must be checked against the meaning and ordering of extracted contours.
  • A change to contour requested-region handling must be checked against image boundaries and the open or closed status of output paths.
  • A change to spatial-object transforms or parent links must be checked against object-space and world-space queries, bounding boxes, registration masks, and scene I/O.
  • A change to spatial-object child depth must be checked against both image sampling and point-set extraction so the two workflows include the intended scene portion.
  • A change to the spatial-object output grid must be checked against mask pixel selection, world-space bounds, and inside tests.
  • A change to scene converter type names or hierarchy IDs must be checked against both reader and writer behavior.
  • A change to wrapped mesh array or metadata fields must be checked against Python round trips and VTK point and cell data exchange.
  • A change to wrapped mesh type or dimension coverage must be checked against the supported MeshToMeshFilter language-boundary combinations.

Important failure modes

TriggerConsequenceGuard
A mesh filter needs point-to-cell links but the links are not built or refreshed.Neighbor or boundary queries can miss cells or use stale relations.Build or update the links before algorithms that depend on reverse cell use.
A transform changes mesh points but attached normals or other direction data are treated as positions.Geometry and its derived directions no longer agree.Transform direction data with the matching transform rules.
Wrapped code uses the unsafe point-container setter instead of the coordinate-aware setter.Point storage can have undefined behavior.Use the coordinate-aware point setter for wrapped mesh data.
A wrapped mesh-to-mesh type or dimension is outside the generated binding set.The intended mesh filter is not available at the language boundary.Use a supported scalar type and image dimension or add matching wrap coverage.
A quad-edge edit targets a boundary, missing, or otherwise unsupported edge state.The local topology operation reports a non-standard status or cannot perform the edit.Check the edge status and validate topology around the edit.
A direct connectivity splice changes a geometric quad-edge without updating its geometry.Origin, destination, or face queries can disagree with the surface connectivity.Use the geometry-aware mesh operation and recheck wire, border, or internal edge state after the edit.
A quad-edge geometric reference is updated without its matching primal or dual relationship.Origin, destination, or face queries can disagree with the surface connectivity.Preserve the paired geometric references and recheck wire, border, or internal edge state after the edit.
A path has an invalid end location or cannot advance to another image index.Iteration can stop early or fail to cover the intended route.Set valid path bounds and handle the zero-offset end condition.
Contour extraction uses the wrong label mode, diagonal connection rule, or orientation setting.Separate regions can join or split unexpectedly, or contour direction can have the wrong meaning.Set these options to match whether the input is an intensity field or a label image.
A contour extraction region excludes part of a feature or reaches the image edge.The output can contain a partial open contour instead of the intended closed boundary.Choose the requested region with its boundary behavior in mind.
A path-to-image conversion relies on an unsuitable default extent or spacing.The output image can crop the route or place it at the wrong scale.Set output size, origin, and spacing when image geometry matters.
A spatial object is sampled on a grid that does not cover its transformed bounds or has unsuitable spacing.The resulting mask can have incomplete coverage and different world-space bounds or inside results.Set the output size, origin, and spacing to cover the object in the required world frame.
A spatial-object transform is stale when a world-space query runs.Inside tests, values, and bounds use the wrong coordinate frame.Update the object or its transform before world-space queries.
An image mask contains no selected pixels.Its mask bounding box is empty and has zero bounds.Treat an empty mask as a valid empty region before making an output image.
A scene reader cannot map a stored type name or parent ID.Objects can load without the intended concrete type or hierarchy.Register the converter and repair parent-child links before traversal.

Key files

FileWhy to read it
Modules/…/itkMesh.hDefines points, cells, optional data, links, boundaries, and mesh pipeline state.
Modules/…/itkMeshSource.hDefines the common mesh output contract for process objects.
Modules/…/itkMeshToMeshFilter.hDefines the mesh-to-mesh pipeline boundary.
Modules/Core/Mesh/wrapping/itkMeshToMeshFilter.wrapShows which scalar mesh types and dimensions cross the language boundary.
Modules/…/itkTransformMeshFilter.hShows how geometric point transforms preserve mesh structure and data.
Modules/…/itkMeshSerializationTest.pyShows the wrapped mesh persistence and VTK exchange boundary.
Modules/…/itkQuadEdgeMesh.hDefines the surface mesh form with quad-edge relationships.
Modules/…/itkQuadEdge.hDefines primal and dual edge links and local adjacency access.
Modules/…/itkGeometricalQuadEdge.hDefines geometric origin and face state for primal and dual quad-edges.
Modules/…/itkQuadEdgeMeshFunctionBase.hDefines the lightweight path for repeated local quad-edge mesh edits.
Modules/…/itkQuadEdgeMeshTopologyChecker.hShows the top-level checks for valid surface topology.
Modules/…/itkPath.hDefines the common parameter-to-location path contract.
Modules/…/itkParametricPath.hDefines continuous paths in image index space.
Modules/…/itkContourExtractor2DImageFilter.hDefines image contour extraction as a path-producing operation.
Modules/…/itkPathToImageFilter.hDefines the path-to-image conversion boundary.
Modules/…/itkSpatialObject.hDefines scene hierarchy, transforms, queries, and common spatial-object state.
Modules/…/itkMeshSpatialObject.hConnects a mesh to the spatial-object scene model.
Modules/…/itkSpatialObjectToImageFilter.hDefines scene sampling and mask generation into images.
Modules/…/itkSpatialObjectToPointSetFilter.hDefines physical-space sampling of point-based scene objects.
Modules/Core/SpatialObjects/test/itkImageMaskSpatialObjectTest4.cxxDemonstrates transformed object rasterization and checks mask world-space bounds in 2D and 3D.
Modules/…/itkSpatialObjectReader.hDefines scene loading and type conversion.
Modules/…/itkSpatialObjectWriter.hDefines scene writing and image-file handling.