[Insight-developers] Exceptions with ImageFileWriter

Lorensen, William E (Research) lorensen at crd.ge.com
Tue Sep 7 22:09:27 EDT 2004


I added some more (hopefully) informative messages to the throw exceptions.

bin/ImageReadWrite c:/lorensen/tmp/foo.png bar
ExceptionObject caught !

itk::ImageFileWriterException (016189E6)
Location: "Unknown"
File: C:\lorensen\Insight\Code\IO\itkImageFileWriter.txx
Line: 145
Description:  Could not create IO object for file bar
  Tried to create one of the following:
    MetaImageIO
    PNGImageIO
    VTKImageIO
    GiplImageIO
    AnalyzeImageIO
    StimulateImageIO
    JPEGImageIO
    TIFFImageIO
    NrrdImageIO
    BMPImageIO
    DICOMImageIO2
  You probably failed to set a file suffix, or
    set the suffix to an unsupported type.

---------------

bin/ImageReadWrite c:/lorensen/tmp/foo bar.mha
ExceptionObject caught !

itk::ImageFileReaderException (01619B26)
Location: "Unknown"
File: C:\lorensen\Insight\Code\IO\itkImageFileReader.txx
Line: 113
Description:  Could not create IO object for file c:/lorensen/tmp/foo
  Tried to create one of the following:
    MetaImageIO
    PNGImageIO
    VTKImageIO
    GiplImageIO
    AnalyzeImageIO
    StimulateImageIO
    JPEGImageIO
    TIFFImageIO
    NrrdImageIO
    BMPImageIO
    DICOMImageIO2
  You probably failed to set a file suffix, or
    set the suffix to an unsupported type.


-----Original Message-----
From: Miller, James V (Research) [mailto:millerjv at crd.ge.com]
Sent: Tuesday, September 07, 2004 9:50 AM
To: 'Kent Williams'
Cc: Insight-developers "(E-mail)
Subject: RE: [Insight-developers] Exceptions with ImageFileWriter


Kent, 

I think reading is a different issue. My concern is in writing
an image.  It is unfortunate that people see a program crash 
(if they do not catch the exception) or an obscure message
(if they do catch the exception) when they mistakeningly 
specify a filename without an extension.

Bill and I were just talking about this.  Perhaps we can expand
the message in the exception.  Instead of just saying an 
appropriate ImageIO could not be found, we could list all 
the ImageIO factories that were tested.

Jim



-----Original Message-----
From: Kent Williams [mailto:norman-k-williams at uiowa.edu]
Sent: Friday, September 03, 2004 3:09 PM
To: Miller, James V " "(Research)
Cc: Insight-developers "(E-mail)
Subject: Re: [Insight-developers] Exceptions with ImageFileWriter


ITK applications should be responsible for idiot-testing their input.
An ITK application should in all but a few cases have a good idea of
what file format it is supposed to write out, and if the user doesn't
provide a suitable extension, the program should either complain about
it or exit.

Look at the way programs like MS Word (or OpenOffice) handle file
dialogs.  Whenever you save a file, you have a choice of reasonable
formats for the object being saved, and you have to choose one. If you
don't provide a suitable filename extension, it's appended to the path
you give it.

There will still be the problem that some formats DON'T have an
associated filename extension. These, luckily, are more obscure formats,
but you have to explicitly create an instance of an ImageIO for that
type and assign it to the file reader:

  itk::ImageIOBase::Pointer io;
  if(filetype == "GE4")
    {
      io = itk::GE4ImageIO::New();
    }
  else if(filetype == "GE5")
    {
      io = itk::GE5ImageIO::New();
    }
  else if(filetype == "GEAdw")
    {
      io = itk::GEAdwImageIO::New();
    }
  else if(filetype == "Siemens")
    {
      io = itk::SiemensVisionImageIO::New();
    }
  else
    {
      return 1;
    }

   imageReader->SetImageIO(io);

In the real world, it would almost always be the case that ther
On Fri, 2004-09-03 at 08:58, Miller, James V (Research) wrote:
> What do people think about adding a "default" format? If no IO 
> factory is found that likes the extension specified, we write the 
> data out in a default preferred format (and add the default extension).
> We should probably also output a warning to the effect that a format
> could not be found and that we are using a default format instead.
>   

_______________________________________________
Insight-developers mailing list
Insight-developers at itk.org
http://www.itk.org/mailman/listinfo/insight-developers


More information about the Insight-developers mailing list