]> Creatis software - creaMaracasVisu.git/blob - lib/Kernel/VTKObjects/SurfaceRenderer/wxMaracasSurfaceRenderingManagerDataMhd.cxx
#3109 creaMaracasVisu Bug New Normal - branch vtk7itk4 compilation with vtk7
[creaMaracasVisu.git] / lib / Kernel / VTKObjects / SurfaceRenderer / wxMaracasSurfaceRenderingManagerDataMhd.cxx
1 /*# ---------------------------------------------------------------------
2 #
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
4 #                        pour la Sant�)
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
8 #
9 #  This software is governed by the CeCILL-B license under French law and
10 #  abiding by the rules of distribution of free software. You can  use,
11 #  modify and/ or redistribute the software under the terms of the CeCILL-B
12 #  license as circulated by CEA, CNRS and INRIA at the following URL
13 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 #  or in the file LICENSE.txt.
15 #
16 #  As a counterpart to the access to the source code and  rights to copy,
17 #  modify and redistribute granted by the license, users are provided only
18 #  with a limited warranty  and the software's author,  the holder of the
19 #  economic rights,  and the successive licensors  have only  limited
20 #  liability.
21 #
22 #  The fact that you are presently reading this means that you have had
23 #  knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
25
26 #include "wxMaracasSurfaceRenderingManagerDataMhd.h"
27
28 #include "vtkStripper.h"
29
30
31 wxMaracasSurfaceRenderingManagerDataMhd::wxMaracasSurfaceRenderingManagerDataMhd(vtkImageData* imagedata, std::string dataname, vtkRenderWindowInteractor*  interactor)
32 : wxMaracasSurfaceRenderingManagerData(NULL, dataname)
33 {
34
35         this->setVtkImageData(imagedata);
36         _dataname = dataname;
37         
38         _maxgreylevel = getMaxLevel(imagedata);
39         _prop3D=NULL;                   
40
41         _tresholdFilter = vtkImageThreshold::New();
42 //EED 2017-01-01 Migration VTK7
43 #if VTK_MAJOR_VERSION <= 5
44         _tresholdFilter->SetInput(this->_imagedata);
45 #else
46         _tresholdFilter->SetInputData(this->_imagedata);
47 #endif
48         _tresholdFilter->SetInValue(255);        
49         _tresholdFilter->SetOutValue(0);
50
51
52         _cubesFilter = vtkMarchingCubes::New(); 
53 //EED 2017-01-01 Migration VTK7
54 #if VTK_MAJOR_VERSION <= 5
55         _cubesFilter->SetInput(_tresholdFilter->GetOutput());
56 #else
57         _cubesFilter->SetInputData(_tresholdFilter->GetOutput());
58 #endif
59         //_cubesFilter->ComputeGradientsOn();
60         _cubesFilter->ComputeScalarsOn();
61         _cubesFilter->ComputeNormalsOn();
62         _cubesFilter->SetNumberOfContours( 1 );
63         _cleanFilter = vtkCleanPolyData::New();         
64 //EED 2017-01-01 Migration VTK7
65 #if VTK_MAJOR_VERSION <= 5
66         _cleanFilter->SetInput( _cubesFilter->GetOutput() );
67 #else
68         _cleanFilter->SetInputData( _cubesFilter->GetOutput() );
69 #endif
70
71         _smooth = vtkSmoothPolyDataFilter::New();
72 //EED 2017-01-01 Migration VTK7
73 #if VTK_MAJOR_VERSION <= 5
74         _smooth->SetInput(_cleanFilter->GetOutput());
75 #else
76         _smooth->SetInputData(_cleanFilter->GetOutput());
77 #endif
78         _smooth->SetNumberOfIterations(6);
79         _smooth->SetRelaxationFactor(0.3);
80         //_smooth->FeatureEdgeSmoothingOff();
81
82         _dataMapper = vtkPolyDataMapper::New( );
83         _dataMapper->ScalarVisibilityOff( );
84         _dataMapper->ImmediateModeRenderingOn();
85         vtkActor* dataActor = vtkActor::New();
86
87         //if(_boxWidgetS1){
88         if(interactor){
89             _boxWidgetS1 = vtkBoxWidget::New();
90             _boxWidgetS1->SetInteractor( interactor );
91             _boxWidgetS1->SetPlaceFactor(1.25);
92
93 //EED 2017-01-01 Migration VTK7
94 #if VTK_MAJOR_VERSION <= 5
95             _boxWidgetS1->SetInput( this->_imagedata );
96 #else
97             _boxWidgetS1->SetInputData( this->_imagedata );
98 #endif
99             _boxWidgetS1->PlaceWidget();
100             boxSurfaceObserver* observer = boxSurfaceObserver::New();
101
102             vtkStripper* striper = vtkStripper::New();
103 //EED 2017-01-01 Migration VTK7
104 #if VTK_MAJOR_VERSION <= 5
105             striper->SetInput( _smooth->GetOutput() );
106 #else
107             striper->SetInputData( _smooth->GetOutput() );
108 #endif
109             //striper->SetInput( _cleanFilter->GetOutput() );
110
111             striper->Update();
112 //EED 2017-01-01 Migration VTK7
113 #if VTK_MAJOR_VERSION <= 5
114             _boxWidgetS1->SetInput(striper->GetOutput());
115 #else
116             _boxWidgetS1->SetInputData(striper->GetOutput());
117 #endif
118             //_boxWidgetS1->PlaceWidget();
119
120
121             _tissuePlanes  = vtkPlanes::New();
122
123             int x1,x2,y1,y2,z1,z2;
124             this->_imagedata->GetExtent(x1,x2,y1,y2,z1,z2);
125             _tissuePlanes->SetBounds  (x1,x2,y1,y2,z1,z2);
126
127
128
129             _boxWidgetS1->GetPlanes( _tissuePlanes );
130
131             _tissueClipper = vtkClipPolyData::New();
132 //EED 2017-01-01 Migration VTK7
133 #if VTK_MAJOR_VERSION <= 5
134             _tissueClipper->SetInput( striper->GetOutput() );
135 #else
136             _tissueClipper->SetInputData( striper->GetOutput() );
137 #endif
138             _tissueClipper->SetClipFunction( _tissuePlanes );
139             _tissueClipper->InsideOutOn( );
140 //EED 2017-01-01 Migration VTK7
141 #if VTK_MAJOR_VERSION <= 5
142             _dataMapper->SetInput( _tissueClipper->GetOutput() );
143 #else
144             _dataMapper->SetInputData( _tissueClipper->GetOutput() );
145 #endif
146             observer->SetPlanes( _tissuePlanes );
147             observer->SetActor( dataActor );
148             _boxWidgetS1->AddObserver( vtkCommand::InteractionEvent              , observer );
149
150
151             _boxWidgetS1->HandlesOn ();
152             _boxWidgetS1->EnabledOff();
153         }else{          
154                 //_dataMapper->SetInput(_cleanFilter->GetOutput());
155 //EED 2017-01-01 Migration VTK7
156 #if VTK_MAJOR_VERSION <= 5
157             _dataMapper->SetInput(_smooth->GetOutput());
158 #else
159             _dataMapper->SetInputData(_smooth->GetOutput());
160 #endif
161         }
162         
163         dataActor->SetMapper(_dataMapper);      
164         float cr=1,cg=0.5,cb=0.5;
165         dataActor->GetProperty()->SetDiffuseColor(1,0.5,0.5   );
166         dataActor->GetProperty()->SetSpecular(.3);
167         dataActor->GetProperty()->SetSpecularPower(20);
168
169         this->_prop3D = dataActor;
170         
171
172         this->changeIsoValue(this->_maxgreylevel);      
173
174
175 }
176
177 void wxMaracasSurfaceRenderingManagerDataMhd::enableBoxWidget(bool enable){
178
179     if(_boxWidgetS1){
180         if(enable){
181             _boxWidgetS1->EnabledOn();
182         }else{
183             _boxWidgetS1->EnabledOff();
184         }
185     }else{
186         cout<<"box widget not initialized!"<<endl;
187     }
188 }
189
190
191 wxMaracasSurfaceRenderingManagerDataMhd::~wxMaracasSurfaceRenderingManagerDataMhd()
192 {
193         _cubesFilter->Delete();
194         _cleanFilter->Delete();
195         _dataMapper->Delete();
196 }
197         
198 void wxMaracasSurfaceRenderingManagerDataMhd::UpdateSurface()
199 {
200         _cubesFilter->Update();    
201         _cleanFilter->Update();
202         _dataMapper->Update();  
203 }
204 /**
205 **      changes the isovalue in a prop3D
206 **/
207 void wxMaracasSurfaceRenderingManagerDataMhd::changeIsoValue(double value){     
208                 
209    
210     _tresholdFilter->ThresholdByLower(value);
211     _tresholdFilter->Update();
212
213     _cubesFilter->SetValue(0,255);
214         _cubesFilter->Update();    
215         _cleanFilter->Update();
216         _dataMapper->Update();  
217         
218         
219         
220 }
221 /**
222 **      changes the isovalue in a prop3D
223 **/
224 void wxMaracasSurfaceRenderingManagerDataMhd::changeIsoValue(double min, double max){
225
226     _tresholdFilter->ThresholdBetween(min, max);
227     _tresholdFilter->Update();
228     _cubesFilter->SetValue(0,255);
229         _cubesFilter->Update();
230         _cleanFilter->Update();
231         _dataMapper->Update();
232
233
234
235 }
236 int wxMaracasSurfaceRenderingManagerDataMhd::getMaxGreyLevel(){
237         return _maxgreylevel;
238 }
239
240 /**
241         ** Get's the max grey level of the image
242         **/
243 int wxMaracasSurfaceRenderingManagerDataMhd::getMaxLevel(vtkImageData* img){
244
245         int ext[6], i, j, k,max=0;
246         img->GetExtent(ext);
247
248         for(i = ext[0]; i < ext[1];i++){
249                 for(j = ext[2]; j < ext[3];j++){
250                         for(k = ext[4]; k < ext[5];k++){
251                 unsigned short* ptr = (unsigned short*)img->GetScalarPointer(i,j,k);
252                                 int temp = (int)*ptr;
253                                 if(temp > max){
254                     max = temp;
255                                 }
256                         }
257                 }
258         }
259         return max;
260
261
262 }
263
264 /**
265 **      Sets the VTK image data
266 **/
267
268 void wxMaracasSurfaceRenderingManagerDataMhd::setVtkImageData(vtkImageData* imagedata){
269         _imagedata = imagedata;
270 }
271
272
273
274