]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/vtkInfoTextImage.cxx
8f70abce157cc31cce2dffdf6cfc062f1534ab0a
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / vtkInfoTextImage.cxx
1 #include "vtkInfoTextImage.h"
2
3 #include "vtkTextProperty.h"
4 #include <vtkImageMapToWindowLevelColors.h>
5 //-------------------------------------------------------------------
6 //-------------------------------------------------------------------
7 //-------------------------------------------------------------------
8
9 vtkInfoTextImage::vtkInfoTextImage()
10 {
11         _vtkText_WindowLevel    = NULL;
12         _vtkText_ColorLevel             = NULL;
13         _vtkText_position               = NULL;
14         _vtkText_pixelIntensity = NULL;
15         _marimagedata                   = NULL;
16 }
17
18 //-------------------------------------------------------------------
19
20 vtkInfoTextImage::~vtkInfoTextImage()
21 {
22 }
23
24 //-------------------------------------------------------------------
25
26 void vtkInfoTextImage::Configure()
27 {
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 );
33         }
34 }
35
36
37 //-------------------------------------------------------------------
38
39 void vtkInfoTextImage::SetMarImageData(marImageData *marimagedata)
40 {
41         _marimagedata=marimagedata;
42 }
43
44 //-------------------------------------------------------------------
45
46 void vtkInfoTextImage::SetWxVtk2DBaseView(wxVtk2DBaseView *wxvtk2Dbaseview)
47 {
48         _wxvtk2Dbaseview=wxvtk2Dbaseview;
49 }
50
51 //-------------------------------------------------------------------
52
53 vtkTextActor *vtkInfoTextImage::Create_Text_Label(int px, int py )
54 {
55         // Text Window Level
56         vtkTextActor *textActor = vtkTextActor::New();
57         textActor->SetDisplayPosition(px, py);
58         textActor->SetInput("0");
59
60         // Set coordinates to match the old vtkScaledTextActor default value
61         textActor->GetPosition2Coordinate()->SetCoordinateSystemToNormalizedViewport();
62         textActor->GetPosition2Coordinate()->SetValue( 0.2 , 0.2 );
63
64         vtkTextProperty *tprop = textActor->GetTextProperty();
65         tprop->SetFontSize(14);
66         tprop->SetFontFamilyToArial();
67         tprop->SetColor(1, 1, 0);
68         _wxvtk2Dbaseview->GetRenderer()->AddActor2D(textActor);
69
70         return textActor;
71 }
72
73 //-------------------------------------------------------------------
74
75 void vtkInfoTextImage::PutWindowLevel()
76 {
77         double value =  _wxvtk2Dbaseview->_imageViewer2XYZ->GetVtkImageViewer2()->GetWindowLevel()->GetWindow() ;
78         char zTzxt[20];
79         char resultText[50];
80
81         strcpy(resultText,"w:");
82
83
84         //ltoa ( (long)value , zTzxt , 10 );
85         sprintf(zTzxt,"%3.4f",value);
86
87         strcat(resultText,zTzxt);
88         _vtkText_WindowLevel            -> SetInput(resultText);
89 }
90
91 //-------------------------------------------------------------------
92
93 void vtkInfoTextImage::PutColorLevel()
94 {
95         double value = _wxvtk2Dbaseview->_imageViewer2XYZ->GetVtkImageViewer2()->GetWindowLevel()->GetLevel();
96         char zTzxt[20];
97         char resultText[50];
98
99         strcpy(resultText,"c:");
100
101 //      itoa (value,zTzxt,10);
102         sprintf(zTzxt,"%3.2f",value);
103
104         strcat(resultText,zTzxt);
105         _vtkText_ColorLevel             -> SetInput(resultText);
106 }
107
108 //-------------------------------------------------------------------
109
110 void vtkInfoTextImage::PutPosition(int xx,int yy, int zz)
111 {
112
113 //EEDx7
114 //      double spa[3];
115 //      _imagedata->GetSpacing(spa);
116 //      xx=xx*(1/spa[0]);
117 //      yy=yy*(1/spa[1]);
118
119
120         char zTzxt[50];
121         char resultText[50];
122         strcpy(resultText,"p: ");
123 //      itoa ((int)xx,zTzxt,10);
124         sprintf(zTzxt,"%d",xx);
125
126         strcat(resultText,zTzxt);
127         strcat(resultText," , ");
128
129 //      itoa ((int)yy,zTzxt,10);
130         sprintf(zTzxt,"%d",yy);
131
132         strcat(resultText,zTzxt);
133         strcat(resultText," , ");
134
135 //      itoa ((int)zz,zTzxt,10);
136         sprintf(zTzxt,"%d",zz);
137
138         strcat(resultText,zTzxt);
139
140
141         
142         int nX = _marimagedata->GetXOriginal(xx);
143         int nY = _marimagedata->GetYOriginal(yy);
144         int nZ = _marimagedata->GetZOriginal(zz);
145
146         strcat(resultText,"   (");
147 //      ltoa ((int)nX,zTzxt,10);
148         sprintf(zTzxt,"%d",nX);
149
150         strcat(resultText,zTzxt);
151         strcat(resultText,",");
152
153 //      ltoa ((int)nY,zTzxt,10);
154         sprintf(zTzxt,"%d",nY);
155
156         strcat(resultText,zTzxt);
157         strcat(resultText,",");
158
159 //      ltoa ((int)nZ,zTzxt,10);
160         sprintf(zTzxt,"%d",nZ);
161
162         strcat(resultText,zTzxt);
163         strcat(resultText,")");
164
165
166
167
168         _vtkText_position               -> SetInput(resultText);
169 }
170
171 //-------------------------------------------------------------------
172
173 void vtkInfoTextImage::PutPixelIntensity(int xx, int yy, int zz)
174 {
175
176 //EEDx2
177         bool ok=true;
178
179         int dim[3];
180         double spa[3];
181         vtkImageData *imagedata = _marimagedata->GetImageData();
182         imagedata->GetDimensions(dim);
183         imagedata->GetSpacing(spa);
184
185 // EEDx7
186 //      xx=xx*(1/spa[0]);
187 //      yy=yy*(1/spa[1]);
188 //      zz=xx*spa[2];
189
190         if ( (xx<0) || (xx>=dim[0]) || (yy<0) || (yy>=dim[1]) || (zz<0) || (zz>=dim[2]) )
191         {
192                 ok=false;
193         }
194
195         
196         char zTzxt[20];
197         char resultText[50];
198         strcpy(resultText,"GL: ");
199         if (ok==true) 
200         {
201                 if (imagedata->GetScalarType()==VTK_BIT)
202                 {
203                         char *pOrg=(char*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
204         //              itoa (*pOrg,zTzxt,10);
205                         if(*pOrg==0)
206                         {
207                                 sprintf(zTzxt,"%d",0);
208                         }
209                         else
210                         {
211                                 sprintf(zTzxt,"%d",1);
212                         }
213                 }
214         
215                 else if (imagedata->GetScalarType()==VTK_CHAR)
216                 {
217                         char *pOrg=(char*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
218         //              itoa (*pOrg,zTzxt,10);
219                         int tmp=*pOrg;
220                         sprintf(zTzxt,"%d",tmp);
221                 }
222
223                 else if (imagedata->GetScalarType()==VTK_SIGNED_CHAR)
224                 {
225                         signed char *pOrg=(signed char*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
226         //              itoa (*pOrg,zTzxt,10);
227                         int tmp=*pOrg;
228                         sprintf(zTzxt,"%d",tmp);
229                 }
230
231                 else if (imagedata->GetScalarType()==VTK_UNSIGNED_CHAR)
232                 {
233                         unsigned char *pOrg=(unsigned char*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
234         //              itoa (*pOrg,zTzxt,10);
235                         int tmp=*pOrg;
236                         sprintf(zTzxt,"%d",tmp);
237                 }
238
239                 else if (imagedata->GetScalarType()==VTK_SHORT)
240                 {
241                         short *pOrg=(short*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
242         //              itoa (*pOrg,zTzxt,10);
243                         int tmp=*pOrg;
244                         sprintf(zTzxt,"%d",tmp);
245                 }
246
247                 else if (imagedata->GetScalarType()==VTK_UNSIGNED_SHORT)
248                 {
249                         unsigned short *pOrg=(unsigned short*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
250         //              itoa (*pOrg,zTzxt,10);
251                         int tmp=*pOrg;
252                         sprintf(zTzxt,"%d",tmp);
253                 }
254         
255                 else if (imagedata->GetScalarType()==VTK_INT)
256                 {
257                         int *pOrg=(int*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
258         //              itoa (*pOrg,zTzxt,10);
259                         sprintf(zTzxt,"%d",*pOrg);
260                 }
261
262                 else if (imagedata->GetScalarType()==VTK_UNSIGNED_INT)
263                 {
264                         unsigned int *pOrg=(unsigned int*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
265         //              itoa (*pOrg,zTzxt,10);
266                         int tmp=*pOrg;
267                         sprintf(zTzxt,"%d",tmp);
268                 }
269
270                 else if (imagedata->GetScalarType()==VTK_LONG)
271                 {
272                         long *pOrg=(long*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
273         //              itoa (*pOrg,zTzxt,10);
274                         double tmp=*pOrg;
275                         sprintf(zTzxt,"%3.4f",tmp);
276                 }
277
278                 else if (imagedata->GetScalarType()==VTK_UNSIGNED_LONG)
279                 {
280                         unsigned long *pOrg=(unsigned long*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
281         //              itoa (*pOrg,zTzxt,10);
282                         double tmp=*pOrg;
283                         sprintf(zTzxt,"%3.4f",tmp);
284                 }
285
286                 else if (imagedata->GetScalarType()==VTK_FLOAT)
287                 {
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.4f",tmp);
292                 }
293
294                 else if (imagedata->GetScalarType()==VTK_DOUBLE)
295                 {
296                         double *pOrg=(double*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
297         //              itoa (*pOrg,zTzxt,10);
298                         double tmp=*pOrg;
299                         sprintf(zTzxt,"%3.4f",tmp);
300                 }
301         } 
302         else 
303         {
304                 strcpy(zTzxt,"---");
305         }
306         strcat(resultText,zTzxt);
307         _vtkText_pixelIntensity -> SetInput(resultText);
308 }