[vtkusers] Save Registration Deformation field in ITK and

Mengda Wu wumengda at gmail.com
Tue Jan 2 15:36:16 EST 2007


Hi Markus,

  Thanks for your help.

  Actually, I am writing two programs. One is processing and saving the data
in ITK. And The other is displaying in VTK.

  Where is your ImageToVTKImageFilter? I fails to find this class in the
ITK.

Mengda

2007/1/2, Markus Weigert <m.weigert at fz-juelich.de>:
>
>  Hi Mengda,
>
> why do you want to save the ITK deformation field to disk and
> read it with a vtk reader???
>
> You can translate the ITK vectorimage directly to VTK using
> itk::ImageToVTKImageFilter and display it.
> This way, you can use ITK Imagereaders and writers to read and
> write your vectordata.
>
> You can do this by the following code:
>
> typedef itk::Image<float,3>  DeformationFieldType;
>
> void visualizeDeformationField(DeformationFieldType::Pointer defField)
> {
>
> try {
>
>    m_DefConnector =
> itk::ImageToVTKImageFilter<DeformationFieldType>::New();
>
>    m_DefConnector->SetInput(defField);
>    m_DefConnector->SetReleaseDataFlag(true);
>    m_DefConnector->Update();
>    vtkImageData* m_vtkImage = m_DefConnector->GetOutput();
>
>       m_outline->SetInput(m_vtkImage);
>    m_outlineMapper->SetInput(m_outline->GetOutput());
>
>       m_outlineActor->SetMapper(m_outlineMapper);
>       m_outlineActor->GetProperty()->SetColor(0.7, 0.3, 0.1);
>
>
>    m_pointData = m_vtkImage->GetPointData();
>
>       if ( m_pointData == NULL )
>       {
>          itkWarningMacro( << "vtkImage->GetPointData() returns NULL!" );
>          return ;
>       }
>       if ( m_pointData->GetNumberOfArrays() == 0 )
>       {
>          itkWarningMacro( <<
> "vtkImage->GetPointData()->GetNumberOfArrays() is 0!" );
>          return ;
>       }
>       else if ( m_pointData->GetArrayName( 0 ) == NULL )
>       {
>          m_vtkImage->GetPointData() ->GetArray( 0 ) ->SetName( "vectors"
> );
>       }
>
>
>    m_arrowSource->Update();
>
>    m_maskPoints->SetInput(m_vtkImage);
>    m_maskPoints->SetMaximumNumberOfPoints(1000);
>    m_maskPoints->RandomModeOn();
>    m_maskPoints->Update();
>
>    m_deformationData->SetPoints(m_maskPoints->GetOutput()->GetPoints());
>
> m_deformationData->GetPointData()->SetVectors(m_maskPoints->GetOutput()->GetPointData()->GetArray(0));
>
>    double* range =
> m_maskPoints->GetOutput()->GetPointData()->GetArray(0)->GetRange();
>    range[0] = 0;
>
>    m_lut->RemoveAllPoints();
>    m_lut->AddRGBPoint(range[0],           0.0, 0.0, 1.0);
>    m_lut->AddRGBPoint(range[0]+(range[1]-range[0])/4, 0.0, 0.5, 0.5);
>    m_lut->AddRGBPoint(range[0]+(range[1]-range[0])/2, 0.0, 1.0, 0.0);
>    m_lut->AddRGBPoint(range[1]-(range[1]-range[0])/4, 0.5, 0.5, 0.0);
>    m_lut->AddRGBPoint(range[1], 1.0, 0.0, 0.0);
>
>    m_scalarBar->SetLookupTable( m_lut );
>    m_scalarBar->SetTitle("Vector magnitude value");
>    m_scalarBar->SetOrientationToVertical();
>    m_scalarBar->GetLabelTextProperty()->SetColor(0,0,1);
>    m_scalarBar->GetTitleTextProperty()->SetColor(0,0,1);
>
>      m_glyph->SetSource( m_arrowSource->GetOutput() );
>      m_glyph->SetInput(m_deformationData);
>      m_glyph->OrientOn();
>      m_glyph->SetVectorModeToUseVector();
>   m_glyph->ScalingOn();
>      m_glyph->SetScaleModeToScaleByVector();
>   m_glyph->SetColorModeToColorByVector();
>   m_glyph->SetScaleFactor( 5.0 );
>      m_glyph->Update();
>
>       m_spikeMapper->SetInput(m_glyph->GetOutput());
>    m_spikeMapper->SetLookupTable( m_lut );
>    m_spikeMapper->Update();
>
>       m_spikeActor->SetMapper(m_spikeMapper);
>       m_spikeActor->GetProperty()->SetColor(0.0, 0.79, 0.34);
>
>       m_3DRenderer->AddActor( m_spikeActor );
>       m_3DRenderer->AddActor( m_outlineActor );
>    m_3DRenderer->AddActor( m_scalarBar );
>
>    m_3DRenderer->GetActiveCamera()->SetViewUp(0, 0, -1);
>    m_3DRenderer->GetActiveCamera()->SetPosition(-2, -2, -2);
>    m_3DRenderer->GetActiveCamera()->SetFocalPoint(0, 0, 0);
>    m_3DRenderer->GetActiveCamera()->ComputeViewPlaneNormal();
>    m_3DRenderer->ResetCamera();
>    m_3DRenderer->ResetCameraClippingRange();
>    m_3DRenderer->SetBackground(0.0, 0.0, 0.0);
>
>    m_3DRenderWindow->Start();
>    m_3DRenderer->Render();
>
>    m_3DRenderWindowInteractor->redraw();
> }
>
>
>
> Kind Regards,
> Markus
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20070102/72f271b6/attachment.htm>


More information about the vtkusers mailing list