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