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()//:ProcessObject()
25 DD("BinaryImageToMeshFilter constructor");
26 // this->ProcessObject::SetNumberOfRequiredInputs(1);
27 // this->ProcessObject::SetNumberOfRequiredOutputs(1);
29 // //m_OutputMesh = vtkPolyData::New();
31 // this->ProcessObject::SetNumberOfRequiredOutputs(1);
32 // itk::DataObject::Pointer a = itk::DataObject::New();
33 // this->ProcessObject::SetNthOutput( 0, a);
35 //--------------------------------------------------------------------
38 //--------------------------------------------------------------------
39 /*template <class ImageType>
41 clitk::BinaryImageToMeshFilter<ImageType>::
42 GenerateOutputInformation()
44 DD("GenerateOutputInformation");
45 // ImagePointer output = this->GetOutput(0);
47 // // Set the region to output
48 // typename ImageType::RegionType m_Region = m_LikeImage->GetLargestPossibleRegion();
49 // typename ImageType::SizeType size = m_Region.GetSize();
53 // m_Region.SetSize(size);
54 // output->SetLargestPossibleRegion(m_Region);
55 // output->SetRequestedRegion(m_Region);
56 // output->SetBufferedRegion(m_Region);
57 // output->SetRegions(m_Region);
58 // output->Allocate();
61 //--------------------------------------------------------------------
64 // template <class ImageType>
66 // clitk::BinaryImageToMeshFilter<ImageType>::
67 // SetInput(unsigned int idx, const ImageType *input)
70 // // process object is not const-correct, the const_cast
71 // // is required here.
72 // this->ProcessObject::SetNthInput( idx,
73 // const_cast< ImageType * >( input ) );
77 // template <class ImageType>
79 // clitk::BinaryImageToMeshFilter<ImageType>::
80 // GetInput(unsigned int idx)
84 // return dynamic_cast< const ImageType * >
85 // ( this->ProcessObject::GetInput(idx) );
89 //--------------------------------------------------------------------
90 template <class ImageType>
92 clitk::BinaryImageToMeshFilter<ImageType>::
94 //GenerateOutputInformation()
98 // Convert itk image into vtk image
99 const ImageType * im = this->GetInput();
100 typedef itk::ImageToVTKImageFilter<ImageType> ConvertType;
101 typename ConvertType::Pointer convert = ConvertType::New();
102 convert->SetInput(im);
104 vtkImageData * input_vtk = convert->GetOutput();
107 vtkSmartPointer<vtkImageClip> clipper = vtkSmartPointer<vtkImageClip>::New();
108 clipper->SetInput(input_vtk);
109 int* extent = input_vtk->GetExtent();
113 vtkSmartPointer<vtkAppendPolyData> append = vtkSmartPointer<vtkAppendPolyData>::New();
114 uint n = input_vtk->GetDimensions()[2];
116 std::vector<vtkSmartPointer<vtkPolyData> > contours;
117 for(uint i=0; i<n; i++) {
119 // FIXME vtkDiscreteMarchingCubes INSTEAD ?
120 vtkSmartPointer<vtkMarchingSquares> squares = vtkSmartPointer<vtkMarchingSquares>::New();
121 squares->SetInput(input_vtk);
122 squares->SetImageRange(extent[0], extent[1], extent[2], extent[3], i, i);
123 squares->SetNumberOfContours(1);
124 squares->SetValue(0, 0.5); // FIXME background (?)
126 // DD(squares->GetNumberOfContours());
128 vtkSmartPointer<vtkPolyData> m = squares->GetOutput();
130 DD(m->GetMaxCellSize());
131 DD(m->GetNumberOfVerts());
132 DD(m->GetNumberOfLines());
133 DD(m->GetNumberOfPolys());
134 DD(m->GetNumberOfStrips());
137 if (false) { // FIXME
138 vtkSmartPointer<vtkDecimatePro> psurface = vtkDecimatePro::New();
139 psurface->SetInputConnection(squares->GetOutputPort());
140 psurface->SetTargetReduction(0.5);
142 m = psurface->GetOutput();
145 vtkSmartPointer<vtkStripper> vs = vtkSmartPointer<vtkStripper>::New();
146 vs->SetInput(squares->GetOutput());
151 //vtkSmartPointer<vtkPolyData> m = squares->GetOutput();
152 contours.push_back(m);
153 DD(m->GetMaxCellSize());
154 DD(m->GetNumberOfVerts());
155 DD(m->GetNumberOfLines());
156 DD(m->GetNumberOfPolys());
157 DD(m->GetNumberOfStrips());
158 // m->Print(std::cout);
160 // FIXME : only add if lines>0
161 if (m->GetNumberOfLines() > 0) {
162 append->AddInput(contours[i]);
168 // for(unsigned int i=0; i<n; i++) {
169 // append->AddInput(contours[i]);
174 m_OutputMesh = vtkSmartPointer<vtkPolyData>::New();
175 m_OutputMesh->DeepCopy(append->GetOutput());
178 vtkSmartPointer<vtkContourFilter> pcontour = vtkContourFilter::New();
179 pcontour->SetValue(0, 0.5);
180 pcontour->SetInput(input_vtk);
182 // vtkAlgorithmOutput *data = pcontour->GetOutputPort();
183 // vtkSmartPointer<vtkPolyDataMapper> skinMapper = vtkPolyDataMapper::New();
184 // skinMapper->SetInputConnection(data); //psurface->GetOutputPort()
185 // skinMapper->ScalarVisibilityOff();
186 m_OutputMesh = pcontour->GetOutput();//data
193 //--------------------------------------------------------------------