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();
67 vtkPolyDataMapper* outlineMapper = vtkPolyDataMapper::New();
68 outlineMapper->SetInputConnection(outline->GetOutputPort());
70 vtkActor* outlineActor = vtkActor::New();
71 outlineActor->SetMapper(outlineMapper);
74 // The shared picker enables us to use 3 planes at one time
75 // and gets the picking order right
76 vtkCellPicker* picker = vtkCellPicker::New();
77 picker->SetTolerance(0.005);
79 // The 3 image plane widgets are used to probe the dataset.
80 vtkImagePlaneWidget* planeWidgetX = vtkImagePlaneWidget::New();
81 planeWidgetX->DisplayTextOn();
82 planeWidgetX->SetInput(I);
83 planeWidgetX->SetPlaneOrientationToXAxes();
84 planeWidgetX->SetSlicePosition((xMax+xMin)/2.);
85 planeWidgetX->SetPicker(picker);
86 planeWidgetX->SetKeyPressActivationValue('x');
87 vtkProperty* prop1 = planeWidgetX->GetPlaneProperty();
88 prop1->SetColor(1, 0, 0);
90 vtkImagePlaneWidget* planeWidgetY = vtkImagePlaneWidget::New();
91 planeWidgetY->DisplayTextOn();
92 planeWidgetY->SetInput(I);
93 planeWidgetY->SetPlaneOrientationToYAxes();
94 planeWidgetY->SetSlicePosition((yMax+yMin)/2.);
95 planeWidgetY->SetPicker(picker);
96 planeWidgetY->SetKeyPressActivationValue('y');
97 vtkProperty* prop2 = planeWidgetY->GetPlaneProperty();
98 prop2->SetColor(1, 1, 0);
99 planeWidgetY->SetLookupTable(planeWidgetX->GetLookupTable());
101 // for the z-slice, turn off texture interpolation:
102 // interpolation is now nearest neighbour, to demonstrate
103 // cross-hair cursor snapping to pixel centers
104 vtkImagePlaneWidget* planeWidgetZ = vtkImagePlaneWidget::New();
105 planeWidgetZ->DisplayTextOn();
106 planeWidgetZ->SetInput(I);
107 planeWidgetZ->SetPlaneOrientationToZAxes();
108 planeWidgetZ->SetSlicePosition((zMax+zMin)/2.);
109 planeWidgetZ->SetPicker(picker);
110 planeWidgetZ->SetKeyPressActivationValue('z');
111 vtkProperty* prop3 = planeWidgetZ->GetPlaneProperty();
112 prop3->SetColor(0, 0, 1);
113 planeWidgetZ->SetLookupTable(planeWidgetX->GetLookupTable());
115 planeWidgetZ->SetWindowLevel(512,256);
117 // Create the RenderWindow and Renderer
118 vtkRenderer* ren = vtkRenderer::New();
119 vtkRenderWindow* renWin = vtkRenderWindow::New();
120 renWin->AddRenderer(ren);
122 // Add the outline actor to the renderer, set the background color and size
123 ren->AddActor(outlineActor);
124 renWin->SetSize(600, 600);
125 ren->SetBackground(0.1, 0.1, 0.2);
128 vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
129 iren->SetInteractorStyle( vtkInteractorStyleTrackballCamera::New() );
130 iren->SetRenderWindow(renWin);
132 // Set the interactor for the widgets
133 planeWidgetX->SetInteractor(iren);
135 planeWidgetY->SetInteractor(iren);
137 planeWidgetZ->SetInteractor(iren);
140 // Create an initial interesting view
141 vtkCamera* cam1 = ren->GetActiveCamera();
142 cam1->SetFocalPoint(0, 0, 0);
143 cam1->SetPosition(0, 0, -1500);
144 //cam1->OrthogonalizeViewUp();
145 cam1->Elevation(110);
146 cam1->SetViewUp(0, 0, -1);
148 ren->ResetCameraClippingRange();
151 // render_widget->Render();
160 planeWidgetX->Delete();
161 planeWidgetY->Delete();
162 planeWidgetZ->Delete();
164 outlineMapper->Delete();
165 outlineActor->Delete();