[Insight-developers] IO Factories

Luis Ibanez ibanez@cs.unc.edu
Mon, 22 Oct 2001 11:33:18 -0400


Wilson,

I agree with you about the ambiguity 
of the method names in ImageIOFactory.

The change that you propose looks fine
to me. In that way the names of the 
methods correspond better to what they
are supposed to do:

1) CanReadFile() just test is this IO object
   is capable of reading this particular format.

2) ReadHeader() read the header, set spacing,
   and set dimensions. I'm not that sure about
   doing the memory allocation here though.

3) ReadData() load the bulk of the pixels and
   perform the necesary conversions.



Bill, if you agree with these modification, I'll
be glad to make the changes.


Thanks


Luis


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

Wilson Chang wrote:
> 
>     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?
>