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 "vtkTextProperty.h"
29 #include <vtkImageMapToWindowLevelColors.h>
30 //-------------------------------------------------------------------
31 //-------------------------------------------------------------------
32 //-------------------------------------------------------------------
34 vtkInfoTextImage::vtkInfoTextImage()
36 _vtkText_WindowLevel = NULL;
37 _vtkText_ColorLevel = NULL;
38 _vtkText_position = NULL;
39 _vtkText_pixelIntensity = NULL;
40 _vtkText_plane = NULL;
44 //-------------------------------------------------------------------
46 vtkInfoTextImage::~vtkInfoTextImage()
50 //-------------------------------------------------------------------
52 void vtkInfoTextImage::Configure()
54 if(_vtkText_WindowLevel == NULL){
55 _vtkText_WindowLevel = Create_Text_Label( 10 , 60 );
56 _vtkText_ColorLevel = Create_Text_Label( 10 , 45 );
57 _vtkText_position = Create_Text_Label( 10 , 30 );
58 _vtkText_pixelIntensity = Create_Text_Label( 10 , 15 );
59 _vtkText_plane = Create_Text_Label( 10 , 0 );
64 //-------------------------------------------------------------------
66 void vtkInfoTextImage::SetMarImageData(marImageData *marimagedata)
68 _marimagedata = marimagedata;
71 //-------------------------------------------------------------------
73 void vtkInfoTextImage::SetWxVtk2DBaseView(wxVtk2DBaseView *wxvtk2Dbaseview)
75 _wxvtk2Dbaseview = wxvtk2Dbaseview;
78 //-------------------------------------------------------------------
80 vtkTextActor *vtkInfoTextImage::Create_Text_Label(int px, int py )
83 vtkTextActor *textActor = vtkTextActor::New();
84 textActor->SetDisplayPosition(px, py);
85 textActor->SetInput("0");
87 // Set coordinates to match the old vtkScaledTextActor default value
88 textActor->GetPosition2Coordinate()->SetCoordinateSystemToNormalizedViewport();
89 textActor->GetPosition2Coordinate()->SetValue( 0.2 , 0.2 );
91 vtkTextProperty *tprop = textActor->GetTextProperty();
92 tprop->SetFontSize(14);
93 tprop->SetFontFamilyToArial();
94 tprop->SetColor(1, 1, 0);
95 _wxvtk2Dbaseview->GetRenderer()->AddActor2D(textActor);
100 //-------------------------------------------------------------------
102 void vtkInfoTextImage::PutWindowLevel()
104 double value = _wxvtk2Dbaseview->_imageViewer2XYZ->GetVtkImageViewer2()->GetWindowLevel()->GetWindow() ;
108 strcpy(resultText,"w:");
111 //ltoa ( (long)value , zTzxt , 10 );
112 sprintf(zTzxt,"%3.4f",value);
114 strcat(resultText,zTzxt);
115 _vtkText_WindowLevel -> SetInput(resultText);
118 //-------------------------------------------------------------------
120 void vtkInfoTextImage::PutColorLevel()
122 double value = _wxvtk2Dbaseview->_imageViewer2XYZ->GetVtkImageViewer2()->GetWindowLevel()->GetLevel();
127 strcpy(resultText,"c:");
129 // itoa (value,zTzxt,10);
130 sprintf(zTzxt,"%3.2f",value);
132 strcat(resultText,zTzxt);
133 _vtkText_ColorLevel -> SetInput(resultText);
136 //-------------------------------------------------------------------
137 void vtkInfoTextImage::PutPlane()
139 int plane = _wxvtk2Dbaseview->GetDirection();
143 if (plane==0) { strcpy(resultText,"plane:YZ"); }
144 if (plane==1) { strcpy(resultText,"plane:XZ"); }
145 if (plane==2) { strcpy(resultText,"plane:XY"); }
147 // itoa (value,zTzxt,10);
148 // sprintf(zTzxt,"%d",value);
150 // strcat(resultText,zTzxt);
151 _vtkText_plane -> SetInput(resultText);
154 //-------------------------------------------------------------------
156 void vtkInfoTextImage::PutPosition(int xx,int yy, int zz)
161 // _imagedata->GetSpacing(spa);
168 strcpy(resultText,"p: ");
169 // itoa ((int)xx,zTzxt,10);
170 sprintf(zTzxt,"%d",xx);
172 strcat(resultText,zTzxt);
173 strcat(resultText," , ");
175 // itoa ((int)yy,zTzxt,10);
176 sprintf(zTzxt,"%d",yy);
178 strcat(resultText,zTzxt);
179 strcat(resultText," , ");
181 // itoa ((int)zz,zTzxt,10);
182 sprintf(zTzxt,"%d",zz);
184 strcat(resultText,zTzxt);
188 int nX = _marimagedata->GetXOriginal(xx);
189 int nY = _marimagedata->GetYOriginal(yy);
190 int nZ = _marimagedata->GetZOriginal(zz);
192 strcat(resultText," (");
193 // ltoa ((int)nX,zTzxt,10);
194 sprintf(zTzxt,"%d",nX);
196 strcat(resultText,zTzxt);
197 strcat(resultText,",");
199 // ltoa ((int)nY,zTzxt,10);
200 sprintf(zTzxt,"%d",nY);
202 strcat(resultText,zTzxt);
203 strcat(resultText,",");
205 // ltoa ((int)nZ,zTzxt,10);
206 sprintf(zTzxt,"%d",nZ);
208 strcat(resultText,zTzxt);
209 strcat(resultText,")");
211 _vtkText_position -> SetInput(resultText);
214 //-------------------------------------------------------------------
216 void vtkInfoTextImage::PutPixelIntensity(int xx, int yy, int zz)
224 vtkImageData *imagedata = _marimagedata->GetImageData();
225 imagedata->GetDimensions(dim);
226 imagedata->GetSpacing(spa);
233 if ( (xx<0) || (xx>=dim[0]) || (yy<0) || (yy>=dim[1]) || (zz<0) || (zz>=dim[2]) )
241 strcpy(resultText,"GL: ");
244 if (imagedata->GetScalarType()==VTK_BIT)
246 char *pOrg=(char*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
247 // itoa (*pOrg,zTzxt,10);
250 sprintf(zTzxt,"%d",0);
254 sprintf(zTzxt,"%d",1);
258 else if (imagedata->GetScalarType()==VTK_CHAR)
260 char *pOrg=(char*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
261 // itoa (*pOrg,zTzxt,10);
263 sprintf(zTzxt,"%d",tmp);
266 else if (imagedata->GetScalarType()==VTK_SIGNED_CHAR)
268 signed char *pOrg=(signed char*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
269 // itoa (*pOrg,zTzxt,10);
271 sprintf(zTzxt,"%d",tmp);
274 else if (imagedata->GetScalarType()==VTK_UNSIGNED_CHAR)
276 unsigned char *pOrg=(unsigned char*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
277 // itoa (*pOrg,zTzxt,10);
279 sprintf(zTzxt,"%d",tmp);
282 else if (imagedata->GetScalarType()==VTK_SHORT)
284 short *pOrg=(short*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
285 // itoa (*pOrg,zTzxt,10);
287 sprintf(zTzxt,"%d",tmp);
290 else if (imagedata->GetScalarType()==VTK_UNSIGNED_SHORT)
292 unsigned short *pOrg=(unsigned short*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
293 // itoa (*pOrg,zTzxt,10);
295 sprintf(zTzxt,"%d",tmp);
298 else if (imagedata->GetScalarType()==VTK_INT)
300 int *pOrg=(int*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
301 // itoa (*pOrg,zTzxt,10);
302 sprintf(zTzxt,"%d",*pOrg);
305 else if (imagedata->GetScalarType()==VTK_UNSIGNED_INT)
307 unsigned int *pOrg=(unsigned int*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
308 // itoa (*pOrg,zTzxt,10);
310 sprintf(zTzxt,"%d",tmp);
313 else if (imagedata->GetScalarType()==VTK_LONG)
315 long *pOrg=(long*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
316 // itoa (*pOrg,zTzxt,10);
318 sprintf(zTzxt,"%3.4f",tmp);
321 else if (imagedata->GetScalarType()==VTK_UNSIGNED_LONG)
323 unsigned long *pOrg=(unsigned long*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
324 // itoa (*pOrg,zTzxt,10);
326 sprintf(zTzxt,"%3.4f",tmp);
329 else if (imagedata->GetScalarType()==VTK_FLOAT)
331 float *pOrg=(float*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
332 // itoa (*pOrg,zTzxt,10);
333 double tmp=(double)*pOrg;
334 sprintf(zTzxt,"%3.4f",tmp);
337 else if (imagedata->GetScalarType()==VTK_DOUBLE)
339 double *pOrg=(double*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
340 // itoa (*pOrg,zTzxt,10);
342 sprintf(zTzxt,"%3.4f",tmp);
349 strcat(resultText,zTzxt);
350 _vtkText_pixelIntensity -> SetInput(resultText);