I’m also using VTKProbeFilter to do the same thing and try to write the output as a .mhd file, but the output file is empty and only contains the header, see below.
Here is my code and can you please let me know any issues regarding the implementation?
Am I doing something wrong here ? Please help me on this matter.
vtkSmartPointer<vtkUnstructuredGridReader> reader =
vtkSmartPointer<vtkUnstructuredGridReader>::New();
reader->SetFileName(ref_volumetric_mesh_path.c_str());
reader->ReadAllVectorsOn();
reader->ReadAllScalarsOn();
reader->Update();
reader->GetOutput()->GetScalarRange();
vtkSmartPointer<vtkUnstructuredGrid> source = reader->GetOutput();
vtkSmartPointer<vtkImageData> input =
vtkSmartPointer<vtkImageData>::New();
input->SetDimensions(60, 60, 100);
input->SetSpacing(0.5, 0.5, 0.5);
input->SetOrigin(0.0, 0.0, 0.0);
input->AllocateScalars(VTK_DOUBLE, 1);
// Interpolate PointData from the mesh to the points of the Image
vtkSmartPointer<vtkProbeFilter> filter = vtkSmartPointer<vtkProbeFilter>::New();
filter->SetInputData(input);
filter->SetSourceData(source);
filter->Update();
vtkSmartPointer<vtkMetaImageWriter> writer = vtkSmartPointer<vtkMetaImageWriter>::New();
writer->SetFileName(ref_volumetric_mesh_voxelized_path.c_str());
writer->SetInputData(filter->GetOutput());
writer->Write();
.mhd file only contains the header. See below.
ObjectType = Image
NDims = 3
BinaryData = True
BinaryDataByteOrderMSB = False
CompressedData = True
TransformMatrix = 1 0 0 0 1 0 0 0 1
Offset = 0 0 0
CenterOfRotation = 0 0 0
ElementSpacing = 0.5 0.5 0.5
DimSize = 60 60 100
AnatomicalOrientation = ???
ElementType = MET_DOUBLE
ElementDataFile = example_gen_image_vol.zraw