2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
8 # This software is governed by the CeCILL-B license under French law and
9 # abiding by the rules of distribution of free software. You can use,
10 # modify and/ or redistribute the software under the terms of the CeCILL-B
11 # license as circulated by CEA, CNRS and INRIA at the following URL
12 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
13 # or in the file LICENSE.txt.
15 # As a counterpart to the access to the source code and rights to copy,
16 # modify and redistribute granted by the license, users are provided only
17 # with a limited warranty and the software's author, the holder of the
18 # economic rights, and the successive licensors have only limited
21 # The fact that you are presently reading this means that you have had
22 # knowledge of the CeCILL-B license and that you accept its terms.
23 # ------------------------------------------------------------------------ */
27 #include <creaVtkBasicSlicer.h>
29 #include "vtkRenderWindow.h"
30 #include "vtkRenderWindowInteractor.h"
32 #include "vtkOutlineFilter.h"
33 #include "vtkPolyDataMapper.h"
35 #include "vtkImagePlaneWidget.h"
36 #include "vtkCellPicker.h"
37 #include "vtkProperty.h"
38 #include "vtkRenderer.h"
39 #include "vtkCamera.h"
41 #include "vtkInteractorStyleTrackballCamera.h"
46 void VtkBasicSlicer( vtkImageData* I )
49 int xMin, xMax, yMin, yMax, zMin, zMax;
50 I->GetExtent(xMin, xMax, yMin, yMax, zMin, zMax);
53 I->GetSpacing(sx, sy, sz);
56 I->GetOrigin(ox,oy,oz);
59 // An outline is shown for context.
61 vtkOutlineFilter* outline = vtkOutlineFilter::New();
64 vtkPolyDataMapper* outlineMapper = vtkPolyDataMapper::New();
65 outlineMapper->SetInputConnection(outline->GetOutputPort());
67 vtkActor* outlineActor = vtkActor::New();
68 outlineActor->SetMapper(outlineMapper);
71 // The shared picker enables us to use 3 planes at one time
72 // and gets the picking order right
73 vtkCellPicker* picker = vtkCellPicker::New();
74 picker->SetTolerance(0.005);
76 // The 3 image plane widgets are used to probe the dataset.
77 vtkImagePlaneWidget* planeWidgetX = vtkImagePlaneWidget::New();
78 planeWidgetX->DisplayTextOn();
79 planeWidgetX->SetInput(I);
80 planeWidgetX->SetPlaneOrientationToXAxes();
81 planeWidgetX->SetSlicePosition((xMax+xMin)/2.);
82 planeWidgetX->SetPicker(picker);
83 planeWidgetX->SetKeyPressActivationValue('x');
84 vtkProperty* prop1 = planeWidgetX->GetPlaneProperty();
85 prop1->SetColor(1, 0, 0);
87 vtkImagePlaneWidget* planeWidgetY = vtkImagePlaneWidget::New();
88 planeWidgetY->DisplayTextOn();
89 planeWidgetY->SetInput(I);
90 planeWidgetY->SetPlaneOrientationToYAxes();
91 planeWidgetY->SetSlicePosition((yMax+yMin)/2.);
92 planeWidgetY->SetPicker(picker);
93 planeWidgetY->SetKeyPressActivationValue('y');
94 vtkProperty* prop2 = planeWidgetY->GetPlaneProperty();
95 prop2->SetColor(1, 1, 0);
96 planeWidgetY->SetLookupTable(planeWidgetX->GetLookupTable());
98 // for the z-slice, turn off texture interpolation:
99 // interpolation is now nearest neighbour, to demonstrate
100 // cross-hair cursor snapping to pixel centers
101 vtkImagePlaneWidget* planeWidgetZ = vtkImagePlaneWidget::New();
102 planeWidgetZ->DisplayTextOn();
103 planeWidgetZ->SetInput(I);
104 planeWidgetZ->SetPlaneOrientationToZAxes();
105 planeWidgetZ->SetSlicePosition((zMax+zMin)/2.);
106 planeWidgetZ->SetPicker(picker);
107 planeWidgetZ->SetKeyPressActivationValue('z');
108 vtkProperty* prop3 = planeWidgetZ->GetPlaneProperty();
109 prop3->SetColor(0, 0, 1);
110 planeWidgetZ->SetLookupTable(planeWidgetX->GetLookupTable());
112 planeWidgetZ->SetWindowLevel(512,256);
114 // Create the RenderWindow and Renderer
115 vtkRenderer* ren = vtkRenderer::New();
116 vtkRenderWindow* renWin = vtkRenderWindow::New();
117 renWin->AddRenderer(ren);
119 // Add the outline actor to the renderer, set the background color and size
120 ren->AddActor(outlineActor);
121 renWin->SetSize(600, 600);
122 ren->SetBackground(0.1, 0.1, 0.2);
125 vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
126 iren->SetInteractorStyle( vtkInteractorStyleTrackballCamera::New() );
127 iren->SetRenderWindow(renWin);
129 // Set the interactor for the widgets
130 planeWidgetX->SetInteractor(iren);
132 planeWidgetY->SetInteractor(iren);
134 planeWidgetZ->SetInteractor(iren);
137 // Create an initial interesting view
138 vtkCamera* cam1 = ren->GetActiveCamera();
139 cam1->SetFocalPoint(0, 0, 0);
140 cam1->SetPosition(0, 0, -1500);
141 //cam1->OrthogonalizeViewUp();
142 cam1->Elevation(110);
143 cam1->SetViewUp(0, 0, -1);
145 ren->ResetCameraClippingRange();
148 // render_widget->Render();
157 planeWidgetX->Delete();
158 planeWidgetY->Delete();
159 planeWidgetZ->Delete();
161 outlineMapper->Delete();
162 outlineActor->Delete();