]> Creatis software - creaVtk.git/blob - lib/creaVtk/cutImageSegmentation.cpp
#2660 creaVtk Feature New Normal - New cutImageSegmentation
[creaVtk.git] / lib / creaVtk / cutImageSegmentation.cpp
1 /*
2 # ---------------------------------------------------------------------
3 #
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5 #                        pour la Sante)
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9 #
10 #  This software is governed by the CeCILL-B license under French law and
11 #  abiding by the rules of distribution of free software. You can  use,
12 #  modify and/ or redistribute the software under the terms of the CeCILL-B
13 #  license as circulated by CEA, CNRS and INRIA at the following URL
14 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15 #  or in the file LICENSE.txt.
16 #
17 #  As a counterpart to the access to the source code and  rights to copy,
18 #  modify and redistribute granted by the license, users are provided only
19 #  with a limited warranty  and the software's author,  the holder of the
20 #  economic rights,  and the successive licensors  have only  limited
21 #  liability.
22 #
23 #  The fact that you are presently reading this means that you have had
24 #  knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------
26 */
27
28 #include "cutImageSegmentation.h"
29
30 cutImageSegmentation::cutImageSegmentation()
31 {
32 }
33
34 cutImageSegmentation::~cutImageSegmentation()
35 {
36 }
37
38 void cutImageSegmentation::SetAnglesImage( vtkImageData* image )
39 {
40         this->m_Image = image;
41 }
42
43 void cutImageSegmentation::SetMesh1(vtkPolyData* mesh)
44 {
45         this->m_Mesh1 = mesh;
46 }
47
48 vtkImageData*
49 cutImageSegmentation::GetResultImage()
50 {
51         return m_ResultImage;
52 }
53
54
55 void cutImageSegmentation::Process()
56 {
57         std::cout << "MLER cutImageSegmentation :: Process Start()" << std::endl;
58
59         if(m_Mesh1 != NULL)
60         {
61                 
62                 vtkLinearExtrusionFilter        *extrude                = vtkLinearExtrusionFilter::New();
63                 vtkPolyDataToImageStencil       *dataToStencil  = vtkPolyDataToImageStencil::New();
64                 vtkImageStencil                         *imageStencil   = vtkImageStencil::New();
65                 //vtkExtractVOI                         *extract                = vtkExtractVOI::New();
66                 vtkAppendPolyData                       *append                 = vtkAppendPolyData::New();
67                 //vtkTriangleFilter                     *triangleFilter = vtkTriangleFilter::New();
68                 vtkStripper                                     *stripper       = vtkStripper::New();
69                 vtkTransformPolyDataFilter  *transformFilter= vtkTransformPolyDataFilter::New();
70
71                 double bounds[6];
72
73                 //vtkPolyDataToImageStencil* stencil = vtkPolyDataToImageStencil::New();
74                 /* Test # 1 Cod Python
75                 extract->SetVOI( 0, 128, 0, 104, 0, 9);
76                 extract->SetSampleRate(1, 1, 1);
77                 extract->SetInput(m_Image);
78                 extract->ReleaseDataFlagOff();
79                 
80
81                 extrude->SetInput(m_Mesh1);
82                 extrude->SetScaleFactor(1);
83                 extrude->SetExtrusionTypeToNormalExtrusion();
84                 extrude->SetVector(0,0,1);
85                 //extrude->Update();
86                 
87                 extrude->Print(std::cout);
88
89                 std::cout << "MLER cutImageSegmentation ---> polygonal data --> image stencil:" << std::endl;
90
91                 //dataToStencil->SetTolerance(0);
92                 dataToStencil->SetInput(extrude->GetOutput());
93                 //dataToStencil->SetOutputSpacing(m_Image->GetSpacing());
94                 //dataToStencil->SetOutputWholeExtent(m_Image->GetExtent());
95                 //dataToStencil->Update();
96
97                 dataToStencil->Print(std::cout);
98
99                 imageStencil->SetInput(extract->GetOutput());
100                 imageStencil->SetStencil(dataToStencil->GetOutput());
101
102                 imageStencil->ReverseStencilOff();
103                 imageStencil->SetBackgroundValue(128);
104                 imageStencil->Update();
105                 
106                 imageStencil->Print(std::cout);
107                 
108                 m_ResultImage = imageStencil->GetOutput();
109                 */
110
111                 /*Test #2
112                 stripper->SetInput(m_Mesh1);
113                 transformFilter->SetInput(stripper->GetOutput());
114                 
115                 dataToStencil->SetOutputOrigin(m_Image->GetOrigin());
116                 dataToStencil->SetOutputSpacing(m_Image->GetSpacing());
117                 dataToStencil->SetOutputWholeExtent(m_Image->GetExtent());
118
119                 dataToStencil->SetInput(transformFilter->GetOutput());
120
121                 imageStencil->SetInput(m_Image);
122                 imageStencil->SetStencil(dataToStencil->GetOutput());
123                 imageStencil->Update();
124
125                 m_ResultImage = imageStencil->GetOutput();
126                 */
127
128                 //Test 3
129                 /*
130                 m_Mesh1->GetBounds(bounds);
131
132                 dataToStencil->SetInput(m_Mesh1);
133                 dataToStencil->SetOutputOrigin(m_Image->GetOrigin());
134                 dataToStencil->SetOutputSpacing(m_Image->GetSpacing());
135                 dataToStencil->SetOutputWholeExtent(m_Image->GetExtent());
136                 dataToStencil->Update();
137
138                 imageStencil->SetInput(m_Image);
139                 imageStencil->SetStencil(dataToStencil->GetOutput());
140                 imageStencil->ReverseStencilOff();
141                 //imageStencil->SetBackgroundValue(100);
142                 imageStencil->Update();
143                 */
144
145                 //Test 4
146                 m_Mesh1->GetBounds(bounds);
147
148                 std::cout << "bounds 0:" << bounds[0]<< std::endl;
149                 std::cout << "bounds 1:" << bounds[1]<< std::endl;
150                 std::cout << "bounds 2:" << bounds[2]<< std::endl;
151                 std::cout << "bounds 3:" << bounds[3]<< std::endl;
152                 std::cout << "bounds 4:" << bounds[4]<< std::endl;
153                 std::cout << "bounds 5:" << bounds[5]<< std::endl;
154
155
156
157                 double origin[3];
158                 //double *spacing = NULL;
159                 //spacing = m_Image->GetSpacing();
160
161                 double spacing[3];
162                 spacing[0] = 2.62565;
163                 spacing[1] = 2.62565;
164                 spacing[2] = 6.25;
165  
166
167                 std::cout << "spacing 0:" << spacing[0]<< std::endl;
168                 std::cout << "spacing 1:" << spacing[1]<< std::endl;
169                 std::cout << "spacing 2:" << spacing[2]<< std::endl;
170
171                 //origin[0] = bounds[0] + spacing[0] / 2;
172                 //origin[1] = bounds[2] + spacing[1] / 2;
173                 //origin[2] = bounds[4] + spacing[2] / 2;
174
175
176                 //MLER -- EED ??????????????????? 64,52,5
177                 origin[0] = 64;
178                 origin[1] = 52;
179                 origin[2] = 5;
180
181                 std::cout << "origin;0:" << origin[0]<< std::endl;
182                 std::cout << "origin 1:" << origin[1]<< std::endl;
183                 std::cout << "origin 2:" << origin[2]<< std::endl;
184
185
186                 m_Image->SetOrigin(origin);
187
188
189                 extrude->SetInput(m_Mesh1);
190                 extrude->SetScaleFactor(1);
191                 extrude->SetExtrusionTypeToNormalExtrusion();
192                 extrude->SetVector(0,0,1);
193                 extrude->Update();
194
195                 dataToStencil->SetTolerance(0);
196                 dataToStencil->SetInput(extrude->GetOutput());
197                 dataToStencil->SetOutputOrigin(origin);
198                 dataToStencil->SetOutputSpacing(spacing);
199                 dataToStencil->SetOutputWholeExtent(m_Image->GetExtent());
200                 dataToStencil->Update();
201
202                 imageStencil->SetInput(m_Image);
203                 imageStencil->SetStencil(dataToStencil->GetOutput());
204                 imageStencil->ReverseStencilOff();
205                 imageStencil->SetBackgroundValue(-200);
206                 imageStencil->Update();
207
208                 m_ResultImage = imageStencil->GetOutput();
209                 
210
211         }//i m_Mesh1 != Null
212         else{
213
214                 std::cout << "MLER cutImageSegmentation :: NO HAY MESH" << std::endl;
215
216         }//else if m_Mesh1
217
218         std::cout << "MLER cutImageSegmentation :: Process End" << std::endl;
219
220 }
221
222 //---------------------------------------------
223 //Method template
224 //---------------------------------------------
225 /*
226 void cutImageSegmentation::FunctionName(int& parameterA)
227 {
228   parameterA = 2 * parameterA;
229   return;
230 }
231 */
232