Search code examples
c++vtk

VTK reader output


I used VTK to read a dicom file and I wanted to get its pixel info. The error was caused by the last line. The error info was 'vtkSmartPointerBase::vtkSmartPointerBase(vtkObjectBase *)': cannot convert argument 1 from 'T *' to 'vtkObjectBase *'. But typeid(reader->GetOutput()).name() was actually vtkImageData. Why this error happened?

std::string inputFilename = "C:\\Users\\26327\\Desktop\\dll4sw\\data\\SE3\\IM0.dcm";
vtkSmartPointer<vtkDICOMImageReader> reader =
    vtkSmartPointer<vtkDICOMImageReader>::New();
reader->SetFileName(inputFilename.c_str());
reader->Update();
cout << typeid(reader->GetOutput()).name() << endl;
vtkSmartPointer<vtkImageData> vtkImage = reader->GetOutput();

Solution

  • You can try the following code to show the difference:

    vtkSmartPointer<vtkImageData> vtkImage = vtkSmartPointer<vtkImageData>::New();
    cout << typeid(vtkImage).name() << endl;
    
    auto result = reader->GetOutput();
    cout << typeid(result ).name() << endl;
    
    

    Might give you some hint.