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