[Insight-users] run time error during display itkimage
Robert Haase
robert_haase at gmx.de
Mon Mar 12 05:39:49 EDT 2012
Hi Alaa,
three things:
1. The second code may be running because you don't call the "displayImage" function.
2. I'm not that familiar to vtk, but is it allowed to cast a "vtkSmartPointer <vtkImageData>" to to "vtkImageData *" as you do it at the end (return) of function "ConvertITKImageToVtkImage"?
3. If you use a debugger, you may figure out, where your code crashes. Alternatively, put lines like
cout << "I'm here at line 57" << endl;
into your code to find out, at which line it crashes.
Regards,
Robert
-------- Original-Nachricht --------
> Datum: Mon, 12 Mar 2012 01:49:55 -0700 (PDT)
> Von: alaa ahmed <alaamegawer at yahoo.com>
> An: "insight-users at itk.org" <insight-users at itk.org>
> Betreff: [Insight-users] run time error during display itkimage
>
>
> hi all
>
> I'm trying to send itkimage pointer to a function then convert it to
> vtkimagedata but after that i
> have run time exception during display them . but if i use the same code
> of conversion in the function i use to open this image all things are going
> good . actually i want to ask what's the different between this code
>
> void ImageWidget::openWithITK()
> {
> QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"),
> QDir::currentPath());
>
> if (!fileName.isEmpty()) {
> // read the image
> typedef itk::ImageFileReader <ImageType> ReaderType;
> ReaderType::Pointer reader = ReaderType::New();
> reader->SetFileName(fileName.toAscii().data());
> reader->Update();
> this->displayImage(ConvertITKImageToVtkImage(reader->GetOutput()));
> }
> }
> void ImageWidget::displayImage(vtkImageData *image)
> {
> int *dim= image->GetDimensions();
> double *spacing = image->GetSpacing();
> double *origin = image->GetOrigin();
>
> float Cx = (dim[0] * spacing[0])/2. + origin[0];
> float Cy = (dim[1] * spacing[1])/2. + origin[1];
> camera->ParallelProjectionOn();
> camera->SetFocalPoint(Cx,Cy,0);
> camera->SetPosition(Cx,Cy,1);
> //
> // // to flip de image
> // camera->SetViewUp (0, 1, 0);
> //
> // set actor properties
> actor->SetInput(image);
> actor->InterpolateOff();
>
> renderer->AddActor(actor);
> renderer->SetActiveCamera(camera);
> renderer->ResetCamera();
>
> qvtkWidget->SetRenderWindow(renderWindow);
>
> // window interactor style for display images
> vtkSmartPointer<vtkInteractorStyleImage> style
> =vtkSmartPointer<vtkInteractorStyleImage>::New();
> // set interactor style to the qvtkWidget Interactor
> qvtkWidget->GetInteractor()->SetInteractorStyle(style);
> qvtkWidget->update();
> this->update();
> }
>
> vtkImageData* ImageWidget::ConvertITKImageToVtkImage(ImageType * image)
> {
> vtkSmartPointer <vtkImageData> vtkImageFromItkImage;
> vtkConnectorType::Pointer connector = vtkConnectorType::New();
> connector->GetExporter()->SetInput(image);
> connector->GetImporter()->Update();
>
> // flip image in Y axis
> vtkSmartPointer<vtkImageFlip> flipYFilter =
> vtkSmartPointer<vtkImageFlip>::New();
> flipYFilter->SetFilteredAxis(1); // flip Y axis
> flipYFilter->SetInput(connector->GetImporter()->GetOutput());
> flipYFilter->Update();
>
> // create vtk image
> vtkImageFromItkImage = vtkSmartPointer<vtkImageData>::New();
> vtkImageFromItkImage->DeepCopy(flipYFilter->GetOutput());
> vtkImageFromItkImage->SetScalarTypeToUnsignedChar();
> vtkImageFromItkImage->Update();
>
> //reader = NULL;
> flipYFilter = NULL;
> connector = NULL;
> return vtkImageFromItkImage;
> }
>
> and that code
>
> void ImageWidget::openWithITK()
> {
> QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"),
> QDir::currentPath());
>
> if (!fileName.isEmpty()) {
> // read the image
> typedef itk::ImageFileReader <ImageType> ReaderType;
> ReaderType::Pointer reader = ReaderType::New();
> reader->SetFileName(fileName.toAscii().data());
> reader->Update();
>
> vtkSmartPointer <vtkImageData> vtkImageFromItkImage;
> vtkConnectorType::Pointer connector = vtkConnectorType::New();
> connector->GetExporter()->SetInput( reader->GetOutput() );
> connector->GetImporter()->Update();
> // flip image in Y axis
> vtkSmartPointer<vtkImageFlip> flipYFilter =
> vtkSmartPointer<vtkImageFlip>::New();
> flipYFilter->SetFilteredAxis(1); // flip Y axis
> flipYFilter->SetInput(connector->GetImporter()->GetOutput());
> flipYFilter->Update();
> // create vtk image
> vtkImageFromItkImage = vtkSmartPointer<vtkImageData>::New();
> vtkImageFromItkImage->DeepCopy(flipYFilter->GetOutput());
> vtkImageFromItkImage->SetScalarTypeToUnsignedChar();
> vtkImageFromItkImage->Update();
>
> //reader = NULL;
> flipYFilter = NULL;
> connector = NULL;
> }
> }
> void ImageWidget::displayImage(vtkImageData *image)
> {
> int *dim= image->GetDimensions();
> double *spacing = image->GetSpacing();
> double *origin = image->GetOrigin();
>
> float Cx = (dim[0] * spacing[0])/2. + origin[0];
> float Cy = (dim[1] * spacing[1])/2. + origin[1];
> camera->ParallelProjectionOn();
> camera->SetFocalPoint(Cx,Cy,0);
> camera->SetPosition(Cx,Cy,1);
> //
> // // to flip de image
> // camera->SetViewUp (0, 1, 0);
> //
> // set actor properties
> actor->SetInput(image);
> actor->InterpolateOff();
>
> renderer->AddActor(actor);
> renderer->SetActiveCamera(camera);
> renderer->ResetCamera();
>
> qvtkWidget->SetRenderWindow(renderWindow);
>
> // window interactor style for display images
> vtkSmartPointer<vtkInteractorStyleImage> style
> =vtkSmartPointer<vtkInteractorStyleImage>::New();
> // set interactor style to the qvtkWidget Interactor
> qvtkWidget->GetInteractor()->SetInteractorStyle(style);
> qvtkWidget->update();
> this->update();
> }
>
> the second works good but the first give me run time error at display
> function.
>
> keep Blessed
>
> Regards
>
> Alaa
--
Empfehlen Sie GMX DSL Ihren Freunden und Bekannten und wir
belohnen Sie mit bis zu 50,- Euro! https://freundschaftswerbung.gmx.de
More information about the Insight-users
mailing list