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 # ------------------------------------------------------------------------ */
27 #include "vtkSTLExtractor.h"
28 #include <vtkImageGaussianSmooth.h>
29 #include <vtkMarchingCubes.h>
30 #include <vtkCleanPolyData.h>
31 #include <vtkTriangleFilter.h>
32 #include <vtkImageContinuousDilate3D.h>
35 vtkSTLExtractor::vtkSTLExtractor(){
36 innerSurface = vtkPolyData::New();
37 outerSurface = vtkPolyData::New();
38 marchingCubesLevel = 128.0;
42 vtkSTLExtractor::~vtkSTLExtractor(){
43 innerSurface->Delete();
44 outerSurface->Delete();
47 void vtkSTLExtractor::setVolume(vtkImageData *volume){
48 this->volume = volume;
52 void vtkSTLExtractor::setMarchingCubesLevel(double level){
53 this->marchingCubesLevel = level;
56 void vtkSTLExtractor::setSigmaLevel(double level){
57 this->sigmaLevel = level;
61 double vtkSTLExtractor::getMarchingCubesLevel(){
62 return marchingCubesLevel;
65 double vtkSTLExtractor::getSigmaLevel(){
70 vtkPolyData* vtkSTLExtractor::getInnerSurface(){
75 vtkPolyData* vtkSTLExtractor::getOuterSurface(){
81 void vtkSTLExtractor::calculate(){
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);
91 gaussFilter->SetInputData(volume);
93 gaussFilter->SetDimensionality(3);
94 gaussFilter->SetStandardDeviation(sigmaLevel);
96 vtkMarchingCubes *cubesFilter = vtkMarchingCubes::New();
97 //EED 2017-01-01 Migration VTK7
98 #if VTK_MAJOR_VERSION <= 5
99 cubesFilter->SetInput(gaussFilter->GetOutput());
101 cubesFilter->SetInputData(gaussFilter->GetOutput());
103 cubesFilter->SetValue(0,marchingCubesLevel);
104 cubesFilter->ComputeGradientsOn ();
105 cubesFilter->ComputeScalarsOn ();
106 cubesFilter->SetNumberOfContours( 1 );
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() );
114 cleanFilter->SetInputData( cubesFilter->GetOutput() );
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() );
123 triangleFilter->SetInputData( cleanFilter->GetOutput() );
125 triangleFilter->Update();
127 innerSurface->DeepCopy(triangleFilter->GetOutput());
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);
138 dilateFilter->SetInputData(volume);
140 dilateFilter->SetKernelSize (3, 3, 3);
141 //EED 2017-01-01 Migration VTK7
142 #if VTK_MAJOR_VERSION <= 5
143 gaussFilter->SetInput( dilateFilter->GetOutput());
145 gaussFilter->SetInputData( dilateFilter->GetOutput());
147 triangleFilter->Update();
149 outerSurface->DeepCopy(triangleFilter->GetOutput());
151 // ------------------------------------------------------------------------
153 // ------------------------------------------------------------------------
155 gaussFilter->Delete();
156 cubesFilter->Delete();
157 cleanFilter->Delete();
158 triangleFilter->Delete();
159 dilateFilter->Delete();