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