2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
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
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.
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
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 # ------------------------------------------------------------------------
28 #include "cutImageSegmentation.h"
30 cutImageSegmentation::cutImageSegmentation()
34 cutImageSegmentation::~cutImageSegmentation()
38 void cutImageSegmentation::SetAnglesImage( vtkImageData* image )
40 this->m_Image = image;
43 void cutImageSegmentation::SetMesh1(vtkPolyData* mesh)
49 cutImageSegmentation::GetResultImage()
55 void cutImageSegmentation::Process()
57 std::cout << "MLER cutImageSegmentation :: Process Start()" << std::endl;
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();
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();
81 extrude->SetInput(m_Mesh1);
82 extrude->SetScaleFactor(1);
83 extrude->SetExtrusionTypeToNormalExtrusion();
84 extrude->SetVector(0,0,1);
87 extrude->Print(std::cout);
89 std::cout << "MLER cutImageSegmentation ---> polygonal data --> image stencil:" << std::endl;
91 //dataToStencil->SetTolerance(0);
92 dataToStencil->SetInput(extrude->GetOutput());
93 //dataToStencil->SetOutputSpacing(m_Image->GetSpacing());
94 //dataToStencil->SetOutputWholeExtent(m_Image->GetExtent());
95 //dataToStencil->Update();
97 dataToStencil->Print(std::cout);
99 imageStencil->SetInput(extract->GetOutput());
100 imageStencil->SetStencil(dataToStencil->GetOutput());
102 imageStencil->ReverseStencilOff();
103 imageStencil->SetBackgroundValue(128);
104 imageStencil->Update();
106 imageStencil->Print(std::cout);
108 m_ResultImage = imageStencil->GetOutput();
112 stripper->SetInput(m_Mesh1);
113 transformFilter->SetInput(stripper->GetOutput());
115 dataToStencil->SetOutputOrigin(m_Image->GetOrigin());
116 dataToStencil->SetOutputSpacing(m_Image->GetSpacing());
117 dataToStencil->SetOutputWholeExtent(m_Image->GetExtent());
119 dataToStencil->SetInput(transformFilter->GetOutput());
121 imageStencil->SetInput(m_Image);
122 imageStencil->SetStencil(dataToStencil->GetOutput());
123 imageStencil->Update();
125 m_ResultImage = imageStencil->GetOutput();
130 m_Mesh1->GetBounds(bounds);
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();
138 imageStencil->SetInput(m_Image);
139 imageStencil->SetStencil(dataToStencil->GetOutput());
140 imageStencil->ReverseStencilOff();
141 //imageStencil->SetBackgroundValue(100);
142 imageStencil->Update();
146 m_Mesh1->GetBounds(bounds);
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;
158 //double *spacing = NULL;
159 //spacing = m_Image->GetSpacing();
162 spacing[0] = 2.62565;
163 spacing[1] = 2.62565;
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;
171 //origin[0] = bounds[0] + spacing[0] / 2;
172 //origin[1] = bounds[2] + spacing[1] / 2;
173 //origin[2] = bounds[4] + spacing[2] / 2;
176 //MLER -- EED ??????????????????? 64,52,5
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;
186 m_Image->SetOrigin(origin);
189 //EED 2017-01-01 Migration VTK7
190 #if VTK_MAJOR_VERSION <= 5
191 extrude->SetInput(m_Mesh1);
193 extrude->SetInputData(m_Mesh1);
195 extrude->SetScaleFactor(1);
196 extrude->SetExtrusionTypeToNormalExtrusion();
197 extrude->SetVector(0,0,1);
200 dataToStencil->SetTolerance(0);
201 //EED 2017-01-01 Migration VTK7
202 #if VTK_MAJOR_VERSION <= 5
203 dataToStencil->SetInput(extrude->GetOutput());
205 dataToStencil->SetInputData(extrude->GetOutput());
207 dataToStencil->SetOutputOrigin(origin);
208 dataToStencil->SetOutputSpacing(spacing);
209 dataToStencil->SetOutputWholeExtent(m_Image->GetExtent());
210 dataToStencil->Update();
212 //EED 2017-01-01 Migration VTK7
213 #if VTK_MAJOR_VERSION <= 5
214 imageStencil->SetInput(m_Image);
215 imageStencil->SetStencil(dataToStencil->GetOutput());
217 imageStencil->SetInputData(m_Image);
218 imageStencil->SetStencilData(dataToStencil->GetOutput());
220 imageStencil->ReverseStencilOff();
221 imageStencil->SetBackgroundValue(-200);
222 imageStencil->Update();
224 m_ResultImage = imageStencil->GetOutput();
230 std::cout << "MLER cutImageSegmentation :: MESH NOT EXIST" << std::endl;
234 std::cout << "MLER cutImageSegmentation :: Process End" << std::endl;
238 //---------------------------------------------
240 //---------------------------------------------
242 void cutImageSegmentation::FunctionName(int& parameterA)
244 parameterA = 2 * parameterA;