I have created a 3D volumetric mesh and saved it as a vtkUnstrcturedGrid (i.e. as a .vtk file). This mesh consists of a box with an ellipsoid where the ellipsoid is inside of this box. This mesh has two scalars where the minimum value is 1 and the maximum is set to 2.
Then I attempted to convert it into a 3D image volume(i.e. as .mha file) using vtkProbeFilter as below.
For that, I have set a vtkImageData object as the InpuData in the probe filter and this unstructured grid as the sourceData. But unfortunately, I’m not able to produce the correct output and the output file is always empty and only contains the header.
Please help me on this matter. Thank you very much for your time and consideration.
vtkSmartPointer<vtkUnstructuredGridReader> reader =
vtkSmartPointer<vtkUnstructuredGridReader>::New();
reader->SetFileName(ref_volumetric_mesh_path.c_str());
reader->ReadAllVectorsOn();
reader->ReadAllScalarsOn();
reader->Update();
vtkSmartPointer<vtkUnstructuredGrid> source = reader->GetOutput();
vtkSmartPointer<vtkImageData> input =
vtkSmartPointer<vtkImageData>::New();
//input->SetDimensions(60, 60, 100);
input->SetDimensions(512, 512, 360);
input->SetSpacing(0.5, 0.5, 0.5);
input->SetOrigin(0.0, 0.0, 0.0);
input->AllocateScalars(VTK_DOUBLE, 2);
// 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();