34 #ifndef __QGoSetOfContoursWaterShedAlgo_h
35 #define __QGoSetOfContoursWaterShedAlgo_h
38 #include "vtkSmartPointer.h"
39 #include "vtkPolyData.h"
40 #include "vtkImageData.h"
41 #include "vtkTransform.h"
42 #include "vtkTransformPolyDataFilter.h"
48 #include "QGoGUILibConfigure.h"
52 #include "vtkPolyDataMapper.h"
54 #include "vtkRenderer.h"
55 #include "vtkRenderWindow.h"
56 #include "vtkRenderWindowInteractor.h"
57 #include "itkImageFileWriter.h"
60 #include "vtkPointData.h"
82 bool iIsInvertedOn =
false);
91 template <
class TPixel >
96 const std::vector<double>& iCenter,
97 typename itk::Image< TPixel, 3 >::Pointer iImages,
98 const unsigned int& iOrientation)
100 assert( iCenter.size() == 3);
102 const unsigned int ImageDimension = 3;
104 typedef TPixel PixelType;
105 typedef itk::Image< PixelType, ImageDimension > ImageType;
106 typedef typename ImageType::Pointer ImagePointer;
107 typedef itk::Image< PixelType, 2 > ImageType2D;
108 typedef typename ImageType2D::Pointer ImageType2DPointer;
109 typedef typename ImageType::SpacingType ImageSpacingType;
111 std::vector<vtkPolyData*> output;
113 ImageSpacingType spacing = iImages->GetSpacing();
120 std::vector< double > bounds( 2 * ImageDimension, 0. );
122 for(
unsigned int dim = 0; dim < ImageDimension; dim++ )
124 bounds[k++] = iCenter[dim] - 2. * radius;
125 bounds[k++] = iCenter[dim] + 2. * radius;
128 int pair = i+ i%2 -1;
134 bounds[2*iOrientation] =
135 iCenter[iOrientation] + (pair*(pow(-1., static_cast<int>(i) ) )*spacing[iOrientation]);
136 bounds[2*iOrientation +1] =
137 iCenter[iOrientation] + (pair*(pow(-1., static_cast<int>(i) ) )*spacing[iOrientation]);
140 ImageType2DPointer ITK_Slice_Image =
141 this->ITKExtractSlice<PixelType>( bounds, iImages );
154 ItkOutPut = Filter.GetOutput2D();
158 vtkImageData * FilterOutPutToVTK =
164 vtkPolyData* temp_output = this->
ExtractPolyData(FilterOutPutToVTK, 0.5);
168 double temp_bounds[6];
169 FilterOutPutToVTK->GetBounds( temp_bounds );
171 double temp_center[3];
172 temp_center[0] = ( temp_bounds[0] + temp_bounds[1] ) * 0.5;
173 temp_center[1] = ( temp_bounds[2] + temp_bounds[3] ) * 0.5;
174 temp_center[2] = ( temp_bounds[4] + temp_bounds[5] ) * 0.5;
176 vtkSmartPointer< vtkTransform > translation2 =
177 vtkSmartPointer< vtkTransform >::New();
179 translation2->Translate(-temp_center[0],
183 vtkSmartPointer< vtkTransformPolyDataFilter > mesh_transform2 =
184 vtkSmartPointer< vtkTransformPolyDataFilter >::New();
185 mesh_transform2->SetTransform(translation2);
186 mesh_transform2->SetInput( temp_output );
187 mesh_transform2->Update();
191 vtkSmartPointer< vtkTransform > translation =
192 vtkSmartPointer< vtkTransform >::New();
194 if(iOrientation == 0)
196 translation->RotateY(-90);
198 else if(iOrientation == 1)
200 translation->RotateX(-90);
202 else if(iOrientation == 2)
207 vtkSmartPointer< vtkTransformPolyDataFilter > mesh_transform =
208 vtkSmartPointer< vtkTransformPolyDataFilter >::New();
209 mesh_transform->SetTransform(translation);
210 mesh_transform->SetInput( mesh_transform2->GetOutput() );
211 mesh_transform->Update();
215 double temp_center2[3];
216 temp_center2[0] = ( bounds[0] + bounds[1] ) * 0.5;
217 temp_center2[1] = ( bounds[2] + bounds[3] ) * 0.5;
218 temp_center2[2] = ( bounds[4] + bounds[5] ) * 0.5;
220 vtkSmartPointer< vtkTransform > translation23 =
221 vtkSmartPointer< vtkTransform >::New();
223 translation23->Translate(temp_center2[0],
227 vtkSmartPointer< vtkTransformPolyDataFilter > mesh_transform23 =
228 vtkSmartPointer< vtkTransformPolyDataFilter >::New();
229 mesh_transform23->SetTransform(translation23);
230 mesh_transform23->SetInput( mesh_transform->GetOutput() );
231 mesh_transform23->Update();
235 temp_output->Delete();
237 vtkPolyData* testt = vtkPolyData::New();
238 testt->DeepCopy(mesh_transform23->GetOutput());
240 output.push_back(testt);
QGoAlgoParameter< double > * m_Beta
~QGoSetOfContoursWaterShedAlgo()
QGoSetOfContoursWaterShedAlgo(std::vector< vtkPoints * > *iSeeds, int iMaxThreshold, QWidget *iParent=0)
QGoAlgoParameter< int > * m_ThresMin
QGoAlgoParameter< int > * m_ThresMax
std::vector< std::vector< vtkPolyData * > > ApplyAlgoSeveralSeeds(GoImageProcessor *iImages, std::string iChannel)
std::vector< vtkPolyData * > ExtractPolyData(std::vector< vtkImageData * > &iInputImage, const double &iThreshold)
QGoAlgoParameter< double > * m_CorrThres
QGoAlgoParameter< double > * m_Radius
std::vector< vtkPolyData * > ApplyWaterShedFilter(const std::vector< double > &iCenter, typename itk::Image< TPixel, 3 >::Pointer iImages, const unsigned int &iOrientation)
class to be the interface between the watershed algo for set of contours and GoFigure ...
QGoAlgoParameter< int > * m_Sampling
void Apply2DFilter(typename itk::Image< TPixel, 2 >::Pointer iITKInput, const int &iThresMin, const int &iThresMax, const double &iCorrTresh, const double &iAlpha, const double &iBeta)
std::vector< vtkPolyData * > ApplyAlgo(GoImageProcessor *iImages, std::string iChannel, bool iIsInvertedOn=false)
return the vtkpolydata created by the algorithm
QGoAlgoParameter< double > * m_Alpha
Output2DType::Pointer Output2DPointer
Watershed segmentation algorithm implementation. Can generate contours and meshes. Will generate 2D objects if m_Dimension<2, 3D objects in the other case.
Interface between image reader and vtkImageData.
vtkImageData * ConvertITK2VTK(typename itk::Image< PixelType, VImageDimension >::Pointer iInput)
class to be the interface between the watershed algo for meshes and GoFigure