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