[Insight-developers] Exceptions with ImageFileWriter

Kent Williams norman-k-williams at uiowa.edu
Fri Sep 3 15:09:03 EDT 2004


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