I can write polyData to a .vtk file but it is an unstructured blob. I need a header to preserve my geometry of my object (I want to read it into an ITK registration application).
I saw the example on PolyData to ImageData: https://vtk.org/Wiki/VTK/Examples/Cxx/PolyData/PolyDataToImageData but this writes it to a .mhd file. Are there any examples that write to a .vtk file?
VTK and ITK can read .mhd (metaimage files), so I would recommend to use this format.
ITK cannot read .vtk image file, the file format can store image or various mesh types, which often can cause misunderstandings, and it is a legacy file format (replaced by XML-based vti, vtp, vtu, … format), so vtk would not be my preferred format.
@lassoan I came to the same conclusion. I rebuilt this morning with the MetalIO factory to read these but I think there has to be another way to convert a vtkImage to an ITK Image. I hacked out this way:
targetIsoValue = 150; // atof(150);
//Put the target image into ITK
VTKImageToImageType::Pointer vtkImageTargetToImageFilter = VTKImageToImageType::New();
ImageType::Pointer targetImage = ImageType::New();
targetImage->Graft(vtkImageTargetToImageFilter->GetOutput()); // Need to do this because QuickView can't accept const
It seems to be working as far as letting the software compile and registering correctly.
Does this way look right to you? Thank you!!!
Without seeing the complete code, I cannot tell much. If the question is if it is better to keep the image in memory to pass it from VTK to ITK (using ITKVTKGlue or VTK image export/ITK image import) than writing to file/reading from file - then the answer is yes.