]> Creatis software - clitk.git/commitdiff
Allow to save vtk mesh in RTStruct2Image
authortbaudier <thomas.baudier@creatis.insa-lyon.fr>
Thu, 5 Jul 2018 08:21:07 +0000 (10:21 +0200)
committertbaudier <thomas.baudier@creatis.insa-lyon.fr>
Thu, 5 Jul 2018 08:21:07 +0000 (10:21 +0200)
common/clitkDicomRTStruct2ImageFilter.cxx
common/clitkDicomRTStruct2ImageFilter.h
tools/clitkDicomRTStruct2Image.cxx
tools/clitkDicomRTStruct2Image.ggo

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();
index 96de26da7698b7451633abb2e77b706bf8474275..f93cbb2969ca833f70682d1307b7f4993eed4cb0 100644 (file)
@@ -44,6 +44,7 @@ namespace clitk {
     void SetOutputSpacing(const double* spacing);
     void SetOutputSize(const unsigned long* size);
     void SetOutputImageFilename(std::string s);
+    void SetWriteMesh(bool b);
     void Update();    
     vtkImageData * GetOutput();
     template <int Dimension> typename itk::Image<unsigned char,Dimension>::ConstPointer GetITKOutput();
@@ -53,6 +54,7 @@ namespace clitk {
   protected:
     bool ImageInfoIsSet() const;
     bool mWriteOutput;
+    bool mWriteMesh;
     bool mCropMask;
     std::string mOutputFilename;
     std::vector<double> mSpacing;
index 302f65ced9ed72ec44964b0650b4e5b01c480832..3790ab7b3100e335da027148e0d797d2ba20f59a 100644 (file)
@@ -40,6 +40,9 @@ int main(int argc, char * argv[]) {
   clitk::DicomRTStruct2ImageFilter filter;
   filter.SetCropMaskEnabled(args_info.crop_flag);
   filter.SetImageFilename(args_info.image_arg);  // Used to get spacing + origin
+  if (args_info.vtk_flag) {
+    filter.SetWriteMesh(true);
+  }
   if (args_info.roiName_given) {
     filter.SetROI(s->GetROIFromROIName(args_info.roiName_arg)); 
     filter.SetOutputImageFilename(args_info.output_arg);
@@ -67,6 +70,9 @@ int main(int argc, char * argv[]) {
         filter.SetROI(roi); 
         filter.SetCropMaskEnabled(args_info.crop_flag);
         filter.SetImageFilename(args_info.image_arg);  // Used to get spacing + origin
+        if (args_info.vtk_flag) {
+          filter.SetWriteMesh(true);
+        }
         name.erase(remove_if(name.begin(), name.end(), isspace), name.end());
         std::string n;
         if (args_info.mha_flag) {
index 6af9ce26166194f847b6ac19ae59ae46a3ffc6e2..8e6159a16ff837ef4148d14193d27017db2abe4a 100644 (file)
@@ -17,4 +17,5 @@ groupoption "roiNameSubstr" s "Substring of ROI name to binarize (reuturns all m
 
 option "crop"         c "Crop binary mask"                                                      flag off
 option "mha"          - "Write the RTStruct as a mha image to avoid special character problems" flag off
+option "vtk"          - "Write the vtk Mesh as a vtk file"                                      flag off