+
+
+//--------------------------------------------------------------------
+void clitk::DicomRT_ROI::ComputeContoursFromImage()
+{
+ DD("ComputeMeshFromImage");
+
+ // Check that an image is loaded
+ if (!mImage) return;
+
+ // Only consider 3D here
+ if (mImage->GetNumberOfDimensions() != 3) {
+ FATAL("DicomRT_ROI::ComputeMeshFromImage only work with 3D images");
+ }
+
+ // Get the VTK image
+ vtkImageData * image = mImage->GetVTKImages()[0];
+
+ // Get initial extend for the clipping
+ vtkSmartPointer<vtkImageClip> clipper = vtkSmartPointer<vtkImageClip>::New();
+ clipper->SetInput(image);
+ int* extent = image->GetExtent();
+ DDV(extent, 6);
+ // std::vector<int> extend;
+
+ // Prepare the marching squares
+ vtkSmartPointer<vtkMarchingSquares> squares = vtkSmartPointer<vtkMarchingSquares>::New();
+ squares->SetInput(clipper->GetOutput());
+
+ // Loop on slice
+ uint n = image->GetDimensions()[2];
+ DD(n);
+ for(uint i=0; i<n; i++) {
+ // Clip to the current slice
+ extent[4] = extent[5] = image->GetOrigin()[2]+i*image->GetSpacing()[2];
+ DDV(extent, 6);
+ clipper->SetOutputWholeExtent(extent[0],extent[1],extent[2],
+ extent[3],extent[4],extent[5]);
+
+
+ squares->Update();
+ DD(squares->GetNumberOfContours());
+ mListOfContours[i]->SetMesh(squares->GetOutput());
+ }
+}
+//--------------------------------------------------------------------