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