我正在尝试使用 VTK 和 C++ 编写一个程序来读取 MRI 数据。但我无法获得主要的 MRI 原始数据的间距。“GetSpacing”仅适用于“ReadImageData”函数。我想我在 C++ 编程中犯了一些错误。但我不知道它在哪里。
vtkImageData* ReadImageData(string mri_imagedata_file)
{
vtkSmartPointer<vtkMetaImageReader> reader =
vtkSmartPointer<vtkMetaImageReader>::New();
reader->SetFileName(mri_imagedata_file.c_str());
reader->Update();
vtkImageData* metaimage = reader->GetOutput();
double sp[3];
metaimage->GetSpacing(sp);
cout << sp[0] << " " << sp[1] << " " << sp[2] <<endl; //<----------It works here.
return metaimage;
}
int main (int argc, char *argv[])
{
if(argc != 2)
{
cerr << "Usage: " << argv[0] << " MRI image data" <<endl;
return EXIT_FAILURE;
}
string mri_imagedata_file = argv[1];// Input "prost00.mhd"
vtkImageData* metaimage = ReadImageData(mri_imagedata_file);
double sp2[3];
metaimage->GetSpacing(sp2);
cout << sp2[0] << " " << sp2[1] << " " << sp2[2] << endl; //<-----It doesn't work here
}
感谢您的关注。