[vtkusers] error when connecting ITK with VTK

David Doria daviddoria at gmail.com
Sun Dec 4 16:41:41 EST 2011


On Sun, Dec 4, 2011 at 4:34 PM, Ralf.Denhof <ralf.denhof at gmx.de> wrote:
> I think this reproduces the error, but I had to run it in Debug-Mode. Then
> it went into the part where the described error is generated.
>
>     typedef itk::Image<unsigned char,2> imagetype;
>     vtkSmartPointer<vtkJPEGReader>
> reader=vtkSmartPointer<vtkJPEGReader>::New();
>     reader->SetFileName("1.jpg");
>
>     vtkSmartPointer<vtkImageActor>
> actor=vtkSmartPointer<vtkImageActor>::New();
>     actor->SetInput(reader->GetOutput());
>
>     vtkSmartPointer<vtkImageCast>
> caster=vtkSmartPointer<vtkImageCast>::New();
>     caster->SetInput(actor->GetInput());
>     caster->SetOutputScalarTypeToUnsignedChar();
>
>     itk::VTKImageToImageFilter<imagetype>::Pointer
> vtk2itk=itk::VTKImageToImageFilter<imagetype>::New();
>     vtk2itk->SetInput(caster->GetOutput());
>     vtk2itk->Update();
>
>     itk::BinaryThresholdImageFilter<imagetype,imagetype>::Pointer
> binaryfilter=itk::BinaryThresholdImageFilter<imagetype,imagetype>::New();
>     binaryfilter->SetLowerThreshold(125*(-1));
>     binaryfilter->SetInput(vtk2itk->GetOutput());
>     binaryfilter->Update();
>
>     itk::ImageToVTKImageFilter<imagetype>::Pointer
> itk2vtk=itk::ImageToVTKImageFilter<imagetype>::New();
>     itk2vtk->SetInput(binaryfilter->GetOutput());
>     itk2vtk->Update();
>
>     vtkSmartPointer<vtkRenderWindowInteractor>
> interactor=vtkSmartPointer<vtkRenderWindowInteractor>::New();
>
>     vtkSmartPointer<vtkImageViewer2>
> viewer=vtkSmartPointer<vtkImageViewer2>::New();
>     viewer->SetInput(itk2vtk->GetOutput());
>     viewer->SetupInteractor(interactor);
>
>     interactor->Initialize();
>     viewer->Render();
>     interactor->Start();

Ralf,

This is still not self contained. The main problem is you didn't send
1.jpg. You should prefer programmatically generating the input rather
than needing an external file when creating small test cases like
this. Also, the includes are missing, main is missing, etc. The ideal
case (for me, and I'd imagine anyone else trying to help someone) is
to be able to copy+paste+build and see the exact same thing you're
seeing.

David



More information about the vtkusers mailing list