[Insight-users] ITK to VTK - Vector Images

Karthik Krishnan Karthik.Krishnan at kitware.com
Mon Nov 7 17:27:18 EST 2005


You might want to ask the VTK list that, as in how do you glyph 
vtkImageData. Its easy to glyph polydata, if you feed your code 
vtkPolyData instead of vtkImageData, (which is what gets imported from 
ITK), it should work fine. I spent a few minutes tinkering with your 
code and it wasn't obvious to me how I could glyph image data easily.

You could convert vtkImageData to vtkPolydata, but I suspect for a large 
image that would take a lot of time and that's probably not the right 
solution anyway.

I remember at some point, I wanted to glyph image data that ITK gave out 
and paraview did the job just fine, so I didn't need to go that far. (If 
your intent isn't to incorporate this into an application, just use 
vtkMetaImageWriter and save the vtkImporter output into a file and use 
Paraview to glyph it).

[ Or you could look at the Paraview sources... ].

Hari Sundar wrote:

>That doesn't seem to make a difference. I think VTK is interpreting
>this as a scalar image. Do I need to somehow force VTK to expect it as
>a vector image ?
>
>Another strange thing is that I am unable to change the color of the
>glyphs. Maybe that tells you something.
>
>I have attached the code so that you can take a look at the output. 
>
>thanks,
>~Hari
>
>--- Karthik Krishnan <Karthik.Krishnan at kitware.com> wrote:
>
>  
>
>>I've done exactly this before and I am certain it works.
>>
>>Your code looks good except for this line:
>>
>>    glyph->SetVectorModeToUseNormal();
>>
>>Usually when you glyph, you want
>>
>>    glyph->SetVectorModeToUseVector();
>>
>>Using the Normal should explain why you see all of them lined up
>>along 
>>one axis. At least I hope that's the reason.
>>
>>HTH
>>Karthik
>>
>>Hari Sundar wrote:
>>
>>    
>>
>>>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
>>>_______________________________________________
>>>Insight-users mailing list
>>>Insight-users at itk.org
>>>http://www.itk.org/mailman/listinfo/insight-users
>>>
>>> 
>>>
>>>      
>>>
>>_______________________________________________
>>Insight-users mailing list
>>Insight-users at itk.org
>>http://www.itk.org/mailman/listinfo/insight-users
>>
>>    
>>
>
>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
>
>------------------------------------------------------------------------
>
>#include "itkCommand.h"
>#include "itkImage.h"
>#include "itkVTKImageExport.h"
>#include "itkVTKImageImport.h"
>#include "itkCurvatureFlowImageFilter.h"
>#include "itkCastImageFilter.h"
>#include "itkRGBPixel.h"
>#include "itkImageFileReader.h"
>#include "itkImageFileWriter.h"
>#include "vtkImageData.h"
>
>#include "vtkImageImport.h"
>#include "vtkImageExport.h"
>#include "vtkPolyDataMapper.h"
>#include "vtkRenderWindow.h"
>#include "vtkCamera.h"
>#include "vtkActor.h"
>#include "vtkProperty.h"
>#include "vtkRenderer.h"
>#include "vtkExtractVOI.h"
>#include "vtkArrowSource.h"
>#include "vtkGlyph3D.h"
>#include "vtkOutlineFilter.h"
>#include "vtkCubeAxesActor2D.h"
>#include "vtkTextProperty.h"
>//#include ".h"
>
>#include "vtkRenderWindowInteractor.h"
>#include "vtkInteractorStyleTrackballCamera.h"
>
>
>/**
> * This will be setup as a callback for a progress event on an ITK
> * filter.
> */
>struct ProgressDisplay
>{
>  ProgressDisplay(itk::ProcessObject* process): m_Process(process) {}
>  
>  void Display()
>    {
>    float progress = m_Process->GetProgress()*100.0;
>    std::cout << "Progress " << progress << " percent." << std::endl;
>    }
>  
>  itk::ProcessObject::Pointer m_Process;
>};
>
>
>/**
> * This function will connect the given itk::VTKImageExport filter to
> * the given vtkImageImport filter.
> */
>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());
>}
>
>/**
> * This function will connect the given vtkImageExport filter to
> * the given itk::VTKImageImport filter.
> */
>template <typename VTK_Exporter, typename ITK_Importer>
>void ConnectPipelines(VTK_Exporter* exporter, ITK_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());
>}
>
>
>/**
> * This program implements an example connection between ITK and VTK
> * pipelines.  The combined pipeline flows as follows:
> *
> * itkImageFileReader ==> itkVTKImageExport ==>
> *    vtkImageImport ==> vtkImageActor
> *
> * The resulting vtkImageActor is displayed in a vtkRenderWindow.
> * Whenever the VTK pipeline executes, information is propagated
> * through the ITK pipeline.  If the ITK pipeline is out of date, it
> * will re-execute and cause the VTK pipeline to update properly as
> * well.
> */
>int main(int argc, char * argv [] )
>{  
>  
>  // Load a color image using ITK and display it with VTK
>  
>  if( argc < 2 ) {
>      std::cerr << "Missing parameters" << std::endl;
>      std::cerr << "Usage: " << argv[0] << " deformationFld " << std::endl;
>      return 1;
>  }
>  
>  try {
>    const unsigned int ImageDimension = 3;
>    typedef float PixelType;
>      
>    //typedef itk::Image <PixelType, ImageDimension> ImageType; 
>    typedef itk::Vector < float, ImageDimension > VectorType;
>    typedef itk::Image <VectorType, ImageDimension > ImageType;
>    typedef itk::ImageFileReader < ImageType > FieldReaderType;
>
>    // typedef itk::RGBPixel< unsigned char > PixelType;
>    // typedef itk::Image< PixelType, 2 > ImageType;
>    
>    // typedef itk::ImageFileReader< ImageType > ReaderType;
>    FieldReaderType::Pointer reader = FieldReaderType::New (); 
>    // ReaderType::Pointer reader  = ReaderType::New();
>    reader->SetFileName( argv[1] );
>    reader->Update();
>
>    typedef itk::VTKImageExport< ImageType > ExportFilterType;
>    ExportFilterType::Pointer itkExporter = ExportFilterType::New();
>
>    itkExporter->SetInput( reader->GetOutput() );
>
>    // Create the vtkImageImport and connect it to the
>    // itk::VTKImageExport instance.
>    vtkImageImport* vtkImporter = vtkImageImport::New();  
>    ConnectPipelines(itkExporter, vtkImporter);
>    
>
>    //------------------------------------------------------------------------
>    // VTK pipeline.
>    //------------------------------------------------------------------------
>
>    // Test ...
>    //float maxVel = vtkImporter->GetOutput()->GetPointData().GetVectors().GetMaxNorm();
>
>    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->SetVOI( 10, 50, 10, 50, 20,30 );
>    m_ExtractVOI->SetSampleRate( 8,8,8 );
>    
>    vtkArrowSource* vector = vtkArrowSource::New();
>    
>    vtkGlyph3D *glyph = vtkGlyph3D::New();
>    glyph->SetInput( m_ExtractVOI->GetOutput());
>    glyph->SetSource( vector->GetOutput() );
>    //glyph->SetVectorModeToUseNormal();
>    glyph->SetVectorModeToUseVector();
>    glyph->SetScaleModeToScaleByVector();
>    glyph->SetScaleFactor(2);
>    
>    vtkPolyDataMapper *spikeMapper = vtkPolyDataMapper::New();
>    spikeMapper->SetInput(glyph->GetOutput());
>    
>    vtkActor *spikeActor = vtkActor::New();
>    spikeActor->SetMapper(spikeMapper);
>    spikeActor->GetProperty()->SetColor(1.0, 0.9, 0.14);
>
>    vtkRenderer *ren= vtkRenderer::New();
>    ren->AddActor( spikeActor );
>    ren->AddActor( outlineActor );
>    ren->SetBackground( 0.2, 0.4, 0.8 );
>
>    /*   vtkTextProperty *tprop = vtkTextProperty::New();
>    tprop->SetColor(1, 1, 1);
>    tprop->ShadowOn();
>        
>    vtkCubeAxesActor2D *axes = vtkCubeAxesActor2D::New();
>    axes->SetInput(outline->GetOutput());
>    axes->SetCamera(ren->GetActiveCamera());
>    axes->SetLabelFormat("%6.4g");
>    axes->SetFlyModeToOuterEdges();
>    axes->SetFontFactor(0.8);
>    axes->SetAxisTitleTextProperty(tprop);
>    axes->SetAxisLabelTextProperty(tprop);
>    ren->AddProp(axes); */
>
>    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;
>}
>  
>
>------------------------------------------------------------------------
>
>_______________________________________________
>Insight-users mailing list
>Insight-users at itk.org
>http://www.itk.org/mailman/listinfo/insight-users
>  
>


More information about the Insight-users mailing list