[Insight-users] writing large files with VTKImageIO...possible bug?

Lyubomir G. Zagorchev Lyubomir.G.Zagorchev at Dartmouth.edu
Tue Oct 20 12:48:15 EDT 2009



When writing binary files with VTKImageIO the buffer is being copied into a temporary array which creates memory issues with large files. I am running the CVS version of ITK.... Could you please verify that? A possible fix is pasted below.

Thanks,

Lyubomir



void VTKImageIO::Write(const void* buffer)
{
.....
.....
  // Write the actual pixel data
  if ( m_FileType == ASCII )
    {
    this->WriteBufferAsASCII(file, buffer, this->GetComponentType(),
                             this->GetImageSizeInComponents());
    }
  else //binary
    {
    int size = this->GetComponentSize();
    typedef ::size_t   BufferSizeType;
    const BufferSizeType numbytes = static_cast<BufferSizeType>( this->GetImageSizeInBytes() );
    //char * tempmemory=new char[numbytes];
    //memcpy(tempmemory,buffer,numbytes);
    //switch( size )
    //  {
    //  case 2:
    //    {
    //    ByteSwapper<short>::SwapRangeFromSystemToBigEndian(reinterpret_cast<short *>(tempmemory), static_cast<BufferSizeType>(this->GetImageSizeInComponents()) );
    //    }
    //    break;
    //  case 4:
    //    {
    //    ByteSwapper<float>::SwapRangeFromSystemToBigEndian(reinterpret_cast<float *>(tempmemory), static_cast<BufferSizeType>(this->GetImageSizeInComponents()) );
    //    }
    //    break;
    //  case 8:
    //    {
    //    ByteSwapper<double>::SwapRangeFromSystemToBigEndian(reinterpret_cast<double *>(tempmemory), static_cast<BufferSizeType>(this->GetImageSizeInComponents()) );
    //    }
    //    break;
    //  }
    //        file.write(static_cast<const char*>(tempmemory), static_cast<std::streamsize>(this->GetImageSizeInBytes()));
    //delete [] tempmemory;


    switch( size )
      {
      case 2:
        {
        ByteSwapper<short>::SwapRangeFromSystemToBigEndian((short *)(buffer), static_cast<BufferSizeType>(this->GetImageSizeInComponents()) );
        }
        break;
      case 4:
        {
        ByteSwapper<float>::SwapRangeFromSystemToBigEndian((float *)(buffer), static_cast<BufferSizeType>(this->GetImageSizeInComponents()) );
        }
        break;
      case 8:
        {
        ByteSwapper<double>::SwapRangeFromSystemToBigEndian((double *)(buffer), static_cast<BufferSizeType>(this->GetImageSizeInComponents()) );
        }
        break;
      }
            file.write(static_cast<const char*>(buffer), static_cast<std::streamsize>(this->GetImageSizeInBytes()));
    }
}


More information about the Insight-users mailing list