]> 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 void cutImageSegmentation::InitValues()
55 {
56
57         
58 }
59
60 void cutImageSegmentation::Process()
61 {
62         std::cout << "MLER cutImageSegmentation :: Process Start()" << std::endl;
63
64         if(m_Mesh1 != NULL)
65         {
66                 
67                 vtkLinearExtrusionFilter        *extrude                = vtkLinearExtrusionFilter::New();
68                 vtkPolyDataToImageStencil       *dataToStencil  = vtkPolyDataToImageStencil::New();
69                 vtkImageStencil                         *imageStencil   = vtkImageStencil::New();
70                 //vtkExtractVOI                         *extract                = vtkExtractVOI::New();
71                 vtkAppendPolyData                       *append                 = vtkAppendPolyData::New();
72                 //vtkTriangleFilter                     *triangleFilter = vtkTriangleFilter::New();
73                 vtkStripper                                     *stripper       = vtkStripper::New();
74                 vtkTransformPolyDataFilter  *transformFilter= vtkTransformPolyDataFilter::New();
75
76                 double bounds[6];
77
78                 //vtkPolyDataToImageStencil* stencil = vtkPolyDataToImageStencil::New();
79                 /* Test # 1 Cod Python
80                 extract->SetVOI( 0, 128, 0, 104, 0, 9);
81                 extract->SetSampleRate(1, 1, 1);
82                 extract->SetInput(m_Image);
83                 extract->ReleaseDataFlagOff();
84                 
85
86                 extrude->SetInput(m_Mesh1);
87                 extrude->SetScaleFactor(1);
88                 extrude->SetExtrusionTypeToNormalExtrusion();
89                 extrude->SetVector(0,0,1);
90                 //extrude->Update();
91                 
92                 extrude->Print(std::cout);
93
94                 std::cout << "MLER cutImageSegmentation ---> polygonal data --> image stencil:" << std::endl;
95
96                 //dataToStencil->SetTolerance(0);
97                 dataToStencil->SetInput(extrude->GetOutput());
98                 //dataToStencil->SetOutputSpacing(m_Image->GetSpacing());
99                 //dataToStencil->SetOutputWholeExtent(m_Image->GetExtent());
100                 //dataToStencil->Update();
101
102                 dataToStencil->Print(std::cout);
103
104                 imageStencil->SetInput(extract->GetOutput());
105                 imageStencil->SetStencil(dataToStencil->GetOutput());
106
107                 imageStencil->ReverseStencilOff();
108                 imageStencil->SetBackgroundValue(128);
109                 imageStencil->Update();
110                 
111                 imageStencil->Print(std::cout);
112                 
113                 m_ResultImage = imageStencil->GetOutput();
114                 */
115
116                 /*Test #2
117                 stripper->SetInput(m_Mesh1);
118                 transformFilter->SetInput(stripper->GetOutput());
119                 
120                 dataToStencil->SetOutputOrigin(m_Image->GetOrigin());
121                 dataToStencil->SetOutputSpacing(m_Image->GetSpacing());
122                 dataToStencil->SetOutputWholeExtent(m_Image->GetExtent());
123
124                 dataToStencil->SetInput(transformFilter->GetOutput());
125
126                 imageStencil->SetInput(m_Image);
127                 imageStencil->SetStencil(dataToStencil->GetOutput());
128                 imageStencil->Update();
129
130                 m_ResultImage = imageStencil->GetOutput();
131                 */
132
133                 //Test 3
134                 /*
135                 m_Mesh1->GetBounds(bounds);
136
137                 dataToStencil->SetInput(m_Mesh1);
138                 dataToStencil->SetOutputOrigin(m_Image->GetOrigin());
139                 dataToStencil->SetOutputSpacing(m_Image->GetSpacing());
140                 dataToStencil->SetOutputWholeExtent(m_Image->GetExtent());
141                 dataToStencil->Update();
142
143                 imageStencil->SetInput(m_Image);
144                 imageStencil->SetStencil(dataToStencil->GetOutput());
145                 imageStencil->ReverseStencilOff();
146                 //imageStencil->SetBackgroundValue(100);
147                 imageStencil->Update();
148                 */
149
150                 //Test 4
151                 m_Mesh1->GetBounds(bounds);
152
153                 std::cout << "bounds 0:" << bounds[0]<< std::endl;
154                 std::cout << "bounds 1:" << bounds[1]<< std::endl;
155                 std::cout << "bounds 2:" << bounds[2]<< std::endl;
156                 std::cout << "bounds 3:" << bounds[3]<< std::endl;
157                 std::cout << "bounds 4:" << bounds[4]<< std::endl;
158                 std::cout << "bounds 5:" << bounds[5]<< std::endl;
159
160
161
162                 double origin[3];
163                 //double *spacing = NULL;
164                 //spacing = m_Image->GetSpacing();
165
166                 double spacing[3];
167                 spacing[0] = 2.62565;
168                 spacing[1] = 2.62565;
169                 spacing[2] = 6.25;
170  
171
172                 std::cout << "spacing 0:" << spacing[0]<< std::endl;
173                 std::cout << "spacing 1:" << spacing[1]<< std::endl;
174                 std::cout << "spacing 2:" << spacing[2]<< std::endl;
175
176                 //origin[0] = bounds[0] + spacing[0] / 2;
177                 //origin[1] = bounds[2] + spacing[1] / 2;
178                 //origin[2] = bounds[4] + spacing[2] / 2;
179
180
181                 //MLER -- EED ??????????????????? 64,52,5
182                 origin[0] = 64;
183                 origin[1] = 52;
184                 origin[2] = 5;
185
186                 std::cout << "origin;0:" << origin[0]<< std::endl;
187                 std::cout << "origin 1:" << origin[1]<< std::endl;
188                 std::cout << "origin 2:" << origin[2]<< std::endl;
189
190
191                 m_Image->SetOrigin(origin);
192
193
194                 extrude->SetInput(m_Mesh1);
195                 extrude->SetScaleFactor(1);
196                 extrude->SetExtrusionTypeToNormalExtrusion();
197                 extrude->SetVector(0,0,1);
198                 extrude->Update();
199
200                 dataToStencil->SetTolerance(0);
201                 dataToStencil->SetInput(extrude->GetOutput());
202                 dataToStencil->SetOutputOrigin(origin);
203                 dataToStencil->SetOutputSpacing(spacing);
204                 dataToStencil->SetOutputWholeExtent(m_Image->GetExtent());
205                 dataToStencil->Update();
206
207                 imageStencil->SetInput(m_Image);
208                 imageStencil->SetStencil(dataToStencil->GetOutput());
209                 imageStencil->ReverseStencilOff();
210                 imageStencil->SetBackgroundValue(-200);
211                 imageStencil->Update();
212
213                 m_ResultImage = imageStencil->GetOutput();
214                 
215
216         }//i m_Mesh1 != Null
217         else{
218
219                 std::cout << "MLER cutImageSegmentation :: NO HAY MESH" << std::endl;
220
221         }//else if m_Mesh1
222
223         std::cout << "MLER cutImageSegmentation :: Process End" << std::endl;
224
225 }
226
227 //---------------------------------------------
228 //Method template
229 //---------------------------------------------
230 /*
231 void cutImageSegmentation::FunctionName(int& parameterA)
232 {
233   parameterA = 2 * parameterA;
234   return;
235 }
236 */
237