[Insight-users] Re: [vtkusers] Save Registration Deformation field in ITK and display in VTK glyph

Mengda Wu wumengda at gmail.com
Tue Jan 2 01:35:23 EST 2007


Hi Luis,

   Yes. Option B will work, but need small modifications:

  Replace Line 481-484 with:

  if( this->GetPixelType() == ImageIOBase::VECTOR )
  {
    file << "VECTORS vectors "
      << this->GetComponentTypeAsString(m_ComponentType) << "\n";
  }
  else
  {
    file << "SCALARS scalars "
      << this->GetComponentTypeAsString(m_ComponentType) << " "
      << this->GetNumberOfComponents() << "\n";
    file << "LOOKUP_TABLE default\n";
  }

I also find vtkAssignAttribute in VTK can overcome this problem without
modifying ITK. Filter the data with before Glyph:

vtkAssignAttribute *assigner = vtkAssignAttribute::New();
assigner->Assign( vtkDataSetAttributes::SCALARS,
vtkDataSetAttributes::VECTORS, vtkAssignAttribute::POINT_DATA);

Therefore, I think it is OK without modifying ITK.

Guanglei

2006/12/31, Luis Ibanez <luis.ibanez at kitware.com>:
>
>
>
> Hi Wei,
>
> Here are a couple of options:
>
>
> A: Have you tried using the vtkImageReader ?
>     instead of using the vtkStructuredPointsReader.
>
>
>
> B: Enjoy Open Source: you could modify the itkVTKImageIO.cxx
>     file in line 481 in order to write out "VECTORS" instead
>     of "SCALARS". You probably want to do this with code such
>     as:
>
>
>      if( this->GetPixeltype() == ImageIOBase::VECTOR )
>        {
>        file << "SCALARS scalars";
>        }
>      else
>        {
>        file << "VECTORS vectors";
>        }
>     file << this->GetComponentTypeAsString( m_ComponentType)...
>
>
>
> "B" is probably a better option. Please give it a try
> and let us know if we should make the changes in the
> CVS repository.
>
>
>
>     Thanks
>
>
>        Luis
>
>
> -------------------
> Wei Xiong wrote:
> > Hi ITKers and VTKers,
> >
> >    I have some problems in saving and displaying registration
> > deformation field in VTK format.
> >
> > The code in ITK is
> >
> >    typedef itk::Vector< float, Dimension >    VectorPixelType;
> >    typedef itk::Image< VectorPixelType, Dimension >
> DeformationFieldType;
> >    typedef itk::ImageFileWriter< DeformationFieldType > FieldWriterType;
> >    FieldWriterType::Pointer fieldWriter = FieldWriterType::New();
> >    fieldWriter->SetFileName( "field.vtk" );
> >    fieldWriter->SetInput( nrreg->GetDeformationField() );
> >    fieldWriter->Update();
> >
> > The code in VTK is
> >
> >   vtkStructuredPointsReader *fieldReader =
> vtkStructuredPointsReader::New();
> >   fieldReader->SetFileName( "field.vtk" );
> >   vtkArrowSource *arrow = vtkArrowSource::New();
> >   vtkMaskPoints *masker = vtkMaskPoints::New();
> >   masker->SetOnRatio( 1000 );
> >   masker->RandomModeOn();
> >   masker->SetInputConnection( fieldReader->GetOutputPort() );
> >   vtkGlyph3D *glyph = vtkGlyph3D::New();
> >   glyph->SetInputConnection( masker->GetOutputPort() );
> >   glyph->SetScaleModeToScaleByVector();
> >   glyph->SetColorModeToColorByVector();
> >   glyph->OrientOn();
> >   glyph->SetVectorModeToUseVector();
> >   glyph->SetSourceConnection( arrow->GetOutputPort() );
> >   vtkPolyDataMapper *glyphmapper = vtkPolyDataMapper::New();
> >   glyphmapper->SetInputConnection(glyph->GetOutputPort());
> >   vtkActor *glyphactor = vtkActor::New();
> >
> > Displaying in VTK results in all arrows just pointing to one direction,
> > say along X-axis.
> > I found this is because ITK save field data in VTK using Data Attribute
> > in the header:
> >
> > SCALARS scalars float 3
> > LOOKUP_TABLE default
> >
> > If I manually change it to:
> >
> > VECTORS vectors float
> >
> > Then, glyphs are displayed correctly.
> >
> > I also tried to use itkVTKImageIO to correct this behavior using the
> code:
> >
> > typedef itk::VTKImageIO  VTKImageIOType;
> > VTKImageIOType::Pointer vtkIO = VTKImageIOType::New();
> > vtkIO->SetComponentType( VTKImageIOType::FLOAT );
> > vtkIO->SetPixelType( VTKImageIOType::VECTOR );
> > fieldWriter->SetImageIO( vtkIO );
> >
> > ITK just saves in the same way. Don't work.
> >
> > Can I change the behavior of ITK or is there any filter in VTK can
> > correct this?
> > Anyone has some ideas on this.
> >
> > Thank you very much!
> > Mengda
> >
> >
> > ------------------------------------------------------------------------
> >
> > _______________________________________________
> > This is the private VTK discussion list.
> > Please keep messages on-topic. Check the FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
> > Follow this link to subscribe/unsubscribe:
> > http://www.vtk.org/mailman/listinfo/vtkusers
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/insight-users/attachments/20070101/e70b7d6e/attachment.htm


More information about the Insight-users mailing list