1 /*# ---------------------------------------------------------------------
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
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
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.
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
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 # ------------------------------------------------------------------------ */
26 #include "wxMaracasSurfaceRenderingManagerDataMhd.h"
28 #include "vtkStripper.h"
31 wxMaracasSurfaceRenderingManagerDataMhd::wxMaracasSurfaceRenderingManagerDataMhd(vtkImageData* imagedata, std::string dataname, vtkRenderWindowInteractor* interactor)
32 : wxMaracasSurfaceRenderingManagerData(NULL, dataname)
35 this->setVtkImageData(imagedata);
38 _maxgreylevel = getMaxLevel(imagedata);
41 _tresholdFilter = vtkImageThreshold::New();
42 //EED 2017-01-01 Migration VTK7
43 #if VTK_MAJOR_VERSION <= 5
44 _tresholdFilter->SetInput(this->_imagedata);
46 _tresholdFilter->SetInputData(this->_imagedata);
48 _tresholdFilter->SetInValue(255);
49 _tresholdFilter->SetOutValue(0);
52 _cubesFilter = vtkMarchingCubes::New();
53 //EED 2017-01-01 Migration VTK7
54 #if VTK_MAJOR_VERSION <= 5
55 _cubesFilter->SetInput(_tresholdFilter->GetOutput());
57 _cubesFilter->SetInputData(_tresholdFilter->GetOutput());
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() );
68 _cleanFilter->SetInputData( _cubesFilter->GetOutput() );
71 _smooth = vtkSmoothPolyDataFilter::New();
72 //EED 2017-01-01 Migration VTK7
73 #if VTK_MAJOR_VERSION <= 5
74 _smooth->SetInput(_cleanFilter->GetOutput());
76 _smooth->SetInputData(_cleanFilter->GetOutput());
78 _smooth->SetNumberOfIterations(6);
79 _smooth->SetRelaxationFactor(0.3);
80 //_smooth->FeatureEdgeSmoothingOff();
82 _dataMapper = vtkPolyDataMapper::New( );
83 _dataMapper->ScalarVisibilityOff( );
85 //EED vtk 8 method deprecated
86 // _dataMapper->ImmediateModeRenderingOn();
88 vtkActor* dataActor = vtkActor::New();
92 _boxWidgetS1 = vtkBoxWidget::New();
93 _boxWidgetS1->SetInteractor( interactor );
94 _boxWidgetS1->SetPlaceFactor(1.25);
96 //EED 2017-01-01 Migration VTK7
97 #if VTK_MAJOR_VERSION <= 5
98 _boxWidgetS1->SetInput( this->_imagedata );
100 _boxWidgetS1->SetInputData( this->_imagedata );
102 _boxWidgetS1->PlaceWidget();
103 boxSurfaceObserver* observer = boxSurfaceObserver::New();
105 vtkStripper* striper = vtkStripper::New();
106 //EED 2017-01-01 Migration VTK7
107 #if VTK_MAJOR_VERSION <= 5
108 striper->SetInput( _smooth->GetOutput() );
110 striper->SetInputData( _smooth->GetOutput() );
112 //striper->SetInput( _cleanFilter->GetOutput() );
115 //EED 2017-01-01 Migration VTK7
116 #if VTK_MAJOR_VERSION <= 5
117 _boxWidgetS1->SetInput(striper->GetOutput());
119 _boxWidgetS1->SetInputData(striper->GetOutput());
121 //_boxWidgetS1->PlaceWidget();
124 _tissuePlanes = vtkPlanes::New();
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);
132 _boxWidgetS1->GetPlanes( _tissuePlanes );
134 _tissueClipper = vtkClipPolyData::New();
135 //EED 2017-01-01 Migration VTK7
136 #if VTK_MAJOR_VERSION <= 5
137 _tissueClipper->SetInput( striper->GetOutput() );
139 _tissueClipper->SetInputData( striper->GetOutput() );
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() );
147 _dataMapper->SetInputData( _tissueClipper->GetOutput() );
149 observer->SetPlanes( _tissuePlanes );
150 observer->SetActor( dataActor );
151 _boxWidgetS1->AddObserver( vtkCommand::InteractionEvent , observer );
154 _boxWidgetS1->HandlesOn ();
155 _boxWidgetS1->EnabledOff();
157 //_dataMapper->SetInput(_cleanFilter->GetOutput());
158 //EED 2017-01-01 Migration VTK7
159 #if VTK_MAJOR_VERSION <= 5
160 _dataMapper->SetInput(_smooth->GetOutput());
162 _dataMapper->SetInputData(_smooth->GetOutput());
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);
172 this->_prop3D = dataActor;
175 this->changeIsoValue(this->_maxgreylevel);
180 void wxMaracasSurfaceRenderingManagerDataMhd::enableBoxWidget(bool enable){
184 _boxWidgetS1->EnabledOn();
186 _boxWidgetS1->EnabledOff();
189 cout<<"box widget not initialized!"<<endl;
194 wxMaracasSurfaceRenderingManagerDataMhd::~wxMaracasSurfaceRenderingManagerDataMhd()
196 _cubesFilter->Delete();
197 _cleanFilter->Delete();
198 _dataMapper->Delete();
201 void wxMaracasSurfaceRenderingManagerDataMhd::UpdateSurface()
203 _cubesFilter->Update();
204 _cleanFilter->Update();
205 _dataMapper->Update();
208 ** changes the isovalue in a prop3D
210 void wxMaracasSurfaceRenderingManagerDataMhd::changeIsoValue(double value){
213 _tresholdFilter->ThresholdByLower(value);
214 _tresholdFilter->Update();
216 _cubesFilter->SetValue(0,255);
217 _cubesFilter->Update();
218 _cleanFilter->Update();
219 _dataMapper->Update();
225 ** changes the isovalue in a prop3D
227 void wxMaracasSurfaceRenderingManagerDataMhd::changeIsoValue(double min, double max){
229 _tresholdFilter->ThresholdBetween(min, max);
230 _tresholdFilter->Update();
231 _cubesFilter->SetValue(0,255);
232 _cubesFilter->Update();
233 _cleanFilter->Update();
234 _dataMapper->Update();
239 int wxMaracasSurfaceRenderingManagerDataMhd::getMaxGreyLevel(){
240 return _maxgreylevel;
244 ** Get's the max grey level of the image
246 int wxMaracasSurfaceRenderingManagerDataMhd::getMaxLevel(vtkImageData* img){
248 int ext[6], i, j, k,max=0;
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;
268 ** Sets the VTK image data
271 void wxMaracasSurfaceRenderingManagerDataMhd::setVtkImageData(vtkImageData* imagedata){
272 _imagedata = imagedata;