1 #include "vtkInfoTextImage.h"
3 #include "vtkTextProperty.h"
4 #include <vtkImageMapToWindowLevelColors.h>
5 //-------------------------------------------------------------------
6 //-------------------------------------------------------------------
7 //-------------------------------------------------------------------
9 vtkInfoTextImage::vtkInfoTextImage()
11 _vtkText_WindowLevel = NULL;
12 _vtkText_ColorLevel = NULL;
13 _vtkText_position = NULL;
14 _vtkText_pixelIntensity = NULL;
18 //-------------------------------------------------------------------
20 vtkInfoTextImage::~vtkInfoTextImage()
24 //-------------------------------------------------------------------
26 void vtkInfoTextImage::Configure()
28 _vtkText_WindowLevel = Create_Text_Label( 10 , 55 );
29 _vtkText_ColorLevel = Create_Text_Label( 10 , 40 );
30 _vtkText_position = Create_Text_Label( 10 , 25 );
31 _vtkText_pixelIntensity = Create_Text_Label( 10 , 10 );
35 //-------------------------------------------------------------------
37 void vtkInfoTextImage::SetMarImageData(marImageData *marimagedata)
39 _marimagedata=marimagedata;
42 //-------------------------------------------------------------------
44 void vtkInfoTextImage::SetWxVtk2DBaseView(wxVtk2DBaseView *wxvtk2Dbaseview)
46 _wxvtk2Dbaseview=wxvtk2Dbaseview;
49 //-------------------------------------------------------------------
51 vtkTextActor *vtkInfoTextImage::Create_Text_Label(int px, int py )
54 vtkTextActor *textActor = vtkTextActor::New();
55 textActor->SetDisplayPosition(px, py);
56 textActor->SetInput("0");
58 // Set coordinates to match the old vtkScaledTextActor default value
59 textActor->GetPosition2Coordinate()->SetCoordinateSystemToNormalizedViewport();
60 textActor->GetPosition2Coordinate()->SetValue( 0.2 , 0.2 );
62 vtkTextProperty *tprop = textActor->GetTextProperty();
63 tprop->SetFontSize(14);
64 tprop->SetFontFamilyToArial();
65 tprop->SetColor(1, 1, 0);
66 _wxvtk2Dbaseview->GetRenderer()->AddActor2D(textActor);
71 //-------------------------------------------------------------------
73 void vtkInfoTextImage::PutWindowLevel()
75 int value = (int)( _wxvtk2Dbaseview->_imageViewer2XYZ->GetVtkImageViewer2()->GetWindowLevel()->GetWindow() );
79 strcpy(resultText,"w:");
82 //ltoa ( (long)value , zTzxt , 10 );
83 sprintf(zTzxt,"%d",value);
85 strcat(resultText,zTzxt);
86 _vtkText_WindowLevel -> SetInput(resultText);
89 //-------------------------------------------------------------------
91 void vtkInfoTextImage::PutColorLevel()
93 int value = (int)(_wxvtk2Dbaseview->_imageViewer2XYZ->GetVtkImageViewer2()->GetWindowLevel()->GetLevel());
97 strcpy(resultText,"c:");
99 // itoa (value,zTzxt,10);
100 sprintf(zTzxt,"%d",value);
102 strcat(resultText,zTzxt);
103 _vtkText_ColorLevel -> SetInput(resultText);
106 //-------------------------------------------------------------------
108 void vtkInfoTextImage::PutPosition(int xx,int yy, int zz)
113 // _imagedata->GetSpacing(spa);
120 strcpy(resultText,"p: ");
121 // itoa ((int)xx,zTzxt,10);
122 sprintf(zTzxt,"%d",xx);
124 strcat(resultText,zTzxt);
125 strcat(resultText," , ");
127 // itoa ((int)yy,zTzxt,10);
128 sprintf(zTzxt,"%d",yy);
130 strcat(resultText,zTzxt);
131 strcat(resultText," , ");
133 // itoa ((int)zz,zTzxt,10);
134 sprintf(zTzxt,"%d",zz);
136 strcat(resultText,zTzxt);
140 int nX = _marimagedata->GetXOriginal(xx);
141 int nY = _marimagedata->GetYOriginal(yy);
142 int nZ = _marimagedata->GetZOriginal(zz);
144 strcat(resultText," (");
145 // ltoa ((int)nX,zTzxt,10);
146 sprintf(zTzxt,"%d",nX);
148 strcat(resultText,zTzxt);
149 strcat(resultText,",");
151 // ltoa ((int)nY,zTzxt,10);
152 sprintf(zTzxt,"%d",nY);
154 strcat(resultText,zTzxt);
155 strcat(resultText,",");
157 // ltoa ((int)nZ,zTzxt,10);
158 sprintf(zTzxt,"%d",nZ);
160 strcat(resultText,zTzxt);
161 strcat(resultText,")");
166 _vtkText_position -> SetInput(resultText);
169 //-------------------------------------------------------------------
171 void vtkInfoTextImage::PutPixelIntensity(int xx, int yy, int zz)
179 vtkImageData *imagedata = _marimagedata->GetImageData();
180 imagedata->GetDimensions(dim);
181 imagedata->GetSpacing(spa);
188 if ( (xx<0) || (xx>=dim[0]) || (yy<0) || (yy>=dim[1]) || (zz<0) || (zz>=dim[2]) )
196 strcpy(resultText,"GL: ");
199 if (imagedata->GetScalarType()==VTK_BIT)
201 char *pOrg=(char*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
202 // itoa (*pOrg,zTzxt,10);
205 sprintf(zTzxt,"%d",0);
209 sprintf(zTzxt,"%d",1);
213 if (imagedata->GetScalarType()==VTK_CHAR)
215 char *pOrg=(char*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
216 // itoa (*pOrg,zTzxt,10);
218 sprintf(zTzxt,"%d",tmp);
221 if (imagedata->GetScalarType()==VTK_SIGNED_CHAR)
223 signed char *pOrg=(signed char*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
224 // itoa (*pOrg,zTzxt,10);
226 sprintf(zTzxt,"%d",tmp);
229 if (imagedata->GetScalarType()==VTK_UNSIGNED_CHAR)
231 unsigned char *pOrg=(unsigned char*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
232 // itoa (*pOrg,zTzxt,10);
234 sprintf(zTzxt,"%d",tmp);
237 if (imagedata->GetScalarType()==VTK_SHORT)
239 short *pOrg=(short*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
240 // itoa (*pOrg,zTzxt,10);
242 sprintf(zTzxt,"%d",tmp);
245 if (imagedata->GetScalarType()==VTK_UNSIGNED_SHORT)
247 unsigned short *pOrg=(unsigned short*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
248 // itoa (*pOrg,zTzxt,10);
250 sprintf(zTzxt,"%d",tmp);
253 if (imagedata->GetScalarType()==VTK_INT)
255 int *pOrg=(int*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
256 // itoa (*pOrg,zTzxt,10);
257 sprintf(zTzxt,"%d",*pOrg);
260 if (imagedata->GetScalarType()==VTK_UNSIGNED_INT)
262 unsigned int *pOrg=(unsigned int*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
263 // itoa (*pOrg,zTzxt,10);
265 sprintf(zTzxt,"%d",tmp);
268 if (imagedata->GetScalarType()==VTK_LONG)
270 long *pOrg=(long*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
271 // itoa (*pOrg,zTzxt,10);
273 sprintf(zTzxt,"%3.2f",tmp);
276 if (imagedata->GetScalarType()==VTK_UNSIGNED_LONG)
278 unsigned long *pOrg=(unsigned long*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
279 // itoa (*pOrg,zTzxt,10);
281 sprintf(zTzxt,"%3.2f",tmp);
284 if (imagedata->GetScalarType()==VTK_FLOAT)
286 float *pOrg=(float*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
287 // itoa (*pOrg,zTzxt,10);
288 double tmp=(double)*pOrg;
289 sprintf(zTzxt,"%3.2f",tmp);
292 if (imagedata->GetScalarType()==VTK_DOUBLE)
294 double *pOrg=(double*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
295 // itoa (*pOrg,zTzxt,10);
297 sprintf(zTzxt,"%3.2f",tmp);
304 strcat(resultText,zTzxt);
305 _vtkText_pixelIntensity -> SetInput(resultText);