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( );
84 _dataMapper->ImmediateModeRenderingOn();
85 vtkActor* dataActor = vtkActor::New();
89 _boxWidgetS1 = vtkBoxWidget::New();
90 _boxWidgetS1->SetInteractor( interactor );
91 _boxWidgetS1->SetPlaceFactor(1.25);
93 //EED 2017-01-01 Migration VTK7
94 #if VTK_MAJOR_VERSION <= 5
95 _boxWidgetS1->SetInput( this->_imagedata );
97 _boxWidgetS1->SetInputData( this->_imagedata );
99 _boxWidgetS1->PlaceWidget();
100 boxSurfaceObserver* observer = boxSurfaceObserver::New();
102 vtkStripper* striper = vtkStripper::New();
103 //EED 2017-01-01 Migration VTK7
104 #if VTK_MAJOR_VERSION <= 5
105 striper->SetInput( _smooth->GetOutput() );
107 striper->SetInputData( _smooth->GetOutput() );
109 //striper->SetInput( _cleanFilter->GetOutput() );
112 //EED 2017-01-01 Migration VTK7
113 #if VTK_MAJOR_VERSION <= 5
114 _boxWidgetS1->SetInput(striper->GetOutput());
116 _boxWidgetS1->SetInputData(striper->GetOutput());
118 //_boxWidgetS1->PlaceWidget();
121 _tissuePlanes = vtkPlanes::New();
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);
129 _boxWidgetS1->GetPlanes( _tissuePlanes );
131 _tissueClipper = vtkClipPolyData::New();
132 //EED 2017-01-01 Migration VTK7
133 #if VTK_MAJOR_VERSION <= 5
134 _tissueClipper->SetInput( striper->GetOutput() );
136 _tissueClipper->SetInputData( striper->GetOutput() );
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() );
144 _dataMapper->SetInputData( _tissueClipper->GetOutput() );
146 observer->SetPlanes( _tissuePlanes );
147 observer->SetActor( dataActor );
148 _boxWidgetS1->AddObserver( vtkCommand::InteractionEvent , observer );
151 _boxWidgetS1->HandlesOn ();
152 _boxWidgetS1->EnabledOff();
154 //_dataMapper->SetInput(_cleanFilter->GetOutput());
155 //EED 2017-01-01 Migration VTK7
156 #if VTK_MAJOR_VERSION <= 5
157 _dataMapper->SetInput(_smooth->GetOutput());
159 _dataMapper->SetInputData(_smooth->GetOutput());
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);
169 this->_prop3D = dataActor;
172 this->changeIsoValue(this->_maxgreylevel);
177 void wxMaracasSurfaceRenderingManagerDataMhd::enableBoxWidget(bool enable){
181 _boxWidgetS1->EnabledOn();
183 _boxWidgetS1->EnabledOff();
186 cout<<"box widget not initialized!"<<endl;
191 wxMaracasSurfaceRenderingManagerDataMhd::~wxMaracasSurfaceRenderingManagerDataMhd()
193 _cubesFilter->Delete();
194 _cleanFilter->Delete();
195 _dataMapper->Delete();
198 void wxMaracasSurfaceRenderingManagerDataMhd::UpdateSurface()
200 _cubesFilter->Update();
201 _cleanFilter->Update();
202 _dataMapper->Update();
205 ** changes the isovalue in a prop3D
207 void wxMaracasSurfaceRenderingManagerDataMhd::changeIsoValue(double value){
210 _tresholdFilter->ThresholdByLower(value);
211 _tresholdFilter->Update();
213 _cubesFilter->SetValue(0,255);
214 _cubesFilter->Update();
215 _cleanFilter->Update();
216 _dataMapper->Update();
222 ** changes the isovalue in a prop3D
224 void wxMaracasSurfaceRenderingManagerDataMhd::changeIsoValue(double min, double max){
226 _tresholdFilter->ThresholdBetween(min, max);
227 _tresholdFilter->Update();
228 _cubesFilter->SetValue(0,255);
229 _cubesFilter->Update();
230 _cleanFilter->Update();
231 _dataMapper->Update();
236 int wxMaracasSurfaceRenderingManagerDataMhd::getMaxGreyLevel(){
237 return _maxgreylevel;
241 ** Get's the max grey level of the image
243 int wxMaracasSurfaceRenderingManagerDataMhd::getMaxLevel(vtkImageData* img){
245 int ext[6], i, j, k,max=0;
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;
265 ** Sets the VTK image data
268 void wxMaracasSurfaceRenderingManagerDataMhd::setVtkImageData(vtkImageData* imagedata){
269 _imagedata = imagedata;