[Insight-users] GradientVectorFlowImageFilter: file writting + fix !

Luis Ibanez luis.ibanez@kitware.com
Wed, 12 Feb 2003 09:47:54 -0500


Hi Mathieu,

Thanks for pointing this out.

The changes you suggested were made on the repository.
CovariantVectors<> of 3 and 4 dimensions were added.

This is however a temporary fix...

The real solution involves to implement types for
Vector, Point, Index, Offset and Covariant vector
for various component types and dimensions.

We have experimented using a Macro for simplifying
the code....

These further changes will be available in the
short/medium term.

Please let us know if you find further problems,


   Thanks


     Luis


-------------------------------------
Mathieu Malaterre wrote:
> Hi all,
> 
>   While I was playing around with GradientVectorFlowImageFilter I tried 
> to save the output to a file. But currently ITK can't handle VTK file 
> with 3 components...so here is the fix + example file:
> 
> //The fix
> // go to line 230 of file Insight/Code/IO/itkImageIOBase.cxx
> //and change this way:
>  else if ( ptype == typeid(CovariantVector<float,2>) )
>    {
>    this->SetNumberOfComponents(2);
>    this->SetPixelType(ImageIOBase::FLOAT);
>    this->SetComponentType(ImageIOBase::FLOAT);
>    }
>  else if ( ptype == typeid(CovariantVector<float,3>) )
>    {
>    this->SetNumberOfComponents(3);
>    this->SetPixelType(ImageIOBase::FLOAT);
>    this->SetComponentType(ImageIOBase::FLOAT);
>    }
>  else
>    {
>    itkExceptionMacro("Pixel type currently not supported.");
>    this->SetPixelType(ImageIOBase::UNKNOWN);
>    this->SetComponentType(ImageIOBase::UNKNOWN);
>    return false;
>    }
> //end of fix
> 
> 
> 
> Example program (could be placed in Insight/Example/IO):
> 
> 
> 
> //Beginning of file: ImageReadWriteVTK.cxx
> 
> #include "itkImageFileReader.h"
> #include "itkImageFileWriter.h"
> #include "itkImage.h"
> #include "itkVTKImageIO.h"
> 
> 
> int main( int argc, char ** argv )
> {
> 
>  // Verify the number of parameters in the command line
>  if( argc < 3 )
>    {
>    std::cerr << "Usage: " << std::endl;
>    std::cerr << argv[0] << " inputImageFile  outputImageFile " << 
> std::endl;
>    return -1;
>    }
> 
>  typedef float            PixelType;
>  const   unsigned int        Dimension = 3;
> 
>  typedef itk::CovariantVector<PixelType, Dimension> GradientPixelType;
>  typedef itk::Image<GradientPixelType, Dimension>    GradientImageType;
> 
>  typedef itk::ImageFileReader< GradientImageType >  ReaderType;
>  typedef itk::ImageFileWriter< GradientImageType >  WriterType;
> 
> 
>  ReaderType::Pointer reader = ReaderType::New();
>  WriterType::Pointer writer = WriterType::New();
> 
> 
>  const char * inputFilename  = argv[1];
>  const char * outputFilename = argv[2];
> 
>  itk::VTKImageIO::Pointer vtkIO = itk::VTKImageIO::New();
>  vtkIO->SetNumberOfComponents(3);
> 
>  reader->SetFileName( inputFilename  );
>  reader->SetImageIO(vtkIO);
> 
>  writer->SetFileName( outputFilename );
>  writer->SetInput( reader->GetOutput() );
>  writer->SetImageIO(vtkIO);
> 
>  try
>    {
>    writer->Update();
>    }
>  catch( itk::ExceptionObject & err )
>    {
>    std::cout << "ExceptionObject caught !" << std::endl;
>    std::cout << err << std::endl;
>    return -1;
>    }
> 
>  return 0;
> 
> 
> }
> 
> //End of file: ImageReadWriteVTK.cxx
> 
> _______________________________________________
> Insight-users mailing list
> Insight-users@public.kitware.com
> http://public.kitware.com/mailman/listinfo/insight-users
>