Hi ITKers and VTKers,<br><br> I have some problems in saving and displaying registration deformation field in VTK format.<br><br>The code in ITK is<br><br> typedef itk::Vector< float, Dimension > VectorPixelType;
<br> typedef itk::Image< VectorPixelType, Dimension > DeformationFieldType;
<br> typedef itk::ImageFileWriter< DeformationFieldType > FieldWriterType;<br> FieldWriterType::Pointer fieldWriter = FieldWriterType::New();<br> fieldWriter->SetFileName( "field.vtk" );<br> fieldWriter->SetInput( nrreg->GetDeformationField() );
<br> fieldWriter->Update();<br><br>The code in VTK is<br><br> vtkStructuredPointsReader *fieldReader = vtkStructuredPointsReader::New();<br> fieldReader->SetFileName( "field.vtk" );<br> vtkArrowSource *arrow = vtkArrowSource::New();
<br> vtkMaskPoints *masker = vtkMaskPoints::New();<br> masker->SetOnRatio( 1000 );<br> masker->RandomModeOn();<br> masker->SetInputConnection( fieldReader->GetOutputPort() );<br> vtkGlyph3D *glyph = vtkGlyph3D::New();
<br> glyph->SetInputConnection( masker->GetOutputPort() );<br> glyph->SetScaleModeToScaleByVector();<br> glyph->SetColorModeToColorByVector(); <br> glyph->OrientOn();<br> glyph->SetVectorModeToUseVector();
<br> glyph->SetSourceConnection( arrow->GetOutputPort() );<br> vtkPolyDataMapper *glyphmapper = vtkPolyDataMapper::New();<br> glyphmapper->SetInputConnection(glyph->GetOutputPort());<br> vtkActor *glyphactor = vtkActor::New();
<br><br>Displaying in VTK results in all arrows just pointing to one direction, say along X-axis.<br>I found this is because ITK save field data in VTK using Data Attribute in the header:<br><br>SCALARS scalars float 3<br>
LOOKUP_TABLE default<br><br>If I manually change it to:<br><br>VECTORS vectors float<br><br>Then, glyphs are displayed correctly.<br><br>I also tried to use itkVTKImageIO to correct this behavior using the code:<br><br>typedef itk::VTKImageIO VTKImageIOType;
<br>VTKImageIOType::Pointer vtkIO = VTKImageIOType::New();<br>vtkIO->SetComponentType( VTKImageIOType::FLOAT );<br>vtkIO->SetPixelType( VTKImageIOType::VECTOR );<br>fieldWriter->SetImageIO( vtkIO );<br><br>ITK just saves in the same way. Don't work.
<br><br>Can I change the behavior of ITK or is there any filter in VTK can correct this? <br>Anyone has some ideas on this. <br><br>Thank you very much!<br>Mengda<br>