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()
54 void cutImageSegmentation::InitValues()
60 void cutImageSegmentation::Process()
62 std::cout << "MLER cutImageSegmentation :: Process Start()" << std::endl;
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();
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();
86 extrude->SetInput(m_Mesh1);
87 extrude->SetScaleFactor(1);
88 extrude->SetExtrusionTypeToNormalExtrusion();
89 extrude->SetVector(0,0,1);
92 extrude->Print(std::cout);
94 std::cout << "MLER cutImageSegmentation ---> polygonal data --> image stencil:" << std::endl;
96 //dataToStencil->SetTolerance(0);
97 dataToStencil->SetInput(extrude->GetOutput());
98 //dataToStencil->SetOutputSpacing(m_Image->GetSpacing());
99 //dataToStencil->SetOutputWholeExtent(m_Image->GetExtent());
100 //dataToStencil->Update();
102 dataToStencil->Print(std::cout);
104 imageStencil->SetInput(extract->GetOutput());
105 imageStencil->SetStencil(dataToStencil->GetOutput());
107 imageStencil->ReverseStencilOff();
108 imageStencil->SetBackgroundValue(128);
109 imageStencil->Update();
111 imageStencil->Print(std::cout);
113 m_ResultImage = imageStencil->GetOutput();
117 stripper->SetInput(m_Mesh1);
118 transformFilter->SetInput(stripper->GetOutput());
120 dataToStencil->SetOutputOrigin(m_Image->GetOrigin());
121 dataToStencil->SetOutputSpacing(m_Image->GetSpacing());
122 dataToStencil->SetOutputWholeExtent(m_Image->GetExtent());
124 dataToStencil->SetInput(transformFilter->GetOutput());
126 imageStencil->SetInput(m_Image);
127 imageStencil->SetStencil(dataToStencil->GetOutput());
128 imageStencil->Update();
130 m_ResultImage = imageStencil->GetOutput();
135 m_Mesh1->GetBounds(bounds);
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();
143 imageStencil->SetInput(m_Image);
144 imageStencil->SetStencil(dataToStencil->GetOutput());
145 imageStencil->ReverseStencilOff();
146 //imageStencil->SetBackgroundValue(100);
147 imageStencil->Update();
151 m_Mesh1->GetBounds(bounds);
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;
163 double *spacing = NULL;
164 spacing = m_Image->GetSpacing();
166 std::cout << "spacing 0:" << spacing[0]<< std::endl;
167 std::cout << "spacing 1:" << spacing[1]<< std::endl;
168 std::cout << "spacing 2:" << spacing[2]<< std::endl;
170 origin[0] = 63;//bounds[0];
171 origin[1] = 44;//bounds[2];
172 origin[2] = 4;//bounds[4];
174 std::cout << "origin;0:" << origin[0]<< std::endl;
175 std::cout << "origin 1:" << origin[1]<< std::endl;
176 std::cout << "origin 2:" << origin[2]<< std::endl;
179 m_Image->SetOrigin(origin);
182 extrude->SetInput(m_Mesh1);
183 extrude->SetScaleFactor(1);
184 extrude->SetExtrusionTypeToNormalExtrusion();
185 extrude->SetVector(0,0,1);
188 dataToStencil->SetTolerance(0);
189 dataToStencil->SetInput(extrude->GetOutput());
190 dataToStencil->SetOutputOrigin(origin);
191 dataToStencil->SetOutputSpacing(spacing);
192 dataToStencil->SetOutputWholeExtent(m_Image->GetExtent());
193 dataToStencil->Update();
195 imageStencil->SetInput(m_Image);
196 imageStencil->SetStencil(dataToStencil->GetOutput());
197 imageStencil->ReverseStencilOff();
198 imageStencil->SetBackgroundValue(0);
199 imageStencil->Update();
201 m_ResultImage = imageStencil->GetOutput();
207 std::cout << "MLER cutImageSegmentation :: NO HAY MESH" << std::endl;
211 std::cout << "MLER cutImageSegmentation :: Process End" << std::endl;
215 //---------------------------------------------
217 //---------------------------------------------
219 void cutImageSegmentation::FunctionName(int& parameterA)
221 parameterA = 2 * parameterA;