]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/kernel/vtkSTLExtractor.cpp
#3109 creaMaracasVisu Bug New Normal - branch vtk7itk4 compilation with vtk7
[creaMaracasVisu.git] / lib / maracasVisuLib / src / kernel / vtkSTLExtractor.cpp
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
27 #include "vtkSTLExtractor.h"
28 #include <vtkImageGaussianSmooth.h>
29 #include <vtkMarchingCubes.h>
30 #include <vtkCleanPolyData.h>
31 #include <vtkTriangleFilter.h>
32 #include <vtkImageContinuousDilate3D.h>
33
34
35 vtkSTLExtractor::vtkSTLExtractor(){
36         innerSurface = vtkPolyData::New();
37         outerSurface = vtkPolyData::New();
38         marchingCubesLevel = 128.0;
39         sigmaLevel = 100.0;
40 }
41
42 vtkSTLExtractor::~vtkSTLExtractor(){
43         innerSurface->Delete();
44         outerSurface->Delete();
45 }
46
47 void vtkSTLExtractor::setVolume(vtkImageData *volume){
48         this->volume = volume;
49 }
50
51
52 void vtkSTLExtractor::setMarchingCubesLevel(double level){
53         this->marchingCubesLevel = level;
54 }
55
56 void vtkSTLExtractor::setSigmaLevel(double level){
57         this->sigmaLevel = level;
58 }
59
60
61 double vtkSTLExtractor::getMarchingCubesLevel(){
62         return marchingCubesLevel;
63 }
64
65 double vtkSTLExtractor::getSigmaLevel(){
66         return sigmaLevel;
67 }
68
69
70 vtkPolyData* vtkSTLExtractor::getInnerSurface(){
71         return innerSurface;
72 }
73
74
75 vtkPolyData* vtkSTLExtractor::getOuterSurface(){
76         return outerSurface;
77 }
78
79
80
81 void vtkSTLExtractor::calculate(){
82
83         // ------------------------------------------------------------------------
84                 //  1. CALCULATING THE INNER SURFACE
85                 // ------------------------------------------------------------------------
86             vtkImageGaussianSmooth *gaussFilter = vtkImageGaussianSmooth::New();
87 //EED 2017-01-01 Migration VTK7
88 #if VTK_MAJOR_VERSION <= 5
89         gaussFilter->SetInput(volume);
90 #else
91         gaussFilter->SetInputData(volume);
92 #endif
93         gaussFilter->SetDimensionality(3);
94         gaussFilter->SetStandardDeviation(sigmaLevel);
95     
96         vtkMarchingCubes *cubesFilter = vtkMarchingCubes::New();
97 //EED 2017-01-01 Migration VTK7
98 #if VTK_MAJOR_VERSION <= 5
99         cubesFilter->SetInput(gaussFilter->GetOutput());
100 #else
101         cubesFilter->SetInputData(gaussFilter->GetOutput());
102 #endif
103         cubesFilter->SetValue(0,marchingCubesLevel);
104                 cubesFilter->ComputeGradientsOn ();
105         cubesFilter->ComputeScalarsOn ();
106                 cubesFilter->SetNumberOfContours( 1 );
107             
108                 // Unir puntos duplicados y remover primitivas degeneradas
109                 vtkCleanPolyData *cleanFilter = vtkCleanPolyData::New();
110 //EED 2017-01-01 Migration VTK7
111 #if VTK_MAJOR_VERSION <= 5
112         cleanFilter->SetInput( cubesFilter->GetOutput() );
113 #else
114         cleanFilter->SetInputData( cubesFilter->GetOutput() );
115 #endif
116                 
117                 // crea poligonos triangulares
118         vtkTriangleFilter *triangleFilter = vtkTriangleFilter::New();
119 //EED 2017-01-01 Migration VTK7
120 #if VTK_MAJOR_VERSION <= 5
121         triangleFilter->SetInput( cleanFilter->GetOutput() );
122 #else
123         triangleFilter->SetInputData( cleanFilter->GetOutput() );
124 #endif
125         triangleFilter->Update();
126
127                 innerSurface->DeepCopy(triangleFilter->GetOutput());
128
129
130                 // ------------------------------------------------------------------------
131                 //  2. CALCULATING THE OUTER SURFACE
132                 // ------------------------------------------------------------------------
133                 vtkImageContinuousDilate3D *dilateFilter = vtkImageContinuousDilate3D ::New();
134 //EED 2017-01-01 Migration VTK7
135 #if VTK_MAJOR_VERSION <= 5
136         dilateFilter->SetInput(volume);
137 #else
138         dilateFilter->SetInputData(volume);
139 #endif
140                 dilateFilter->SetKernelSize (3, 3, 3);
141 //EED 2017-01-01 Migration VTK7
142 #if VTK_MAJOR_VERSION <= 5
143                 gaussFilter->SetInput( dilateFilter->GetOutput());
144 #else
145                 gaussFilter->SetInputData( dilateFilter->GetOutput());
146 #endif
147         triangleFilter->Update();
148                 
149             outerSurface->DeepCopy(triangleFilter->GetOutput());
150
151                 // ------------------------------------------------------------------------
152                 //  3. CLEANING UP
153                 // ------------------------------------------------------------------------
154
155                 gaussFilter->Delete();
156                 cubesFilter->Delete();
157                 cleanFilter->Delete();
158             triangleFilter->Delete();
159         dilateFilter->Delete();
160 }