[Insight-developers] IO Factories

Wilson Chang wmcst6+@pitt.edu
Mon, 22 Oct 2001 09:56:49 -0400


    When I was writing the VOL image reader, I noticed something a bit
confusing.  Based on the name of the function, I thought that the only thing
the CanReadFile() function would have to do is return true or false.
However this is not the case.  In addition to returning true or false, it
seems necessary for the CanReadFile() function to set the values of the
m_Dimensions array.  This is why ReadHeader() must be called in teh
CanReadFile().  This, so that the ImageFileReader::GenerateData() can
allocate space for the image right after testing whether a file is readable
or not.  It would seem more logical to allocate the space for the image
after explicitly calling ReadHeader() instead of implicitly calling
ReadHeader() inside of CanReadFile().

So currently the order of execution is.
1. CanReadFile()  : test if file is readable which implicitly calls the
ReadHeader() to set image dimensions
2. Allocate space for the image
3. Read the data

whereas it seems more intuitive to do it in this order:
1. CanReadFile() : test if the file is readable (without having to read the
header and set the image dimensions)
2. ReadHeader() : explicitly call instead of implicly call the header after
it is found to be readable.  Set image dimensions.
3. Allocate space for the image
4. Read the data

In this case, CanReadFile() would maybe only have to read the magic number,
instead of reading the whole header and setting image dimensions as well.
Does that sound like a logical change?

wilson----- Original Message -----
From: "Luis Ibanez" <ibanez@choroid.cs.unc.edu>
To: "Bill Hoffman" <bill.hoffman@kitware.com>
Cc: "insight-Developers" <insight-developers@public.kitware.com>
Sent: Monday, October 22, 2001 12:28 AM
Subject: [Insight-developers] IO Factories


>
> Hi Bill,
>
>
> I just made some changes in relation to the IO factories.
>
> 1) Removed itkImageFileReader.h and .txx from Code/BasicFilters
>    because it conflicts with the files of the same name in Code/IO.
>
> 2) Added to each IO factory the static method RegisterOneFactor().
>    In that way, each application can register the a particular
>    factory by using only one static call, like for example:
>
>    itk::PNGImageIOFactory::RegisterOneFactory();
>
> 3) Removed the method InitializeBuiltinTypes() from ImageIOFactory
>    because it was forcing application to be aware of all the
>    file formats. An appliction using only MetaImage or VOL was
>    forced to #include PNG and to link with png libraries.
>
>    As opposed to this mechanism, application can use the
>    RegisterOneFactory() method for registeaingr factories for
>    every file format they need.
>
> 4) The files in Testing/Code/IO were modified according to (3).
>
> 5) I still don't see who the static itkLoad() method can be used
>    for something different that PNG, I'm missing something...
>
>
>
>
> Thanks,
>
>
> Luis
>
>
>
>
> _______________________________________________
> Insight-developers mailing list
> Insight-developers@public.kitware.com
> http://public.kitware.com/mailman/listinfo/insight-developers
>