From 0141f3887fe8e6e429621b603b6359be679e9fb5 Mon Sep 17 00:00:00 2001 From: tbaudier Date: Thu, 5 Jul 2018 10:21:07 +0200 Subject: [PATCH] Allow to save vtk mesh in RTStruct2Image --- common/clitkDicomRTStruct2ImageFilter.cxx | 22 ++++++++++++++++++++++ common/clitkDicomRTStruct2ImageFilter.h | 2 ++ tools/clitkDicomRTStruct2Image.cxx | 6 ++++++ tools/clitkDicomRTStruct2Image.ggo | 1 + 4 files changed, 31 insertions(+) diff --git a/common/clitkDicomRTStruct2ImageFilter.cxx b/common/clitkDicomRTStruct2ImageFilter.cxx index 8605217..29ca84f 100644 --- a/common/clitkDicomRTStruct2ImageFilter.cxx +++ b/common/clitkDicomRTStruct2ImageFilter.cxx @@ -31,6 +31,7 @@ #include #include #include +#include //-------------------------------------------------------------------- @@ -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 meshWriter = vtkSmartPointer::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(); diff --git a/common/clitkDicomRTStruct2ImageFilter.h b/common/clitkDicomRTStruct2ImageFilter.h index 96de26d..f93cbb2 100644 --- a/common/clitkDicomRTStruct2ImageFilter.h +++ b/common/clitkDicomRTStruct2ImageFilter.h @@ -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 typename itk::Image::ConstPointer GetITKOutput(); @@ -53,6 +54,7 @@ namespace clitk { protected: bool ImageInfoIsSet() const; bool mWriteOutput; + bool mWriteMesh; bool mCropMask; std::string mOutputFilename; std::vector mSpacing; diff --git a/tools/clitkDicomRTStruct2Image.cxx b/tools/clitkDicomRTStruct2Image.cxx index 302f65c..3790ab7 100644 --- a/tools/clitkDicomRTStruct2Image.cxx +++ b/tools/clitkDicomRTStruct2Image.cxx @@ -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) { diff --git a/tools/clitkDicomRTStruct2Image.ggo b/tools/clitkDicomRTStruct2Image.ggo index 6af9ce2..8e6159a 100644 --- a/tools/clitkDicomRTStruct2Image.ggo +++ b/tools/clitkDicomRTStruct2Image.ggo @@ -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 -- 2.45.2