[vtkusers] error when connecting ITK with VTK
Ralf.Denhof
ralf.denhof at gmx.de
Sun Dec 4 17:18:53 EST 2011
Sorry...
This example contains generated data and represents the constellation in
my project. Thanks for being patient with me :)
/
#include "vtkSmartPointer.h"
#include "vtkJPEGReader.h"
#include "itkImageToVTKImageFilter.h"
#include "itkVTKImageToImageFilter.h"
#include "vtkImageCast.h"
#include "vtkImageActor.h"
#include "itkBinaryThresholdImageFilter.h"
#include "vtkImageViewer2.h"
#include "vtkRenderWindowInteractor.h"
#include "vcl_cstdlib.h"
int main(int argc,char*argv[]){
typedef itk::Image<unsigned char,2> imagetype;
imagetype::IndexType start;
start[0]=0;
start[1]=0;
imagetype::SizeType size;
size[0]=16;
size[1]=16;
imagetype::RegionType region;
region.SetSize(size);
region.SetIndex(start);
imagetype::Pointer img=imagetype::New();
img->SetRegions(region);
img->Allocate();
imagetype::IndexType pixelValue1;
int pixval=0;
for (int y=size[1]-1;y>=0;y--)
for (int x=0;x<size[0];x++)
{
pixelValue1[0]=x;
pixelValue1[1]=y;
img->SetPixel(pixelValue1,255- rand()%256);
pixval++;
}
img->Update();
itk::ImageToVTKImageFilter<imagetype>::Pointer
itk2vtk1=itk::ImageToVTKImageFilter<imagetype>::New();
itk2vtk1->SetInput(img);
itk2vtk1->Update();
vtkSmartPointer<vtkImageActor>
actor=vtkSmartPointer<vtkImageActor>::New();
actor->SetInput(itk2vtk1->GetOutput());
vtkSmartPointer<vtkRenderWindowInteractor>
interactor=vtkSmartPointer<vtkRenderWindowInteractor>::New();
vtkSmartPointer<vtkImageViewer2>
viewer=vtkSmartPointer<vtkImageViewer2>::New();
viewer->SetInput(itk2vtk1->GetOutput());
viewer->SetupInteractor(interactor);
interactor->Initialize();
viewer->Render();
interactor->Start();
vtkSmartPointer<vtkImageCast>
caster=vtkSmartPointer<vtkImageCast>::New();
caster->SetInput(viewer->GetImageActor()->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<vtkImageViewer2>
viewer2=vtkSmartPointer<vtkImageViewer2>::New();
viewer->SetInput(itk2vtk->GetOutput());
viewer->SetupInteractor(interactor);
interactor->Initialize();
viewer->Render();
interactor->Start();
}
/
Am 04.12.2011 22:41, schrieb David Doria:
> 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20111204/d9ad6278/attachment.htm>
More information about the vtkusers
mailing list