[Insight-users] Bug in metaimage class
Jolinda Smith
jolinda at darkwing . uoregon . edu
Fri, 22 Aug 2003 10:25:42 -0700
Hi all,
I haven't checked this against the latest CVS, so I apologize if this
has already been fixed. Currently, metaimage headers that state the
actual header size (instead of -1) are not read correctly. The metaimage
class includes the method bool M_ReadElements(std::ifstream * _fstream,
void * _data, int _dataQuantity), line 1177 of metaimage.cxx. This
method includes the lines:
if(m_HeaderSize>(int)0)
{
_fstream->seekg(m_HeaderSize, std::ios::cur);
if((int)_fstream->gcount() != m_HeaderSize)
{
std::cout << "MetaImage: Read: header not read correctly" <<
std::endl;
return false;
}
}
Because changing the seek pointer doesn't extract any data, the test
against gcount() will always fail. A better test would be against
good():
if(m_HeaderSize>(int)0)
{
_fstream->seekg(m_HeaderSize, std::ios::beg);
if (!_fstream->good())
{
std::cout << "MetaImage: Read: header not read correctly" <<
std::endl;
return false;
}
}
I also think it's preferable to seek from the beginning of the file
instead of from the current position, although of course those will be
the same if this is the first operation on the file.
I'll head over to the web site to see if I can figure out how to use
GNATS.
Jolinda