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 int *w_ext = _img->GetWholeExtent();
84 //cout<<w_ext[0]<<" "<<w_ext[1]<<" "<<w_ext[2]<<" "<<w_ext[3]<<" "<<w_ext[4]<<" "<<w_ext[5]<<" "<<endl;
85 _imageactorx = vtkImageActor::New();
86 _imageactorx->SetInput(_img);
87 xslice = (w_ext[4] + w_ext[5])/2;
88 _imageactorx->SetDisplayExtent(w_ext[0], w_ext[1], w_ext[2], w_ext[3], xslice, xslice);
91 _imageactory = vtkImageActor::New();
92 _imageactory->SetInput(_img);
93 yslice = (w_ext[2] + w_ext[3])/2;
94 _imageactory->SetDisplayExtent(w_ext[0], w_ext[1], yslice, yslice, w_ext[4], w_ext[5]);
96 _imageactorz = vtkImageActor::New();
97 _imageactorz->SetInput(_img);
98 zslice = (w_ext[0] + w_ext[1])/2;
99 _imageactorz->SetDisplayExtent(zslice, zslice, w_ext[2], w_ext[3], w_ext[4], w_ext[5]);
104 void ImagePlaneWidget::setImage(vtkImageData* img){
108 int *dims = _img->GetDimensions( );
109 unsigned int sliceX = dims[0]/2;
110 unsigned int sliceY = dims[1]/2;
111 unsigned int sliceZ = dims[2]/2;
113 // Set input X,Y and Z plane
115 _xwidget->SetInput( _img );
116 _xwidget->SetPlaneOrientationToXAxes( );
117 _xwidget->SetSliceIndex( sliceX );
118 _xwidget->TextureInterpolateOff();
119 _xwidget->SetResliceInterpolateToLinear();
121 _xwidget->DisplayTextOn();
122 _xwidget->GetTextProperty()->SetColor(0.3, 0.3, 0.3);
125 _ywidget->SetInput( _img );
126 _ywidget->SetPlaneOrientationToYAxes( );
127 _ywidget->SetSliceIndex( sliceY );
128 _ywidget->TextureInterpolateOff();
129 _ywidget->SetResliceInterpolateToLinear();
130 _ywidget->DisplayTextOn();
131 _ywidget->GetTextProperty()->SetColor(0.3, 0.3, 0.3);
135 _zwidget->SetInput( _img );
136 _zwidget->SetPlaneOrientationToZAxes( );
137 _zwidget->SetSliceIndex( sliceZ );
138 _zwidget->TextureInterpolateOff();
139 _zwidget->SetResliceInterpolateToLinear();
140 _zwidget->DisplayTextOn();
142 _zwidget->GetTextProperty()->SetColor(0.3, 0.3, 0.3);
145 void ImagePlaneWidget::SetLookupTable(vtkLookupTable *lookuptable){
147 _xwidget->SetLookupTable(lookuptable);
148 _ywidget->SetLookupTable(lookuptable);
149 _zwidget->SetLookupTable(lookuptable);
152 void ImagePlaneWidget::SetColorTable(vtkColorTransferFunction *colortransfer){
153 SetLookupTable((vtkLookupTable*)colortransfer);
156 void ImagePlaneWidget::showPlanes(bool show){
170 void ImagePlaneWidget::invariant(){
172 throw "Image data is not initialized";
174 if(!_xwidget ||!_ywidget || !_zwidget){
175 throw "The widgets are not initialized";
180 void ImagePlaneWidget::setSliceXImageActor(int value){
181 int *w_ext = _img->GetWholeExtent();
183 _imageactorx->SetDisplayExtent(w_ext[0], w_ext[1], w_ext[2], w_ext[3], xslice, xslice);
184 m_Interactor->Render();
186 void ImagePlaneWidget::setSliceYImageActor(int value){
187 int *w_ext = _img->GetWholeExtent();
189 _imageactory->SetDisplayExtent(w_ext[0], w_ext[1], yslice, yslice, w_ext[4], w_ext[5]);
190 m_Interactor->Render();
192 void ImagePlaneWidget::setSliceZImageActor(int value){
193 int *w_ext = _img->GetWholeExtent();
195 _imageactorz->SetDisplayExtent(zslice, zslice, w_ext[2], w_ext[3], w_ext[4], w_ext[5]);
196 m_Interactor->Render();