[ITK] [ITK-users] ITK and VTK connection problem

Matt McCormick matt.mccormick at kitware.com
Thu Jul 5 11:56:31 EDT 2018


Hi,

The itk::ImageToVTKImageFilter should be used instead of the
itk::VTKImageImport class directly. See, for example:

  https://itk.org/ITKExamples/src/Bridge/VtkGlue/ConvertAnitkImageTovtkImageData/Documentation.html

HTH,
Matt
On Thu, Jul 5, 2018 at 9:52 AM Ashef Shahrior <ashahrior.91994 at gmail.com> wrote:
>
> From ITK Software Guide Book, I am trying to do Region Growing - Connected Threshold segmentation and show it using VTK. In the guide book, the segmented image is written into another file. But I don't want to write it but rather display it using VTK renderer. But it seems to be not working. Can anyone see my code and help me out, please? Here's my code:
>
> #include <iostream>
> #include <string.h>
> #include <windows.h>
> #include <time.h>
> #include <dos.h>
>
> #include "itkConnectedThresholdImageFilter.h"
>
> #include "itkImage.h"
> #include "itkCastImageFilter.h"
>
> #include "itkCurvatureFlowImageFilter.h"
>
> #include "itkImageFileReader.h"
> #include "itkImageFileWriter.h"
>
> #include "itkVTKImageExport.h"
> #include "itkVTKImageImport.h"
> #include "itkRGBPixel.h"
>
> #include "vtkImageData.h"
> #include "vtkImageImport.h"
> #include "vtkImageExport.h"
> #include "vtkImageActor.h"
> #include "vtkRenderer.h"
> #include "vtkRenderWindow.h"
> #include "vtkRenderWindowInteractor.h"
> #include "vtkInteractorStyleImage.h"
>
> using namespace std;
>
> 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());
> }
>
> 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());
> }
>
>
> void main()
> {
>     char inputImage[1000], seedx[10], seedy[10], lThreshold[100], uThreshold[100];
>
>     cout<< "Input values: "<<endl;
>     cin >> inputImage;
>     cin>>seedx;
>     cin>>seedy;
>     cin>>lThreshold;
>     cin>>uThreshold;
>
>     const     unsigned int    Dimension = 2;
>
>     typedef   float           InternalPixelType;
>     typedef itk::Image< InternalPixelType, Dimension >  InternalImageType;
>
>     typedef unsigned char                            OutputPixelType;
>     typedef itk::Image< OutputPixelType, Dimension > OutputImageType;
>
>     typedef itk::CurvatureFlowImageFilter< InternalImageType, InternalImageType > CurvatureFlowImageFilterType;
>
>     CurvatureFlowImageFilterType::Pointer smoothing = CurvatureFlowImageFilterType::New();
>
>     typedef itk::ConnectedThresholdImageFilter< InternalImageType, InternalImageType > ConnectedFilterType;
>
>     ConnectedFilterType::Pointer connectedThreshold = ConnectedFilterType::New();
>
>     typedef itk::CastImageFilter< InternalImageType, OutputImageType > CastingFilterType;
>
>     CastingFilterType::Pointer caster = CastingFilterType::New();
>
>     typedef  itk::ImageFileReader< InternalImageType > ReaderType;
>     typedef  itk::ImageFileWriter<  OutputImageType  > WriterType;
>
>     ReaderType::Pointer reader = ReaderType::New();
>     WriterType::Pointer writer = WriterType::New();
>
>     reader->SetFileName( inputImage );
>     reader->Update();
>     //writer->SetFileName( outputImage );
>
>     smoothing->SetInput( reader->GetOutput() );
>     smoothing->SetNumberOfIterations( 5 );
>     smoothing->SetTimeStep( 0.125 );
>
>     //writer->SetInput( caster->GetOutput() );
>     const InternalPixelType lowerThreshold = atof( lThreshold );
>     const InternalPixelType upperThreshold = atof( uThreshold );
>
>     connectedThreshold->SetInput( smoothing->GetOutput() );
>     connectedThreshold->SetLower(  lowerThreshold  );
>     connectedThreshold->SetUpper(  upperThreshold  );
>
>     connectedThreshold->SetReplaceValue( 255 );
>
>     InternalImageType::IndexType  index;
>
>     index[0] = atoi( seedx );
>     index[1] = atoi( seedy );
>
>     connectedThreshold->SetSeed( index );
>     connectedThreshold->Update();
>
>     //caster->SetInput( connectedThreshold->GetOutput() );
> caster->SetInput(connectedThreshold->GetOutput());
>
>     typedef itk::VTKImageExport< InternalImageType > ExportFilterType; //
>     ExportFilterType::Pointer itkExporter = ExportFilterType::New(); //
>
>         //itkExporter->SetInput( caster->GetOutput() ); // this line gives me error warning, so i did the following line
> itkExporter->SetInput(connectedThreshold->GetOutput());
>
>
>
>     vtkImageImport* vtkImporter = vtkImageImport::New();  //
>     ConnectPipelines(itkExporter, vtkImporter);
>
>     typedef itk::VTKImageImport< InternalImageType > ImportFilterType; //
>     ImportFilterType::Pointer itkImporter = ImportFilterType::New(); //
>
>
>     vtkImageExport* vtkExporter = vtkImageExport::New();
>     ConnectPipelines(vtkExporter, itkImporter);
>
> #if VTK_MAJOR_VERSION <= 5
>     vtkExporter->SetInput( vtkImporter->GetOutput() );
> #else
>     vtkImporter->Update();
>     vtkExporter->SetInputData( vtkImporter->GetOutput() );
> #endif
>
>     vtkImageActor* actor = vtkImageActor::New();
> #if VTK_MAJOR_VERSION <= 5
>     actor->SetInput(vtkImporter->GetOutput());
> #else
>     actor->SetInputData(vtkImporter->GetOutput());
> #endif
>
>     vtkInteractorStyleImage * interactorStyle = vtkInteractorStyleImage::New();
>
>     vtkRenderer* renderer = vtkRenderer::New();
>     vtkRenderWindow* renWin = vtkRenderWindow::New();
>     vtkRenderWindowInteractor* iren = vtkRenderWindowInteractor::New();
>
>     renWin->SetSize(500, 500);
>     renWin->AddRenderer(renderer);
>     iren->SetRenderWindow(renWin);
>     iren->SetInteractorStyle( interactorStyle );
>
>     renderer->AddActor(actor);
>     renderer->SetBackground(0.4392, 0.5020, 0.5647);
>
>     renWin->Render();
>     iren->Start();
>
>     actor->Delete();
>     interactorStyle->Delete();
>     vtkImporter->Delete();
>     vtkExporter->Delete();
>     renWin->Delete();
>     renderer->Delete();
>     iren->Delete();
> }
>
> Thanks in advance.
> The ITK community is transitioning from this mailing list to discourse.itk.org. Please join us there!
> ________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.php
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> https://itk.org/mailman/listinfo/insight-users
The ITK community is transitioning from this mailing list to discourse.itk.org. Please join us there!
________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html

Kitware offers ITK Training Courses, for more information visit:
http://www.kitware.com/products/protraining.php

Please keep messages on-topic and check the ITK FAQ at:
http://www.itk.org/Wiki/ITK_FAQ

Follow this link to subscribe/unsubscribe:
https://itk.org/mailman/listinfo/insight-users


More information about the Community mailing list