34 #ifndef __QGoContourLevelSetAlgo_h
35 #define __QGoContourLevelSetAlgo_h
41 #include "QGoGUILibConfigure.h"
42 #include "vtkSmartPointer.h"
43 #include "vtkPolyData.h"
44 #include "vtkImageData.h"
46 #include "vtkTransform.h"
47 #include "vtkTransformPolyDataFilter.h"
66 bool iIsInvertedOn =
false);
70 template <
class TPixel>
72 const std::vector<double>& iCenter,
73 typename itk::Image< TPixel, 3 >::Pointer iImages,
74 const unsigned int& iOrientation)
76 assert( iCenter.size() == 3);
78 const unsigned int ImageDimension = 3;
80 typedef TPixel PixelType;
81 typedef itk::Image< PixelType, ImageDimension > ImageType;
82 typedef typename ImageType::Pointer ImagePointer;
83 typedef itk::Image< PixelType, 2 > ImageType2D;
84 typedef typename ImageType2D::Pointer ImageType2DPointer;
89 std::vector< double > bounds( 2 * ImageDimension, 0. );
91 for(
unsigned int dim = 0; dim < ImageDimension; dim++ )
93 bounds[k++] = iCenter[dim] - 2. * radius;
94 bounds[k++] = iCenter[dim] + 2. * radius;
97 bounds[2*iOrientation] = iCenter[iOrientation];
98 bounds[2*iOrientation +1] = iCenter[iOrientation];
102 std::cout <<
"bounds: " << bounds[i] << std::endl;
106 ImageType2DPointer ITK_Slice_Image =
107 this->ITKExtractSlice<PixelType>( bounds, iImages );
119 ItkOutPut = Filter.GetOutput2D();
123 vtkImageData * FilterOutPutToVTK =
129 vtkPolyData* temp_output = this->
ExtractPolyData(FilterOutPutToVTK, 0.5);
133 double temp_bounds[6];
134 FilterOutPutToVTK->GetBounds( temp_bounds );
136 double temp_center[3];
137 temp_center[0] = ( temp_bounds[0] + temp_bounds[1] ) * 0.5;
138 temp_center[1] = ( temp_bounds[2] + temp_bounds[3] ) * 0.5;
139 temp_center[2] = ( temp_bounds[4] + temp_bounds[5] ) * 0.5;
141 vtkSmartPointer< vtkTransform > translation2 =
142 vtkSmartPointer< vtkTransform >::New();
144 translation2->Translate(-temp_center[0],
148 vtkSmartPointer< vtkTransformPolyDataFilter > mesh_transform2 =
149 vtkSmartPointer< vtkTransformPolyDataFilter >::New();
150 mesh_transform2->SetTransform(translation2);
151 mesh_transform2->SetInput( temp_output );
152 mesh_transform2->Update();
156 vtkSmartPointer< vtkTransform > translation =
157 vtkSmartPointer< vtkTransform >::New();
159 if(iOrientation == 0)
161 translation->RotateY(-90);
163 else if(iOrientation == 1)
165 translation->RotateX(-90);
167 else if(iOrientation == 2)
172 vtkSmartPointer< vtkTransformPolyDataFilter > mesh_transform =
173 vtkSmartPointer< vtkTransformPolyDataFilter >::New();
174 mesh_transform->SetTransform(translation);
175 mesh_transform->SetInput( mesh_transform2->GetOutput() );
176 mesh_transform->Update();
180 double temp_center2[3];
181 temp_center2[0] = ( bounds[0] + bounds[1] ) * 0.5;
182 temp_center2[1] = ( bounds[2] + bounds[3] ) * 0.5;
183 temp_center2[2] = ( bounds[4] + bounds[5] ) * 0.5;
185 vtkSmartPointer< vtkTransform > translation23 =
186 vtkSmartPointer< vtkTransform >::New();
188 translation23->Translate(temp_center2[0],
192 vtkSmartPointer< vtkTransformPolyDataFilter > mesh_transform23 =
193 vtkSmartPointer< vtkTransformPolyDataFilter >::New();
194 mesh_transform23->SetTransform(translation23);
195 mesh_transform23->SetInput( mesh_transform->GetOutput() );
196 mesh_transform23->Update();
201 vtkPolyData* mesh = vtkPolyData::New();
202 mesh->DeepCopy( mesh_transform23->GetOutput() );
204 temp_output->Delete();
Levelset segmentation algorithm implementation. Can generate contours and meshes. Will generate 2D ob...
Output2DType::Pointer Output2DPointer
~QGoContourLevelSetAlgo()
class to be the interface between the levelset algo for contours and GoFigure
QGoContourLevelSetAlgo(std::vector< vtkPoints * > *iSeeds, QWidget *iParent=0)
void Apply2DFilter(typename itk::Image< TPixel, 2 >::Pointer iITKInput, const std::vector< double > &iCenter, const double &iRadius, const int &iIterations, const int &iCurvature)
std::vector< vtkPolyData * > ExtractPolyData(std::vector< vtkImageData * > &iInputImage, const double &iThreshold)
vtkPolyData * ApplyLevelSetFilter(const std::vector< double > &iCenter, typename itk::Image< TPixel, 3 >::Pointer iImages, const unsigned int &iOrientation)
QGoAlgoParameter< double > * m_Radius
QGoAlgoParameter< int > * m_Iterations
std::vector< vtkPolyData * > ApplyAlgo(GoImageProcessor *iImages, std::string iChannel, bool iIsInvertedOn=false)
return the vtkpolydata created by the algorithm
class to be the interface between the levelset algo for meshes, contours and set of contours and GoFi...
QGoAlgoParameter< int > * m_Curvature
Interface between image reader and vtkImageData.
vtkImageData * ConvertITK2VTK(typename itk::Image< PixelType, VImageDimension >::Pointer iInput)