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