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