]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMPRBaseData.cxx
creaMaracasVisu Library
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / wxMPRBaseData.cxx
1
2
3 #include <vtkPlanes.h>
4 #include <vtkProperty.h> 
5 #include <vtkPolyData.h> 
6 #include <vtkDataSet.h> 
7 #include <vtkCellArray.h>
8 #include <vtkTransform.h>
9 #include <vtkTransformFilter.h>
10 #include <vtkDataSetReader.h>
11
12 #include "wxMPRBaseData.h"
13 #include "pPlotter/HistogramDialog.h"
14
15
16
17 //-------------------------------------------------------------------
18 //-------------------------------------------------------------------
19 //-------------------------------------------------------------------
20
21 vtkBaseData::vtkBaseData()
22 {
23
24         _z                                       = 0;
25         _t                                       = 0;
26         _marImageData            = NULL;
27 }
28
29 //-------------------------------------------------------------------
30 vtkBaseData::~vtkBaseData()
31 {
32 }
33
34 //-------------------------------------------------------------------
35 void vtkBaseData::SetMarImageData(marImageData *marimagedata)
36 {
37         _marImageData = marimagedata;
38         Configure();
39 }
40
41 //-------------------------------------------------------------------
42 vtkImageData* vtkBaseData::GetImageData()
43 {
44         return _marImageData->GetImageDataT(_t);
45 }
46 //-------------------------------------------------------------------
47 marImageData* vtkBaseData::GetMarImageData()
48 {
49         return _marImageData;
50 }
51
52 //-------------------------------------------------------------------
53
54 void vtkBaseData::Configure()  // virtual
55 {
56 }
57
58 //-------------------------------------------------------------------
59 void vtkBaseData::SetZ(double z){
60         int maxZ;
61
62 //      int dim[3];
63 //      _marImageData->GetDimensions(dim);
64 //      maxZ=dim[2];
65
66         int ext[6];
67         _marImageData->GetImageData()->GetWholeExtent(ext);
68         maxZ=ext[5]-ext[4]+1;
69
70         if (z>=maxZ)
71         {
72                 z=maxZ-1;
73         }
74         if (z<=0)
75         {
76                 z=0;
77         }
78
79         _z=z;
80 }
81 //-------------------------------------------------------------------
82 double vtkBaseData::GetZ()
83 {
84         return _z;
85 }
86 //-------------------------------------------------------------------
87 int vtkBaseData::GetT()
88 {
89         return _t;
90 }
91 //-------------------------------------------------------------------
92 void vtkBaseData::SetT(double t)
93 {
94         int maxT = _marImageData->GetMaxT();
95         if (t>=maxT)
96         {
97                 t=maxT-1;
98         }
99         if (t<=0)
100         {
101                 t=0;
102         }
103         _t=t;
104 }
105
106 //-------------------------------------------------------------------
107 //-------------------------------------------------------------------
108 //-------------------------------------------------------------------
109 vtkMPRBaseData::vtkMPRBaseData()
110 {
111   _x=0;
112   _y=0;
113   _z=0;
114   _transformOrientation = NULL;
115 }
116 //-------------------------------------------------------------------
117 vtkMPRBaseData::~vtkMPRBaseData()
118 {
119         if (_marImageData)                      delete _marImageData;
120         if (_transformOrientation)      _transformOrientation ->Delete();
121 }
122 //-------------------------------------------------------------------
123 void vtkMPRBaseData::Configure()
124 {
125         _marImageData->GetImageData()->GetExtent (_x1,_x2,_y1,_y2,_z1,_z2);
126         _transformOrientation=vtkTransform::New();
127         _transformOrientation->Identity();
128 }
129 //-------------------------------------------------------------------
130 void vtkMPRBaseData::GetDimensionExtention(int *x1,int *x2,int *y1,int *y2,int *z1,int *z2)
131 {
132         *x1=_x1;
133         *x2=_x2;
134         *y1=_y1;
135         *y2=_y2;
136         *z1=_z1;
137         *z2=_z2;
138 }
139
140
141 //------------------------------------------------------------------------
142 int vtkMPRBaseData::GetMaxPositionX( )
143 {
144         return _x2;
145 }
146 //------------------------------------------------------------------------
147 int vtkMPRBaseData::GetMaxPositionY( )
148 {
149         return _y2;
150 }
151 //------------------------------------------------------------------------
152 int vtkMPRBaseData::GetMaxPositionZ( )
153 {
154         return _z2;
155 }
156 //-------------------------------------------------------------------
157 double vtkMPRBaseData::GetX()
158 {
159         return _x;
160 }
161 //-------------------------------------------------------------------
162 double  vtkMPRBaseData::GetY()
163 {
164         return _y;
165 }
166 //-------------------------------------------------------------------
167 void vtkMPRBaseData::SetX(double x)
168 {
169         int dim[3];
170         _marImageData->GetImageData()->GetDimensions(dim);
171         if (x<0)
172         {
173                 x=0;
174         }
175         if (x>=dim[0])
176         {
177                 x=dim[0]-1;
178         };
179         _x=x;
180 }
181 //-------------------------------------------------------------------
182 void vtkMPRBaseData::SetY(double y)
183 {
184         int dim[3];
185         _marImageData->GetImageData()->GetDimensions(dim);
186         if (y<0)
187         {
188                 y=0;
189         }
190         if (y>=dim[1])
191         {
192                 y=dim[1]-1;
193         };
194         _y=y;
195 }
196 //-------------------------------------------------------------------
197 vtkTransform *vtkMPRBaseData::GetTransformOrientation()
198 {
199         return _transformOrientation; 
200 }
201 //-------------------------------------------------------------------
202 void vtkMPRBaseData::SetNormal(double nx, double ny, double nz)
203 {
204         double alfa = atan2(ny,nx) * 180.0 / 3.1416;
205         double beta = atan2( nz, sqrt( nx*nx + ny*ny )  ) * 180.0 / 3.1416;
206         _transformOrientation->Identity();              
207         _transformOrientation->RotateWXYZ(alfa,0,0,1);
208         _transformOrientation->RotateWXYZ(-beta,0,1,0);
209 }
210 //-------------------------------------------------------------------
211 void vtkMPRBaseData::InitTransformOrientation(vtkTransform *trans)
212 {
213         _transformOrientation->SetMatrix( trans->GetMatrix() );
214 }
215
216
217
218 //-------------------------------------------------------------------
219 //-------------------------------------------------------------------
220 //-------------------------------------------------------------------
221
222
223 vtkMPR3DDataViewer::vtkMPR3DDataViewer()
224 {
225         _visiblePosition[0]=false;
226         _visiblePosition[1]=false;
227         _visiblePosition[2]=false;
228         _ctfun = NULL;
229 }
230 //-------------------------------------------------------------------
231 vtkMPR3DDataViewer::~vtkMPR3DDataViewer()
232 {
233         _outlineData            -> Delete();
234         _mapOutline                     -> Delete();
235         _outline                        -> Delete();
236
237 //      if (_bwLut)                             _bwLut                          -> Delete();
238 //      if (_hueLut)                    _hueLut                         -> Delete();
239 //      if (_satLut)                    _satLut                         -> Delete();
240         if (_ctfun)                             _ctfun                          -> Delete();
241         if (_saggitalColors)    _saggitalColors         -> Delete();
242         if (_saggital)                  _saggital                       -> Delete();
243         if (_axialColors)               _axialColors            -> Delete();
244         if (_axial)                             _axial                          -> Delete();
245         if (_coronalColors)             _coronalColors          -> Delete();
246         if (_coronal)                   _coronal                        -> Delete();
247
248 }
249 //-------------------------------------------------------------------
250 vtkActor* vtkMPR3DDataViewer::GetOutlineActor()
251 {
252         return _outline;
253 }
254 //-------------------------------------------------------------------
255 vtkImageActor* vtkMPR3DDataViewer::GetImageActor(int id)
256 {
257         vtkImageActor *tmpVtkActor=NULL;
258         if (id==0){
259                 tmpVtkActor = GetvtkActor_saggital();
260         }
261         if (id==1){
262                 tmpVtkActor = GetvtkActor_coronal();
263         }
264         if (id==2){
265                 tmpVtkActor = GetvtkActor_axial();
266         }
267         return tmpVtkActor;
268 }
269 //-------------------------------------------------------------------
270 void vtkMPR3DDataViewer::Refresh()
271 {
272         int x = (int)(_vtkmprbasedata->GetX());
273         int y = (int)(_vtkmprbasedata->GetY());
274         int z = (int)(_vtkmprbasedata->GetZ());
275
276         SetPositionX( x );
277         SetPositionY( y );
278         SetPositionZ( z );
279 }
280 //-------------------------------------------------------------------
281 void vtkMPR3DDataViewer::SetVtkMPRBaseData(vtkMPRBaseData *vtkmprbasedata)
282 {
283         _vtkmprbasedata=vtkmprbasedata;
284 }
285 //-------------------------------------------------------------------
286 vtkMPRBaseData* vtkMPR3DDataViewer::GetVtkMPRBaseData()
287 {
288         return _vtkmprbasedata;
289 }
290 //-------------------------------------------------------------------
291
292 vtkColorTransferFunction *vtkMPR3DDataViewer::GetvtkColorTransferFunction()
293 {
294         return _ctfun;
295 }
296 //-------------------------------------------------------------------
297
298 std::vector<double>* vtkMPR3DDataViewer::GetctFunVectorPoint()
299 {
300         return &_ctFunVectorPoint;
301 }
302 //-------------------------------------------------------------------
303 std::vector<double>*     vtkMPR3DDataViewer::GetctFunVectorRed()
304 {
305         return &_ctFunVectorRed;
306 }
307
308 //-------------------------------------------------------------------
309 std::vector<double>*     vtkMPR3DDataViewer::GetctFunVectorGreen()
310 {
311         return &_ctFunVectorGreen;
312 }
313
314 //-------------------------------------------------------------------
315 std::vector<double>*     vtkMPR3DDataViewer::GetctFunVectorBlue()
316 {
317         return &_ctFunVectorBlue;
318 }
319
320 //-------------------------------------------------------------------
321 void vtkMPR3DDataViewer::Configure()
322 {
323 /*
324   // Start by creatin a black/white lookup table.
325         _bwLut = vtkLookupTable::New();
326     _bwLut->SetTableRange (0, 2000);
327     _bwLut->SetSaturationRange (0, 0);
328     _bwLut->SetHueRange (0, 0);
329     _bwLut->SetValueRange (0, 1);
330
331   // Now create a lookup table that consists of the full hue circle
332   // (from HSV).
333         _hueLut = vtkLookupTable::New();
334     _hueLut->SetTableRange (0, 2000);
335     _hueLut->SetHueRange (0, 1);
336     _hueLut->SetSaturationRange (1, 1);
337     _hueLut->SetValueRange (1, 1);
338
339   // Finally, create a lookup table with a single hue but having a range
340   // in the saturation of the hue.
341         _satLut = vtkLookupTable::New();
342     _satLut->SetTableRange (0, 2000);
343     _satLut->SetHueRange (.6, .6);
344     _satLut->SetSaturationRange (0, 1);
345     _satLut->SetValueRange (1, 1);
346 */
347
348
349         double range[2];
350         _vtkmprbasedata->GetImageData()->GetScalarRange(range);
351         double max = range[1];
352
353         
354         _ctFunVectorPoint.push_back(max*0/4);
355         _ctFunVectorPoint.push_back(max*1/4);
356         _ctFunVectorPoint.push_back(max*2/4);
357         _ctFunVectorPoint.push_back(max*3/4);
358         _ctFunVectorPoint.push_back(max*4/4);
359
360         _ctFunVectorRed.push_back(0.0);
361         _ctFunVectorRed.push_back(1.0);
362         _ctFunVectorRed.push_back(0.0);
363         _ctFunVectorRed.push_back(0.0);
364         _ctFunVectorRed.push_back(0.0);
365
366         _ctFunVectorGreen.push_back(0.0);
367         _ctFunVectorGreen.push_back(0.0);
368         _ctFunVectorGreen.push_back(0.0);
369         _ctFunVectorGreen.push_back(1.0);
370         _ctFunVectorGreen.push_back(0.2);
371
372         _ctFunVectorBlue.push_back(0.0);
373         _ctFunVectorBlue.push_back(0.0);
374         _ctFunVectorBlue.push_back(1.0);
375         _ctFunVectorBlue.push_back(0.0);
376         _ctFunVectorBlue.push_back(0.0);
377
378
379         _ctfun = vtkColorTransferFunction::New();
380
381         int i,size=_ctFunVectorPoint.size();
382         for (i=0;i<size;i++)
383         {
384                 _ctfun->AddRGBPoint( _ctFunVectorPoint[i] , _ctFunVectorRed[i],_ctFunVectorGreen[i],_ctFunVectorBlue[i]);
385                 
386         }
387 /*
388         _ctfun->AddRGBPoint( 100 ,0 ,0,0);
389         _ctfun->AddRGBPoint( 200 ,1 ,0,0);
390         _ctfun->AddRGBPoint( 300 ,0 ,1,0);
391         _ctfun->AddRGBPoint( 400 ,0 ,0,1);
392 */
393         void *p=this;
394
395   // Create the first of the three planes. The filter vtkImageMapToColors
396   // maps the data through the corresponding lookup table created above.  The
397   // vtkImageActor is a type of vtkProp and conveniently displays an image on
398   // a single quadrilateral plane. It does this using texture mapping and as
399   // a result is quite fast. (Note: the input image has to be unsigned char
400   // values, which the vtkImageMapToColors produces.) Note also that by
401   // specifying the DisplayExtent, the pipeline requests data of this extent
402   // and the vtkImageMapToColors only processes a slice of data.
403         _saggitalColors = vtkImageMapToColors::New();
404     _saggitalColors->SetInput( _vtkmprbasedata->GetImageData() );
405 //    _saggitalColors->SetLookupTable(_bwLut);
406     _saggitalColors->SetLookupTable(_ctfun);
407         _saggital = vtkImageActor::New();
408     _saggital->SetInput(_saggitalColors->GetOutput());
409
410
411   // Create the second (axial) plane of the three planes. We use the
412   // same approach as before except that the extent differs.
413         _axialColors = vtkImageMapToColors::New();
414     _axialColors->SetInput( _vtkmprbasedata->GetImageData() );
415 //    _axialColors->SetLookupTable(_hueLut);
416     _axialColors->SetLookupTable(_ctfun);
417         _axial = vtkImageActor::New();
418     _axial->SetInput(_axialColors->GetOutput());
419
420         // Create the third (coronal) plane of the three planes. We use 
421   // the same approach as before except that the extent differs.
422         _coronalColors = vtkImageMapToColors::New();
423     _coronalColors->SetInput( _vtkmprbasedata->GetImageData() );
424 //    _coronalColors->SetLookupTable(_satLut);
425     _coronalColors->SetLookupTable(_ctfun);
426         _coronal = vtkImageActor::New();
427     _coronal->SetInput(_coronalColors->GetOutput());
428
429   // An outline provides context around the data.
430   //
431         _outlineData = vtkOutlineFilter::New();
432     _outlineData->SetInput((vtkDataSet *) _vtkmprbasedata->GetImageData() );
433         _mapOutline = vtkPolyDataMapper::New();
434     _mapOutline->SetInput(_outlineData->GetOutput());
435         _outline = vtkActor::New();
436     _outline->SetMapper(_mapOutline);
437     _outline->GetProperty()->SetColor(0,0,0);
438
439         int ext[6];
440         _vtkmprbasedata->GetImageData()->GetExtent(ext);
441
442
443
444 }
445
446 //-------------------------------------------------------------------
447 vtkImageActor * vtkMPR3DDataViewer::GetvtkActor_saggital()
448 {
449         return _saggital;
450 }
451 //-------------------------------------------------------------------
452 vtkImageActor * vtkMPR3DDataViewer::GetvtkActor_coronal()
453 {
454         return _coronal;
455 }
456 //-------------------------------------------------------------------
457 vtkImageActor * vtkMPR3DDataViewer::GetvtkActor_axial()
458 {
459         return _axial;
460 }
461
462 //------------------------------------------------------------------------
463 void vtkMPR3DDataViewer::SetPositionX(int pos){
464         int x1,x2,y1,y2,z1,z2;
465         _vtkmprbasedata->GetDimensionExtention(&x1,&x2,&y1,&y2,&z1,&z2);
466         _saggital->SetDisplayExtent( pos , pos , y1 ,y2 , z1 , z2 );
467 }
468 //------------------------------------------------------------------------
469 void vtkMPR3DDataViewer::SetPositionY(int pos){
470         int x1,x2,y1,y2,z1,z2;
471         _vtkmprbasedata->GetDimensionExtention(&x1,&x2,&y1,&y2,&z1,&z2);
472         _coronal->SetDisplayExtent(x1,x2, pos,pos, z1,z2);
473 }
474 //------------------------------------------------------------------------
475 void vtkMPR3DDataViewer::SetPositionZ(int pos){
476         int x1,x2,y1,y2,z1,z2;
477         _vtkmprbasedata->GetDimensionExtention(&x1,&x2,&y1,&y2,&z1,&z2);
478         _axial->SetDisplayExtent(x1,x2, y1,y2, pos,pos);
479 }
480 //-------------------------------------------------------------------
481 void vtkMPR3DDataViewer::SetVisiblePosition(int idPosition, bool visible)
482 {
483         _visiblePosition[idPosition]=visible;
484 }
485 //-------------------------------------------------------------------
486 bool vtkMPR3DDataViewer::GetVisiblePosition(int idPosition)
487 {
488         return _visiblePosition[idPosition];
489 }
490 //-------------------------------------------------------------------
491 //-------------------------------------------------------------------
492 //-------------------------------------------------------------------
493
494
495 vtkClipping3DDataViewer::vtkClipping3DDataViewer()
496 {
497         int i;
498         for (i=0; i<VTKMPRDATA_MAXTISSUE; i++){
499                 _visibleTissue[i]               = false;
500                 _representationType[i]  = true;
501         }
502         _visibleVolume=false;
503 }
504 //-------------------------------------------------------------------
505 vtkClipping3DDataViewer::~vtkClipping3DDataViewer()
506 {
507         int i;
508         for (i=0; i< VTKMPRDATA_MAXTISSUE ; i++){
509                 _mCubes[i]                              ->Delete();
510                 _tissueStripper[i]              ->Delete();
511                 _tissueMapper[i]                ->Delete();
512                 _tissuePlanes[i]                ->Delete();
513                 _tissueClipper[i]               ->Delete();
514         }
515         _outlineData            ->Delete();
516         _mapOutline                     ->Delete();
517         _outline                        ->Delete();
518         // Volume
519         _tfun                           ->Delete();
520         _ctfun                          ->Delete();
521         _compositeFunction      ->Delete();
522         _volumeMapper           ->Delete();
523         _volumeProperty         ->Delete();
524         _newvol                         ->Delete();
525         _volumePlanes           ->Delete();
526
527         for (i=0; i< VTKMPRDATA_MAXTISSUE ; i++){
528                 _tissue[i]              -> Delete();
529                 _observerS[i]   -> Delete();
530         }
531         _observerV              -> Delete();
532 }
533 //-------------------------------------------------------------------
534 vtkActor* vtkClipping3DDataViewer::GetOutlineActor()
535 {
536         return _outline;
537 }
538 //-------------------------------------------------------------------
539 vtkClipPolyData* vtkClipping3DDataViewer::GetTissueClipper(int id)
540 {
541         return this->_tissueClipper[id];
542 }
543 //-------------------------------------------------------------------
544 vtkPolyDataMapper* vtkClipping3DDataViewer::GetTissueMapper(int id)
545 {
546         return _tissueMapper[id];
547 }
548 //-------------------------------------------------------------------
549 vtkPlanes* vtkClipping3DDataViewer::GetTissuePlanes(int id)
550 {
551         return _tissuePlanes[id];
552 }
553 //-------------------------------------------------------------------
554 vtkStripper* vtkClipping3DDataViewer::GetTissueStripper(int id)
555 {
556         return _tissueStripper[id];
557 }
558 //-------------------------------------------------------------------
559 void vtkClipping3DDataViewer::Refresh()
560 {
561 //      _volumeMapper->SetClippingPlanes(_volumePlanes);
562
563 //      this->_volumeMapper->Update();
564 //      this->_newvol->Update();
565
566 //      _newvol->VisibilityOn();
567
568         
569 // _volumeMapper = vtkVolumeRayCastMapper::New();
570 //      _volumeMapper->SetInput( this->GetVtkMPRBaseData()->GetImageData() );
571 //      _volumeMapper->SetVolumeRayCastFunction(_compositeFunction);
572 //      _volumeMapper->SetClippingPlanes( _volumePlanes );
573 //      _newvol->SetMapper(_volumeMapper );
574
575
576 }
577 //-------------------------------------------------------------------
578 void vtkClipping3DDataViewer::RefreshSurface()
579 {
580         int i;
581         for (i=0; i< VTKMPRDATA_MAXTISSUE ; i++)
582         {
583                 SetIsovalue(i, (int) (GetIsovalue(i)+1) );
584 //              this->GetMCubes(i)->Update();
585         }
586 }
587 //-------------------------------------------------------------------
588 void vtkClipping3DDataViewer::SetVtkMPRBaseData(vtkMPRBaseData *vtkmprbasedata)
589 {
590         _vtkmprbasedata=vtkmprbasedata;
591 }
592 //-------------------------------------------------------------------
593 vtkMPRBaseData* vtkClipping3DDataViewer::GetVtkMPRBaseData()
594 {
595         return _vtkmprbasedata;
596 }
597
598
599 //-------------------------------------------------------------------
600 void vtkClipping3DDataViewer::SetVisibleTissue(int idTissue, bool visible)
601 {
602         _visibleTissue[idTissue]=visible;
603 }
604 //-------------------------------------------------------------------
605 bool vtkClipping3DDataViewer::GetVisibleTissue(int idTissue){
606         return _visibleTissue[idTissue];
607 }
608 //-------------------------------------------------------------------
609 void vtkClipping3DDataViewer::SetRepresentationType(int idTissue, bool representationType)
610 {
611         _representationType[idTissue]=representationType;
612 }
613 //-------------------------------------------------------------------
614 bool vtkClipping3DDataViewer::GetRepresentationType(int idTissue)
615 {
616         return _representationType[idTissue];
617 }
618
619 //-------------------------------------------------------------------
620 vtkActor* vtkClipping3DDataViewer::GetTissueActor(int id){
621         return _tissue[id];
622 }
623
624 //-------------------------------------------------------------------
625 boxSurfaceObserver *vtkClipping3DDataViewer::GetObserverS(int idObserverS)
626 {
627         return _observerS[idObserverS];
628 }
629 //-------------------------------------------------------------------
630 boxSurfaceObserver *vtkClipping3DDataViewer::GetObserverV()
631 {
632         return _observerV;
633 }
634
635 //-------------------------------------------------------------------
636 bool vtkClipping3DDataViewer::GetVisibleVolume()
637 {
638         return _visibleVolume;
639 }
640 //-------------------------------------------------------------------
641 void vtkClipping3DDataViewer::SetVisibleVolume(bool visiblevolume)
642 {
643         _visibleVolume = visiblevolume;
644 }
645
646
647 //-------------------------------------------------------------------
648 void vtkClipping3DDataViewer::Configure_Tissue()
649 {
650
651         double range[2];
652         int i;
653         for (i=0; i< VTKMPRDATA_MAXTISSUE ; i++){
654                 // Visualisation - original volume
655                 vtkImageData *imagedata=_vtkmprbasedata->GetImageData();
656                 imagedata->GetScalarRange( range );
657                 _mCubes[i] = vtkMarchingCubes::New( );
658                 _mCubes[i]->SetInput( imagedata );
659
660                 _mCubes[i]->SetValue( 0, range[1]*(4+i) / 8 );
661 //              _mCubes[i]->SetValue( 0, 1500 );
662
663             _tissueStripper[i] = vtkStripper::New();
664             _tissueStripper[i]->SetInput( _mCubes[i]->GetOutput( ) );
665
666
667
668                 _tissuePlanes[i]  = vtkPlanes::New();
669    
670                 int x1,x2,y1,y2,z1,z2;
671                 imagedata->GetExtent(x1,x2,y1,y2,z1,z2);
672                 _tissuePlanes[i]->SetBounds  (x1,x2,y1,y2,z1,z2);
673                 
674                 _tissueClipper[i] = vtkClipPolyData::New();
675                 _tissueClipper[i]->SetInput( _tissueStripper[i]->GetOutput() );
676                 _tissueClipper[i]->SetClipFunction( _tissuePlanes[i] );
677                 _tissueClipper[i]->InsideOutOn( );
678
679                 _tissueMapper[i] = vtkPolyDataMapper::New( );
680                 _tissueMapper[i]->SetInput( _tissueClipper[i]->GetOutput() );
681                 _tissueMapper[i]->ScalarVisibilityOff( );
682 //              _tissueMapper[i]->Update();
683
684         }
685                 
686
687
688         // vtkActor tissue
689         for (i=0; i< VTKMPRDATA_MAXTISSUE ; i++){
690                 // tissue
691                 _tissue[i] = vtkActor::New();
692                 _tissue[i]->SetMapper( GetTissueMapper(i) );
693                 float cr=1,cg=0.5,cb=0.5;
694                 _tissue[i]->GetProperty()->SetDiffuseColor(cr/255, cg/255   , cb/255   );
695                 _tissue[i]->GetProperty()->SetSpecular(.3);
696                 _tissue[i]->GetProperty()->SetSpecularPower(20);
697                 _tissue[i]->GetProperty()->SetOpacity(0.5);
698                 if (i==0) _tissue[i]->GetProperty()->SetColor(0.85, 0.85   , 0.85   );
699                 if (i==1) _tissue[i]->GetProperty()->SetColor(0, 0  ,  1  );
700                 if (i==2) _tissue[i]->GetProperty()->SetColor(0.85, 0.20   , 0.20   );
701                 if (i==3) _tissue[i]->GetProperty()->SetColor(0, 1   , 0   );
702         }
703
704         for (i=0; i< VTKMPRDATA_MAXTISSUE ; i++)
705         {
706                 _observerS[i] = boxSurfaceObserver::New();
707                 _observerS[i]->SetPlanes( GetTissuePlanes(i) );
708                 _observerS[i]->SetActor( _tissue[i] );
709         }
710
711 }
712
713 //-----------------------------------------------------------------------------
714
715 void vtkClipping3DDataViewer::Configure_Volume()
716 {
717   // Volume
718
719   _tfun = vtkPiecewiseFunction::New();
720   _ctfun = vtkColorTransferFunction::New();
721
722         double range[2];
723         this->_vtkmprbasedata->GetImageData()->GetScalarRange(range);
724         double max = range[1];
725
726         /*
727         adding the poinst of the transference function
728         */
729         //X
730         greyValuesTransferenceFVector.push_back(max * 0/2);
731         greyValuesTransferenceFVector.push_back(max * 1/2);
732         greyValuesTransferenceFVector.push_back(max * 2/2);
733         //Y
734         intensityValuesTransferenceFVector.push_back(0.0);
735         intensityValuesTransferenceFVector.push_back(1.0);
736         intensityValuesTransferenceFVector.push_back(1.0);
737
738         _tfun->AddPoint(max * 0/2 , 0.0);
739         _tfun->AddPoint(max * 1/2 , 1.0);
740         _tfun->AddPoint(max * 2/2 , 1.0);
741
742         /*
743                 Adding the colors to the vectors        
744         */
745         //RED
746         redColorsOfColorTransferenceFVector.push_back(0.0);
747         redColorsOfColorTransferenceFVector.push_back(1.0);
748         redColorsOfColorTransferenceFVector.push_back(0.0);
749         redColorsOfColorTransferenceFVector.push_back(0.0);
750         redColorsOfColorTransferenceFVector.push_back(0.0);
751
752         //GREEN
753         greenColorsOfColorTransferenceFVector.push_back(0.0);
754         greenColorsOfColorTransferenceFVector.push_back(0.0);
755         greenColorsOfColorTransferenceFVector.push_back(0.0);
756         greenColorsOfColorTransferenceFVector.push_back(1.0);
757         greenColorsOfColorTransferenceFVector.push_back(0.2);
758         
759         //BLUE
760         blueColorsOfColorTransferenceFVector.push_back(0.0);
761         blueColorsOfColorTransferenceFVector.push_back(0.0);
762         blueColorsOfColorTransferenceFVector.push_back(1.0);
763         blueColorsOfColorTransferenceFVector.push_back(0.0);
764         blueColorsOfColorTransferenceFVector.push_back(0.0);
765         //GREY VALUE    
766         greyValueColorsOfColorTransferenceFVector.push_back(max*0/4);
767         greyValueColorsOfColorTransferenceFVector.push_back(max*1/4);
768         greyValueColorsOfColorTransferenceFVector.push_back(max*2/4);
769         greyValueColorsOfColorTransferenceFVector.push_back(max*3/4);
770         greyValueColorsOfColorTransferenceFVector.push_back(max*4/4);
771
772         _ctfun->AddRGBPoint( max*0/4 , 0.0, 0.0, 0.0);
773         _ctfun->AddRGBPoint( max*1/4 , 1.0, 0.0, 0.0);
774         _ctfun->AddRGBPoint( max*2/4 , 0.0, 0.0, 1.0);
775         _ctfun->AddRGBPoint( max*3/4 , 0.0, 1.0, 0.0);
776         _ctfun->AddRGBPoint( max*4/4 , 0.0, 0.2, 0.0);
777
778   _volumePlanes  = vtkPlanes::New();
779 //      int x1,x2,y1,y2,z1,z2;
780 //      vtkImageData *imagedata=_vtkmprbasedata->GetImageData();
781 //      imagedata->GetExtent(x1,x2,y1,y2,z1,z2);
782 //      _volumePlanes->SetBounds(x1,x2,y1,y2,z1,z2);
783
784   _compositeFunction = vtkVolumeRayCastCompositeFunction::New();
785
786   _volumeMapper = vtkVolumeRayCastMapper::New();
787         _volumeMapper->SetInput( this->GetVtkMPRBaseData()->GetImageData() );
788         _volumeMapper->SetVolumeRayCastFunction(_compositeFunction);
789         _volumeMapper->SetClippingPlanes( _volumePlanes );
790         _volumeMapper->AutoAdjustSampleDistancesOn();
791
792   _volumeProperty = vtkVolumeProperty::New();
793         _volumeProperty->SetColor(_ctfun);
794         _volumeProperty->SetScalarOpacity( _tfun );
795 // EED 31/03/2008
796         _volumeProperty->SetInterpolationTypeToLinear();
797         _volumeProperty->ShadeOn();
798         _volumeProperty->DisableGradientOpacityOn();
799
800 //      _volumeProperty->SetInterpolationTypeToNearest();
801 //      _volumeProperty->ShadeOff();
802 //      _volumeProperty->SetAmbient(0.3);
803 //      _volumeProperty->SetDiffuse(0.1);
804 //      _volumeProperty->SetSpecular(0.8);
805 //      _volumeProperty->DisableGradientOpacityOn();
806
807   _newvol = vtkVolume::New();
808         _newvol->SetMapper(_volumeMapper );
809         _newvol->SetProperty(_volumeProperty );
810
811   _observerV = boxSurfaceObserver::New();
812         _observerV->SetPlanes( _volumePlanes );
813         _observerV->SetActor( _newvol );
814         _observerV->SetvtkVolumeRayCastMapper( _volumeMapper );
815 }
816
817
818 //-------------------------------------------------------------------
819 void vtkClipping3DDataViewer::Configure()
820 {
821         Configure_Tissue();
822         Configure_Volume();
823
824   // An outline provides context around the data.
825   //
826         _outlineData = vtkOutlineFilter::New();
827     _outlineData->SetInput((vtkDataSet *) _vtkmprbasedata->GetImageData() );
828         _mapOutline = vtkPolyDataMapper::New();
829     _mapOutline->SetInput(_outlineData->GetOutput());
830         _outline = vtkActor::New();
831     _outline->SetMapper(_mapOutline);
832     _outline->GetProperty()->SetColor(0,0,0);
833 }
834
835
836 //-------------------------------------------------------------------
837 void vtkClipping3DDataViewer::SetIsovalue(int idTissue, int isoValue)
838 {
839         _mCubes[idTissue]->SetValue(0, isoValue);
840 }
841 //-------------------------------------------------------------------
842 double vtkClipping3DDataViewer::GetIsovalue(int idTissue)
843 {
844         return _mCubes[idTissue]->GetValue(0);
845 }
846 //-------------------------------------------------------------------
847 vtkVolume* vtkClipping3DDataViewer::GetVolumeActor()
848 {
849    return _newvol;
850 }
851 //-------------------------------------------------------------------
852 vtkVolumeRayCastMapper* vtkClipping3DDataViewer::GetVolumeMapper(){
853         return _volumeMapper;
854 }
855 //-------------------------------------------------------------------
856 vtkPlanes* vtkClipping3DDataViewer::GetVolumePlanes()
857 {
858         return _volumePlanes;
859 }
860
861 //-------------------------------------------------------------------
862 vtkMarchingCubes *vtkClipping3DDataViewer::GetMCubes(int idTissue)
863 {
864         return _mCubes[idTissue];
865 }
866 //--------------------------------------------------------------------
867 //-------------------
868 //Getters Vectors
869 //-------------------
870
871 std::vector<double>*    vtkClipping3DDataViewer::GetGreyValuesTransferenceFVector()
872 {
873         return &greyValuesTransferenceFVector;
874 }
875 //--------------------------------------------------------------------
876 std::vector<double>*    vtkClipping3DDataViewer::GetIntensityValuesTransferenceFVector()
877 {
878         return &intensityValuesTransferenceFVector;
879 }
880 //--------------------------------------------------------------------
881 std::vector<double>*    vtkClipping3DDataViewer::GetRedColorsOfColorTransferenceFVector()
882 {
883         return &redColorsOfColorTransferenceFVector;
884 }
885 //--------------------------------------------------------------------
886 std::vector<double>*    vtkClipping3DDataViewer::GetGreenColorsOfColorTransferenceFVector()
887 {
888         return &greenColorsOfColorTransferenceFVector;
889 }
890 //--------------------------------------------------------------------
891 std::vector<double>*    vtkClipping3DDataViewer::GetBlueColorsOfColorTransferenceFVector()
892 {       
893         return &blueColorsOfColorTransferenceFVector;
894 }
895 //--------------------------------------------------------------------
896 std::vector<double>*    vtkClipping3DDataViewer::GetGreyValueColorsOfColorTransferenceFVector()
897 {
898         return &greyValueColorsOfColorTransferenceFVector;
899 }
900 //--------------------------------------------------------------------
901 //--------------------------------------
902 //Getters transference function
903 //and color of the transference function
904 //---------------------------------------
905 vtkPiecewiseFunction* vtkClipping3DDataViewer::GetTransferencefunction()
906 {
907         return this->_tfun;
908 }
909 //--------------------------------------------------------------------
910 vtkColorTransferFunction* vtkClipping3DDataViewer::GetColorTransferenceFunction()
911 {
912         return this->_ctfun;
913 }
914
915 //-------------------------------------------------------------------
916
917 void vtkClipping3DDataViewer::ReadVolumeFunctions()
918 {
919 /*
920         int i=0,xi,yi,r,g,b,gValue;
921         vtkImageData *imagedata = this->_vtkmprbasedata->GetImageData();
922         
923         HistogramDialog* hDlg=new HistogramDialog(NULL,_T("Histogram Dialog"),imagedata);
924         // 
925         // put in a method
926         //
927         int tfSize=this->greyValuesTransferenceFVector.size();
928                 if(tfSize>0)
929                 {
930                         int i=0,y;
931                         hDlg->erasePointsTransferenceFunction();
932                         while(i<tfSize)
933                         {
934                                 double g=greyValuesTransferenceFVector[i];
935                                 double in=intensityValuesTransferenceFVector[i];
936                                 hDlg->addPointToTransferenceFunction(g,in*100);
937                                 i++;
938                         }
939                         
940                 }
941
942         int ctfSize=this->redColorsOfColorTransferenceFVector.size();
943         if(ctfSize>0)
944         {
945                 int i=0,y;
946                         while(i<ctfSize)
947                         {
948                                 double gr=greyValueColorsOfColorTransferenceFVector[i];
949                                 double r=redColorsOfColorTransferenceFVector[i];
950                                 double g=greenColorsOfColorTransferenceFVector[i];
951                                 double b=blueColorsOfColorTransferenceFVector[i];
952                                 hDlg->addColorPoint(gr,r*255,g*255,b*255);
953                                 i++;
954                         }
955         }
956         //If it is smooth activate next line
957         //hDlg->updatePlotter();
958         //setting variables if the user wants to do refresh
959         hDlg->setCTF(_ctfun);
960         hDlg->setTF(_tfun);
961         
962         //
963         // when the user had changed the transference Function
964         //
965         if(hDlg->ShowModal()== wxID_OK )
966         {       
967                         // -- vtkPiecewiseFunction --
968                         this->_tfun->RemoveAllPoints();
969                         greyValuesTransferenceFVector.clear();
970                         intensityValuesTransferenceFVector.clear();
971                 
972                         int nTFPoints=hDlg->getSizeTransferenceFunction();
973                         i=0;
974                         while(i<nTFPoints)
975                         {
976                                 hDlg->getTransferenceFunctionPoint(i,xi,yi);
977                                 this->_tfun->AddPoint( xi , yi/100.0 );
978                                 greyValuesTransferenceFVector.push_back(xi);
979                                 intensityValuesTransferenceFVector.push_back(yi/100.0);
980                                 i++;
981                         }       
982                         // -- vtkColorTransferFunction  --
983                         this->_ctfun->RemoveAllPoints ();
984                         //clean colors
985                         redColorsOfColorTransferenceFVector.clear();
986                         greenColorsOfColorTransferenceFVector.clear();
987                         blueColorsOfColorTransferenceFVector.clear();
988                         greyValueColorsOfColorTransferenceFVector.clear();
989
990                         int nCTFpoints=hDlg->getSizeBarColor();
991                         i=0;    
992                         while(i<nCTFpoints)
993                         {
994                                 hDlg->getDataBarColorPoint(i,xi,r,g,b);
995                                 this->_ctfun->AddRGBPoint(xi,r/255.0,g/255.0,b/255.0 );
996                                 redColorsOfColorTransferenceFVector.push_back(r/255.0);
997                                 greenColorsOfColorTransferenceFVector.push_back(g/255.0);
998                                 blueColorsOfColorTransferenceFVector.push_back(b/255.0);
999                                 greyValueColorsOfColorTransferenceFVector.push_back(xi);
1000                                 i++;
1001                         }
1002                         
1003                         this->_volumeMapper->Update();
1004                         this->_newvol->Update();
1005         }
1006         
1007         else
1008         {
1009                 
1010                 if(hDlg->getRefreshed())
1011                 {
1012                         int i=0,size;
1013                         //--Transference Function----
1014                         this->_tfun->RemoveAllPoints();
1015                         i=0;
1016                         size=greyValuesTransferenceFVector.size();
1017                         for(i=0;i<size;i++)
1018                         {
1019                                 double grey1=greyValuesTransferenceFVector[i];
1020                                 double  in2=intensityValuesTransferenceFVector[i];
1021                                 this->_tfun->AddPoint( grey1 , in2 );
1022                         }
1023                         
1024                         // -- vtkColorTransferFunction  --
1025                         _ctfun->RemoveAllPoints ();
1026                         
1027                         i=0;
1028                         size=greyValueColorsOfColorTransferenceFVector.size();          
1029                         for(i=0;i<size;i++)
1030                         {
1031                                 double grey2=(greyValueColorsOfColorTransferenceFVector)[i];
1032                                 double red =(redColorsOfColorTransferenceFVector)[i];
1033                                 double green =(greenColorsOfColorTransferenceFVector)[i];
1034                                 double blue = (blueColorsOfColorTransferenceFVector)[i];
1035                                 _ctfun->AddRGBPoint(grey2,red,green,blue);
1036                         }
1037                         this->_volumeMapper->Update();
1038                         this->_newvol->Update();
1039                  }
1040                  
1041         }
1042         hDlg->Destroy();
1043 */
1044 }
1045 /*
1046 void vtkClipping3DDataViewer::ReadVolumeFunctions(char *namefile)
1047 {
1048         char tmp[256];
1049         short int       max;
1050         double          range[2];
1051         double          x,val,r,g,b;
1052
1053         FILE *ff = fopen ( namefile ,"r");
1054
1055         // --  MAX  --
1056         fscanf(ff,"%s",tmp);
1057         if (strcmp(tmp,"MAX")==0)
1058         {
1059                 vtkImageData *vtkimagedata              = this->_vtkmprbasedata->GetImageData();
1060                 vtkimagedata->GetScalarRange(range);
1061                 max = (int) (range[1]);
1062         } else {
1063                 max = atoi(tmp);
1064         }
1065
1066         fscanf(ff,"%s",tmp);   // --
1067
1068         // -- vtkPiecewiseFunction --
1069         this->_tfun->RemoveAllPoints();
1070         fscanf(ff,"%s",tmp);   
1071         while ( strcmp(tmp,"--")!=0 )
1072         {
1073                 x=atof(tmp);
1074                 fscanf(ff,"%s",tmp);   
1075                 val=atof(tmp);
1076                 this->_tfun->AddPoint( x*max , val );
1077                 fscanf(ff,"%s",tmp);   
1078         }
1079
1080         this->_ctfun->RemoveAllPoints ();
1081         // -- vtkColorTransferFunction  --
1082         while ( !feof(ff))
1083         {
1084                 fscanf(ff,"%s",tmp);   
1085                 x=atof(tmp);
1086                 fscanf(ff,"%s",tmp);   
1087                 r=atof(tmp);
1088                 fscanf(ff,"%s",tmp);   
1089                 g=atof(tmp);
1090                 fscanf(ff,"%s",tmp);   
1091                 b=atof(tmp);
1092                 this->_ctfun->AddRGBPoint( x*max , r,g,b );                     
1093         }
1094
1095
1096         this->_volumeMapper->Update();
1097         this->_newvol->Update();
1098
1099
1100         fclose(ff);
1101 }
1102 */
1103
1104 //-------------------------------------------------------------------
1105 // EED 23 Mai 2007
1106 void vtkClipping3DDataViewer::ReadMeshVTK(char *namefile)
1107 {
1108         vtkDataSetReader *reader = vtkDataSetReader::New();
1109         reader->SetFileName(namefile);
1110         reader->Update();
1111         _tissueStripper[3]->SetInput( reader->GetPolyDataOutput()  );
1112 }