Translate One Mesh#
Synopsis#
translate one itk::Mesh
Results#
Code#
C++#
#include "itkMesh.h"
#include "itkMeshFileReader.h"
#include "itkMeshFileWriter.h"
#include "itkTranslationTransform.h"
#include "itkTransformMeshFilter.h"
int
main(int argc, char * argv[])
{
if (argc != 3)
{
std::cerr << "Usage: " << std::endl;
std::cerr << argv[0];
std::cerr << " <InputFileName> <OutputFileName>";
std::cerr << std::endl;
return EXIT_FAILURE;
}
const char * inputFileName = argv[1];
const char * outputFileName = argv[2];
constexpr unsigned int Dimension = 3;
using PixelType = double;
using MeshType = itk::Mesh<PixelType, Dimension>;
using ReaderType = itk::MeshFileReader<MeshType>;
auto reader = ReaderType::New();
reader->SetFileName(inputFileName);
using TransformType = itk::TranslationTransform<MeshType::PointType::CoordRepType, Dimension>;
auto translation = TransformType::New();
TransformType::OutputVectorType displacement;
displacement.Fill(1.);
translation->Translate(displacement);
using FilterType = itk::TransformMeshFilter<MeshType, MeshType, TransformType>;
auto filter = FilterType::New();
filter->SetInput(reader->GetOutput());
filter->SetTransform(translation);
using WriterType = itk::MeshFileWriter<MeshType>;
auto writer = WriterType::New();
writer->SetFileName(outputFileName);
writer->SetInput(filter->GetOutput());
try
{
writer->Update();
}
catch (const itk::ExceptionObject & error)
{
std::cerr << "Error: " << error << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
Classes demonstrated#
-
template<typename TInputMesh, typename TOutputMesh, typename TTransform>
class TransformMeshFilter : public itk::MeshToMeshFilter<TInputMesh, TOutputMesh> TransformMeshFilter applies a transform to all the points of a mesh.
The additional content of the mesh is passed untouched. Including the connectivity and the additional information contained on cells and points.
Meshes that have added information like normal vector on the points, will have to take care of transforming this data by other means.