changeset 3551:173c7f363d8f

DicomMap::RemoveBinaryTags
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sat, 26 Oct 2019 15:59:59 +0200
parents 0f5f9a5eed25
children 5abca33b2d01
files Core/DicomFormat/DicomMap.cpp Core/DicomFormat/DicomMap.h UnitTestsSources/DicomMapTests.cpp
diffstat 3 files changed, 43 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/Core/DicomFormat/DicomMap.cpp	Fri Oct 25 18:09:42 2019 +0200
+++ b/Core/DicomFormat/DicomMap.cpp	Sat Oct 26 15:59:59 2019 +0200
@@ -1294,6 +1294,29 @@
   }
 
 
+  void DicomMap::RemoveBinaryTags()
+  {
+    Map kept;
+
+    for (Map::iterator it = map_.begin(); it != map_.end(); ++it)
+    {
+      assert(it->second != NULL);
+
+      if (!it->second->IsBinary() &&
+          !it->second->IsNull())
+      {
+        kept[it->first] = it->second;
+      }
+      else
+      {
+        delete it->second;
+      }
+    }
+
+    map_ = kept;
+  }
+
+
   void DicomMap::Print(FILE* fp) const
   {
     DicomArray a(*this);
--- a/Core/DicomFormat/DicomMap.h	Fri Oct 25 18:09:42 2019 +0200
+++ b/Core/DicomFormat/DicomMap.h	Sat Oct 26 15:59:59 2019 +0200
@@ -238,6 +238,8 @@
                                const std::string& defaultValue,
                                bool allowBinary) const;
 
+    void RemoveBinaryTags();
+
     void Print(FILE* fp) const;  // For debugging only
   };
 }
--- a/UnitTestsSources/DicomMapTests.cpp	Fri Oct 25 18:09:42 2019 +0200
+++ b/UnitTestsSources/DicomMapTests.cpp	Sat Oct 26 15:59:59 2019 +0200
@@ -566,6 +566,24 @@
 }
 
 
+TEST(DicomMap, RemoveBinary)
+{
+  DicomMap b;
+  b.SetValue(DICOM_TAG_PATIENT_NAME, "A", false);
+  b.SetValue(DICOM_TAG_PATIENT_ID, "B", true);
+  b.SetValue(DICOM_TAG_STUDY_INSTANCE_UID, DicomValue());  // NULL
+  b.SetValue(DICOM_TAG_SERIES_INSTANCE_UID, DicomValue("C", false));
+  b.SetValue(DICOM_TAG_SOP_INSTANCE_UID, DicomValue("D", true));
+
+  b.RemoveBinaryTags();
+
+  std::string s;
+  ASSERT_EQ(2u, b.GetSize());
+  ASSERT_TRUE(b.LookupStringValue(s, DICOM_TAG_PATIENT_NAME, false)); ASSERT_EQ("A", s);
+  ASSERT_TRUE(b.LookupStringValue(s, DICOM_TAG_SERIES_INSTANCE_UID, false)); ASSERT_EQ("C", s);
+}
+
+
 
 TEST(DicomWebJson, Multiplicity)
 {