[Insight-users] std::bad_alloc on rendering with vtkImagePlaneWidget

Lodron, Gerald Gerald.Lodron at joanneum.at
Tue Oct 6 08:14:49 EDT 2009


Hello ITK user group,
 
I already loaded an DICOM 3d image in ITK and succesfully piped it to an vtkImage Object. I also already visualized it like in the Medical1.cxx example but now I want to use the vtkImagePlaneWidget. 
 
The code compiles and links but in the Renderer() procedure of the vtkRenderer i get a std::bad_alloc exception. Does anybody know something about that? Here is my code:

...
...
vtkImage is the vtkImageData object with an 3d image
...
 
vtkRenderer *aRenderer = vtkRenderer::New();
vtkRenderWindow *renWin = vtkRenderWindow::New();
renWin->AddRenderer(aRenderer);
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
iren->SetRenderWindow(renWin);

vtkCellPicker *cellPicker = vtkCellPicker::New();
cellPicker->SetTolerance(0.005);

vtkImagePlaneWidget* planeWidgetX = vtkImagePlaneWidget::New();
planeWidgetX->DisplayTextOn();
planeWidgetX->SetInput(vtkImage);
planeWidgetX->SetPlaneOrientationToXAxes();
planeWidgetX->SetSliceIndex(0);
planeWidgetX->SetPicker(cellPicker);
planeWidgetX->SetKeyPressActivationValue('x');
planeWidgetX->GetPlaneProperty()->SetColor(1, 0, 0);
planeWidgetX->SetWindowLevel(2000, 500);
planeWidgetX->GetColorMap()->PassAlphaToOutputOff();
planeWidgetX->SetInteractor(iren);
planeWidgetX->On();

vtkImagePlaneWidget* planeWidgetY = vtkImagePlaneWidget::New();
planeWidgetY->DisplayTextOn();
planeWidgetY->SetInput(vtkImage);
planeWidgetY->SetPlaneOrientationToYAxes();
planeWidgetY->SetSliceIndex(0);
planeWidgetY->SetPicker(cellPicker);
planeWidgetY->SetKeyPressActivationValue('y');
planeWidgetY->GetPlaneProperty()->SetColor(1, 1, 0);
planeWidgetY->SetWindowLevel(2000, 500);
planeWidgetY->GetColorMap()->PassAlphaToOutputOff();
planeWidgetY->SetInteractor(iren);
planeWidgetY->On();

vtkImagePlaneWidget* planeWidgetZ = vtkImagePlaneWidget::New();
planeWidgetZ->DisplayTextOn();
planeWidgetZ->SetInput(vtkImage);
planeWidgetZ->SetPlaneOrientationToZAxes();
planeWidgetZ->SetSliceIndex(0);
planeWidgetZ->SetPicker(cellPicker);
planeWidgetZ->SetKeyPressActivationValue('z');
planeWidgetZ->GetPlaneProperty()->SetColor(0, 0, 1);
planeWidgetZ->SetWindowLevel(2000, 500);
planeWidgetZ->GetColorMap()->PassAlphaToOutputOff();
planeWidgetZ->SetInteractor(iren);
planeWidgetZ->On();

aRenderer->Render(); //Render with std:bad_alloc
iren->Initialize();
iren->Start(); 

aRenderer->Delete();
renWin->Delete();
iren->Delete();
cellPicker->Delete();
planeWidgetX->Delete();
planeWidgetY->Delete();
planeWidgetZ->Delete();

 
I am quite new to ITK and VTK so if anybody has some tips it would be great!

Best regards,
Gerald


More information about the Insight-users mailing list