]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/vtkClipping3DDataViewer.cxx
#3474 Refresh optimization DrawAxisTree3D Box
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / vtkClipping3DDataViewer.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 "vtkClipping3DDataViewer.h"
28 #include "vtkDataSetReader.h"
29 #include "vtkProperty.h"
30
31 vtkClipping3DDataViewer::vtkClipping3DDataViewer()
32 {
33         int i;
34         for (i=0; i<VTKMPRDATA_MAXTISSUE; i++)
35         {
36                 _visibleTissue[i]               = false;
37                 _representationType[i]  = true;
38         }
39         _visibleVolume                          = false;
40         _isRayCasting                           = true;
41     _isMIP                                              = false;
42         _interpolation                          = false;
43         _shade                                          = false;
44
45     _volumerendererdata         = VolumeRendererData::New();
46
47 #if (VTK_MAJOR_VERSION <= 7) 
48     _volumeMapper                       = vtkVolumeRayCastMapper::New();
49     _compositeFunction          = vtkVolumeRayCastCompositeFunction::New();
50         _compositeFunctionMIP   = vtkVolumeRayCastMIPFunction::New();
51 #else 
52     _volumeMapper                       = vtkFixedPointVolumeRayCastMapper::New();
53 #endif
54
55     _newvol                             = vtkVolume::New();
56     _volumeProperty             = vtkVolumeProperty::New();
57
58 }
59 //-------------------------------------------------------------------
60 vtkClipping3DDataViewer::~vtkClipping3DDataViewer()
61 {
62         int i;
63         for (i=0; i< VTKMPRDATA_MAXTISSUE ; i++)
64         {
65                 _mCubes[i]->Delete();
66                 _tissueStripper[i]->Delete();
67                 _tissueMapper[i]->Delete();
68                 _tissuePlanes[i]->Delete();
69                 _tissueClipper[i]->Delete();
70         } // for i
71
72         // Volume
73         _tfun->Delete();
74         _ctfun->Delete();
75 #if (VTK_MAJOR_VERSION <= 7) 
76         _compositeFunction->Delete();
77 #else 
78         // ..
79 #endif
80         _volumeMapper->Delete();
81         _volumeProperty->Delete();
82         _newvol->Delete();
83         _volumePlanes->Delete();
84
85         for (i=0; i< VTKMPRDATA_MAXTISSUE ; i++){
86                 _tissue[i]-> Delete();
87                 _observerS[i]-> Delete();
88         }
89         _observerV-> Delete();
90 }
91
92 //-------------------------------------------------------------------
93 vtkClipPolyData* vtkClipping3DDataViewer::GetTissueClipper(int id)
94 {
95         return this->_tissueClipper[id];
96 }
97 //-------------------------------------------------------------------
98 vtkPolyDataMapper* vtkClipping3DDataViewer::GetTissueMapper(int id)
99 {
100         return _tissueMapper[id];
101 }
102 //-------------------------------------------------------------------
103 vtkPlanes* vtkClipping3DDataViewer::GetTissuePlanes(int id)
104 {
105         return _tissuePlanes[id];
106 }
107 //-------------------------------------------------------------------
108 vtkStripper* vtkClipping3DDataViewer::GetTissueStripper(int id)
109 {
110         return _tissueStripper[id];
111 }
112 //-------------------------------------------------------------------
113 void vtkClipping3DDataViewer::Refresh()
114 {
115 //      _volumeMapper->SetClippingPlanes(_volumePlanes);
116
117 //      this->_volumeMapper->Update();
118 //      this->_newvol->Update();
119
120 //      _newvol->VisibilityOn();
121
122
123 // _volumeMapper = vtkVolumeRayCastMapper::New();
124 //      _volumeMapper->SetInput( this->GetVtkMPRBaseData()->GetImageData() );
125 //      _volumeMapper->SetVolumeRayCastFunction(_compositeFunction);
126 //      _volumeMapper->SetClippingPlanes( _volumePlanes );
127 //      _newvol->SetMapper(_volumeMapper );
128
129
130 }
131 //-------------------------------------------------------------------
132 void vtkClipping3DDataViewer::RefreshSurface()
133 {
134         int i;
135         for (i=0; i< VTKMPRDATA_MAXTISSUE ; i++)
136         {
137                 SetIsovalue(i, (int) (GetIsovalue(i)+1) );
138 //              this->GetMCubes(i)->Update();
139         }
140 }
141 //-------------------------------------------------------------------
142 void vtkClipping3DDataViewer::SetVtkMPRBaseData(vtkMPRBaseData *vtkmprbasedata)
143 {
144         _vtkmprbasedata=vtkmprbasedata;
145 }
146 //-------------------------------------------------------------------
147 vtkMPRBaseData* vtkClipping3DDataViewer::GetVtkMPRBaseData()
148 {
149         return _vtkmprbasedata;
150 }
151
152
153 //-------------------------------------------------------------------
154 void vtkClipping3DDataViewer::SetVisibleTissue(int idTissue, bool visible)
155 {
156         _visibleTissue[idTissue]=visible;
157 }
158 //-------------------------------------------------------------------
159 bool vtkClipping3DDataViewer::GetVisibleTissue(int idTissue){
160         return _visibleTissue[idTissue];
161 }
162 //-------------------------------------------------------------------
163 void vtkClipping3DDataViewer::SetRepresentationType(int idTissue, bool representationType)
164 {
165         _representationType[idTissue]=representationType;
166 }
167 //-------------------------------------------------------------------
168 bool vtkClipping3DDataViewer::GetRepresentationType(int idTissue)
169 {
170         return _representationType[idTissue];
171 }
172
173 //-------------------------------------------------------------------
174 vtkActor* vtkClipping3DDataViewer::GetTissueActor(int id){
175         return _tissue[id];
176 }
177
178 //-------------------------------------------------------------------
179 boxSurfaceObserver *vtkClipping3DDataViewer::GetObserverS(int idObserverS)
180 {
181         return _observerS[idObserverS];
182 }
183 //-------------------------------------------------------------------
184 boxSurfaceObserver *vtkClipping3DDataViewer::GetObserverV()
185 {
186         return _observerV;
187 }
188
189 //-------------------------------------------------------------------
190 bool vtkClipping3DDataViewer::GetVisibleVolume()
191 {
192         return _visibleVolume;
193 }
194 //-------------------------------------------------------------------
195 void vtkClipping3DDataViewer::SetVisibleVolume(bool visiblevolume)
196 {
197         _visibleVolume = visiblevolume;
198 }
199
200 bool vtkClipping3DDataViewer::GetVisibleVolumeBox()
201 {
202         return _visibleVolumeBox;
203 }
204 //-------------------------------------------------------------------
205 void vtkClipping3DDataViewer::SetVisibleVolumeBox(bool visibleBox)
206 {
207         _visibleVolumeBox = visibleBox;
208 }
209
210
211 //-------------------------------------------------------------------
212 void vtkClipping3DDataViewer::SetImage()
213 {
214         int i;
215         vtkImageData *imagedata=_vtkmprbasedata->GetImageData();
216         for (i=0; i< VTKMPRDATA_MAXTISSUE ; i++)
217         {
218 //EED 2017-01-01 Migration VTK7
219 #if VTK_MAJOR_VERSION <= 5
220                 _mCubes[i]->SetInput( imagedata );
221 #else
222                 _mCubes[i]->SetInputData( imagedata );
223 #endif
224         } // for
225 //EED 2017-01-01 Migration VTK7
226 #if VTK_MAJOR_VERSION <= 5
227         _volumeMapper->SetInput( imagedata );
228 #else
229         _volumeMapper->SetInputData( imagedata );
230 #endif
231         _volumerendererdata->SetImageData( imagedata );
232 }
233
234 //-------------------------------------------------------------------
235 void vtkClipping3DDataViewer::Configure_Tissue()
236 {
237         int i;
238         double range[2];
239         vtkImageData *imagedata=_vtkmprbasedata->GetImageData();
240         imagedata->GetScalarRange( range );
241         for (i=0; i< VTKMPRDATA_MAXTISSUE ; i++)
242         {
243                 // Visualisation - original volume
244                 _mCubes[i] = vtkMarchingCubes::New( );
245
246 //EED 2017-01-01 Migration VTK7
247 #if VTK_MAJOR_VERSION <= 5
248                 _mCubes[i]->SetInput( imagedata );
249 #else
250                 _mCubes[i]->SetInputData( imagedata );
251 #endif
252
253                 _mCubes[i]->SetValue( 0, range[1]*(4+i) / 8 );
254 //              _mCubes[i]->SetValue( 0, 1500 );
255             _tissueStripper[i] = vtkStripper::New();
256
257 //EED 2017-01-01 Migration VTK7
258 #if VTK_MAJOR_VERSION <= 5
259             _tissueStripper[i]->SetInput( _mCubes[i]->GetOutput( ) );
260 #else
261             _tissueStripper[i]->SetInputData( _mCubes[i]->GetOutput( ) );
262 #endif
263
264                 _tissuePlanes[i]  = vtkPlanes::New();
265                 int x1,x2,y1,y2,z1,z2;
266                 imagedata->GetExtent(x1,x2,y1,y2,z1,z2);
267                 _tissuePlanes[i]->SetBounds(x1,x2,y1,y2,z1,z2);
268                 _tissueClipper[i] = vtkClipPolyData::New();
269                 _tissueClipper[i]->SetClipFunction( _tissuePlanes[i] );
270                 _tissueClipper[i]->InsideOutOn( );
271
272 //EED 2017-01-01 Migration VTK7
273 #if VTK_MAJOR_VERSION <= 5
274                 _tissueClipper[i]->SetInput( _tissueStripper[i]->GetOutput() );
275 #else
276                 _tissueClipper[i]->SetInputData( _tissueStripper[i]->GetOutput() );
277 #endif
278
279                 _tissueMapper[i] = vtkPolyDataMapper::New( );
280
281 //EED 2017-01-01 Migration VTK7
282 #if VTK_MAJOR_VERSION <= 5
283                 _tissueMapper[i]->SetInput( _tissueClipper[i]->GetOutput() );
284 #else
285                 _mCubes[i]->Update();
286                 _tissueStripper[i]->Update();
287                 _tissueClipper[i]->Update();
288                 _tissueMapper[i]->SetInputData( _tissueClipper[i]->GetOutput() );
289                 _tissueMapper[i]->Update();
290 #endif
291
292
293                 _tissueMapper[i]->ScalarVisibilityOff( );
294 //              _tissueMapper[i]->Update();
295         } // for i  
296
297         // vtkActor tissue
298         for (i=0; i< VTKMPRDATA_MAXTISSUE ; i++){
299                 // tissue
300                 _tissue[i] = vtkActor::New();
301                 _tissue[i]->SetMapper( GetTissueMapper(i) );
302                 float cr=1,cg=0.5,cb=0.5;
303                 _tissue[i]->GetProperty()->SetDiffuseColor(cr/255, cg/255   , cb/255   );
304                 _tissue[i]->GetProperty()->SetSpecular(.3);
305                 _tissue[i]->GetProperty()->SetSpecularPower(20);
306                 _tissue[i]->GetProperty()->SetOpacity(0.5);
307                 if (i==0) { _tissue[i]->GetProperty()->SetColor(0.85, 0.85   , 0.85   );        }
308                 if (i==1) { _tissue[i]->GetProperty()->SetColor(0, 0  ,  1  );                          }
309                 if (i==2) { _tissue[i]->GetProperty()->SetColor(0.85, 0.20   , 0.20   );        }
310                 if (i==3) { _tissue[i]->GetProperty()->SetColor(0, 1   , 0   );                         }
311         } // for
312
313         for (i=0; i< VTKMPRDATA_MAXTISSUE ; i++)
314         {
315                 _observerS[i] = boxSurfaceObserver::New();
316                 _observerS[i]->SetPlanes( GetTissuePlanes(i) );
317                 _observerS[i]->SetActor( _tissue[i] );
318                 _observerS[i]->SetFilters( _mCubes[i], _tissueStripper[i] ,_tissueClipper[i] );
319         } // for
320 }
321
322 //-----------------------------------------------------------------------------
323
324 void vtkClipping3DDataViewer::Configure_Volume()
325 {
326   // Volume
327
328  /** if(_newvol != NULL)
329   {
330     _newvol->Delete();
331     _volumeMapper->Delete();
332     _volumeProperty->Delete();
333   }*/
334
335   _tfun = vtkPiecewiseFunction::New();
336   _ctfun = vtkColorTransferFunction::New();
337
338         double range[2];
339         this->_vtkmprbasedata->GetImageData()->GetScalarRange(range);
340         double max = range[1];
341         
342         /*
343         adding the poinst of the transference function
344         */
345         //X
346         greyValuesTransferenceFVector.push_back(max * 0/2);  // JPR ?? 0/2
347         greyValuesTransferenceFVector.push_back(max * 1/2);  // JPR ?? division entiere?
348         greyValuesTransferenceFVector.push_back(max * 2/2);
349         //Y
350         intensityValuesTransferenceFVector.push_back(0.0);
351         intensityValuesTransferenceFVector.push_back(1.0);
352         intensityValuesTransferenceFVector.push_back(1.0);
353
354         _tfun->AddPoint(max * 0/2 , 0.0);
355         _tfun->AddPoint(max * 1/2 , 1.0);
356         _tfun->AddPoint(max * 2/2 , 1.0);
357
358         /*
359                 Adding the colors to the vectors
360         */
361         //RED
362         redColorsOfColorTransferenceFVector.push_back(0.0);
363         redColorsOfColorTransferenceFVector.push_back(1.0);
364         redColorsOfColorTransferenceFVector.push_back(0.0);
365         redColorsOfColorTransferenceFVector.push_back(0.0);
366         redColorsOfColorTransferenceFVector.push_back(0.0);
367
368         //GREEN
369         greenColorsOfColorTransferenceFVector.push_back(0.0);
370         greenColorsOfColorTransferenceFVector.push_back(0.0);
371         greenColorsOfColorTransferenceFVector.push_back(0.0);
372         greenColorsOfColorTransferenceFVector.push_back(1.0);
373         greenColorsOfColorTransferenceFVector.push_back(0.2);
374
375         //BLUE
376         blueColorsOfColorTransferenceFVector.push_back(0.0);
377         blueColorsOfColorTransferenceFVector.push_back(0.0);
378         blueColorsOfColorTransferenceFVector.push_back(1.0);
379         blueColorsOfColorTransferenceFVector.push_back(0.0);
380         blueColorsOfColorTransferenceFVector.push_back(0.0);
381         //GREY VALUE
382         greyValueColorsOfColorTransferenceFVector.push_back(max*0/4);
383         greyValueColorsOfColorTransferenceFVector.push_back(max*1/4);
384         greyValueColorsOfColorTransferenceFVector.push_back(max*2/4);
385         greyValueColorsOfColorTransferenceFVector.push_back(max*3/4);
386         greyValueColorsOfColorTransferenceFVector.push_back(max*4/4);
387
388         _ctfun->AddRGBPoint( max*0/4 , 0.0, 0.0, 0.0);
389         _ctfun->AddRGBPoint( max*1/4 , 1.0, 0.0, 0.0);
390         _ctfun->AddRGBPoint( max*2/4 , 0.0, 0.0, 1.0);
391         _ctfun->AddRGBPoint( max*3/4 , 0.0, 1.0, 0.0);
392         _ctfun->AddRGBPoint( max*4/4 , 0.0, 0.2, 0.0);
393
394   _volumePlanes  = vtkPlanes::New();
395 //      int x1,x2,y1,y2,z1,z2;
396 //      vtkImageData *imagedata=_vtkmprbasedata->GetImageData();
397 //      imagedata->GetExtent(x1,x2,y1,y2,z1,z2);
398 //      _volumePlanes->SetBounds(x1,x2,y1,y2,z1,z2);
399
400         // EED 13/03/2011
401
402  // _volumeMapper = vtkVolumeRayCastMapper::New();
403
404
405 //EED 2017-01-01 Migration VTK7
406 #if VTK_MAJOR_VERSION <= 5
407         _volumeMapper->SetInput( this->GetVtkMPRBaseData()->GetImageData() );
408 #else
409         _volumeMapper->SetInputData( this->GetVtkMPRBaseData()->GetImageData() );
410 #endif
411
412
413 #if (VTK_MAJOR_VERSION <= 7) 
414     _volumeMapper->SetVolumeRayCastFunction(_compositeFunction);
415         // _volumeMapper->SetVolumeRayCastFunction(_compositeFunctionMIP);
416 #else 
417         // ..
418 #endif
419         
420 //
421         _volumeMapper->SetClippingPlanes( _volumePlanes );
422         _volumeMapper->AutoAdjustSampleDistancesOn();
423
424     _volumeProperty->SetInterpolationTypeToNearest();
425     //_volumeProperty = vtkVolumeProperty::New();
426         _volumeProperty->SetColor(_ctfun);
427         _volumeProperty->SetScalarOpacity( _tfun );
428
429 // EED 31/03/2008
430         _volumeProperty->DisableGradientOpacityOn();
431
432
433 //      _volumeProperty->SetInterpolationTypeToNearest();
434 //      _volumeProperty->ShadeOff();
435 //      _volumeProperty->SetAmbient(0.3);
436 //      _volumeProperty->SetDiffuse(0.1);
437 //      _volumeProperty->SetSpecular(0.8);
438 //      _volumeProperty->DisableGradientOpacityOn();
439
440  // _newvol = vtkVolume::New();
441         _newvol->SetMapper(_volumeMapper );
442         _newvol->SetProperty(_volumeProperty );
443
444     _observerV = boxSurfaceObserver::New();
445         _observerV->SetPlanes( _volumePlanes );
446         _observerV->SetActor( _newvol );
447         
448 #if (VTK_MAJOR_VERSION <= 7) 
449         _observerV->SetvtkVolumeRayCastMapper( _volumeMapper );
450 #else 
451         _observerV->SetvtkFixedPointVolumeRayCastMapper( _volumeMapper );
452 #endif
453 }
454
455 //-----------------------------------------------------------------------------
456
457 void vtkClipping3DDataViewer::Configure_VolumeBox()
458 {
459         _volumerendererdata->SetImageData(_vtkmprbasedata->GetImageData());
460
461
462     vector<double> *gv = this->GetGreyValuesTransferenceFVector();
463     vector<double> *op = this->GetIntensityValuesTransferenceFVector();
464
465     _volumerendererdata->SetLookUpTable((vtkLookupTable*)(_ctfun));
466     _volumerendererdata->OpacityChanged(*gv, *op);
467
468     //_wxvtkclipping3Dview->VisibleVolumeActor( false );
469     //_volumerendererdata->ShowVolume(event.IsChecked() );
470        //_volumerendererdata->BoundingBoxChanged(event.IsChecked() );
471 }
472
473 //-----------------------------------------------------------------------------
474
475 void vtkClipping3DDataViewer::SetRenderer(vtkRenderer* renderer)
476 {
477     _volumerendererdata->SetRenderer(renderer);
478
479 }
480
481 //-----------------------------------------------------------------------------
482 void vtkClipping3DDataViewer::SetInteractor(vtkRenderWindowInteractor* interactor)
483 {
484
485     _volumerendererdata->SetInteractor(interactor);
486 }
487
488
489 //-----------------------------------------------------------------------------
490 void vtkClipping3DDataViewer::BoxActorChanged(bool changed)
491 {
492     vector<double> *gv = this->GetGreyValuesTransferenceFVector();
493     vector<double> *op = this->GetIntensityValuesTransferenceFVector();
494
495    _volumerendererdata->ShowVolume(changed);
496     _volumerendererdata->OpacityChanged(*gv, *op);
497     _volumerendererdata->BoundingBoxChanged(changed);
498
499 }
500
501 //-----------------------------------------------------------------------------
502 void vtkClipping3DDataViewer::UpdateVolumeBox(vector<double> gf, vector<double> vf, vtkColorTransferFunction* ctfun)
503 {
504         _volumerendererdata->SetLookUpTable((vtkLookupTable*)(ctfun));
505         _volumerendererdata->OpacityChanged(gf, vf);
506 }
507
508
509 //-----------------------------------------------------------------------------
510 void vtkClipping3DDataViewer::updateVolume()
511 {
512
513 #if (VTK_MAJOR_VERSION <= 7) 
514     if(_isRayCasting)
515     {
516         _volumeMapper->SetVolumeRayCastFunction(_compositeFunction);
517         _volumerendererdata->changeCompositeMIPFunction(0);
518     }    else if(_isMIP) {
519         _volumeMapper->SetVolumeRayCastFunction(_compositeFunctionMIP);
520         _volumerendererdata->changeCompositeMIPFunction(1);
521     }
522 #else 
523         // ...   here Composition of MIP
524         printf("EED vtkClipping3DDataViewer::updateVolume ...   here Composition or MIP \n");
525 #endif
526
527
528     if(_interpolation)
529     {
530         _volumeProperty->SetInterpolationTypeToLinear();
531     } else {
532         _volumeProperty->SetInterpolationTypeToNearest();
533     } // if _interpolation
534
535     if(_shade)
536     {
537         _volumeProperty->ShadeOn();
538     } else {
539         _volumeProperty->ShadeOff();
540     } // if _shade
541
542 }
543
544 //-------------------------------------------------------------------
545 void vtkClipping3DDataViewer::Configure()
546 {
547         Configure_Tissue();
548         Configure_Volume();
549     Configure_VolumeBox();
550 }
551
552
553 //-------------------------------------------------------------------
554 void vtkClipping3DDataViewer::SetIsovalue(int idTissue, int isoValue)
555 {
556         _mCubes[idTissue]->SetValue(0, isoValue);
557 //EED 2017-01-01 Migration VTK7
558 #if VTK_MAJOR_VERSION <= 5
559         // ..
560 #else
561         _mCubes[idTissue]->Update();
562         _tissueStripper[idTissue]->Update();
563         _tissueClipper[idTissue]->Update();
564 #endif
565 }
566 //-------------------------------------------------------------------
567 double vtkClipping3DDataViewer::GetIsovalue(int idTissue)
568 {
569         return _mCubes[idTissue]->GetValue(0);
570 }
571 //-------------------------------------------------------------------
572 vtkVolume* vtkClipping3DDataViewer::GetVolumeActor()
573 {
574    return _newvol;
575 }
576 //-------------------------------------------------------------------
577 #if (VTK_MAJOR_VERSION <= 7) 
578         vtkVolumeRayCastMapper* vtkClipping3DDataViewer::GetVolumeMapper()
579 #else 
580         vtkFixedPointVolumeRayCastMapper* vtkClipping3DDataViewer::GetVolumeMapper()
581 #endif
582 {
583         return _volumeMapper;
584 }
585 //-------------------------------------------------------------------
586 vtkPlanes* vtkClipping3DDataViewer::GetVolumePlanes()
587 {
588         return _volumePlanes;
589 }
590
591 //-------------------------------------------------------------------
592 vtkMarchingCubes *vtkClipping3DDataViewer::GetMCubes(int idTissue)
593 {
594         return _mCubes[idTissue];
595 }
596 //--------------------------------------------------------------------
597 //-------------------
598 //Getters Vectors
599 //-------------------
600
601 std::vector<double>*    vtkClipping3DDataViewer::GetGreyValuesTransferenceFVector()
602 {
603         return &greyValuesTransferenceFVector;
604 }
605 //--------------------------------------------------------------------
606 std::vector<double>*    vtkClipping3DDataViewer::GetIntensityValuesTransferenceFVector()
607 {
608         return &intensityValuesTransferenceFVector;
609 }
610 //--------------------------------------------------------------------
611 std::vector<double>*    vtkClipping3DDataViewer::GetRedColorsOfColorTransferenceFVector()
612 {
613         return &redColorsOfColorTransferenceFVector;
614 }
615 //--------------------------------------------------------------------
616 std::vector<double>*    vtkClipping3DDataViewer::GetGreenColorsOfColorTransferenceFVector()
617 {
618         return &greenColorsOfColorTransferenceFVector;
619 }
620 //--------------------------------------------------------------------
621 std::vector<double>*    vtkClipping3DDataViewer::GetBlueColorsOfColorTransferenceFVector()
622 {
623         return &blueColorsOfColorTransferenceFVector;
624 }
625 //--------------------------------------------------------------------
626 std::vector<double>*    vtkClipping3DDataViewer::GetGreyValueColorsOfColorTransferenceFVector()
627 {
628         return &greyValueColorsOfColorTransferenceFVector;
629 }
630 //--------------------------------------------------------------------
631 //--------------------------------------
632 //Getters transference function
633 //and color of the transference function
634 //---------------------------------------
635 vtkPiecewiseFunction* vtkClipping3DDataViewer::GetTransferencefunction()
636 {
637         return this->_tfun;
638 }
639 //--------------------------------------------------------------------
640 vtkColorTransferFunction* vtkClipping3DDataViewer::GetColorTransferenceFunction()
641 {
642         return this->_ctfun;
643 }
644
645 //-------------------------------------------------------------------
646
647 void vtkClipping3DDataViewer::ReadVolumeFunctions()
648 {
649 /*
650         int i=0,xi,yi,r,g,b,gValue;
651         vtkImageData *imagedata = this->_vtkmprbasedata->GetImageData();
652
653         HistogramDialog* hDlg=new HistogramDialog(NULL,_T("Histogram Dialog"),imagedata);
654         //
655         // put in a method
656         //
657         int tfSize=this->greyValuesTransferenceFVector.size();
658                 if(tfSize>0)
659                 {
660                         int i=0,y;
661                         hDlg->erasePointsTransferenceFunction();
662                         while(i<tfSize)
663                         {
664                                 double g=greyValuesTransferenceFVector[i];
665                                 double in=intensityValuesTransferenceFVector[i];
666                                 hDlg->addPointToTransferenceFunction(g,in*100);
667                                 i++;
668                         }
669
670                 }
671
672         int ctfSize=this->redColorsOfColorTransferenceFVector.size();
673         if(ctfSize>0)
674         {
675                 int i=0,y;
676                         while(i<ctfSize)
677                         {
678                                 double gr=greyValueColorsOfColorTransferenceFVector[i];
679                                 double r=redColorsOfColorTransferenceFVector[i];
680                                 double g=greenColorsOfColorTransferenceFVector[i];
681                                 double b=blueColorsOfColorTransferenceFVector[i];
682                                 hDlg->addColorPoint(gr,r*255,g*255,b*255);
683                                 i++;
684                         }
685         }
686         //If it is smooth activate next line
687         //hDlg->updatePlotter();
688         //setting variables if the user wants to do refresh
689         hDlg->setCTF(_ctfun);
690         hDlg->setTF(_tfun);
691
692         //
693         // when the user had changed the transference Function
694         //
695         if(hDlg->ShowModal()== wxID_OK )
696         {
697                         // -- vtkPiecewiseFunction --
698                         this->_tfun->RemoveAllPoints();
699                         greyValuesTransferenceFVector.clear();
700                         intensityValuesTransferenceFVector.clear();
701
702                         int nTFPoints=hDlg->getSizeTransferenceFunction();
703                         i=0;
704                         while(i<nTFPoints)
705                         {
706                                 hDlg->getTransferenceFunctionPoint(i,xi,yi);
707                                 this->_tfun->AddPoint( xi , yi/100.0 );
708                                 greyValuesTransferenceFVector.push_back(xi);
709                                 intensityValuesTransferenceFVector.push_back(yi/100.0);
710                                 i++;
711                         }
712                         // -- vtkColorTransferFunction  --
713                         this->_ctfun->RemoveAllPoints ();
714                         //clean colors
715                         redColorsOfColorTransferenceFVector.clear();
716                         greenColorsOfColorTransferenceFVector.clear();
717                         blueColorsOfColorTransferenceFVector.clear();
718                         greyValueColorsOfColorTransferenceFVector.clear();
719
720                         int nCTFpoints=hDlg->getSizeBarColor();
721                         i=0;
722                         while(i<nCTFpoints)
723                         {
724                                 hDlg->getDataBarColorPoint(i,xi,r,g,b);
725                                 this->_ctfun->AddRGBPoint(xi,r/255.0,g/255.0,b/255.0 );
726                                 redColorsOfColorTransferenceFVector.push_back(r/255.0);
727                                 greenColorsOfColorTransferenceFVector.push_back(g/255.0);
728                                 blueColorsOfColorTransferenceFVector.push_back(b/255.0);
729                                 greyValueColorsOfColorTransferenceFVector.push_back(xi);
730                                 i++;
731                         }
732
733                         this->_volumeMapper->Update();
734                         this->_newvol->Update();
735         }
736
737         else
738         {
739
740                 if(hDlg->getRefreshed())
741                 {
742                         int i=0,size;
743                         //--Transference Function----
744                         this->_tfun->RemoveAllPoints();
745                         i=0;
746                         size=greyValuesTransferenceFVector.size();
747                         for(i=0;i<size;i++)
748                         {
749                                 double grey1=greyValuesTransferenceFVector[i];
750                                 double  in2=intensityValuesTransferenceFVector[i];
751                                 this->_tfun->AddPoint( grey1 , in2 );
752                         }
753
754                         // -- vtkColorTransferFunction  --
755                         _ctfun->RemoveAllPoints ();
756
757                         i=0;
758                         size=greyValueColorsOfColorTransferenceFVector.size();
759                         for(i=0;i<size;i++)
760                         {
761                                 double grey2=(greyValueColorsOfColorTransferenceFVector)[i];
762                                 double red =(redColorsOfColorTransferenceFVector)[i];
763                                 double green =(greenColorsOfColorTransferenceFVector)[i];
764                                 double blue = (blueColorsOfColorTransferenceFVector)[i];
765                                 _ctfun->AddRGBPoint(grey2,red,green,blue);
766                         }
767                         this->_volumeMapper->Update();
768                         this->_newvol->Update();
769                  }
770
771         }
772         hDlg->Destroy();
773 */
774 }
775 /*
776 void vtkClipping3DDataViewer::ReadVolumeFunctions(char *namefile)
777 {
778         char tmp[256];
779         short int       max;
780         double          range[2];
781         double          x,val,r,g,b;
782
783         FILE *ff = fopen ( namefile ,"r");
784
785         // --  MAX  --
786         fscanf(ff,"%s",tmp);
787         if (strcmp(tmp,"MAX")==0)
788         {
789                 vtkImageData *vtkimagedata              = this->_vtkmprbasedata->GetImageData();
790                 vtkimagedata->GetScalarRange(range);
791                 max = (int) (range[1]);
792         } else {
793                 max = atoi(tmp);
794         }
795
796         fscanf(ff,"%s",tmp);   // --
797
798         // -- vtkPiecewiseFunction --
799         this->_tfun->RemoveAllPoints();
800         fscanf(ff,"%s",tmp);
801         while ( strcmp(tmp,"--")!=0 )
802         {
803                 x=atof(tmp);
804                 fscanf(ff,"%s",tmp);
805                 val=atof(tmp);
806                 this->_tfun->AddPoint( x*max , val );
807                 fscanf(ff,"%s",tmp);
808         }
809
810         this->_ctfun->RemoveAllPoints ();
811         // -- vtkColorTransferFunction  --
812         while ( !feof(ff))
813         {
814                 fscanf(ff,"%s",tmp);
815                 x=atof(tmp);
816                 fscanf(ff,"%s",tmp);
817                 r=atof(tmp);
818                 fscanf(ff,"%s",tmp);
819                 g=atof(tmp);
820                 fscanf(ff,"%s",tmp);
821                 b=atof(tmp);
822                 this->_ctfun->AddRGBPoint( x*max , r,g,b );
823         }
824
825
826         this->_volumeMapper->Update();
827         this->_newvol->Update();
828
829
830         fclose(ff);
831 }
832 */
833
834 //-------------------------------------------------------------------
835 // EED 23 Mai 2007
836 void vtkClipping3DDataViewer::ReadMeshVTK(char *namefile)
837 {
838         vtkDataSetReader *reader = vtkDataSetReader::New();
839         reader->SetFileName(namefile);
840         reader->Update();
841
842 //EED 2017-01-01 Migration VTK7
843 #if VTK_MAJOR_VERSION <= 5
844         _tissueStripper[3]->SetInput( reader->GetPolyDataOutput()  );
845 #else
846         _tissueStripper[3]->SetInputData( reader->GetPolyDataOutput()  );
847 #endif
848
849 }
850
851 void vtkClipping3DDataViewer::setColorTransferFunction(vtkColorTransferFunction* colortable){
852
853         _volumeProperty->SetColor(colortable);
854
855 }
856
857
858 void vtkClipping3DDataViewer::SetRayCasting(bool active)
859 {
860     _isRayCasting   =   active;
861
862 }
863
864 void vtkClipping3DDataViewer::SetMIPActive(bool active)
865 {
866     _isMIP  = active;
867 }
868
869 void vtkClipping3DDataViewer::SetInterpolation(bool active)
870 {
871     _interpolation = active;
872 }
873
874 void vtkClipping3DDataViewer::SetShade(bool active)
875 {
876     _shade  =   active;
877 }
878