]> Creatis software - clitk.git/blobdiff - itk/clitkBinaryImageToMeshFilter.txx
Ensure compatibility with newer version of VTK9
[clitk.git] / itk / clitkBinaryImageToMeshFilter.txx
index 9ffe4a204cfd62e5722b0027ec57de3ddbff981a..b242dcf81d744ae675762389bdb45594b63edcc3 100644 (file)
 //--------------------------------------------------------------------
 template <class ImageType>
 clitk::BinaryImageToMeshFilter<ImageType>::
-BinaryImageToMeshFilter()//:ProcessObject()
+BinaryImageToMeshFilter():itk::Object()
 {
-  DD("BinaryImageToMeshFilter constructor");
-  // this->ProcessObject::SetNumberOfRequiredInputs(1);
-  // this->ProcessObject::SetNumberOfRequiredOutputs(1);
-
-  // //m_OutputMesh = vtkPolyData::New();
-
-  // this->ProcessObject::SetNumberOfRequiredOutputs(1);
-  // itk::DataObject::Pointer a = itk::DataObject::New();
-  // this->ProcessObject::SetNthOutput( 0, a);
+  m_ThresholdValue = 0.5; // (for image with 0=background and 1=foreground) 
 }
 //--------------------------------------------------------------------
 
 
-//--------------------------------------------------------------------
-/*template <class ImageType>
-  void 
-  clitk::BinaryImageToMeshFilter<ImageType>::
-  GenerateOutputInformation() 
-  {
-  DD("GenerateOutputInformation");
-  // ImagePointer output = this->GetOutput(0);
-  
-  // // Set the region to output
-  // typename ImageType::RegionType m_Region = m_LikeImage->GetLargestPossibleRegion();
-  // typename ImageType::SizeType size = m_Region.GetSize();
-  // size[0]++;
-  // size[1]++;
-  // size[2]++;
-  // m_Region.SetSize(size);  
-  // output->SetLargestPossibleRegion(m_Region);
-  // output->SetRequestedRegion(m_Region);
-  // output->SetBufferedRegion(m_Region);
-  // output->SetRegions(m_Region);
-  // output->Allocate();
-  }
-*/
-//--------------------------------------------------------------------
-
-
-// template <class ImageType>
-// void
-// clitk::BinaryImageToMeshFilter<ImageType>::
-// SetInput(unsigned int idx, const ImageType *input)
-// {
-//   DD(idx);
-//   // process object is not const-correct, the const_cast
-//   // is required here.
-//   this->ProcessObject::SetNthInput( idx,
-//                                     const_cast< ImageType * >( input ) );
-//   DD("end");
-// }
-
-// template <class ImageType>
-// const ImageType *
-// clitk::BinaryImageToMeshFilter<ImageType>::
-// GetInput(unsigned int idx)
-// {
-//   DD("GetInput");
-//   DD(idx);
-//   return dynamic_cast< const ImageType * >
-//          ( this->ProcessObject::GetInput(idx) );
-// }
-
-
 //--------------------------------------------------------------------
 template <class ImageType>
 void
 clitk::BinaryImageToMeshFilter<ImageType>::
 Update()
-//GenerateOutputInformation()
 {
-  DD("Update");
-
   // Convert itk image into vtk image
   const ImageType * im = this->GetInput();
   typedef itk::ImageToVTKImageFilter<ImageType> ConvertType;
@@ -105,90 +43,62 @@ Update()
   
   // Get extend
   vtkSmartPointer<vtkImageClip> clipper = vtkSmartPointer<vtkImageClip>::New();
+#if VTK_MAJOR_VERSION <= 5
   clipper->SetInput(input_vtk);
+#else
+  clipper->SetInputData(input_vtk);
+#endif
   int* extent = input_vtk->GetExtent();
-  DDV(extent, 6);
 
   // Loop on slices
   vtkSmartPointer<vtkAppendPolyData> append = vtkSmartPointer<vtkAppendPolyData>::New();
   uint n = input_vtk->GetDimensions()[2];
-  DD(n);
-  std::vector<vtkSmartPointer<vtkPolyData> > contours;
+  // std::vector<vtkSmartPointer<vtkPolyData> > contours;
   for(uint i=0; i<n; i++) {
-    DD(i);
-    // FIXME     vtkDiscreteMarchingCubes INSTEAD ?
     vtkSmartPointer<vtkMarchingSquares> squares = vtkSmartPointer<vtkMarchingSquares>::New();
+#if VTK_MAJOR_VERSION <= 5
     squares->SetInput(input_vtk);
+#else
+    squares->SetInputData(input_vtk);
+#endif
     squares->SetImageRange(extent[0], extent[1], extent[2], extent[3], i, i);
     squares->SetNumberOfContours(1);
-    squares->SetValue(0, 0.5); // FIXME background (?)
-    squares->Update();
-    // DD(squares->GetNumberOfContours());
-    
+    squares->SetValue(0, m_ThresholdValue);
+    squares->Update();    
     vtkSmartPointer<vtkPolyData> m = squares->GetOutput();
 
-    DD(m->GetMaxCellSize());
-    DD(m->GetNumberOfVerts());
-    DD(m->GetNumberOfLines());
-    DD(m->GetNumberOfPolys());
-    DD(m->GetNumberOfStrips());
+    // Strip (needed)
+    vtkSmartPointer<vtkStripper> vs = vtkSmartPointer<vtkStripper>::New();
+#if VTK_MAJOR_VERSION <= 5
+    vs->SetInput(squares->GetOutput());
+#else
+    vs->SetInputData(squares->GetOutput());
+#endif
+    vs->Update();
+    m = vs->GetOutput();
 
     // Decimate
-    if (false) { // FIXME
+    if (false) { // FIXME (do not work)
       vtkSmartPointer<vtkDecimatePro> psurface = vtkDecimatePro::New();
       psurface->SetInputConnection(squares->GetOutputPort());
       psurface->SetTargetReduction(0.5);
       psurface->Update();
       m = psurface->GetOutput();
     }
-    if (true) {
-      vtkSmartPointer<vtkStripper> vs = vtkSmartPointer<vtkStripper>::New();
-      vs->SetInput(squares->GetOutput());
-      vs->Update();
-      m = vs->GetOutput();
-    }
-    
-    //vtkSmartPointer<vtkPolyData> m = squares->GetOutput();
-    contours.push_back(m);
-    DD(m->GetMaxCellSize());
-    DD(m->GetNumberOfVerts());
-    DD(m->GetNumberOfLines());
-    DD(m->GetNumberOfPolys());
-    DD(m->GetNumberOfStrips());
-    // m->Print(std::cout);
 
-    // FIXME : only add if lines>0
+    // only add if lines>0
     if (m->GetNumberOfLines() > 0) {
-      append->AddInput(contours[i]);
+#if VTK_MAJOR_VERSION <= 5
+      append->AddInput(m);//contours[i]);
+#else
+      append->AddInputData(m);//contours[i]);
+#endif
     }
   }
-  DD("done");
-  DD("now append");
-  // for(unsigned int i=0; i<n; i++) {
-  //   append->AddInput(contours[i]);
-  // }
   append->Update();
   
-  DD(" copy");
   m_OutputMesh = vtkSmartPointer<vtkPolyData>::New();
   m_OutputMesh->DeepCopy(append->GetOutput());
-
-  /* // NO (3D)
-  vtkSmartPointer<vtkContourFilter> pcontour = vtkContourFilter::New();
-  pcontour->SetValue(0, 0.5);
-  pcontour->SetInput(input_vtk);
-  pcontour->Update();
-  // vtkAlgorithmOutput *data = pcontour->GetOutputPort();
-  // vtkSmartPointer<vtkPolyDataMapper> skinMapper = vtkPolyDataMapper::New();
-  // skinMapper->SetInputConnection(data); //psurface->GetOutputPort()
-  // skinMapper->ScalarVisibilityOff();
-  m_OutputMesh = pcontour->GetOutput();//data
-  */
-
-  DD("end");
-  int a=12;
-  DD("erelre");
 }
 //--------------------------------------------------------------------