1 /*# ---------------------------------------------------------------------
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9 # This software is governed by the CeCILL-B license under French law and
10 # abiding by the rules of distribution of free software. You can use,
11 # modify and/ or redistribute the software under the terms of the CeCILL-B
12 # license as circulated by CEA, CNRS and INRIA at the following URL
13 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 # or in the file LICENSE.txt.
16 # As a counterpart to the access to the source code and rights to copy,
17 # modify and redistribute granted by the license, users are provided only
18 # with a limited warranty and the software's author, the holder of the
19 # economic rights, and the successive licensors have only limited
22 # The fact that you are presently reading this means that you have had
23 # knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
26 #include "imageplanewidget.h"
28 #include "vtkSmartPointer.h"
30 #include "vtkImageActor.h"
31 #include "vtkImageAppendComponents.h"
32 #include "vtkRenderWindowInteractor.h"
33 #include "vtkTextProperty.h"
37 ImagePlaneWidget::ImagePlaneWidget()
49 void ImagePlaneWidget::initialize(vtkRenderWindowInteractor* interactor){
50 m_Interactor = interactor;
52 _xwidget = vtkImagePlaneWidget::New( );
53 _ywidget = vtkImagePlaneWidget::New( );
54 _zwidget = vtkImagePlaneWidget::New( );
57 _xwidget->SetInteractor( interactor );
58 _ywidget->SetInteractor( interactor );
59 _zwidget->SetInteractor( interactor );
62 bool ImagePlaneWidget::showImageActors(bool show){
63 if(show && m_Interactor){
65 initializeImageActors();
67 m_Interactor->GetRenderWindow ()->GetRenderers ()->GetFirstRenderer ()->AddViewProp(_imageactorx);
68 m_Interactor->GetRenderWindow ()->GetRenderers ()->GetFirstRenderer ()->AddViewProp(_imageactory);
69 m_Interactor->GetRenderWindow ()->GetRenderers ()->GetFirstRenderer ()->AddViewProp(_imageactorz);
71 }else if(_imageactorx){
72 m_Interactor->GetRenderWindow ()->GetRenderers ()->GetFirstRenderer ()->RemoveViewProp(_imageactorx);
73 m_Interactor->GetRenderWindow ()->GetRenderers ()->GetFirstRenderer ()->RemoveViewProp(_imageactory);
74 m_Interactor->GetRenderWindow ()->GetRenderers ()->GetFirstRenderer ()->RemoveViewProp(_imageactorz);
81 void ImagePlaneWidget::initializeImageActors(){
83 //cout<<w_ext[0]<<" "<<w_ext[1]<<" "<<w_ext[2]<<" "<<w_ext[3]<<" "<<w_ext[4]<<" "<<w_ext[5]<<" "<<endl;
84 _imageactorx = vtkImageActor::New();
86 //EED 2017-01-01 Migration VTK7
87 #if VTK_MAJOR_VERSION <= 5
88 int *w_ext = _img->GetWholeExtent();
89 _imageactorx->SetInput(_img);
91 int *w_ext = _img->GetExtent();
92 _imageactorx->SetInputData(_img);
95 xslice = (w_ext[4] + w_ext[5])/2;
96 _imageactorx->SetDisplayExtent(w_ext[0], w_ext[1], w_ext[2], w_ext[3], xslice, xslice);
99 _imageactory = vtkImageActor::New();
101 //EED 2017-01-01 Migration VTK7
102 #if VTK_MAJOR_VERSION <= 5
103 _imageactory->SetInput(_img);
105 _imageactory->SetInputData(_img);
108 yslice = (w_ext[2] + w_ext[3])/2;
109 _imageactory->SetDisplayExtent(w_ext[0], w_ext[1], yslice, yslice, w_ext[4], w_ext[5]);
111 _imageactorz = vtkImageActor::New();
113 //EED 2017-01-01 Migration VTK7
114 #if VTK_MAJOR_VERSION <= 5
115 _imageactorz->SetInput(_img);
117 _imageactorz->SetInputData(_img);
120 zslice = (w_ext[0] + w_ext[1])/2;
121 _imageactorz->SetDisplayExtent(zslice, zslice, w_ext[2], w_ext[3], w_ext[4], w_ext[5]);
126 void ImagePlaneWidget::setImage(vtkImageData* img){
130 int *dims = _img->GetDimensions( );
131 unsigned int sliceX = dims[0]/2;
132 unsigned int sliceY = dims[1]/2;
133 unsigned int sliceZ = dims[2]/2;
135 // Set input X,Y and Z plane
138 //EED 2017-01-01 Migration VTK7
139 #if VTK_MAJOR_VERSION <= 5
140 _xwidget->SetInput( _img );
142 _xwidget->SetInputData( _img );
145 _xwidget->SetPlaneOrientationToXAxes( );
146 _xwidget->SetSliceIndex( sliceX );
147 _xwidget->TextureInterpolateOff();
148 _xwidget->SetResliceInterpolateToLinear();
150 _xwidget->DisplayTextOn();
151 _xwidget->GetTextProperty()->SetColor(0.3, 0.3, 0.3);
155 //EED 2017-01-01 Migration VTK7
156 #if VTK_MAJOR_VERSION <= 5
157 _ywidget->SetInput( _img );
159 _ywidget->SetInputData( _img );
162 _ywidget->SetPlaneOrientationToYAxes( );
163 _ywidget->SetSliceIndex( sliceY );
164 _ywidget->TextureInterpolateOff();
165 _ywidget->SetResliceInterpolateToLinear();
166 _ywidget->DisplayTextOn();
167 _ywidget->GetTextProperty()->SetColor(0.3, 0.3, 0.3);
173 //EED 2017-01-01 Migration VTK7
174 #if VTK_MAJOR_VERSION <= 5
175 _zwidget->SetInput( _img );
177 _zwidget->SetInputData( _img );
181 _zwidget->SetPlaneOrientationToZAxes( );
182 _zwidget->SetSliceIndex( sliceZ );
183 _zwidget->TextureInterpolateOff();
184 _zwidget->SetResliceInterpolateToLinear();
185 _zwidget->DisplayTextOn();
187 _zwidget->GetTextProperty()->SetColor(0.3, 0.3, 0.3);
190 void ImagePlaneWidget::SetLookupTable(vtkLookupTable *lookuptable){
192 _xwidget->SetLookupTable(lookuptable);
193 _ywidget->SetLookupTable(lookuptable);
194 _zwidget->SetLookupTable(lookuptable);
197 void ImagePlaneWidget::SetColorTable(vtkColorTransferFunction *colortransfer){
198 SetLookupTable((vtkLookupTable*)colortransfer);
201 void ImagePlaneWidget::showPlanes(bool show){
215 void ImagePlaneWidget::invariant()
218 throw "Image data is not initialized";
220 if(!_xwidget ||!_ywidget || !_zwidget){
221 throw "The widgets are not initialized";
226 void ImagePlaneWidget::setSliceXImageActor(int value)
228 //EED 2017-01-01 Migration VTK7
229 #if VTK_MAJOR_VERSION <= 5
230 int *w_ext = _img->GetWholeExtent();
232 int *w_ext = _img->GetExtent();
236 _imageactorx->SetDisplayExtent(w_ext[0], w_ext[1], w_ext[2], w_ext[3], xslice, xslice);
237 m_Interactor->Render();
240 void ImagePlaneWidget::setSliceYImageActor(int value)
242 //EED 2017-01-01 Migration VTK7
243 #if VTK_MAJOR_VERSION <= 5
244 int *w_ext = _img->GetWholeExtent();
246 int *w_ext = _img->GetExtent();
249 _imageactory->SetDisplayExtent(w_ext[0], w_ext[1], yslice, yslice, w_ext[4], w_ext[5]);
250 m_Interactor->Render();
254 void ImagePlaneWidget::setSliceZImageActor(int value)
257 //EED 2017-01-01 Migration VTK7
258 #if VTK_MAJOR_VERSION <= 5
259 int *w_ext = _img->GetWholeExtent();
261 int *w_ext = _img->GetExtent();
265 _imageactorz->SetDisplayExtent(zslice, zslice, w_ext[2], w_ext[3], w_ext[4], w_ext[5]);
266 m_Interactor->Render();