]> Creatis software - clitk.git/blobdiff - tools/clitkImage2DicomGenericFilter.txx
Add preserve studyUID in clitkImage2Dicom
[clitk.git] / tools / clitkImage2DicomGenericFilter.txx
index c58bd2ff1606004bab3955cf9b02723901ed2f41..37fa8a55a3cfc45052692396cb6300fcc22281af 100644 (file)
@@ -216,14 +216,22 @@ Image2DicomGenericFilter<args_info_type>::UpdateWithDimAndPixelType()
   // to keep the same study UID. But we need new series and frame of
   // reference UID's.
 #if ITK_VERSION_MAJOR >= 4
-  gdcm::UIDGenerator suid;
-  std::string seriesUID = suid.Generate();
   gdcm::UIDGenerator fuid;
   std::string frameOfReferenceUID = fuid.Generate();
 #else
-  std::string seriesUID = gdcm::Util::CreateUniqueUID( gdcmIO->GetUIDPrefix());
   std::string frameOfReferenceUID = gdcm::Util::CreateUniqueUID( gdcmIO->GetUIDPrefix());
 #endif
+  std::string seriesUID;
+  if (m_ArgsInfo.newUID_flag) {
+#if ITK_VERSION_MAJOR >= 4
+    gdcm::UIDGenerator suid;
+    seriesUID = suid.Generate();
+#else
+    seriesUID = gdcm::Util::CreateUniqueUID( gdcmIO->GetUIDPrefix());
+#endif
+  } else {
+    itk::ExposeMetaData<std::string>(*inputDict, "0020|000e", seriesUID);
+  }
   std::string studyUID;
   std::string sopClassUID;
   itk::ExposeMetaData<std::string>(*inputDict, "0020|000d", studyUID);
@@ -374,7 +382,10 @@ Image2DicomGenericFilter<args_info_type>::UpdateWithDimAndPixelType()
   // Generate the file names
   OutputNamesGeneratorType::Pointer outputNames = OutputNamesGeneratorType::New();
   std::string seriesFormat(m_ArgsInfo.outputDcm_arg);
-  seriesFormat = seriesFormat + "/" + "IM%d.dcm";
+  seriesFormat = seriesFormat + "/";
+  if (m_ArgsInfo.nameDicom_given)
+    seriesFormat = seriesFormat + m_ArgsInfo.nameDicom_arg + "_";
+  seriesFormat = seriesFormat + "IM%d.dcm";
   outputNames->SetSeriesFormat(seriesFormat.c_str());
   outputNames->SetStartIndex(1);
   outputNames->SetEndIndex(outputSize[2]);