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