From a384b1aa2ad35011b2741fca00a2a52e26b30e8f Mon Sep 17 00:00:00 2001
From: tbaudier <thomas.baudier@creatis.insa-lyon.fr>
Date: Thu, 28 Feb 2019 14:07:52 +0100
Subject: [PATCH] Add reverse flag in clitkDicom2Image

Sometimes (eg: with MR from HEH), the basic algorithm is not sufficient to sort dicom slices
The sorting reverse the slice order
---
 tools/clitkDicom2Image.cxx | 5 +++++
 tools/clitkDicom2Image.ggo | 1 +
 2 files changed, 6 insertions(+)

diff --git a/tools/clitkDicom2Image.cxx b/tools/clitkDicom2Image.cxx
index e705f85..614c5d9 100644
--- a/tools/clitkDicom2Image.cxx
+++ b/tools/clitkDicom2Image.cxx
@@ -246,6 +246,11 @@ int main(int argc, char * argv[])
        }
     }
 
+    //===========================================
+    // Reverse the slice order (for MR from HEH)
+    if (args_info.reverse_flag)
+      std::reverse(sorted_files.begin(), sorted_files.end());
+
     //===========================================
     // Read write serie
     vvImageReader::Pointer reader = vvImageReader::New();
diff --git a/tools/clitkDicom2Image.ggo b/tools/clitkDicom2Image.ggo
index 049ff98..8563d46 100644
--- a/tools/clitkDicom2Image.ggo
+++ b/tools/clitkDicom2Image.ggo
@@ -10,3 +10,4 @@ option "std_input"      - "Take the like of input file from stdin, to support hu
 option "focal_origin"   - "Output files with FOCAL-like origin, instead of the origin present in the dicom files" flag off
 option "patientSystem"  p "Open the image with patient coordinate system" flag off
 option "instanceNumber" n "Sort the images regarding instance number in dicom tag" flag off
+option "reverse"        r "Reverse the slice order" flag off
-- 
2.49.0