[Insight-users] Runtime error while connecting itk with vtk

Julien Jomier jjomier at cs.unc.edu
Mon Dec 20 13:43:00 EST 2004


Hi Sotiris,

I think the problem comes from the definition of the image type:

try replacing:

typedef itk::Image<float, 2> ImageType;

by

typedef itk::Image<double, 2> ImageType;

because the VTKImageImport is expecting the pixel type of the image to 
match the data type of the vtkExporter.

In your code you have:

vtkExporter->SetInput(source->GetOutput());
with the source defined by default as a double, therefore your image 
type should be double. You can also modify the pixel type of the source 
if you want.

A good way to debug this in the future is to put a try/catch statement. 
something like:

[snip]

try
   {
   denoiser -> Update();
   }
catch( itk::ExceptionObject & exp )
   {
   std::cerr << "Exception caught !" << std::endl;
   std::cerr << exp << std::endl;
   }

[snip]


Hope that helps,

Julien

Sotiris Dimopoulos wrote:
> Hi to all!
> 
> I started using itk 1.8( xp,visual studio 6) few days
> ago so i don't have experience with it..i try to
> connect vtk with itk in my project (read images with
> vtk,do the image processing with itk and do the
> visualization with vtk again),so when i try to test
> the procedure vtk -> itk -> vtk,described in an
> example i found (see at the end of the mail), although
> the compile-build process its flowless(0 warnings,0
> errors) when i try to execute the "exe" file i get a
> "runtime error"  and the  message "abnormal
> termination"...
> 
> Have you got an idea of what might be?  
> 
> I'm sending you the example that i used as a guide
> which makes me the same error when entering to the itk
> pipeline (the first image is displayed ok, but when i
> close the first and i'm about to see the other two i
> get the message i decribed above)  :
> 
> #include "itkImage.h"
> #include "itkVTKImageExport.h"
> #include "itkVTKImageImport.h"
> #include "itkCurvatureFlowImageFilter.h" 
> #include "vtkImageImport.h"
> #include "vtkImageExport.h"
> #include "vtkImageShiftScale.h"
> #include "vtkImageNoiseSource.h"
> #include "vtkImageActor.h"
> #include "vtkRenderer.h"
> #include "vtkRenderWindow.h"
> #include "vtkRenderWindowInteractor.h" 
> #include "vtk2itk2vtk.h"
> 
> int main()
> 
> {  
> 
>   // VTK pipeline.
> 
>   
>   vtkImageNoiseSource* source =
> vtkImageNoiseSource::New();
> 
>   source->SetWholeExtent(0, 255, 0, 255, 0, 0);
> 
>   source->SetMinimum(0);
> 
>   source->SetMaximum(1); 
> 
> 
>   // Create a vtkImageShiftScale to convert the
> floating point image
> 
>   // to an unsigned char image.  
> 
>   vtkImageShiftScale* shifter =
> vtkImageShiftScale::New();
> 
>   shifter->SetInput(source->GetOutput());
> 
>   shifter->SetScale(256);
> 
>   shifter->SetOutputScalarTypeToUnsignedChar(); 
> 
> 
>   // Create a vtkImageActor to help render the image. 
> Connect it to
> 
>   // the vtkImageShiftScale instance.
> 
>   vtkImageActor* actor = vtkImageActor::New();
> 
>   actor->SetInput(shifter->GetOutput());
> 
>   
> 
>   // Create a renderer, render window, and render
> window interactor to
> 
>   // display the results.
> 
>   vtkRenderer* renderer = vtkRenderer::New();
> 
>   vtkRenderWindow* renWin = vtkRenderWindow::New();
> 
>   vtkRenderWindowInteractor* iren =
> vtkRenderWindowInteractor::New();
> 
>   
> 
>   renWin->SetSize(500, 500);
> 
>   renWin->AddRenderer(renderer);
> 
>   iren->SetRenderWindow(renWin);
> 
>   
> 
>   // Add the vtkImageActor to the renderer for
> display.
> 
>   renderer->AddActor(actor);
> 
>   renderer->SetBackground(0.4392, 0.5020, 0.5647); 
> 
> 
>   // Bring up the render window and begin interaction.
> 
>   renWin->Render();
> 
>   iren->Start();
> 
>   
> // Create a vtkExport object.
> 
>   vtkImageExport* vtkExporter = vtkImageExport::New();
> 
>   vtkExporter->SetInput(source->GetOutput());
> 
>   
> 
>    // VTK to ITK pipeline connection.
> 
>   
> 
>   typedef itk::Image<float, 2> ImageType;
> 
>   typedef itk::VTKImageImport<ImageType>
> ImageImportType;
> 
>   ImageImportType::Pointer itkImporter =
> ImageImportType::New();
> 
>   ConnectPipelines(vtkExporter, itkImporter);
> 
>   
> 
>   // ITK pipeline.
> 
>   
> 
>   typedef itk::CurvatureFlowImageFilter<ImageType,
> ImageType> DenoiserType;
> 
>   
> 
>   // Create the itk::CurvatureFlowImageFilter to
> smooth the source data.
> 
>   DenoiserType::Pointer denoiser =
> DenoiserType::New();
> 
>   denoiser->SetInput(itkImporter->GetOutput());
> 
>   denoiser->SetTimeStep(0.15);
> 
>   denoiser->SetNumberOfIterations(8); 
> 
> 
>  
>   // ITK to VTK pipeline connection.
> 
>    
> 
>   typedef itk::VTKImageExport<ImageType>
> ImageExportType;
> 
>   
> 
> // Create the itk::VTKImageExport instance and connect
> it to the
> 
>   // itk::CurvatureFlowImageFilter.
> 
>   ImageExportType::Pointer itkExporter =
> ImageExportType::New();
> 
>   itkExporter->SetInput(denoiser->GetOutput());
> 
>   
> 
>   // Create the vtkImageImport and connect it to the
> 
>   // itk::VTKImageExport instance.
> 
>   vtkImageImport* vtkImporter = vtkImageImport::New();
>  
> 
>   ConnectPipelines(itkExporter, vtkImporter);
> 
>   
> 
>   // VTK pipeline.
> 
>  
> 
> 
>   // Convert the floating point image to an unsigned
> char image.  
> 
>   shifter->SetInput(vtkImporter->GetOutput());
> 
>   shifter->SetScale(256);
> 
>   shifter->SetOutputScalarTypeToUnsignedChar(); 
> 
> 
>   // Update the input to actor. 
> 
>   actor->SetInput(shifter->GetOutput());
> 
>   iren->Start(); 
> 
> 
>   // After last interaction is quit, modifiy the ITK
> pipeline and
> 
>   // begin interaction again.  The user will see the
> ITK pipeline
> 
>   // re-execute due only to the update request through
> the VTK
> 
>   // pipeline.
> 
>   source->SetMinimum(0.5);
> 
>   iren->Start();
> 
>   
> 
>   // VTK does not use smart pointers, so we must clean
> up its pipeline
> 
>   // explicitly.
> 
>   iren->Delete();
> 
>   renWin->Delete();
> 
>   renderer->Delete();
> 
>   actor->Delete();
> 
>   shifter->Delete();
> 
>   vtkImporter->Delete();
> 
>   source->Delete();
> 
>   vtkExporter->Delete();
> 
>   
> 
>   return 0;
>   }
> 
> 
> Thanks
> 
> 
> ____________________________________________________________
> Do You Yahoo!?
> Αποκτήστε τη δωρεάν @yahoo.gr διεύθυνση σας στο http://www.otenet.gr
> _______________________________________________
> 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