1 /*# ---------------------------------------------------------------------
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
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
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.
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
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 # ------------------------------------------------------------------------ */
26 #include "vtkInfoTextImage.h"
28 #include "vtkTextProperty.h"
29 #include <vtkImageMapToWindowLevelColors.h>
30 //-------------------------------------------------------------------
31 //-------------------------------------------------------------------
32 //-------------------------------------------------------------------
34 vtkInfoTextImage::vtkInfoTextImage()
36 _vtkText_WindowLevel = NULL;
37 _vtkText_ColorLevel = NULL;
38 _vtkText_position = NULL;
39 _vtkText_pixelIntensity = NULL;
40 _vtkText_plane = NULL;
44 //-------------------------------------------------------------------
46 vtkInfoTextImage::~vtkInfoTextImage()
50 //-------------------------------------------------------------------
52 void vtkInfoTextImage::Configure()
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
64 //-------------------------------------------------------------------
66 void vtkInfoTextImage::SetMarImageData(marImageData *marimagedata)
68 _marimagedata = marimagedata;
71 //-------------------------------------------------------------------
73 void vtkInfoTextImage::SetWxVtk2DBaseView(wxVtk2DBaseView *wxvtk2Dbaseview)
75 _wxvtk2Dbaseview = wxvtk2Dbaseview;
78 //-------------------------------------------------------------------
80 vtkTextActor *vtkInfoTextImage::Create_Text_Label(int px, int py )
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);
97 //-------------------------------------------------------------------
99 void vtkInfoTextImage::PutWindowLevel()
101 double value = _wxvtk2Dbaseview->_imageViewer2XYZ->GetVtkImageViewer2()->GetWindowLevel()->GetWindow() ;
104 strcpy(resultText,"w:");
105 sprintf(zTzxt,"%3.4f",value);
106 strcat(resultText,zTzxt);
107 _vtkText_WindowLevel -> SetInput(resultText);
110 //-------------------------------------------------------------------
112 void vtkInfoTextImage::PutColorLevel()
114 double value = _wxvtk2Dbaseview->_imageViewer2XYZ->GetVtkImageViewer2()->GetWindowLevel()->GetLevel();
117 strcpy(resultText,"c:");
118 // itoa (value,zTzxt,10);
119 sprintf(zTzxt,"%3.2f",value);
120 strcat(resultText,zTzxt);
121 _vtkText_ColorLevel -> SetInput(resultText);
124 //-------------------------------------------------------------------
125 void vtkInfoTextImage::PutPlane()
127 int plane = _wxvtk2Dbaseview->GetDirection();
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);
136 //-------------------------------------------------------------------
138 void vtkInfoTextImage::PutPosition(int xx,int yy, int zz)
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);
167 //-------------------------------------------------------------------
169 void vtkInfoTextImage::PutPixelIntensity(int xx, int yy, int zz)
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]) )
183 strcpy(resultText,"GL: ");
186 if (imagedata->GetScalarType()==VTK_BIT)
188 char *pOrg=(char*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
191 sprintf(zTzxt,"%d",0);
193 sprintf(zTzxt,"%d",1);
195 } else if (imagedata->GetScalarType()==VTK_CHAR) {
196 char *pOrg=(char*)imagedata->GetScalarPointer ((int)xx,(int)yy,(int)zz);
197 // itoa (*pOrg,zTzxt,10);
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);
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);
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);
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);
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);
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);
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);
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);
248 sprintf(zTzxt,"%3.4f",tmp);
249 } // if imagedata Type
253 strcat(resultText,zTzxt);
254 _vtkText_pixelIntensity -> SetInput(resultText);