]> Creatis software - creaMaracasVisu.git/blob - lib/Kernel/VTKObjects/SurfaceRenderer/wxMaracasSurfaceRenderingManagerDataMhd.cxx
#3404 creaMaracasVisu Feature New Normal - vtk8itk5wx3-macos
[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         
85 //EED   vtk 8 method deprecated
86 //      _dataMapper->ImmediateModeRenderingOn();
87
88         vtkActor* dataActor = vtkActor::New();
89
90         //if(_boxWidgetS1){
91         if(interactor){
92             _boxWidgetS1 = vtkBoxWidget::New();
93             _boxWidgetS1->SetInteractor( interactor );
94             _boxWidgetS1->SetPlaceFactor(1.25);
95
96 //EED 2017-01-01 Migration VTK7
97 #if VTK_MAJOR_VERSION <= 5
98             _boxWidgetS1->SetInput( this->_imagedata );
99 #else
100             _boxWidgetS1->SetInputData( this->_imagedata );
101 #endif
102             _boxWidgetS1->PlaceWidget();
103             boxSurfaceObserver* observer = boxSurfaceObserver::New();
104
105             vtkStripper* striper = vtkStripper::New();
106 //EED 2017-01-01 Migration VTK7
107 #if VTK_MAJOR_VERSION <= 5
108             striper->SetInput( _smooth->GetOutput() );
109 #else
110             striper->SetInputData( _smooth->GetOutput() );
111 #endif
112             //striper->SetInput( _cleanFilter->GetOutput() );
113
114             striper->Update();
115 //EED 2017-01-01 Migration VTK7
116 #if VTK_MAJOR_VERSION <= 5
117             _boxWidgetS1->SetInput(striper->GetOutput());
118 #else
119             _boxWidgetS1->SetInputData(striper->GetOutput());
120 #endif
121             //_boxWidgetS1->PlaceWidget();
122
123
124             _tissuePlanes  = vtkPlanes::New();
125
126             int x1,x2,y1,y2,z1,z2;
127             this->_imagedata->GetExtent(x1,x2,y1,y2,z1,z2);
128             _tissuePlanes->SetBounds  (x1,x2,y1,y2,z1,z2);
129
130
131
132             _boxWidgetS1->GetPlanes( _tissuePlanes );
133
134             _tissueClipper = vtkClipPolyData::New();
135 //EED 2017-01-01 Migration VTK7
136 #if VTK_MAJOR_VERSION <= 5
137             _tissueClipper->SetInput( striper->GetOutput() );
138 #else
139             _tissueClipper->SetInputData( striper->GetOutput() );
140 #endif
141             _tissueClipper->SetClipFunction( _tissuePlanes );
142             _tissueClipper->InsideOutOn( );
143 //EED 2017-01-01 Migration VTK7
144 #if VTK_MAJOR_VERSION <= 5
145             _dataMapper->SetInput( _tissueClipper->GetOutput() );
146 #else
147             _dataMapper->SetInputData( _tissueClipper->GetOutput() );
148 #endif
149             observer->SetPlanes( _tissuePlanes );
150             observer->SetActor( dataActor );
151             _boxWidgetS1->AddObserver( vtkCommand::InteractionEvent              , observer );
152
153
154             _boxWidgetS1->HandlesOn ();
155             _boxWidgetS1->EnabledOff();
156         }else{          
157                 //_dataMapper->SetInput(_cleanFilter->GetOutput());
158 //EED 2017-01-01 Migration VTK7
159 #if VTK_MAJOR_VERSION <= 5
160             _dataMapper->SetInput(_smooth->GetOutput());
161 #else
162             _dataMapper->SetInputData(_smooth->GetOutput());
163 #endif
164         }
165         
166         dataActor->SetMapper(_dataMapper);      
167         float cr=1,cg=0.5,cb=0.5;
168         dataActor->GetProperty()->SetDiffuseColor(1,0.5,0.5   );
169         dataActor->GetProperty()->SetSpecular(.3);
170         dataActor->GetProperty()->SetSpecularPower(20);
171
172         this->_prop3D = dataActor;
173         
174
175         this->changeIsoValue(this->_maxgreylevel);      
176
177
178 }
179
180 void wxMaracasSurfaceRenderingManagerDataMhd::enableBoxWidget(bool enable){
181
182     if(_boxWidgetS1){
183         if(enable){
184             _boxWidgetS1->EnabledOn();
185         }else{
186             _boxWidgetS1->EnabledOff();
187         }
188     }else{
189         cout<<"box widget not initialized!"<<endl;
190     }
191 }
192
193
194 wxMaracasSurfaceRenderingManagerDataMhd::~wxMaracasSurfaceRenderingManagerDataMhd()
195 {
196         _cubesFilter->Delete();
197         _cleanFilter->Delete();
198         _dataMapper->Delete();
199 }
200         
201 void wxMaracasSurfaceRenderingManagerDataMhd::UpdateSurface()
202 {
203         _cubesFilter->Update();    
204         _cleanFilter->Update();
205         _dataMapper->Update();  
206 }
207 /**
208 **      changes the isovalue in a prop3D
209 **/
210 void wxMaracasSurfaceRenderingManagerDataMhd::changeIsoValue(double value){     
211                 
212    
213     _tresholdFilter->ThresholdByLower(value);
214     _tresholdFilter->Update();
215
216     _cubesFilter->SetValue(0,255);
217         _cubesFilter->Update();    
218         _cleanFilter->Update();
219         _dataMapper->Update();  
220         
221         
222         
223 }
224 /**
225 **      changes the isovalue in a prop3D
226 **/
227 void wxMaracasSurfaceRenderingManagerDataMhd::changeIsoValue(double min, double max){
228
229     _tresholdFilter->ThresholdBetween(min, max);
230     _tresholdFilter->Update();
231     _cubesFilter->SetValue(0,255);
232         _cubesFilter->Update();
233         _cleanFilter->Update();
234         _dataMapper->Update();
235
236
237
238 }
239 int wxMaracasSurfaceRenderingManagerDataMhd::getMaxGreyLevel(){
240         return _maxgreylevel;
241 }
242
243 /**
244         ** Get's the max grey level of the image
245         **/
246 int wxMaracasSurfaceRenderingManagerDataMhd::getMaxLevel(vtkImageData* img){
247
248         int ext[6], i, j, k,max=0;
249         img->GetExtent(ext);
250
251         for(i = ext[0]; i < ext[1];i++){
252                 for(j = ext[2]; j < ext[3];j++){
253                         for(k = ext[4]; k < ext[5];k++){
254                 unsigned short* ptr = (unsigned short*)img->GetScalarPointer(i,j,k);
255                                 int temp = (int)*ptr;
256                                 if(temp > max){
257                     max = temp;
258                                 }
259                         }
260                 }
261         }
262         return max;
263
264
265 }
266
267 /**
268 **      Sets the VTK image data
269 **/
270
271 void wxMaracasSurfaceRenderingManagerDataMhd::setVtkImageData(vtkImageData* imagedata){
272         _imagedata = imagedata;
273 }
274
275
276
277