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 gaussFilter->SetInput(volume);
88 gaussFilter->SetDimensionality(3);
89 gaussFilter->SetStandardDeviation(sigmaLevel);
91 vtkMarchingCubes *cubesFilter = vtkMarchingCubes::New();
92 cubesFilter->SetInput(gaussFilter->GetOutput());
93 cubesFilter->SetValue(0,marchingCubesLevel);
94 cubesFilter->ComputeGradientsOn ();
95 cubesFilter->ComputeScalarsOn ();
96 cubesFilter->SetNumberOfContours( 1 );
98 // Unir puntos duplicados y remover primitivas degeneradas
99 vtkCleanPolyData *cleanFilter = vtkCleanPolyData::New();
100 cleanFilter->SetInput ( cubesFilter->GetOutput() );
102 // crea poligonos triangulares
103 vtkTriangleFilter *triangleFilter = vtkTriangleFilter::New();
104 triangleFilter->SetInput( cleanFilter->GetOutput() );
105 triangleFilter->Update();
107 innerSurface->DeepCopy(triangleFilter->GetOutput());
110 // ------------------------------------------------------------------------
111 // 2. CALCULATING THE OUTER SURFACE
112 // ------------------------------------------------------------------------
113 vtkImageContinuousDilate3D *dilateFilter = vtkImageContinuousDilate3D ::New();
114 dilateFilter->SetInput (volume);
115 dilateFilter->SetKernelSize (3, 3, 3);
116 gaussFilter->SetInput( dilateFilter->GetOutput());
117 triangleFilter->Update();
119 outerSurface->DeepCopy(triangleFilter->GetOutput());
121 // ------------------------------------------------------------------------
123 // ------------------------------------------------------------------------
125 gaussFilter->Delete();
126 cubesFilter->Delete();
127 cleanFilter->Delete();
128 triangleFilter->Delete();
129 dilateFilter->Delete();