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