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