[Insight-users] ITK to VTK - Vector Images

Hari Sundar mudrarakshasha at yahoo.com
Mon Nov 7 14:07:56 EST 2005


Hi,

I am trying to set up a simple connection between ITK and VTK. It
doesn't seem to be working correctly. I started with the
itkReadITKImageShowVTK.cxx example file under InsightApplications. This
example compiles and works correctly.

I want to load in a displacement field (MHD file, 3D, 3 Components per
voxel), and show arrows at each voxel location. However the program
that I wrote doesn't display correctly. I see all the arrows aligned
with the X axis and of constant length. 

Why isn't VTK seeing this as a Vector dataset ? I have attached the
main code.

thanks,
~Hari

--
try {
    const unsigned int ImageDimension = 3;
    typedef float PixelType;
      
    typedef itk::Vector < float, ImageDimension > VectorType;
    typedef itk::Image <VectorType, ImageDimension > ImageType;
    typedef itk::ImageFileReader < ImageType > FieldReaderType;

    FieldReaderType::Pointer reader = FieldReaderType::New (); 
    reader->SetFileName( argv[1] );
    reader->Update();

    typedef itk::VTKImageExport< ImageType > ExportFilterType;
    ExportFilterType::Pointer itkExporter = ExportFilterType::New();

    itkExporter->SetInput( reader->GetOutput() );

    vtkImageImport* vtkImporter = vtkImageImport::New();  
    ConnectPipelines(itkExporter, vtkImporter);
    
    vtkOutlineFilter *outline = vtkOutlineFilter::New();
    outline->SetInput(vtkImporter->GetOutput());

    vtkPolyDataMapper *outlineMapper = vtkPolyDataMapper::New();
    outlineMapper->SetInput(outline->GetOutput());

    vtkActor *outlineActor = vtkActor::New();
    outlineActor->SetMapper(outlineMapper);
    outlineActor->GetProperty()->SetColor(0.7, 0.3, 0.1);
    
    vtkExtractVOI *m_ExtractVOI  = vtkExtractVOI::New();
    m_ExtractVOI->SetInput(vtkImporter->GetOutput() );
    m_ExtractVOI->SetSampleRate( 4,4,4 );
    
    vtkArrowSource* vector = vtkArrowSource::New();
    
    vtkGlyph3D *glyph = vtkGlyph3D::New();
    glyph->SetInput( m_ExtractVOI->GetOutput());
    glyph->SetSource( vector->GetOutput() );
    glyph->SetVectorModeToUseNormal();
    glyph->SetScaleModeToScaleByVector();
    glyph->SetScaleFactor(2);
    
    vtkPolyDataMapper *spikeMapper = vtkPolyDataMapper::New();
    spikeMapper->SetInput(glyph->GetOutput());
    
    vtkActor *spikeActor = vtkActor::New();
    spikeActor->SetMapper(spikeMapper);
    spikeActor->GetProperty()->SetColor(0.0, 0.79, 0.34);

    vtkRenderer *ren= vtkRenderer::New();
    ren->AddActor( spikeActor );
    ren->AddActor( outlineActor );
    ren->SetBackground( 0.1, 0.2, 0.4 );

    vtkRenderWindow *renWin = vtkRenderWindow::New();
    renWin->SetSize(600,600);
    renWin->AddRenderer( ren );  
    
    vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
    iren->SetRenderWindow(renWin);
    
    vtkInteractorStyleTrackballCamera *style =
vtkInteractorStyleTrackballCamera::New();
    iren->SetInteractorStyle(style);
    
    iren->Initialize();
    iren->Start();
    
    
  }
  catch( itk::ExceptionObject & e ) {
    std::cerr << "Exception catched !! " << e << std::endl;
  }

  return 0;
}

 template <typename ITK_Exporter, typename VTK_Importer>
void ConnectPipelines(ITK_Exporter exporter, VTK_Importer* importer)
{
 
importer->SetUpdateInformationCallback(exporter->GetUpdateInformationCallback());
 
importer->SetPipelineModifiedCallback(exporter->GetPipelineModifiedCallback());
  importer->SetWholeExtentCallback(exporter->GetWholeExtentCallback());
  importer->SetSpacingCallback(exporter->GetSpacingCallback());
  importer->SetOriginCallback(exporter->GetOriginCallback());
  importer->SetScalarTypeCallback(exporter->GetScalarTypeCallback());
 
importer->SetNumberOfComponentsCallback(exporter->GetNumberOfComponentsCallback());
 
importer->SetPropagateUpdateExtentCallback(exporter->GetPropagateUpdateExtentCallback());
  importer->SetUpdateDataCallback(exporter->GetUpdateDataCallback());
  importer->SetDataExtentCallback(exporter->GetDataExtentCallback());
 
importer->SetBufferPointerCallback(exporter->GetBufferPointerCallback());
  importer->SetCallbackUserData(exporter->GetCallbackUserData());
}


bhogaa na bhuktaa vayameva bhuktaaH
tapo na tapta.n vayameva taptaaH |
kaalo na yaato vayameva yaataaH
tR^ishhNaa na jiirNaa vayameva jiirNaaH ||


		
__________________________________ 
Yahoo! FareChase: Search multiple travel sites in one click.
http://farechase.yahoo.com


More information about the Insight-users mailing list