]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/vtkInfoTextImage.cxx
#3322 creaContours Feature New Normal - Show reference contour Befor After actual...
[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         } // if vtkText_WindowLevel
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         // Set coordinates to match the old vtkScaledTextActor default value
87         textActor->GetPosition2Coordinate()->SetCoordinateSystemToNormalizedViewport();
88         textActor->GetPosition2Coordinate()->SetValue( 0.2 , 0.2 );
89         vtkTextProperty *tprop = textActor->GetTextProperty();
90         tprop->SetFontSize(14);
91         tprop->SetFontFamilyToArial();
92         tprop->SetColor(1, 1, 0);
93         _wxvtk2Dbaseview->GetRenderer()->AddActor2D(textActor);
94         return textActor;
95 }
96
97 //-------------------------------------------------------------------
98
99 void vtkInfoTextImage::PutWindowLevel()
100 {
101         double value =  _wxvtk2Dbaseview->_imageViewer2XYZ->GetVtkImageViewer2()->GetWindowLevel()->GetWindow() ;
102         char zTzxt[20];
103         char resultText[50];
104         strcpy(resultText,"w:");
105         sprintf(zTzxt,"%3.4f",value);
106         strcat(resultText,zTzxt);
107         _vtkText_WindowLevel            -> SetInput(resultText);
108 }
109
110 //-------------------------------------------------------------------
111
112 void vtkInfoTextImage::PutColorLevel()
113 {
114         double value = _wxvtk2Dbaseview->_imageViewer2XYZ->GetVtkImageViewer2()->GetWindowLevel()->GetLevel();
115         char zTzxt[20];
116         char resultText[50];
117         strcpy(resultText,"c:");
118 //      itoa (value,zTzxt,10);
119         sprintf(zTzxt,"%3.2f",value);
120         strcat(resultText,zTzxt);
121         _vtkText_ColorLevel             -> SetInput(resultText);
122 }
123
124 //-------------------------------------------------------------------
125 void vtkInfoTextImage::PutPlane()
126 {
127         int plane = _wxvtk2Dbaseview->GetDirection();
128         char zTzxt[20];
129         char resultText[50];
130         if (plane==0) { strcpy(resultText,"plane:YZ"); }
131         if (plane==1) { strcpy(resultText,"plane:XZ"); }
132         if (plane==2) { strcpy(resultText,"plane:XY"); }
133         _vtkText_plane          -> SetInput(resultText);
134 }
135
136 //-------------------------------------------------------------------
137
138 void vtkInfoTextImage::PutPosition(int xx,int yy, int zz)
139 {
140         char zTzxt[50];
141         char resultText[50];
142         strcpy(resultText,"p: ");
143         sprintf(zTzxt,"%d",xx);
144         strcat(resultText,zTzxt);
145         strcat(resultText," , ");
146         sprintf(zTzxt,"%d",yy);
147         strcat(resultText,zTzxt);
148         strcat(resultText," , ");
149         sprintf(zTzxt,"%d",zz);
150         strcat(resultText,zTzxt);
151         int nX = _marimagedata->GetXOriginal(xx);
152         int nY = _marimagedata->GetYOriginal(yy);
153         int nZ = _marimagedata->GetZOriginal(zz);
154         strcat(resultText,"   (");
155         sprintf(zTzxt,"%d",nX);
156         strcat(resultText,zTzxt);
157         strcat(resultText,",");
158         sprintf(zTzxt,"%d",nY);
159         strcat(resultText,zTzxt);
160         strcat(resultText,",");
161         sprintf(zTzxt,"%d",nZ);
162         strcat(resultText,zTzxt);
163         strcat(resultText,")");
164         _vtkText_position               -> SetInput(resultText);
165 }
166
167 //-------------------------------------------------------------------
168
169 void vtkInfoTextImage::PutPixelIntensity(int xx, int yy, int zz)
170 {
171         bool ok=true;
172         int dim[3];
173         double spa[3];
174         vtkImageData *imagedata = _marimagedata->GetImageData();
175         imagedata->GetDimensions(dim);
176         imagedata->GetSpacing(spa);
177         if ( (xx<0) || (xx>=dim[0]) || (yy<0) || (yy>=dim[1]) || (zz<0) || (zz>=dim[2]) )
178         {
179                 ok=false;
180         }
181         char zTzxt[20];
182         char resultText[50];
183         strcpy(resultText,"GL: ");
184         if (ok==true) 
185         {
186                 if (imagedata->GetScalarType()==VTK_BIT)
187                 {
188                         char *pOrg=(char*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
189                         if(*pOrg==0)
190                         {
191                                 sprintf(zTzxt,"%d",0);
192                         } else {
193                                 sprintf(zTzxt,"%d",1);
194                         } // if pOrg
195                 } else if (imagedata->GetScalarType()==VTK_CHAR) {
196                         char *pOrg=(char*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
197         //              itoa (*pOrg,zTzxt,10);
198                         int tmp=*pOrg;
199                         sprintf(zTzxt,"%d",tmp);
200                 } else if (imagedata->GetScalarType()==VTK_SIGNED_CHAR) {
201                         signed char *pOrg=(signed char*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
202         //              itoa (*pOrg,zTzxt,10);
203                         int tmp=*pOrg;
204                         sprintf(zTzxt,"%d",tmp);
205                 } else if (imagedata->GetScalarType()==VTK_UNSIGNED_CHAR) {
206                         unsigned char *pOrg=(unsigned char*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
207         //              itoa (*pOrg,zTzxt,10);
208                         int tmp=*pOrg;
209                         sprintf(zTzxt,"%d",tmp);
210                 } else if (imagedata->GetScalarType()==VTK_SHORT) {
211                         short *pOrg=(short*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
212         //              itoa (*pOrg,zTzxt,10);
213                         int tmp=*pOrg;
214                         sprintf(zTzxt,"%d",tmp);
215                 } else if (imagedata->GetScalarType()==VTK_UNSIGNED_SHORT) {
216                         unsigned short *pOrg=(unsigned short*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
217         //              itoa (*pOrg,zTzxt,10);
218                         int tmp=*pOrg;
219                         sprintf(zTzxt,"%d",tmp);
220                 } else if (imagedata->GetScalarType()==VTK_INT) {
221                         int *pOrg=(int*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
222         //              itoa (*pOrg,zTzxt,10);
223                         sprintf(zTzxt,"%d",*pOrg);
224                 } else if (imagedata->GetScalarType()==VTK_UNSIGNED_INT) {
225                         unsigned int *pOrg=(unsigned int*)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_LONG) {
230                         long *pOrg=(long*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
231         //              itoa (*pOrg,zTzxt,10);
232                         double tmp=*pOrg;
233                         sprintf(zTzxt,"%3.4f",tmp);
234                 } else if (imagedata->GetScalarType()==VTK_UNSIGNED_LONG) {
235                         unsigned long *pOrg=(unsigned long*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
236         //              itoa (*pOrg,zTzxt,10);
237                         double tmp=*pOrg;
238                         sprintf(zTzxt,"%3.4f",tmp);
239                 } else if (imagedata->GetScalarType()==VTK_FLOAT) {
240                         float *pOrg=(float*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
241         //              itoa (*pOrg,zTzxt,10);
242                         double tmp=(double)*pOrg;
243                         sprintf(zTzxt,"%3.4f",tmp);
244                 } else if (imagedata->GetScalarType()==VTK_DOUBLE) {
245                         double *pOrg=(double*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
246         //              itoa (*pOrg,zTzxt,10);
247                         double tmp=*pOrg;
248                         sprintf(zTzxt,"%3.4f",tmp);
249                 } // if imagedata  Type
250         }  else  {
251                 strcpy(zTzxt,"---");
252         } // if ok
253         strcat(resultText,zTzxt);
254         _vtkText_pixelIntensity -> SetInput(resultText);
255 }