]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/vtkImageViewer2_XYZ.cxx
b03173ef2ffc0475ab2f30cfd0e829c90aaca6fb
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / vtkImageViewer2_XYZ.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 "vtkImageViewer2_XYZ.h"
27 #include "vtkRenderer.h"
28 #include "vtkImageActor.h"
29 #include "vtkImageData.h"
30
31
32
33 #include "vtkLookupTable.h"
34 #include "vtkObjectFactory.h"
35
36 class /*VTK_COMMON_EXPORT*/ vtkLookupTableDirectionVector2 : public vtkScalarsToColors
37 {
38 public:
39         // Description:
40         // Construct with range=[0,1]; and hsv ranges set up for rainbow color table 
41         // (from red to blue).
42         static vtkLookupTableDirectionVector2 *New();
43         
44         vtkTypeMacro(vtkLookupTableDirectionVector2,vtkScalarsToColors);
45         void PrintSelf(ostream& os, vtkIndent indent);
46
47         double *GetRange() { return this->GetTableRange(); };
48         void SetRange(double min, double max) { this->SetTableRange(min, max); };
49         void SetRange(double rng[2]) { this->SetRange(rng[0], rng[1]); };
50         
51         void SetTableRange(double r[2]); 
52         virtual void SetTableRange(double min, double max);
53         vtkGetVectorMacro(TableRange,double,2);
54                         
55         unsigned char *MapValue(double v);
56         
57         void GetColor(double x, double rgb[3]);
58         
59
60         void MapScalarsThroughTable2(void *input, unsigned char *output,
61                                                                  int inputDataType, int numberOfValues,
62                                                                  int inputIncrement, int outputIncrement);
63                 
64 protected:
65         double TableRange[2];
66         vtkLookupTableDirectionVector2(int sze=256, int ext=256);
67         ~vtkLookupTableDirectionVector2();
68                 
69 private:
70         vtkLookupTableDirectionVector2(const vtkLookupTableDirectionVector2&);  // Not implemented.
71         void operator=(const vtkLookupTableDirectionVector2&);  // Not implemented.
72 };
73
74
75
76
77 vtkStandardNewMacro(vtkLookupTableDirectionVector2);
78
79 // Construct with range=(0,1); and hsv ranges set up for rainbow color table 
80 // (from red to blue).
81 vtkLookupTableDirectionVector2::vtkLookupTableDirectionVector2(int sze, int ext)
82 {
83         this->TableRange[0] = 0.0;
84         this->TableRange[1] = 1.0;
85 }
86
87 //----------------------------------------------------------------------------
88 vtkLookupTableDirectionVector2::~vtkLookupTableDirectionVector2()
89 {
90 }
91
92 unsigned char *vtkLookupTableDirectionVector2::MapValue(double v)
93 {
94         
95         //int idx = this->GetIndex(v);
96         //return (this->Table->GetPointer(0) + 4*idx);  
97         return 0;
98 }
99
100 void vtkLookupTableDirectionVector2::GetColor(double v, double rgb[3])
101 {
102 //      unsigned char *rgb8 = this->MapValue(v);
103 //      rgb[0] = rgb8[0]/255.0;
104 //      rgb[1] = rgb8[1]/255.0;
105 //      rgb[2] = rgb8[2]/255.0;
106
107         rgb[0] = 1;
108         rgb[1] = 1;
109         rgb[2] = 0;
110 }
111
112
113 void vtkLookupTableDirectionVector2::SetTableRange(double r[2])
114 {
115         this->SetTableRange(r[0],r[1]);
116 }
117
118 //----------------------------------------------------------------------------
119 // Set the minimum/maximum scalar values for scalar mapping. Scalar values
120 // less than minimum range value are clamped to minimum range value.
121 // Scalar values greater than maximum range value are clamped to maximum
122 // range value.
123 void vtkLookupTableDirectionVector2::SetTableRange(double rmin, double rmax)
124 {
125         if (rmax < rmin)
126     {
127                 vtkErrorMacro("Bad table range: ["<<rmin<<", "<<rmax<<"]");
128                 return;
129     }
130         
131         if (this->TableRange[0] == rmin && this->TableRange[1] == rmax)
132     {
133                 return;
134     }
135         
136         this->TableRange[0] = rmin;
137         this->TableRange[1] = rmax;
138         
139         this->Modified();
140 }
141
142
143
144 //----------------------------------------------------------------------------
145 // Although this is a relatively expensive calculation,
146 // it is only done on the first render. Colors are cached
147 // for subsequent renders.
148 template<class T>
149 void vtkLookupTableMapDirVectorEED2(vtkLookupTableDirectionVector2 *self, T *input, 
150                           unsigned char *output, int length, 
151                           int inIncr, int outFormat)
152 {
153         int i;
154         for (i = 0; i < length; ++i)
155     {
156                         *output++ = static_cast<T>(input[0]);  // red
157                         *output++ = static_cast<T>(input[1]);  // green
158                         *output++ = static_cast<T>(input[2]);  // blue
159 //                      *output++ = 255;
160                         input   = input+inIncr;
161         } // for
162
163 }
164
165
166 //----------------------------------------------------------------------------
167 void vtkLookupTableDirectionVector2::MapScalarsThroughTable2(void *input, 
168                                              unsigned char *output,
169                                              int inputDataType, 
170                                              int numberOfValues,
171                                              int inputIncrement,
172                                              int outputFormat)
173 {
174 // if (this->UseMagnitude && inputIncrement > 1)
175 // {
176      switch (inputDataType)
177      {
178        vtkTemplateMacro( vtkLookupTableMapDirVectorEED2(this,static_cast<VTK_TT*>(input),output,
179                          numberOfValues,inputIncrement,outputFormat);
180                          return 
181                         );
182         case VTK_BIT:
183             vtkErrorMacro("Cannot comput magnitude of bit array.");
184             break;
185         default:
186             vtkErrorMacro(<< "MapImageThroughTable: Unknown input ScalarType");
187      } /// switch
188 // } //if
189 }  
190
191
192 //----------------------------------------------------------------------------
193 void vtkLookupTableDirectionVector2::PrintSelf(ostream& os, vtkIndent indent)
194 {
195         this->Superclass::PrintSelf(os,indent); 
196 }
197
198
199
200
201 //-------------------------------------------------------------------
202 //-------------------------------------------------------------------
203 //-------------------------------------------------------------------
204 vtkImageViewer2_XYZ::vtkImageViewer2_XYZ()
205 {
206         _vtkimageviewer2 = vtkImageViewer2::New();
207         _vtkimageviewer2->GetRenderer()->GradientBackgroundOn();
208         _vtkimageviewer2->GetRenderer()->SetBackground( 0.33 , 0.33 , 0.33 );
209         _vtkimageviewer2->GetRenderer()->SetBackground2( 0.66 , 0.66 , 0.66 );
210         _colortable = NULL;
211 }
212 //-------------------------------------------------------------------
213 vtkImageViewer2_XYZ::~vtkImageViewer2_XYZ()
214 {
215         //_vtkimageviewer2->Delete();
216 }
217 //-------------------------------------------------------------------
218 void vtkImageViewer2_XYZ::SetExtentDimension(int x1,int x2,
219                                                                                          int y1,int y2,
220                                                                                          int z1,int z2)
221 {
222         _x1 = x1;
223         _x2 = x2;
224         _y1 = y1;
225         _y2 = y2;
226         _z1 = z1;
227         _z2 = z2;
228 }
229
230 //-------------------------------------------------------------------
231 void vtkImageViewer2_XYZ::SetXSlice(int slice)
232 {
233         vtkImageActor *imageActor = _vtkimageviewer2->GetImageActor();
234         imageActor->SetDisplayExtent(slice, slice, _y1, _y2, _z1, _z2 );  
235 }
236
237 //-------------------------------------------------------------------
238 void vtkImageViewer2_XYZ::SetYSlice(int slice)
239 {
240         vtkImageActor *imageActor = _vtkimageviewer2->GetImageActor();
241         imageActor->SetDisplayExtent(_x1, _x2, slice, slice, _z1, _z2 );  
242 }
243
244 //-------------------------------------------------------------------
245 void vtkImageViewer2_XYZ::SetZSlice(int slice)
246 {
247 #if (VTK_MAJOR_VERSION >= 5)
248 //              _vtkimageviewer2->SetSlice( slice );
249         vtkImageActor *imageActor = _vtkimageviewer2->GetImageActor();
250         imageActor->SetDisplayExtent(_x1, _x2, _y1, _y2, slice, slice );  
251 #else
252                 _vtkimageviewer2->SetZSlice( slice );
253 #endif
254 }
255 //-------------------------------------------------------------------
256 int vtkImageViewer2_XYZ::GetXSlice()
257 {
258         vtkImageActor *imageActor = _vtkimageviewer2->GetImageActor();
259         return imageActor->GetDisplayExtent()[0];
260 }
261
262 //-------------------------------------------------------------------
263 int vtkImageViewer2_XYZ::GetYSlice()
264 {
265         vtkImageActor *imageActor = _vtkimageviewer2->GetImageActor();
266         return imageActor->GetDisplayExtent()[2];
267 }
268
269 //-------------------------------------------------------------------
270 int vtkImageViewer2_XYZ::GetZSlice()
271 {
272          int result;
273 #if (VTK_MAJOR_VERSION >= 5)
274                 result= _vtkimageviewer2->GetSlice( );
275 #else
276                 result= _vtkimageviewer2->GetZSlice( );
277 #endif  
278         return result;
279 }
280
281 //-------------------------------------------------------------------
282 vtkImageViewer2 *vtkImageViewer2_XYZ::GetVtkImageViewer2()
283 {
284         return _vtkimageviewer2;
285 }
286
287 //-------------------------------------------------------------------
288 void vtkImageViewer2_XYZ::setColorTransferFunction(vtkColorTransferFunction* colortable)
289 {       
290         if(colortable!=NULL && colortable->GetSize()>0 && _colortable!=colortable)
291         {
292                 _colortable = colortable;
293                 vtkImageMapToWindowLevelColors* imagemaptowindowlevel = _vtkimageviewer2->GetWindowLevel();
294                 imagemaptowindowlevel->SetLookupTable(_colortable);
295         } // if colortable
296 }
297
298 //-------------------------------------------------------------------
299 void vtkImageViewer2_XYZ::setScalarsToColors(vtkScalarsToColors* colortable, int outputformat)
300 {
301 /* outputformat      VTK-8.1.1/Common/Core/vtkSystemIncludes.h
302         VTK_LUMINANCE       1
303         VTK_LUMINANCE_ALPHA 2
304         VTK_RGB             3
305         VTK_RGBA            4
306 */
307         if( _colortable!=colortable)
308         {
309                 _colortable = colortable;
310                 _vtkimageviewer2->GetWindowLevel()->SetOutputFormat( outputformat );
311                 _vtkimageviewer2->GetWindowLevel()->SetLookupTable(colortable);
312 //              _vtkimageviewer2->GetWindowLevel()->SetOutputFormatToRGB();
313 //      vtkLookupTableDirectionVector2 *_LutEED = vtkLookupTableDirectionVector2::New();
314 //      _LutEED->SetVectorModeToRGBColors();
315 //      _vtkimageviewer2->GetWindowLevel()->SetLookupTable(_LutEED);
316         } // if colortable
317 }
318
319