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