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 "vtkInfoTextImage.h"
28 #include "vtkProperty2D.h"
29 #include "vtkTextProperty.h"
30 #include <vtkImageMapToWindowLevelColors.h>
31 //-------------------------------------------------------------------
32 //-------------------------------------------------------------------
33 //-------------------------------------------------------------------
35 vtkInfoTextImage::vtkInfoTextImage()
37 _vtkText_WindowLevel = NULL;
38 _vtkText_ColorLevel = NULL;
39 _vtkText_position = NULL;
40 _vtkText_pixelIntensity = NULL;
41 _vtkText_plane = NULL;
45 //-------------------------------------------------------------------
47 vtkInfoTextImage::~vtkInfoTextImage()
51 //-------------------------------------------------------------------
53 void vtkInfoTextImage::Configure()
55 if(_vtkText_WindowLevel == NULL){
56 _vtkText_WindowLevel = Create_Text_Label( 10 , 60 );
57 _vtkText_ColorLevel = Create_Text_Label( 10 , 45 );
58 _vtkText_position = Create_Text_Label( 10 , 30 );
59 _vtkText_pixelIntensity = Create_Text_Label( 10 , 15 );
60 _vtkText_plane = Create_Text_Label( 10 , 0 );
61 } // if vtkText_WindowLevel
64 void vtkInfoTextImage::SetOpacity(double opacity)
66 if (_vtkText_WindowLevel!=NULL)
68 _vtkText_WindowLevel->GetProperty()->SetOpacity( opacity );
70 if (_vtkText_ColorLevel!=NULL)
72 _vtkText_ColorLevel->GetProperty()->SetOpacity( opacity );
74 if (_vtkText_position!=NULL)
76 _vtkText_position->GetProperty()->SetOpacity( opacity );
78 if (_vtkText_pixelIntensity!=NULL)
80 _vtkText_pixelIntensity->GetProperty()->SetOpacity( opacity );
82 if (_vtkText_plane!=NULL)
84 _vtkText_plane->GetProperty()->SetOpacity( opacity );
88 //-------------------------------------------------------------------
90 void vtkInfoTextImage::SetMarImageData(marImageData *marimagedata)
92 _marimagedata = marimagedata;
95 //-------------------------------------------------------------------
97 void vtkInfoTextImage::SetWxVtk2DBaseView(wxVtk2DBaseView *wxvtk2Dbaseview)
99 _wxvtk2Dbaseview = wxvtk2Dbaseview;
102 //-------------------------------------------------------------------
104 vtkTextActor *vtkInfoTextImage::Create_Text_Label(int px, int py )
107 vtkTextActor *textActor = vtkTextActor::New();
108 textActor->SetDisplayPosition(px, py);
109 textActor->SetInput("0");
110 // Set coordinates to match the old vtkScaledTextActor default value
111 textActor->GetPosition2Coordinate()->SetCoordinateSystemToNormalizedViewport();
112 textActor->GetPosition2Coordinate()->SetValue( 0.2 , 0.2 );
113 vtkTextProperty *tprop = textActor->GetTextProperty();
114 tprop->SetFontSize(14);
115 tprop->SetFontFamilyToArial();
116 tprop->SetColor(1, 1, 0);
117 _wxvtk2Dbaseview->GetRenderer()->AddActor2D(textActor);
121 //-------------------------------------------------------------------
123 void vtkInfoTextImage::PutWindowLevel()
125 double value = _wxvtk2Dbaseview->_imageViewer2XYZ->GetVtkImageViewer2()->GetWindowLevel()->GetWindow() ;
128 strcpy(resultText,"w:");
129 sprintf(zTzxt,"%3.4f",value);
130 strcat(resultText,zTzxt);
131 _vtkText_WindowLevel -> SetInput(resultText);
134 //-------------------------------------------------------------------
136 void vtkInfoTextImage::PutColorLevel()
138 double value = _wxvtk2Dbaseview->_imageViewer2XYZ->GetVtkImageViewer2()->GetWindowLevel()->GetLevel();
141 strcpy(resultText,"c:");
142 // itoa (value,zTzxt,10);
143 sprintf(zTzxt,"%3.2f",value);
144 strcat(resultText,zTzxt);
145 _vtkText_ColorLevel -> SetInput(resultText);
148 //-------------------------------------------------------------------
149 void vtkInfoTextImage::PutPlane()
151 int plane = _wxvtk2Dbaseview->GetDirection();
154 if (plane==0) { strcpy(resultText,"plane:YZ"); }
155 if (plane==1) { strcpy(resultText,"plane:XZ"); }
156 if (plane==2) { strcpy(resultText,"plane:XY"); }
157 _vtkText_plane -> SetInput(resultText);
160 //-------------------------------------------------------------------
162 void vtkInfoTextImage::PutPosition(int xx,int yy, int zz)
166 strcpy(resultText,"p: ");
167 sprintf(zTzxt,"%d",xx);
168 strcat(resultText,zTzxt);
169 strcat(resultText," , ");
170 sprintf(zTzxt,"%d",yy);
171 strcat(resultText,zTzxt);
172 strcat(resultText," , ");
173 sprintf(zTzxt,"%d",zz);
174 strcat(resultText,zTzxt);
175 int nX = _marimagedata->GetXOriginal(xx);
176 int nY = _marimagedata->GetYOriginal(yy);
177 int nZ = _marimagedata->GetZOriginal(zz);
178 strcat(resultText," (");
179 sprintf(zTzxt,"%d",nX);
180 strcat(resultText,zTzxt);
181 strcat(resultText,",");
182 sprintf(zTzxt,"%d",nY);
183 strcat(resultText,zTzxt);
184 strcat(resultText,",");
185 sprintf(zTzxt,"%d",nZ);
186 strcat(resultText,zTzxt);
187 strcat(resultText,")");
188 _vtkText_position -> SetInput(resultText);
191 //-------------------------------------------------------------------
193 void vtkInfoTextImage::PutPixelIntensity(int xx, int yy, int zz)
198 vtkImageData *imagedata = _marimagedata->GetImageData();
199 imagedata->GetDimensions(dim);
200 imagedata->GetSpacing(spa);
201 if ( (xx<0) || (xx>=dim[0]) || (yy<0) || (yy>=dim[1]) || (zz<0) || (zz>=dim[2]) )
207 strcpy(resultText,"GL: ");
210 if (imagedata->GetScalarType()==VTK_BIT)
212 char *pOrg=(char*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
215 sprintf(zTzxt,"%d",0);
217 sprintf(zTzxt,"%d",1);
219 } else if (imagedata->GetScalarType()==VTK_CHAR) {
220 char *pOrg=(char*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
221 // itoa (*pOrg,zTzxt,10);
223 sprintf(zTzxt,"%d",tmp);
224 } else if (imagedata->GetScalarType()==VTK_SIGNED_CHAR) {
225 signed char *pOrg=(signed char*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
226 // itoa (*pOrg,zTzxt,10);
228 sprintf(zTzxt,"%d",tmp);
229 } else if (imagedata->GetScalarType()==VTK_UNSIGNED_CHAR) {
230 unsigned char *pOrg=(unsigned char*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
231 // itoa (*pOrg,zTzxt,10);
233 sprintf(zTzxt,"%d",tmp);
234 } else if (imagedata->GetScalarType()==VTK_SHORT) {
235 short *pOrg=(short*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
236 // itoa (*pOrg,zTzxt,10);
238 sprintf(zTzxt,"%d",tmp);
239 } else if (imagedata->GetScalarType()==VTK_UNSIGNED_SHORT) {
240 unsigned short *pOrg=(unsigned short*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
241 // itoa (*pOrg,zTzxt,10);
243 sprintf(zTzxt,"%d",tmp);
244 } else if (imagedata->GetScalarType()==VTK_INT) {
245 int *pOrg=(int*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
246 // itoa (*pOrg,zTzxt,10);
247 sprintf(zTzxt,"%d",*pOrg);
248 } else if (imagedata->GetScalarType()==VTK_UNSIGNED_INT) {
249 unsigned int *pOrg=(unsigned int*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
250 // itoa (*pOrg,zTzxt,10);
252 sprintf(zTzxt,"%d",tmp);
253 } else if (imagedata->GetScalarType()==VTK_LONG) {
254 long *pOrg=(long*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
255 // itoa (*pOrg,zTzxt,10);
257 sprintf(zTzxt,"%3.4f",tmp);
258 } else if (imagedata->GetScalarType()==VTK_UNSIGNED_LONG) {
259 unsigned long *pOrg=(unsigned long*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
260 // itoa (*pOrg,zTzxt,10);
262 sprintf(zTzxt,"%3.4f",tmp);
263 } else if (imagedata->GetScalarType()==VTK_FLOAT) {
264 float *pOrg=(float*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
265 // itoa (*pOrg,zTzxt,10);
266 double tmp=(double)*pOrg;
267 sprintf(zTzxt,"%3.4f",tmp);
268 } else if (imagedata->GetScalarType()==VTK_DOUBLE) {
269 double *pOrg=(double*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
270 // itoa (*pOrg,zTzxt,10);
272 sprintf(zTzxt,"%3.4f",tmp);
273 } // if imagedata Type
277 strcat(resultText,zTzxt);
278 _vtkText_pixelIntensity -> SetInput(resultText);