[Insight-developers] Exceptions with ImageFileWriter

Miller, James V (Research) millerjv at crd.ge.com
Tue Sep 7 09:49:38 EDT 2004


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.
>   



More information about the Insight-developers mailing list