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