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