[vtkusers] Testing DICOM reading success in C++

Glen Lehmann glehmann at atamai.com
Thu Nov 9 14:08:13 EST 2006


Hi Chris,

vtkDICOMImageReader does not have a CanReadDirectory (or similar)
method just yet.

The following is a rather ugly, but viable alternative:

- vtkGlobFileNames is in VTK cvs (it's not in 5.0, maybe it's in 5.2?)
- use vtkGlobFileNames to collect the file names in dirname
- loop through vtkGlobFileNames::GetFileNames()
- check each file using vtkDICOMImageReader::CanReadFile
- if CanReadFile is successfull, append the file name to a
vtkStringArray ("goodnames")
- Set the file names via vtkDICOMImageReader::SetFileNames(goodnames)

HTH,

Glen

On 09/11/06, Chris Want <cwant at ualberta.ca> wrote:
>
> Hi all,
>
> I am writing a program that reads DICOM data, and
> I have a vtkDICOMImageReader called 'reader' and some
> very standard code like this:
>
> reader->SetDirectoryName(dirname);
> reader->Update();
>
> Now, if I put something bogus into the variable dirname,
> VTK prints some error message like:
>
> ERROR: In /usr/local/src/vtk/VTK/IO/vtkDICOMImageReader.cxx, line 158
> vtkDICOMImageReader (0x1a549c0): Couldn't open blahblahblah
>
> ERROR: In /usr/local/src/vtk/VTK/IO/vtkDICOMImageReader.cxx, line 256
> vtkDICOMImageReader (0x1a549c0): Either a filename was not specified or
> the specified directory does not contain any DICOM images.
>
> ... but the code happily chugs along as if the DICOM data read
> had been successful, and ends up processing empty data.
>
> Neither reader->SetDirectoryName() nor reader->Update() have
> a return code that I can test ... does anybody know the
> correct way to test that the reader was successful using C++?
>
> Regards,
> Chris
>
> --
>   ____________________________________________________________________
> ( Chris Want                                                         )
> ( Research Computing Support                                         )
> ( Academic Information and Communication Technologies (AICT)         )
> ( University of Alberta                                              )
> ( Tel: 1-780-492-9418                                                )
>   --------------------------------------------------------------------
> _______________________________________________
> This is the private VTK discussion list.
> Please keep messages on-topic. Check the FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>



More information about the vtkusers mailing list