]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/vtkMPR3DDataViewer.cxx
#3012 creaMaracasVisu Bug New Normal - Update Image in ViewerNV
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / vtkMPR3DDataViewer.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
27 #include "vtkMPR3DDataViewer.h"
28
29
30 vtkMPR3DDataViewer::vtkMPR3DDataViewer()
31 {
32         _visiblePosition[0]=false;
33         _visiblePosition[1]=false;
34         _visiblePosition[2]=false;
35         _ctfun                  = NULL;
36         _vtkmprbasedata = NULL;
37
38         _ctfun                  = NULL;
39         _saggitalColors = NULL;
40         _saggital               = NULL;
41         _axialColors    = NULL;
42         _axial                  = NULL;
43         _coronalColors  = NULL;
44         _coronal                = NULL;
45         _mapOutline             = NULL;
46         _outline                = NULL;
47         _outlineData    = NULL;
48 }
49 //-------------------------------------------------------------------
50 vtkMPR3DDataViewer::~vtkMPR3DDataViewer()
51 {
52         if(_outlineData) {_outlineData-> Delete();}
53         if(_mapOutline)  {_mapOutline-> Delete();}
54         if(_outline)     {_outline-> Delete();}
55
56 //      if (_bwLut)                             _bwLut->Delete();
57 //      if (_hueLut)                    _hueLut->Delete();
58 //      if (_satLut)                    _satLut->Delete();
59         if (_ctfun)                             _ctfun->Delete();
60         if (_saggitalColors)    _saggitalColors ->Delete();
61         if (_saggital)                  _saggital->Delete();
62         if (_axialColors)               _axialColors->Delete();
63         if (_axial)                             _axial->Delete();
64         if (_coronalColors)             _coronalColors->Delete();
65         if (_coronal)                   _coronal->Delete();
66
67 }
68 //-------------------------------------------------------------------
69 vtkActor* vtkMPR3DDataViewer::GetOutlineActor()
70 {
71         return _outline;
72 }
73 //-------------------------------------------------------------------
74 vtkImageActor* vtkMPR3DDataViewer::GetImageActor(int id)
75 {
76         vtkImageActor *tmpVtkActor=NULL;
77         if (id==0)
78         {
79                 tmpVtkActor = GetvtkActor_saggital();
80         }
81         if (id==1)
82         {
83                 tmpVtkActor = GetvtkActor_coronal();
84         }
85         if (id==2)
86         {
87                 tmpVtkActor = GetvtkActor_axial();
88         }
89         return tmpVtkActor;
90 }
91
92 //-------------------------------------------------------------------
93 void vtkMPR3DDataViewer::Refresh()
94 {
95         int x = (int)(_vtkmprbasedata->GetX());
96         int y = (int)(_vtkmprbasedata->GetY());
97         int z = (int)(_vtkmprbasedata->GetZ());
98         SetPositionX( x );
99         SetPositionY( y );
100         SetPositionZ( z );
101 }
102 //-------------------------------------------------------------------
103 void vtkMPR3DDataViewer::SetVtkMPRBaseData(vtkMPRBaseData *vtkmprbasedata)
104 {
105         _vtkmprbasedata=vtkmprbasedata;
106 }
107 //-------------------------------------------------------------------
108 vtkMPRBaseData* vtkMPR3DDataViewer::GetVtkMPRBaseData()
109 {
110         return _vtkmprbasedata;
111 }
112 //-------------------------------------------------------------------
113
114 vtkColorTransferFunction *vtkMPR3DDataViewer::GetvtkColorTransferFunction()
115 {
116         return _ctfun;
117 }
118 //-------------------------------------------------------------------
119
120 std::vector<double>* vtkMPR3DDataViewer::GetctFunVectorPoint()
121 {
122         return &_ctFunVectorPoint;
123 }
124 //-------------------------------------------------------------------
125 std::vector<double>*     vtkMPR3DDataViewer::GetctFunVectorRed()
126 {
127         return &_ctFunVectorRed;
128 }
129
130 //-------------------------------------------------------------------
131 std::vector<double>*     vtkMPR3DDataViewer::GetctFunVectorGreen()
132 {
133         return &_ctFunVectorGreen;
134 }
135
136 //-------------------------------------------------------------------
137 std::vector<double>*     vtkMPR3DDataViewer::GetctFunVectorBlue()
138 {
139         return &_ctFunVectorBlue;
140 }
141
142 //-------------------------------------------------------------------
143 void vtkMPR3DDataViewer::SetImage()
144 {
145         _saggitalColors->SetInput( _vtkmprbasedata->GetImageData() );
146         _axialColors->SetInput( _vtkmprbasedata->GetImageData() );
147         _coronalColors->SetInput( _vtkmprbasedata->GetImageData() );
148 }
149
150 //-------------------------------------------------------------------
151 void vtkMPR3DDataViewer::Configure()
152 {
153 /*
154   // Start by creatin a black/white lookup table.
155         _bwLut = vtkLookupTable::New();
156     _bwLut->SetTableRange (0, 2000);
157     _bwLut->SetSaturationRange (0, 0);
158     _bwLut->SetHueRange (0, 0);
159     _bwLut->SetValueRange (0, 1);
160
161   // Now create a lookup table that consists of the full hue circle
162   // (from HSV).
163         _hueLut = vtkLookupTable::New();
164     _hueLut->SetTableRange (0, 2000);
165     _hueLut->SetHueRange (0, 1);
166     _hueLut->SetSaturationRange (1, 1);
167     _hueLut->SetValueRange (1, 1);
168
169   // Finally, create a lookup table with a single hue but having a range
170   // in the saturation of the hue.
171         _satLut = vtkLookupTable::New();
172     _satLut->SetTableRange (0, 2000);
173     _satLut->SetHueRange (.6, .6);
174     _satLut->SetSaturationRange (0, 1);
175     _satLut->SetValueRange (1, 1);
176 */
177
178
179         double range[2];
180         double delta;
181         
182         if(_vtkmprbasedata->GetImageData())
183         {
184                 _vtkmprbasedata->GetImageData()->GetScalarRange(range);
185                 delta = range[1]-range[0];
186                                 
187                 _ctFunVectorPoint.clear();
188                 _ctFunVectorPoint.push_back( range[0] + delta*0/4 );
189                 _ctFunVectorPoint.push_back( range[0] + delta*1/4 );
190                 _ctFunVectorPoint.push_back( range[0] + delta*2/4 );
191                 _ctFunVectorPoint.push_back( range[0] + delta*3/4 );
192                 _ctFunVectorPoint.push_back( range[0] + delta*4/4 );
193
194                 _ctFunVectorRed.clear();
195                 _ctFunVectorRed.push_back(0.0);
196                 _ctFunVectorRed.push_back(1.0);
197                 _ctFunVectorRed.push_back(0.0);
198                 _ctFunVectorRed.push_back(0.0);
199                 _ctFunVectorRed.push_back(0.0);
200
201                 _ctFunVectorGreen.clear();
202                 _ctFunVectorGreen.push_back(0.0);
203                 _ctFunVectorGreen.push_back(0.0);
204                 _ctFunVectorGreen.push_back(0.0);
205                 _ctFunVectorGreen.push_back(1.0);
206                 _ctFunVectorGreen.push_back(0.2);
207
208                 _ctFunVectorBlue.clear();
209                 _ctFunVectorBlue.push_back(0.0);
210                 _ctFunVectorBlue.push_back(0.0);
211                 _ctFunVectorBlue.push_back(1.0);
212                 _ctFunVectorBlue.push_back(0.0);
213                 _ctFunVectorBlue.push_back(0.0);
214
215                 if(_ctfun==NULL)
216                 {
217                         _ctfun = vtkColorTransferFunction::New();
218                 }
219                 _ctfun->RemoveAllPoints();
220
221                 int i,size=_ctFunVectorPoint.size();
222                 for (i=0;i<size;i++)
223                 {
224                         _ctfun->AddRGBPoint( _ctFunVectorPoint[i] , _ctFunVectorRed[i],_ctFunVectorGreen[i],_ctFunVectorBlue[i]);
225                         
226                 }
227         /*
228                 _ctfun->AddRGBPoint( 100 ,0 ,0,0);
229                 _ctfun->AddRGBPoint( 200 ,1 ,0,0);
230                 _ctfun->AddRGBPoint( 300 ,0 ,1,0);
231                 _ctfun->AddRGBPoint( 400 ,0 ,0,1);
232         */
233         //      void *p=this; // JPRx
234
235         // Create the first of the three planes. The filter vtkImageMapToColors
236         // maps the data through the corresponding lookup table created above.  The
237         // vtkImageActor is a type of vtkProp and conveniently displays an image on
238         // a single quadrilateral plane. It does this using texture mapping and as
239         // a result is quite fast. (Note: the input image has to be unsigned char
240         // values, which the vtkImageMapToColors produces.) Note also that by
241         // specifying the DisplayExtent, the pipeline requests data of this extent
242         // and the vtkImageMapToColors only processes a slice of data.
243                 
244                 if(_saggitalColors==NULL){
245                         _saggitalColors = vtkImageMapToColors::New();
246                 }
247                 _saggitalColors->RemoveAllInputs();
248                 _saggitalColors->SetInput( _vtkmprbasedata->GetImageData() );
249                 
250         //    _saggitalColors->SetLookupTable(_bwLut);
251                 
252                 _saggitalColors->SetLookupTable(_ctfun);
253                 
254
255                 if(_saggital==NULL){
256                         _saggital = vtkImageActor::New();
257                         _saggital->SetInput(_saggitalColors->GetOutput());
258                 }       
259                 //_saggitalColors->Update();
260         
261
262
263         // Create the second (axial) plane of the three planes. We use the
264         // same approach as before except that the extent differs.
265
266                 
267                 if(_axialColors==NULL){
268                         _axialColors = vtkImageMapToColors::New();
269                 }
270
271                 _axialColors->RemoveAllInputs();
272                 _axialColors->SetInput( _vtkmprbasedata->GetImageData() );
273         //    _axialColors->SetLookupTable(_hueLut);
274                 _axialColors->SetLookupTable(_ctfun);
275
276                 if(_axial==NULL){
277                         _axial = vtkImageActor::New();
278                         _axial->SetInput(_axialColors->GetOutput());
279                 }
280                 
281                 //_axialColors->Update();
282         
283
284                 // Create the third (coronal) plane of the three planes. We use 
285         // the same approach as before except that the extent differs.
286                 if(_coronalColors==NULL){
287                         _coronalColors = vtkImageMapToColors::New();
288                 }
289                 _coronalColors->RemoveAllInputs();
290                 _coronalColors->SetInput( _vtkmprbasedata->GetImageData() );
291         //    _coronalColors->SetLookupTable(_satLut);
292                 _coronalColors->SetLookupTable(_ctfun);
293
294                 if(_coronal==NULL){
295                         _coronal = vtkImageActor::New();
296                         _coronal->SetInput(_coronalColors->GetOutput());
297                 }
298                 
299         
300
301         // An outline provides context around the data.
302         //
303                 if(_outlineData==NULL){
304                         _outlineData = vtkOutlineFilter::New();
305                 }
306                 _outlineData->RemoveAllInputs();
307                 if(_vtkmprbasedata->GetImageData()){
308                         _outlineData->SetInput((vtkDataSet *) _vtkmprbasedata->GetImageData() );
309                 }
310
311                 if(_mapOutline==NULL){
312                         _mapOutline = vtkPolyDataMapper::New();
313                         _mapOutline->SetInput(_outlineData->GetOutput());
314                 }
315                 _mapOutline->Update();    
316                 //_mapOutline->RemoveAllInputs();
317         
318                 if(_outline==NULL){
319                         _outline = vtkActor::New();
320                         _outline->SetMapper(_mapOutline);
321                         _outline->GetProperty()->SetColor(0,0,0);
322                 }
323         }
324         
325         
326
327         
328         
329     
330
331         //int ext[6];
332         //_vtkmprbasedata->GetImageData()->GetExtent(ext);
333
334         
335
336
337 }
338
339 //-------------------------------------------------------------------
340 vtkImageActor * vtkMPR3DDataViewer::GetvtkActor_saggital()
341 {
342         return _saggital;
343 }
344 //-------------------------------------------------------------------
345 vtkImageActor * vtkMPR3DDataViewer::GetvtkActor_coronal()
346 {
347         return _coronal;
348 }
349 //-------------------------------------------------------------------
350 vtkImageActor * vtkMPR3DDataViewer::GetvtkActor_axial()
351 {
352         return _axial;
353 }
354
355 //------------------------------------------------------------------------
356 void vtkMPR3DDataViewer::SetPositionX(int pos)
357 {
358         int x1,x2,y1,y2,z1,z2;
359         _vtkmprbasedata->GetDimensionExtention(&x1,&x2,&y1,&y2,&z1,&z2);
360         if(_saggital)
361         {
362                 _saggital->SetDisplayExtent( pos , pos , y1 ,y2 , z1 , z2 );
363 //EED 2016/02/19
364                 _saggital->SetInterpolate(  GetVtkMPRBaseData()->GetInterpolate() );
365         }
366 }
367
368 //------------------------------------------------------------------------
369 void vtkMPR3DDataViewer::SetPositionY(int pos)
370 {
371         int x1,x2,y1,y2,z1,z2;
372         _vtkmprbasedata->GetDimensionExtention(&x1,&x2,&y1,&y2,&z1,&z2);
373         if(_coronal)
374         {
375                 _coronal->SetDisplayExtent(x1,x2, pos,pos, z1,z2);
376 //EED 2016/02/19
377                 _coronal->SetInterpolate(  GetVtkMPRBaseData()->GetInterpolate() );
378         }
379 }
380 //------------------------------------------------------------------------
381 void vtkMPR3DDataViewer::SetPositionZ(int pos)
382 {
383         int x1,x2,y1,y2,z1,z2;
384         _vtkmprbasedata->GetDimensionExtention(&x1,&x2,&y1,&y2,&z1,&z2);
385         if(_axial)
386         {
387                 _axial->SetDisplayExtent(x1,x2, y1,y2, pos,pos);
388 //EED 2016/02/19
389                 _axial->SetInterpolate(  GetVtkMPRBaseData()->GetInterpolate() );
390         }
391 }
392 //-------------------------------------------------------------------
393 void vtkMPR3DDataViewer::SetVisiblePosition(int idPosition, bool visible)
394 {
395         _visiblePosition[idPosition]=visible;
396 }
397 //-------------------------------------------------------------------
398 bool vtkMPR3DDataViewer::GetVisiblePosition(int idPosition)
399 {
400         return _visiblePosition[idPosition];
401 }
402
403 void vtkMPR3DDataViewer::setColorTransferFunction(vtkColorTransferFunction* colortable){
404         if(_saggitalColors)
405         {
406                 _saggitalColors->SetLookupTable(colortable);
407                 _coronalColors->SetLookupTable(colortable);
408                 _axialColors->SetLookupTable(colortable);
409         }
410 }
411