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