Working With Point and Cell Data#
Synopsis#
Associate point and cell data with a mesh.
Results#
Output:
66
66
5
128
128
10
mesh.vtk is also created.
Code#
C++#
// Include the relevant header files.
#include "itkMesh.h"
#include "itkRegularSphereMeshSource.h"
#include "itkMeshFileWriter.h"
// We define the dimension and coordinate type...
constexpr unsigned int Dimension = 3;
using TCoordinate = float;
// ...and then type alias the mesh, sphere, and writer.
using TMesh = itk::Mesh<TCoordinate, Dimension>;
using TSphere = itk::RegularSphereMeshSource<TMesh>;
using TMeshWriter = itk::MeshFileWriter<TMesh>;
int
main()
{
// Create the sphere source.
auto sphere = TSphere::New();
sphere->Update();
// We now assign it to a mesh pointer.
TMesh::Pointer mesh = sphere->GetOutput();
// It is necessary to disconnect the mesh from the pipeline;
// otherwise, the point and cell data will be deallocated
// when we call "Update()" on the writer later in the program.
mesh->DisconnectPipeline();
// Let's assign a value to each of the mesh's points...
for (unsigned int i = 0; i < mesh->GetNumberOfPoints(); ++i)
mesh->SetPointData(i, 5.0);
// ...and assign a different value to each of the mesh's cells.
for (unsigned int i = 0; i < mesh->GetNumberOfCells(); ++i)
mesh->SetCellData(i, 10.0);
// We'll print out some data about the points...
std::cout << mesh->GetNumberOfPoints() << std::endl; // 66
std::cout << mesh->GetPointData()->Size() << std::endl; // 66
std::cout << mesh->GetPointData()->ElementAt(0) << std::endl << std::endl; // 5.0
// ...and about the cells.
std::cout << mesh->GetNumberOfCells() << std::endl; // 128
std::cout << mesh->GetCellData()->Size() << std::endl; // 128
std::cout << mesh->GetCellData()->ElementAt(0) << std::endl << std::endl; // 10.0
// Finally, we'll write the data to file. Note that the only mesh file
// formats supported by ITK which support cell and point data are .vtk and .gii.
auto meshWriter = TMeshWriter::New();
meshWriter->SetFileName("mesh.vtk");
meshWriter->SetInput(mesh);
meshWriter->Update();
return EXIT_SUCCESS;
}
Classes demonstrated#
-
template<typename TPixelType, unsigned int VDimension = 3, typename TMeshTraits = DefaultStaticMeshTraits<TPixelType, VDimension, VDimension>>
class Mesh : public itk::PointSet<TPixelType, VDimension, TMeshTraits> Implements the N-dimensional mesh structure.
Mesh is an adaptive, evolving structure. Typically points and cells are created, with the cells referring to their defining points. If additional topological information is required, then BuildCellLinks() is called and links from the points back to the cells that use them are created. This allows implicit topological information about the faces and edges of the cells to be determined. (For example, a “face” neighbor to a cell can be determined by intersection the sets of cells that use the points defining the face. This is an inherent assumption on the manifold relationship of the cells in the mesh.) In some cases, either because the mesh is non-manifold, because we wish to explicitly store information with the faces and edges of the mesh, or because performance requirements demand that boundaries are explicitly represented (the set intersection does not need to be performed); then Mesh can be further extended by adding explicit boundary assignments.
- Overview
Mesh implements the N-dimensional mesh structure for ITK. It provides an API to perform operations on points, cells, boundaries, etc., but does not tie down the underlying implementation and storage. A “MeshTraits” structure is used to define the container and identifier types that will be used to access the mesh. See DefaultStaticMeshTraits for the set of type definitions needed. All types that are defined in the “MeshTraits” structure will have duplicate type alias in the resulting mesh itself.
One of the most important parts of using this mesh is how to create cells to insert into it. The cells for the mesh take two template parameters. The first is the pixel type, and should correspond exactly to that type given to the mesh. The second is a “CellTraits” which holds a sub-set of the “MeshTraits” structure definitions, and is also a member of them. Any cell which is to be inserted to a mesh should have MeshTraits::CellTraits as its second template parameter.
- Usage
Mesh has three template parameters. The first is the pixel type, or the type of data stored (optionally) with points, cells, and/or boundaries. The second is the geometric dimension of the points defining the mesh. This also limits the maximum topological dimension of the cells that can be inserted. The third template parameter is the “MeshTraits” structure controlling type information for the mesh. Most users will be happy with the defaults, and will not have to worry about this third argument.
Template parameters for Mesh:
TPixelType = The type stored as data for an entity (cell, point, or boundary).
TMeshTraits = Type information structure for the mesh.
- References
No reference information is available.
- ITK Sphinx Examples:
Subclassed by itk::SimplexMesh< TPixelType, VDimension, TMeshTraits >