]> Creatis software - clitk.git/blobdiff - common/clitkDicomRTStruct2ImageFilter.cxx
Allow to save vtk mesh in RTStruct2Image
[clitk.git] / common / clitkDicomRTStruct2ImageFilter.cxx
index 86052170850c9a373294bb686574d60c94ce0d1f..29ca84fab88f9c62fe13822f70f80e34562210df 100644 (file)
@@ -31,6 +31,7 @@
 #include <vtkImageStencil.h>
 #include <vtkLinearExtrusionFilter.h>
 #include <vtkMetaImageWriter.h>
+#include <vtkXMLPolyDataWriter.h>
 
 
 //--------------------------------------------------------------------
@@ -38,6 +39,7 @@ clitk::DicomRTStruct2ImageFilter::DicomRTStruct2ImageFilter()
 {
   mROI = NULL;
   mWriteOutput = false;
+  mWriteMesh = true;
   mCropMask = true;
 }
 //--------------------------------------------------------------------
@@ -83,6 +85,14 @@ void clitk::DicomRTStruct2ImageFilter::SetCropMaskEnabled(bool b)
 //--------------------------------------------------------------------
 
 
+//--------------------------------------------------------------------
+void clitk::DicomRTStruct2ImageFilter::SetWriteMesh(bool b)
+{
+  mWriteMesh = b;
+}
+//--------------------------------------------------------------------
+
+
 //--------------------------------------------------------------------
 void clitk::DicomRTStruct2ImageFilter::SetOutputImageFilename(std::string s)
 {
@@ -181,6 +191,18 @@ void clitk::DicomRTStruct2ImageFilter::Update()
 
   // Get Mesh
   vtkPolyData * mesh = mROI->GetMesh();
+  if (mWriteMesh) {
+    vtkSmartPointer<vtkXMLPolyDataWriter> meshWriter = vtkSmartPointer<vtkXMLPolyDataWriter>::New();
+    std::string vtkName = mOutputFilename;
+    vtkName += ".vtk";
+    meshWriter->SetFileName(vtkName.c_str());
+#if VTK_MAJOR_VERSION <= 5
+    meshWriter->SetInput(mesh);
+#else
+    meshWriter->SetInputData(mesh);
+#endif
+    meshWriter->Write();
+  }
 
   // Get bounds
   double *bounds=mesh->GetBounds();