[Insight-users] VTKImageIO bug + feature request (fix inside)

Luis Ibanez luis.ibanez@kitware.com
Tue, 18 Mar 2003 22:58:58 -0500


Hi Mathieu,

Thanks for localizing the error and providing the fix.

Your modifications were commited into the repository.

If you have a chance, please give it a try in your
platform.


Thanks


Luis


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

Mathieu Malaterre wrote:
> Hi all,
>     I would like to know if there is any one of you that use VTK 
> *binary* files for storing data ?
> 
>     I realized that the file reader/writer is working...at one condition 
> you don't try to load the file through VTK on a Little Endian Box (guess 
> what is my architecure ;)).
> 
>     So I would like to know if this was done on purpose or not ? As VTK 
> Binary format (as defined in : 
> http://public.kitware.com/VTK/pdf/file-formats.pdf) are in *BIG ENDIAN*. 
> It should be easy to add the ByteWaping in the VTKImageIO.
> 
> That is to say in itkVTKImageIO.cxx, line 342:
> 
>   file.read(static_cast<char*>(buffer), this->GetImageSizeInBytes());
>   int size = this->GetPixelSize();
>   switch( size )
>   {
>     case 2:
>      ByteSwapper<short>::SwapRangeFromSystemToBigEndian((short *)buffer, 
> this->GetImageSizeInComponents() );
>      break;
>     case 4:
>      ByteSwapper<float>::SwapRangeFromSystemToBigEndian((float *)buffer, 
> this->GetImageSizeInComponents() );
>      break;
>     case 6:
>      ByteSwapper<double>::SwapRangeFromSystemToBigEndian((double 
> *)buffer, this->GetImageSizeInComponents() );
>      break;
>   }
> 
> 
> Same idea line 420 for writting...
> 
> ---
> 
> In requested feature I would like to add the handling of tag 
> 'COLOR_SCALARS'. Sometime this tag is used even if the scalar range is 
> between 0 and 255.
> For example this pipeline:
> 
> vtkTIFFReader -> vtkStructuredPointsWriter
> 
> leads to a structured points image with COLOR_SCALARS instead of SCALARS.
> 
> This could be -almost- easily fixed with:
> Go in itkVTKImageIO.cxx, line 258:
> 
>      else if ( text.find("COLOR_SCALARS") < text.length() ||
>               text.find("color_scalars") < text.length() )
>       {
>       readScalars = true;
> 
>       int myscal;
>       sscanf(line, "%*s %*s %d", &myscal);
>       if ( myscal == 1 )
>         {
>           if ( this->GetFileType() == ASCII ) {
>             SetPixelType(FLOAT);
>             SetComponentType(FLOAT);
>           }
>           else {
>             SetPixelType(UCHAR);
>             SetComponentType(UCHAR);
>           }
>         }
>       else
>         {
>         itkExceptionMacro(<<"UNKNOWN");
>         }
>       }
> 
>     else if ( text.find("SCALARS") < text.length() ||
>               text.find("scalars") < text.length() )
> 
> 
> If someone would like to commit this modification. He'll has to take 
> care of line 322/323:
> 
> 322:       file.getline(line,255);
> 323:       text = line;
> 
> This is only needed to get rid of LOOKUP_TABLE but not in the case of 
> COLORS_SCALAR
> 
> ---
> 
>     For people urged to try it you'll find the c++ file here:
> 
> http://www.creatis.insa-lyon.fr/~malaterre/vtk/itkVTKImageIO.cxx
> 
> 
> HTH,
> mathieu
> 
>