1 /*=========================================================================
2 Program: vv http://www.creatis.insa-lyon.fr/rio/vv
5 - University of LYON http://www.universite-lyon.fr/
6 - Léon Bérard cancer center http://www.centreleonberard.fr
7 - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr
9 This software is distributed WITHOUT ANY WARRANTY; without even
10 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11 PURPOSE. See the copyright notices for more information.
13 It is distributed under dual licence
15 - BSD See included LICENSE.txt file
16 - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ======================================================================-====*/
20 //--------------------------------------------------------------------
21 template <class ImageType>
22 clitk::BinaryImageToMeshFilter<ImageType>::
23 BinaryImageToMeshFilter():itk::Object()
25 m_ThresholdValue = 0.5; // (for image with 0=background and 1=foreground)
27 //--------------------------------------------------------------------
30 //--------------------------------------------------------------------
31 template <class ImageType>
33 clitk::BinaryImageToMeshFilter<ImageType>::
36 // Convert itk image into vtk image
37 const ImageType * im = this->GetInput();
38 typedef itk::ImageToVTKImageFilter<ImageType> ConvertType;
39 typename ConvertType::Pointer convert = ConvertType::New();
40 convert->SetInput(im);
42 vtkImageData * input_vtk = convert->GetOutput();
45 vtkSmartPointer<vtkImageClip> clipper = vtkSmartPointer<vtkImageClip>::New();
46 #if VTK_MAJOR_VERSION <= 5
47 clipper->SetInput(input_vtk);
49 clipper->SetInputData(input_vtk);
51 int* extent = input_vtk->GetExtent();
54 vtkSmartPointer<vtkAppendPolyData> append = vtkSmartPointer<vtkAppendPolyData>::New();
55 uint n = input_vtk->GetDimensions()[2];
56 // std::vector<vtkSmartPointer<vtkPolyData> > contours;
57 for(uint i=0; i<n; i++) {
58 vtkSmartPointer<vtkMarchingSquares> squares = vtkSmartPointer<vtkMarchingSquares>::New();
59 #if VTK_MAJOR_VERSION <= 5
60 squares->SetInput(input_vtk);
62 squares->SetInputData(input_vtk);
64 squares->SetImageRange(extent[0], extent[1], extent[2], extent[3], i, i);
65 squares->SetNumberOfContours(1);
66 squares->SetValue(0, m_ThresholdValue);
68 vtkSmartPointer<vtkPolyData> m = squares->GetOutput();
71 vtkSmartPointer<vtkStripper> vs = vtkSmartPointer<vtkStripper>::New();
72 #if VTK_MAJOR_VERSION <= 5
73 vs->SetInput(squares->GetOutput());
75 vs->SetInputData(squares->GetOutput());
81 if (false) { // FIXME (do not work)
82 vtkSmartPointer<vtkDecimatePro> psurface = vtkDecimatePro::New();
83 psurface->SetInputConnection(squares->GetOutputPort());
84 psurface->SetTargetReduction(0.5);
86 m = psurface->GetOutput();
89 // only add if lines>0
90 if (m->GetNumberOfLines() > 0) {
91 #if VTK_MAJOR_VERSION <= 5
92 append->AddInput(m);//contours[i]);
94 append->AddInputData(m);//contours[i]);
100 m_OutputMesh = vtkSmartPointer<vtkPolyData>::New();
101 m_OutputMesh->DeepCopy(append->GetOutput());
103 //--------------------------------------------------------------------