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;
43 //-------------------------------------------------------------------
45 vtkInfoTextImage::~vtkInfoTextImage()
49 //-------------------------------------------------------------------
51 void vtkInfoTextImage::Configure()
53 if(_vtkText_WindowLevel == NULL){
54 _vtkText_WindowLevel = Create_Text_Label( 10 , 55 );
55 _vtkText_ColorLevel = Create_Text_Label( 10 , 40 );
56 _vtkText_position = Create_Text_Label( 10 , 25 );
57 _vtkText_pixelIntensity = Create_Text_Label( 10 , 10 );
62 //-------------------------------------------------------------------
64 void vtkInfoTextImage::SetMarImageData(marImageData *marimagedata)
66 _marimagedata=marimagedata;
69 //-------------------------------------------------------------------
71 void vtkInfoTextImage::SetWxVtk2DBaseView(wxVtk2DBaseView *wxvtk2Dbaseview)
73 _wxvtk2Dbaseview=wxvtk2Dbaseview;
76 //-------------------------------------------------------------------
78 vtkTextActor *vtkInfoTextImage::Create_Text_Label(int px, int py )
81 vtkTextActor *textActor = vtkTextActor::New();
82 textActor->SetDisplayPosition(px, py);
83 textActor->SetInput("0");
85 // Set coordinates to match the old vtkScaledTextActor default value
86 textActor->GetPosition2Coordinate()->SetCoordinateSystemToNormalizedViewport();
87 textActor->GetPosition2Coordinate()->SetValue( 0.2 , 0.2 );
89 vtkTextProperty *tprop = textActor->GetTextProperty();
90 tprop->SetFontSize(14);
91 tprop->SetFontFamilyToArial();
92 tprop->SetColor(1, 1, 0);
93 _wxvtk2Dbaseview->GetRenderer()->AddActor2D(textActor);
98 //-------------------------------------------------------------------
100 void vtkInfoTextImage::PutWindowLevel()
102 double value = _wxvtk2Dbaseview->_imageViewer2XYZ->GetVtkImageViewer2()->GetWindowLevel()->GetWindow() ;
106 strcpy(resultText,"w:");
109 //ltoa ( (long)value , zTzxt , 10 );
110 sprintf(zTzxt,"%3.4f",value);
112 strcat(resultText,zTzxt);
113 _vtkText_WindowLevel -> SetInput(resultText);
116 //-------------------------------------------------------------------
118 void vtkInfoTextImage::PutColorLevel()
120 double value = _wxvtk2Dbaseview->_imageViewer2XYZ->GetVtkImageViewer2()->GetWindowLevel()->GetLevel();
124 strcpy(resultText,"c:");
126 // itoa (value,zTzxt,10);
127 sprintf(zTzxt,"%3.2f",value);
129 strcat(resultText,zTzxt);
130 _vtkText_ColorLevel -> SetInput(resultText);
133 //-------------------------------------------------------------------
135 void vtkInfoTextImage::PutPosition(int xx,int yy, int zz)
140 // _imagedata->GetSpacing(spa);
147 strcpy(resultText,"p: ");
148 // itoa ((int)xx,zTzxt,10);
149 sprintf(zTzxt,"%d",xx);
151 strcat(resultText,zTzxt);
152 strcat(resultText," , ");
154 // itoa ((int)yy,zTzxt,10);
155 sprintf(zTzxt,"%d",yy);
157 strcat(resultText,zTzxt);
158 strcat(resultText," , ");
160 // itoa ((int)zz,zTzxt,10);
161 sprintf(zTzxt,"%d",zz);
163 strcat(resultText,zTzxt);
167 int nX = _marimagedata->GetXOriginal(xx);
168 int nY = _marimagedata->GetYOriginal(yy);
169 int nZ = _marimagedata->GetZOriginal(zz);
171 strcat(resultText," (");
172 // ltoa ((int)nX,zTzxt,10);
173 sprintf(zTzxt,"%d",nX);
175 strcat(resultText,zTzxt);
176 strcat(resultText,",");
178 // ltoa ((int)nY,zTzxt,10);
179 sprintf(zTzxt,"%d",nY);
181 strcat(resultText,zTzxt);
182 strcat(resultText,",");
184 // ltoa ((int)nZ,zTzxt,10);
185 sprintf(zTzxt,"%d",nZ);
187 strcat(resultText,zTzxt);
188 strcat(resultText,")");
193 _vtkText_position -> SetInput(resultText);
196 //-------------------------------------------------------------------
198 void vtkInfoTextImage::PutPixelIntensity(int xx, int yy, int zz)
206 vtkImageData *imagedata = _marimagedata->GetImageData();
207 imagedata->GetDimensions(dim);
208 imagedata->GetSpacing(spa);
215 if ( (xx<0) || (xx>=dim[0]) || (yy<0) || (yy>=dim[1]) || (zz<0) || (zz>=dim[2]) )
223 strcpy(resultText,"GL: ");
226 if (imagedata->GetScalarType()==VTK_BIT)
228 char *pOrg=(char*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
229 // itoa (*pOrg,zTzxt,10);
232 sprintf(zTzxt,"%d",0);
236 sprintf(zTzxt,"%d",1);
240 else if (imagedata->GetScalarType()==VTK_CHAR)
242 char *pOrg=(char*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
243 // itoa (*pOrg,zTzxt,10);
245 sprintf(zTzxt,"%d",tmp);
248 else if (imagedata->GetScalarType()==VTK_SIGNED_CHAR)
250 signed char *pOrg=(signed char*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
251 // itoa (*pOrg,zTzxt,10);
253 sprintf(zTzxt,"%d",tmp);
256 else if (imagedata->GetScalarType()==VTK_UNSIGNED_CHAR)
258 unsigned char *pOrg=(unsigned char*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
259 // itoa (*pOrg,zTzxt,10);
261 sprintf(zTzxt,"%d",tmp);
264 else if (imagedata->GetScalarType()==VTK_SHORT)
266 short *pOrg=(short*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
267 // itoa (*pOrg,zTzxt,10);
269 sprintf(zTzxt,"%d",tmp);
272 else if (imagedata->GetScalarType()==VTK_UNSIGNED_SHORT)
274 unsigned short *pOrg=(unsigned short*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
275 // itoa (*pOrg,zTzxt,10);
277 sprintf(zTzxt,"%d",tmp);
280 else if (imagedata->GetScalarType()==VTK_INT)
282 int *pOrg=(int*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
283 // itoa (*pOrg,zTzxt,10);
284 sprintf(zTzxt,"%d",*pOrg);
287 else if (imagedata->GetScalarType()==VTK_UNSIGNED_INT)
289 unsigned int *pOrg=(unsigned int*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
290 // itoa (*pOrg,zTzxt,10);
292 sprintf(zTzxt,"%d",tmp);
295 else if (imagedata->GetScalarType()==VTK_LONG)
297 long *pOrg=(long*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
298 // itoa (*pOrg,zTzxt,10);
300 sprintf(zTzxt,"%3.4f",tmp);
303 else if (imagedata->GetScalarType()==VTK_UNSIGNED_LONG)
305 unsigned long *pOrg=(unsigned long*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
306 // itoa (*pOrg,zTzxt,10);
308 sprintf(zTzxt,"%3.4f",tmp);
311 else if (imagedata->GetScalarType()==VTK_FLOAT)
313 float *pOrg=(float*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
314 // itoa (*pOrg,zTzxt,10);
315 double tmp=(double)*pOrg;
316 sprintf(zTzxt,"%3.4f",tmp);
319 else if (imagedata->GetScalarType()==VTK_DOUBLE)
321 double *pOrg=(double*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
322 // itoa (*pOrg,zTzxt,10);
324 sprintf(zTzxt,"%3.4f",tmp);
331 strcat(resultText,zTzxt);
332 _vtkText_pixelIntensity -> SetInput(resultText);