2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
10 # This software is governed by the CeCILL-B license under French law and
11 # abiding by the rules of distribution of free software. You can use,
12 # modify and/ or redistribute the software under the terms of the CeCILL-B
13 # license as circulated by CEA, CNRS and INRIA at the following URL
14 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15 # or in the file LICENSE.txt.
17 # As a counterpart to the access to the source code and rights to copy,
18 # modify and redistribute granted by the license, users are provided only
19 # with a limited warranty and the software's author, the holder of the
20 # economic rights, and the successive licensors have only limited
23 # The fact that you are presently reading this means that you have had
24 # knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------
30 #include <creaVtkBasicSlicer.h>
32 #include "vtkRenderWindow.h"
33 #include "vtkRenderWindowInteractor.h"
35 #include "vtkOutlineFilter.h"
36 #include "vtkPolyDataMapper.h"
38 #include "vtkImagePlaneWidget.h"
39 #include "vtkCellPicker.h"
40 #include "vtkProperty.h"
41 #include "vtkRenderer.h"
42 #include "vtkCamera.h"
44 #include "vtkInteractorStyleTrackballCamera.h"
49 void VtkBasicSlicer( vtkImageData* I )
52 int xMin, xMax, yMin, yMax, zMin, zMax;
53 I->GetExtent(xMin, xMax, yMin, yMax, zMin, zMax);
56 I->GetSpacing(sx, sy, sz);
59 I->GetOrigin(ox,oy,oz);
62 // An outline is shown for context.
64 vtkOutlineFilter* outline = vtkOutlineFilter::New();
66 //EED 2017-01-01 Migration VTK7
67 #if (VTK_MAJOR_VERSION <= 5)
70 #if (VTK_MAJOR_VERSION >= 6)
71 outline->SetInputData(I);
74 vtkPolyDataMapper* outlineMapper = vtkPolyDataMapper::New();
75 outlineMapper->SetInputConnection(outline->GetOutputPort());
77 vtkActor* outlineActor = vtkActor::New();
78 outlineActor->SetMapper(outlineMapper);
81 // The shared picker enables us to use 3 planes at one time
82 // and gets the picking order right
83 vtkCellPicker* picker = vtkCellPicker::New();
84 picker->SetTolerance(0.005);
86 // The 3 image plane widgets are used to probe the dataset.
87 vtkImagePlaneWidget* planeWidgetX = vtkImagePlaneWidget::New();
88 planeWidgetX->DisplayTextOn();
90 //EED 2017-01-01 Migration VTK7
91 #if (VTK_MAJOR_VERSION <= 5)
92 planeWidgetX->SetInput(I);
94 #if (VTK_MAJOR_VERSION >= 6)
95 planeWidgetX->SetInputData(I);
98 planeWidgetX->SetPlaneOrientationToXAxes();
99 planeWidgetX->SetSlicePosition((xMax+xMin)/2.);
100 planeWidgetX->SetPicker(picker);
101 planeWidgetX->SetKeyPressActivationValue('x');
102 vtkProperty* prop1 = planeWidgetX->GetPlaneProperty();
103 prop1->SetColor(1, 0, 0);
105 vtkImagePlaneWidget* planeWidgetY = vtkImagePlaneWidget::New();
106 planeWidgetY->DisplayTextOn();
108 //EED 2017-01-01 Migration VTK7
109 #if (VTK_MAJOR_VERSION <= 5)
110 planeWidgetY->SetInput(I);
112 #if (VTK_MAJOR_VERSION >= 6)
113 planeWidgetY->SetInputData(I);
116 planeWidgetY->SetPlaneOrientationToYAxes();
117 planeWidgetY->SetSlicePosition((yMax+yMin)/2.);
118 planeWidgetY->SetPicker(picker);
119 planeWidgetY->SetKeyPressActivationValue('y');
120 vtkProperty* prop2 = planeWidgetY->GetPlaneProperty();
121 prop2->SetColor(1, 1, 0);
122 planeWidgetY->SetLookupTable(planeWidgetX->GetLookupTable());
124 // for the z-slice, turn off texture interpolation:
125 // interpolation is now nearest neighbour, to demonstrate
126 // cross-hair cursor snapping to pixel centers
127 vtkImagePlaneWidget* planeWidgetZ = vtkImagePlaneWidget::New();
128 planeWidgetZ->DisplayTextOn();
130 //EED 2017-01-01 Migration VTK7
131 #if (VTK_MAJOR_VERSION <= 5)
132 planeWidgetZ->SetInput(I);
134 #if (VTK_MAJOR_VERSION >= 6)
135 planeWidgetZ->SetInputData(I);
139 planeWidgetZ->SetPlaneOrientationToZAxes();
140 planeWidgetZ->SetSlicePosition((zMax+zMin)/2.);
141 planeWidgetZ->SetPicker(picker);
142 planeWidgetZ->SetKeyPressActivationValue('z');
143 vtkProperty* prop3 = planeWidgetZ->GetPlaneProperty();
144 prop3->SetColor(0, 0, 1);
145 planeWidgetZ->SetLookupTable(planeWidgetX->GetLookupTable());
147 planeWidgetZ->SetWindowLevel(512,256);
149 // Create the RenderWindow and Renderer
150 vtkRenderer* ren = vtkRenderer::New();
151 vtkRenderWindow* renWin = vtkRenderWindow::New();
152 renWin->AddRenderer(ren);
154 // Add the outline actor to the renderer, set the background color and size
155 ren->AddActor(outlineActor);
156 renWin->SetSize(600, 600);
157 ren->SetBackground(0.1, 0.1, 0.2);
160 vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
161 iren->SetInteractorStyle( vtkInteractorStyleTrackballCamera::New() );
162 iren->SetRenderWindow(renWin);
164 // Set the interactor for the widgets
165 planeWidgetX->SetInteractor(iren);
167 planeWidgetY->SetInteractor(iren);
169 planeWidgetZ->SetInteractor(iren);
172 // Create an initial interesting view
173 vtkCamera* cam1 = ren->GetActiveCamera();
174 cam1->SetFocalPoint(0, 0, 0);
175 cam1->SetPosition(0, 0, -1500);
176 //cam1->OrthogonalizeViewUp();
177 cam1->Elevation(110);
178 cam1->SetViewUp(0, 0, -1);
180 ren->ResetCameraClippingRange();
183 // render_widget->Render();
192 planeWidgetX->Delete();
193 planeWidgetY->Delete();
194 planeWidgetZ->Delete();
196 outlineMapper->Delete();
197 outlineActor->Delete();