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 if(_vtkText_WindowLevel == NULL){
29 _vtkText_WindowLevel = Create_Text_Label( 10 , 55 );
30 _vtkText_ColorLevel = Create_Text_Label( 10 , 40 );
31 _vtkText_position = Create_Text_Label( 10 , 25 );
32 _vtkText_pixelIntensity = Create_Text_Label( 10 , 10 );
37 //-------------------------------------------------------------------
39 void vtkInfoTextImage::SetMarImageData(marImageData *marimagedata)
41 _marimagedata=marimagedata;
44 //-------------------------------------------------------------------
46 void vtkInfoTextImage::SetWxVtk2DBaseView(wxVtk2DBaseView *wxvtk2Dbaseview)
48 _wxvtk2Dbaseview=wxvtk2Dbaseview;
51 //-------------------------------------------------------------------
53 vtkTextActor *vtkInfoTextImage::Create_Text_Label(int px, int py )
56 vtkTextActor *textActor = vtkTextActor::New();
57 textActor->SetDisplayPosition(px, py);
58 textActor->SetInput("0");
60 // Set coordinates to match the old vtkScaledTextActor default value
61 textActor->GetPosition2Coordinate()->SetCoordinateSystemToNormalizedViewport();
62 textActor->GetPosition2Coordinate()->SetValue( 0.2 , 0.2 );
64 vtkTextProperty *tprop = textActor->GetTextProperty();
65 tprop->SetFontSize(14);
66 tprop->SetFontFamilyToArial();
67 tprop->SetColor(1, 1, 0);
68 _wxvtk2Dbaseview->GetRenderer()->AddActor2D(textActor);
73 //-------------------------------------------------------------------
75 void vtkInfoTextImage::PutWindowLevel()
77 int value = (int)( _wxvtk2Dbaseview->_imageViewer2XYZ->GetVtkImageViewer2()->GetWindowLevel()->GetWindow() );
81 strcpy(resultText,"w:");
84 //ltoa ( (long)value , zTzxt , 10 );
85 sprintf(zTzxt,"%d",value);
87 strcat(resultText,zTzxt);
88 _vtkText_WindowLevel -> SetInput(resultText);
91 //-------------------------------------------------------------------
93 void vtkInfoTextImage::PutColorLevel()
95 int value = (int)(_wxvtk2Dbaseview->_imageViewer2XYZ->GetVtkImageViewer2()->GetWindowLevel()->GetLevel());
99 strcpy(resultText,"c:");
101 // itoa (value,zTzxt,10);
102 sprintf(zTzxt,"%d",value);
104 strcat(resultText,zTzxt);
105 _vtkText_ColorLevel -> SetInput(resultText);
108 //-------------------------------------------------------------------
110 void vtkInfoTextImage::PutPosition(int xx,int yy, int zz)
115 // _imagedata->GetSpacing(spa);
122 strcpy(resultText,"p: ");
123 // itoa ((int)xx,zTzxt,10);
124 sprintf(zTzxt,"%d",xx);
126 strcat(resultText,zTzxt);
127 strcat(resultText," , ");
129 // itoa ((int)yy,zTzxt,10);
130 sprintf(zTzxt,"%d",yy);
132 strcat(resultText,zTzxt);
133 strcat(resultText," , ");
135 // itoa ((int)zz,zTzxt,10);
136 sprintf(zTzxt,"%d",zz);
138 strcat(resultText,zTzxt);
142 int nX = _marimagedata->GetXOriginal(xx);
143 int nY = _marimagedata->GetYOriginal(yy);
144 int nZ = _marimagedata->GetZOriginal(zz);
146 strcat(resultText," (");
147 // ltoa ((int)nX,zTzxt,10);
148 sprintf(zTzxt,"%d",nX);
150 strcat(resultText,zTzxt);
151 strcat(resultText,",");
153 // ltoa ((int)nY,zTzxt,10);
154 sprintf(zTzxt,"%d",nY);
156 strcat(resultText,zTzxt);
157 strcat(resultText,",");
159 // ltoa ((int)nZ,zTzxt,10);
160 sprintf(zTzxt,"%d",nZ);
162 strcat(resultText,zTzxt);
163 strcat(resultText,")");
168 _vtkText_position -> SetInput(resultText);
171 //-------------------------------------------------------------------
173 void vtkInfoTextImage::PutPixelIntensity(int xx, int yy, int zz)
181 vtkImageData *imagedata = _marimagedata->GetImageData();
182 imagedata->GetDimensions(dim);
183 imagedata->GetSpacing(spa);
190 if ( (xx<0) || (xx>=dim[0]) || (yy<0) || (yy>=dim[1]) || (zz<0) || (zz>=dim[2]) )
198 strcpy(resultText,"GL: ");
201 if (imagedata->GetScalarType()==VTK_BIT)
203 char *pOrg=(char*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
204 // itoa (*pOrg,zTzxt,10);
207 sprintf(zTzxt,"%d",0);
211 sprintf(zTzxt,"%d",1);
215 if (imagedata->GetScalarType()==VTK_CHAR)
217 char *pOrg=(char*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
218 // itoa (*pOrg,zTzxt,10);
220 sprintf(zTzxt,"%d",tmp);
223 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);
231 if (imagedata->GetScalarType()==VTK_UNSIGNED_CHAR)
233 unsigned char *pOrg=(unsigned char*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
234 // itoa (*pOrg,zTzxt,10);
236 sprintf(zTzxt,"%d",tmp);
239 if (imagedata->GetScalarType()==VTK_SHORT)
241 short *pOrg=(short*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
242 // itoa (*pOrg,zTzxt,10);
244 sprintf(zTzxt,"%d",tmp);
247 if (imagedata->GetScalarType()==VTK_UNSIGNED_SHORT)
249 unsigned short *pOrg=(unsigned short*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
250 // itoa (*pOrg,zTzxt,10);
252 sprintf(zTzxt,"%d",tmp);
255 if (imagedata->GetScalarType()==VTK_INT)
257 int *pOrg=(int*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
258 // itoa (*pOrg,zTzxt,10);
259 sprintf(zTzxt,"%d",*pOrg);
262 if (imagedata->GetScalarType()==VTK_UNSIGNED_INT)
264 unsigned int *pOrg=(unsigned int*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
265 // itoa (*pOrg,zTzxt,10);
267 sprintf(zTzxt,"%d",tmp);
270 if (imagedata->GetScalarType()==VTK_LONG)
272 long *pOrg=(long*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
273 // itoa (*pOrg,zTzxt,10);
275 sprintf(zTzxt,"%3.2f",tmp);
278 if (imagedata->GetScalarType()==VTK_UNSIGNED_LONG)
280 unsigned long *pOrg=(unsigned long*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
281 // itoa (*pOrg,zTzxt,10);
283 sprintf(zTzxt,"%3.2f",tmp);
286 if (imagedata->GetScalarType()==VTK_FLOAT)
288 float *pOrg=(float*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
289 // itoa (*pOrg,zTzxt,10);
290 double tmp=(double)*pOrg;
291 sprintf(zTzxt,"%3.2f",tmp);
294 if (imagedata->GetScalarType()==VTK_DOUBLE)
296 double *pOrg=(double*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
297 // itoa (*pOrg,zTzxt,10);
299 sprintf(zTzxt,"%3.2f",tmp);
306 strcat(resultText,zTzxt);
307 _vtkText_pixelIntensity -> SetInput(resultText);