]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMaracasSurfaceRenderingManagerDataMhd.cxx
*** empty log message ***
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / wxMaracasSurfaceRenderingManagerDataMhd.cxx
1
2 #include "wxMaracasSurfaceRenderingManagerDataMhd.h"
3 #include "vtkStripper.h"
4
5 wxMaracasSurfaceRenderingManagerDataMhd::wxMaracasSurfaceRenderingManagerDataMhd(vtkImageData* imagedata, std::string dataname, vtkRenderWindowInteractor*  interactor)
6 : wxMaracasSurfaceRenderingManagerData(NULL, dataname)
7 {
8
9         this->setVtkImageData(imagedata);
10         _dataname = dataname;
11         
12         _maxgreylevel = getMaxLevel(imagedata);
13         _prop3D=NULL;                   
14
15         _cubesFilter = vtkMarchingCubes::New(); 
16         _cubesFilter->SetInput(this->_imagedata);               
17         _cubesFilter->ComputeGradientsOn ();
18         _cubesFilter->ComputeScalarsOn ();
19         _cubesFilter->SetNumberOfContours( 1 );
20         _cleanFilter = vtkCleanPolyData::New();         
21         _cleanFilter->SetInput ( _cubesFilter->GetOutput() );
22
23         _dataMapper = vtkPolyDataMapper::New( );
24         _dataMapper->ScalarVisibilityOff( );
25         _dataMapper->ImmediateModeRenderingOn();
26
27         if(_boxWidgetS1){
28
29                 _boxWidgetS1 = vtkBoxWidget::New();
30                 _boxWidgetS1->SetInteractor( interactor );
31                 _boxWidgetS1->SetPlaceFactor(1.25); 
32
33                 _boxWidgetS1->SetInput( this->_imagedata );
34                 _boxWidgetS1->PlaceWidget();    
35                 //_boxWidgetS1->AddObserver( vtkCommand::InteractionEvent                , _vtkclipping3Ddataviewer->GetObserverS(i) );
36                 _boxWidgetS1->HandlesOn ();
37                 _boxWidgetS1->Off();
38
39                 vtkStripper* striper = vtkStripper::New();
40             striper->SetInput( _cleanFilter->GetOutput() );
41                 //striper->SetInput( _cubesFilter->GetOutput() );
42                 
43                 striper->Update();
44                 _boxWidgetS1->SetInput(striper->GetOutput());
45                 _boxWidgetS1->PlaceWidget();
46
47                 _tissuePlanes  = vtkPlanes::New();
48    
49                 int x1,x2,y1,y2,z1,z2;
50                 this->_imagedata->GetExtent(x1,x2,y1,y2,z1,z2);
51                 _tissuePlanes->SetBounds  (x1,x2,y1,y2,z1,z2);
52
53                 _boxWidgetS1->GetPlanes( _tissuePlanes );
54                 
55                 _tissueClipper = vtkClipPolyData::New();
56                 _tissueClipper->SetInput( striper->GetOutput() );
57                 _tissueClipper->SetClipFunction( _tissuePlanes );
58                 _tissueClipper->InsideOutOn( );
59                 _dataMapper->SetInput( _tissueClipper->GetOutput() );
60                 
61         }else{          
62                 _dataMapper->SetInput(_cleanFilter->GetOutput());               
63                 
64         }
65         vtkActor* dataActor = vtkActor::New();
66         dataActor->SetMapper(_dataMapper);      
67         this->_prop3D = dataActor;
68
69         
70
71         this->changeIsoValue(this->_maxgreylevel);      
72
73
74 }
75
76 wxMaracasSurfaceRenderingManagerDataMhd::~wxMaracasSurfaceRenderingManagerDataMhd(){    
77         _cubesFilter->Delete();
78         _cleanFilter->Delete();
79         _dataMapper->Delete();
80 }
81         
82 void wxMaracasSurfaceRenderingManagerDataMhd::UpdateSurface(){
83         _cubesFilter->Update();    
84         _cleanFilter->Update();
85         _dataMapper->Update();  
86 }
87 /**
88 **      changes the isovalue in a prop3D
89 **/
90 void wxMaracasSurfaceRenderingManagerDataMhd::changeIsoValue(double value){     
91                 
92    
93     _cubesFilter->SetValue(0,value);            
94         _cubesFilter->Update();    
95         _cleanFilter->Update();
96         _dataMapper->Update();  
97         
98         
99         
100 }
101 int wxMaracasSurfaceRenderingManagerDataMhd::getMaxGreyLevel(){
102         return _maxgreylevel;
103 }
104
105 /**
106         ** Get's the max grey level of the image
107         **/
108 int wxMaracasSurfaceRenderingManagerDataMhd::getMaxLevel(vtkImageData* img){
109
110         int ext[6], i, j, k,max=0;
111         img->GetExtent(ext);
112
113         for(i = ext[0]; i < ext[1];i++){
114                 for(j = ext[2]; j < ext[3];j++){
115                         for(k = ext[4]; k < ext[5];k++){
116                 unsigned short* ptr = (unsigned short*)img->GetScalarPointer(i,j,k);
117                                 int temp = (int)*ptr;
118                                 if(temp > max){
119                     max = temp;
120                                 }
121                         }
122                 }
123         }
124         return max;
125
126
127 }
128
129 /**
130 **      Sets the VTK image data
131 **/
132
133 void wxMaracasSurfaceRenderingManagerDataMhd::setVtkImageData(vtkImageData* imagedata){
134         _imagedata = imagedata;
135 }
136