1
votes

I am trying to read and save in a raw form a DICOM series. At runtime, the program crashes and the following error is generated:

DICOMParser couldn't parse.

Here is my code:

int main(int argc, char* argv[])
{
    // Verify input arguments
    std::string folder = "C:/dicom decompress/GM_23/2801/0";

    //std::string folder = "C:\\VTK\\vtkdata-5.8.0\\Data\\DicomTestImages";

    // Read all the DICOM files in the specified directory.
    vtkSmartPointer<vtkDICOMImageReader> reader =
    vtkSmartPointer<vtkDICOMImageReader>::New();
    reader->SetDirectoryName(folder.c_str());
    reader->Update();
    vtkSmartPointer<vtkImageWriter> writer =  vtkSmartPointer<vtkImageWriter>::New();

    writer->SetInputConnection(reader->GetOutputPort());
    //  writer->SetFilePrefix(folder.c_str());
    writer->SetFilePattern("3d.raw");
    writer->Write();
    writer->Update();

    return EXIT_SUCCESS;
}
1

1 Answers

1
votes

Probably your application finds a file that is not a DICOM, in that directory (consider that your directory could also contain hidden files, as '.DS_Store' if you are working on a Mac.

The best way I can think of is to handle the exception regarding the file parsing. Looking at the class vtkDicomImageReader, there is a method called CanReadFile, and it seems that it is the handler of that error, troughout this snippet:

  bool canRead = this->Parser->IsDICOMFile();
  if (canRead)
    {
    return 1;
    }
  else
    {
    vtkErrorMacro("DICOMParser couldn't parse : " << fname);
    return 0;
    }

The method is protected, but you could derive that class and handle the exception in the way that you prefer.

As an additional note, consider that you can also avoid the VTK warning window using

vtkImageData::GlobalWarningDisplayOff();

(at least, the final user won't visualize that), but to handling the exception is always the most priority thing, though.

Let me know if this helps.