[Insight-users] Adding custom IO class

Luis Ibanez luis.ibanez@kitware.com
Thu, 14 Nov 2002 19:00:16 -0500


Hi Parag,

Your experiment is quite interesting.
This is basically what the design of IO
factories is intended to support in ITK.

The mechanism should allow you to do
exactly what you are trying to achieve
in this case: Addind a new file format
reader without having to introduce it
into the toolkit.

So, probably something needs to be fixed
on the factory registration mechanism.

I'll be happy to take a look at your
files and try to find a fix to the
problem.

I'm wondering if this could be a
windows specific problem....
have you ever tried the same code
under linux ?

About the automatic registration,
this may be trickier. Currently
the we are only registering factories
that are actually part of the toolkit.
The code is handwriten in

    Insight/Code/IO

    itkImageIOFactory.cxx

in the method

     RegisterBuiltInFactories()

adding your class here will actually
create a dependendy in ITK and compromise
the decoupling of the factories.
You probably may want to stick with the
extra line of code required for register
one factory...

----

Please send me the files so we can
track this down.

Thank



   Luis


======================================
Parag Chandra wrote:
> Hi all,
> 
>  
> 
> I've been using various parts of Insight for a couple of years now, but 
> yesterday was the first time I tried to extend it. I created a very 
> simple IO class (LPImageIO) derived from ImageIOBase, and corresponding 
> factory (LPImageIOFactory) derived from ObjectFactoryBase. I followed 
> the example of MetaImageIO very closely, but I put these two classes 
> into their own library and linked it into my custom application along 
> with all the other ITK libraries. My app is very simple, it's just this:
> 
>  
> 
> typedef itk::Image<double, 2> ImageType;
> typedef itk::ImageFileReader<ImageType> ReaderType;
> typedef itk::ImageFileWriter<ImageType> WriterType;
> 
>         itk::LPImageIOFactory::RegisterOneFactory();
>         ReaderType::Pointer reader = ReaderType::New();
>         reader->SetFileName(argv[1]);
>         WriterType::Pointer writer = WriterType::New();
>         writer->SetImageIO(itk::LPImageIO::New());
>         writer->SetInput(reader->GetOutput());
>         writer->SetFileName(argv[2]);
>         writer->Update();
> 
> My custom library and my test app build without problems (MSVC6 w/ 
> latest service pack), but running the program causes all sorts of 
> strange, unhandled exceptions in odd places. The effects I'm seeing seem 
> to be caused by improperly constructed objects. If I change one of the 
> lines above to read:
> 
>  
> 
> writer->SetImageIO(itk::PNGImageIO::New());
> 
>  
> 
> and give it a PNG file as input, the program runs just fine, so I'm 
> pretty certain that ITK is working correctly. So I tried a little 
> experiment and made LPImageIO and LPImageIOFactory part of 
>  ITKCommon.lib. Now my test program runs just fine. So my question is, 
> do extensions to Insight (or at least the IO framework) need to actually 
> be part of ITK, or can they be in their own libraries? Seems like the 
> latter is the preferred case, and should be possible, but I suspect that 
> there's some problems during construction/static initialization when 
> crossing boundaries between libraries. Maybe I've forgotten something 
> very simple. I can send the .h and .cxx files (4 total) on request if 
> that would help. On a related note, how can I get the IO framework to 
> automatically register my new IO class so that the call to 
> ::RegisterOneFactory() is no longer necessary? Thanks in advance for any 
> help on this matter.
> 
>  
> 
> Best regards,
> 
> Parag Chandra
>