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 _tresholdFilter->SetInput(this->_imagedata);
43 _tresholdFilter->SetInValue(255);
44 _tresholdFilter->SetOutValue(0);
47 _cubesFilter = vtkMarchingCubes::New();
48 _cubesFilter->SetInput(_tresholdFilter->GetOutput());
49 //_cubesFilter->ComputeGradientsOn();
50 _cubesFilter->ComputeScalarsOn();
51 _cubesFilter->ComputeNormalsOn();
52 _cubesFilter->SetNumberOfContours( 1 );
53 _cleanFilter = vtkCleanPolyData::New();
54 _cleanFilter->SetInput ( _cubesFilter->GetOutput() );
56 _smooth = vtkSmoothPolyDataFilter::New();
57 _smooth->SetInput(_cleanFilter->GetOutput());
58 _smooth->SetNumberOfIterations(6);
59 _smooth->SetRelaxationFactor(0.3);
60 //_smooth->FeatureEdgeSmoothingOff();
62 _dataMapper = vtkPolyDataMapper::New( );
63 _dataMapper->ScalarVisibilityOff( );
64 _dataMapper->ImmediateModeRenderingOn();
65 vtkActor* dataActor = vtkActor::New();
69 _boxWidgetS1 = vtkBoxWidget::New();
70 _boxWidgetS1->SetInteractor( interactor );
71 _boxWidgetS1->SetPlaceFactor(1.25);
73 _boxWidgetS1->SetInput( this->_imagedata );
74 _boxWidgetS1->PlaceWidget();
75 boxSurfaceObserver* observer = boxSurfaceObserver::New();
77 vtkStripper* striper = vtkStripper::New();
78 striper->SetInput( _smooth->GetOutput() );
79 //striper->SetInput( _cleanFilter->GetOutput() );
82 _boxWidgetS1->SetInput(striper->GetOutput());
83 //_boxWidgetS1->PlaceWidget();
86 _tissuePlanes = vtkPlanes::New();
88 int x1,x2,y1,y2,z1,z2;
89 this->_imagedata->GetExtent(x1,x2,y1,y2,z1,z2);
90 _tissuePlanes->SetBounds (x1,x2,y1,y2,z1,z2);
94 _boxWidgetS1->GetPlanes( _tissuePlanes );
96 _tissueClipper = vtkClipPolyData::New();
97 _tissueClipper->SetInput( striper->GetOutput() );
98 _tissueClipper->SetClipFunction( _tissuePlanes );
99 _tissueClipper->InsideOutOn( );
100 _dataMapper->SetInput( _tissueClipper->GetOutput() );
101 observer->SetPlanes( _tissuePlanes );
102 observer->SetActor( dataActor );
103 _boxWidgetS1->AddObserver( vtkCommand::InteractionEvent , observer );
106 _boxWidgetS1->HandlesOn ();
107 _boxWidgetS1->EnabledOff();
109 //_dataMapper->SetInput(_cleanFilter->GetOutput());
110 _dataMapper->SetInput(_smooth->GetOutput());
113 dataActor->SetMapper(_dataMapper);
114 float cr=1,cg=0.5,cb=0.5;
115 dataActor->GetProperty()->SetDiffuseColor(1,0.5,0.5 );
116 dataActor->GetProperty()->SetSpecular(.3);
117 dataActor->GetProperty()->SetSpecularPower(20);
119 this->_prop3D = dataActor;
122 this->changeIsoValue(this->_maxgreylevel);
127 void wxMaracasSurfaceRenderingManagerDataMhd::enableBoxWidget(bool enable){
131 _boxWidgetS1->EnabledOn();
133 _boxWidgetS1->EnabledOff();
136 cout<<"box widget not initialized!"<<endl;
141 wxMaracasSurfaceRenderingManagerDataMhd::~wxMaracasSurfaceRenderingManagerDataMhd()
143 _cubesFilter->Delete();
144 _cleanFilter->Delete();
145 _dataMapper->Delete();
148 void wxMaracasSurfaceRenderingManagerDataMhd::UpdateSurface()
150 _cubesFilter->Update();
151 _cleanFilter->Update();
152 _dataMapper->Update();
155 ** changes the isovalue in a prop3D
157 void wxMaracasSurfaceRenderingManagerDataMhd::changeIsoValue(double value){
160 _tresholdFilter->ThresholdByLower(value);
161 _tresholdFilter->Update();
163 _cubesFilter->SetValue(0,255);
164 _cubesFilter->Update();
165 _cleanFilter->Update();
166 _dataMapper->Update();
172 ** changes the isovalue in a prop3D
174 void wxMaracasSurfaceRenderingManagerDataMhd::changeIsoValue(double min, double max){
176 _tresholdFilter->ThresholdBetween(min, max);
177 _tresholdFilter->Update();
178 _cubesFilter->SetValue(0,255);
179 _cubesFilter->Update();
180 _cleanFilter->Update();
181 _dataMapper->Update();
186 int wxMaracasSurfaceRenderingManagerDataMhd::getMaxGreyLevel(){
187 return _maxgreylevel;
191 ** Get's the max grey level of the image
193 int wxMaracasSurfaceRenderingManagerDataMhd::getMaxLevel(vtkImageData* img){
195 int ext[6], i, j, k,max=0;
198 for(i = ext[0]; i < ext[1];i++){
199 for(j = ext[2]; j < ext[3];j++){
200 for(k = ext[4]; k < ext[5];k++){
201 unsigned short* ptr = (unsigned short*)img->GetScalarPointer(i,j,k);
202 int temp = (int)*ptr;
215 ** Sets the VTK image data
218 void wxMaracasSurfaceRenderingManagerDataMhd::setVtkImageData(vtkImageData* imagedata){
219 _imagedata = imagedata;