[Insight-users] Re: [vtkusers] Save Registration Deformation field
in ITK and display in VTK glyph
Luis Ibanez
luis.ibanez at kitware.com
Sun Dec 31 09:52:48 EST 2006
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
More information about the Insight-users
mailing list