3 #include <creaVtkBasicSlicer.h>
5 #include "vtkRenderWindow.h"
6 #include "vtkRenderWindowInteractor.h"
8 #include "vtkOutlineFilter.h"
9 #include "vtkPolyDataMapper.h"
11 #include "vtkImagePlaneWidget.h"
12 #include "vtkCellPicker.h"
13 #include "vtkProperty.h"
14 #include "vtkRenderer.h"
15 #include "vtkCamera.h"
20 void VtkBasicSlicer( vtkImageData* I )
23 int xMin, xMax, yMin, yMax, zMin, zMax;
24 I->GetExtent(xMin, xMax, yMin, yMax, zMin, zMax);
27 I->GetSpacing(sx, sy, sz);
30 I->GetOrigin(ox,oy,oz);
33 // An outline is shown for context.
35 vtkOutlineFilter* outline = vtkOutlineFilter::New();
38 vtkPolyDataMapper* outlineMapper = vtkPolyDataMapper::New();
39 outlineMapper->SetInputConnection(outline->GetOutputPort());
41 vtkActor* outlineActor = vtkActor::New();
42 outlineActor->SetMapper(outlineMapper);
45 // The shared picker enables us to use 3 planes at one time
46 // and gets the picking order right
47 vtkCellPicker* picker = vtkCellPicker::New();
48 picker->SetTolerance(0.005);
50 // The 3 image plane widgets are used to probe the dataset.
51 vtkImagePlaneWidget* planeWidgetX = vtkImagePlaneWidget::New();
52 planeWidgetX->DisplayTextOn();
53 planeWidgetX->SetInput(I);
54 planeWidgetX->SetPlaneOrientationToXAxes();
55 planeWidgetX->SetSlicePosition((xMax+xMin)/2.);
56 planeWidgetX->SetPicker(picker);
57 planeWidgetX->SetKeyPressActivationValue('x');
58 vtkProperty* prop1 = planeWidgetX->GetPlaneProperty();
59 prop1->SetColor(1, 0, 0);
61 vtkImagePlaneWidget* planeWidgetY = vtkImagePlaneWidget::New();
62 planeWidgetY->DisplayTextOn();
63 planeWidgetY->SetInput(I);
64 planeWidgetY->SetPlaneOrientationToYAxes();
65 planeWidgetY->SetSlicePosition((yMax+yMin)/2.);
66 planeWidgetY->SetPicker(picker);
67 planeWidgetY->SetKeyPressActivationValue('y');
68 vtkProperty* prop2 = planeWidgetY->GetPlaneProperty();
69 prop2->SetColor(1, 1, 0);
70 planeWidgetY->SetLookupTable(planeWidgetX->GetLookupTable());
72 // for the z-slice, turn off texture interpolation:
73 // interpolation is now nearest neighbour, to demonstrate
74 // cross-hair cursor snapping to pixel centers
75 vtkImagePlaneWidget* planeWidgetZ = vtkImagePlaneWidget::New();
76 planeWidgetZ->DisplayTextOn();
77 planeWidgetZ->SetInput(I);
78 planeWidgetZ->SetPlaneOrientationToZAxes();
79 planeWidgetZ->SetSlicePosition((zMax+zMin)/2.);
80 planeWidgetZ->SetPicker(picker);
81 planeWidgetZ->SetKeyPressActivationValue('z');
82 vtkProperty* prop3 = planeWidgetZ->GetPlaneProperty();
83 prop3->SetColor(0, 0, 1);
84 planeWidgetZ->SetLookupTable(planeWidgetX->GetLookupTable());
86 planeWidgetZ->SetWindowLevel(512,256);
88 // Create the RenderWindow and Renderer
89 vtkRenderer* ren = vtkRenderer::New();
90 vtkRenderWindow* renWin = vtkRenderWindow::New();
91 renWin->AddRenderer(ren);
93 // Add the outline actor to the renderer, set the background color and size
94 ren->AddActor(outlineActor);
95 renWin->SetSize(600, 600);
96 ren->SetBackground(0.1, 0.1, 0.2);
99 vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
100 iren->SetRenderWindow(renWin);
102 // Set the interactor for the widgets
103 planeWidgetX->SetInteractor(iren);
105 planeWidgetY->SetInteractor(iren);
107 planeWidgetZ->SetInteractor(iren);
110 // Create an initial interesting view
111 vtkCamera* cam1 = ren->GetActiveCamera();
112 cam1->SetFocalPoint(0, 0, 0);
113 cam1->SetPosition(0, 0, -500);
114 //cam1->OrthogonalizeViewUp();
115 cam1->Elevation(110);
116 cam1->SetViewUp(0, 0, -1);
118 ren->ResetCameraClippingRange();
121 // render_widget->Render();
130 planeWidgetX->Delete();
131 planeWidgetY->Delete();
132 planeWidgetZ->Delete();
134 outlineMapper->Delete();
135 outlineActor->Delete();