vtkResampleToImage filter output save as a mhd file

I have created an unstructuredGrid and passed it into vtkResampleToImage filter in order to sample its point and cell data on to a uniform grid of points.
Now I want to write this output as a 3D image volume i.e. in .mhd format. I have tried it as below code, but it generated an empty file with only the header.

How can I save the vtkResampleToImage fitler output as .mhd format ?

vtkSmartPointer<vtkUnstructuredGridReader> reader =
        vtkSmartPointer<vtkUnstructuredGridReader>::New();
reader->SetFileName(ref_volumetric_mesh_path.c_str());
reader->ReadAllScalarsOn();
reader->SetReadAllScalars(true);
reader->Update();

vtkSmartPointer<vtkResampleToImage> filter = vtkSmartPointer<vtkResampleToImage>::New();
filter->SetInputDataObject(reader->GetOutput());
filter->SetInputConnection(reader->GetOutputPort());
filter->SetSamplingDimensions(60, 60, 100);
filter->Update();

vtkSmartPointer<vtkMetaImageWriter> writer = vtkSmartPointer<vtkMetaImageWriter>::New();
writer->SetFileName(ref_volumetric_mesh_voxelized_path.c_str());
writer->SetInputData(filter->GetOutput());
writer->Write();