[Insight-users] fstream::fail() fails in the Mac.
Luis Ibanez
luis.ibanez@kitware.com
Thu, 06 Mar 2003 10:16:14 -0500
Hi Phillip,
We were able to reproduce the problem that you
reported with the RawImage reader.
After tracking it down, it results to be a problem
in the Mac implementation of the fstream.fail()
method.
The read is succesful, but "fail()" incorrectly
reports an error simply because the end of the
file was reached.
We fixed the RawImageIO reader so that in the Mac
it doesn't test for ""fail()" but for the number
of bytes actually read against the expected number
of bytes.
The fix was taken from VTK which has already been
immunized against Mac code disorders :-)
--
If you CVS update you may be able to use the
RawImageIO reader now.
Please let us know if you encounter any problem.
Thanks
Luis
------------------------------
Phillip Cheng wrote:
> Hello,
>
> I'm new to ITK and am trying to read in a simple raw image volume, but
> I'm not sure what I'm doing wrong. I'm running the current ITK CVS on
> Mac OS X 10.2.4. Here's a sample:
>
> ====================================================
>
> #include "itkImage.h"
> #include "itkImageFileReader.h"
> #include "itkRawImageIO.h"
>
> int main()
> {
> typedef itk::Image<float,3> ImageType;
>
> typedef itk::ImageFileReader<ImageType> ReaderType;
> ReaderType::Pointer reader=ReaderType::New();
>
> typedef itk::RawImageIO<float,3> ImageIOType;
> ImageIOType::Pointer rawImageIO=ImageIOType::New();
>
> reader->SetImageIO(rawImageIO);
> reader->SetFileName("pet.img");
>
> rawImageIO->SetByteOrderToBigEndian();
> rawImageIO->SetFileTypeToBinary();
> rawImageIO->SetFileDimensionality(3);
>
> rawImageIO->SetOrigin(0,0.0);
> rawImageIO->SetOrigin(1,0.0);
> rawImageIO->SetOrigin(2,0.0);
>
> rawImageIO->SetDimensions(0,128);
> rawImageIO->SetDimensions(1,128);
> rawImageIO->SetDimensions(2,36);
>
> rawImageIO->SetSpacing(0,4.3);
> rawImageIO->SetSpacing(1,4.3);
> rawImageIO->SetSpacing(2,4.25);
>
> try
> {
> reader->Update();
> }
> catch(itk::ExceptionObject& err)
> {
> std::cout << "Error: "<< err << std::endl;
> }
> }
> ============================================
>
> When I run this, I get the following message:
>
> Error:
> itk::ExceptionObject (0x1c6230)
> Location: "Unknown"
> File: /Users/pmcheng/ITK/Insight/Code/IO/itkRawImageIO.txx
> Line: 190
> Description: itk::ERROR: RawImageIO(0x1c4070): Read failed: Wanted
> 2359296 bytes, but read 2359296 bytes.
>
>
> I'm not sure what this error means. The file "pet.img" that I'm trying
> to load is exactly 2359296 bytes and is a big-endian 128x128x36 floating
> point array.
>
> Thanks for any help.
>
> Phillip Cheng
>
> _______________________________________________
> Insight-users mailing list
> Insight-users@public.kitware.com
> http://public.kitware.com/mailman/listinfo/insight-users
>