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