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