changeset 19:6a29dfe563b3

fix bug on empty sequences
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 20 May 2015 12:09:38 +0200
parents d3dc9727c51e
children d5cd40f12c86
files Core/Dicom.cpp
diffstat 1 files changed, 26 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/Core/Dicom.cpp	Wed May 20 12:03:33 2015 +0200
+++ b/Core/Dicom.cpp	Wed May 20 12:09:38 2015 +0200
@@ -336,20 +336,22 @@
       if (isSequence)
       {
         gdcm::SmartPointer<gdcm::SequenceOfItems> seq = it->GetValueAsSQ();
-
-        for (gdcm::SequenceOfItems::SizeType i = 1; i <= seq->GetNumberOfItems(); i++)
+        if (seq.GetPointer() != NULL)
         {
-          pugi::xml_node item = node.append_child("Item");
-          std::string number = boost::lexical_cast<std::string>(i);
-          item.append_attribute("number").set_value(number.c_str());
+          for (gdcm::SequenceOfItems::SizeType i = 1; i <= seq->GetNumberOfItems(); i++)
+          {
+            pugi::xml_node item = node.append_child("Item");
+            std::string number = boost::lexical_cast<std::string>(i);
+            item.append_attribute("number").set_value(number.c_str());
 
-          std::string childUri;
-          if (!bulkUri.empty())
-          {
-            childUri = bulkUri + std::string(path) + "/" + number + "/";
+            std::string childUri;
+            if (!bulkUri.empty())
+            {
+              childUri = bulkUri + std::string(path) + "/" + number + "/";
+            }
+
+            DicomToXmlInternal(item, dictionary, file, seq->GetItem(i).GetNestedDataSet(), sourceEncoding, childUri);
           }
-
-          DicomToXmlInternal(item, dictionary, file, seq->GetItem(i).GetNestedDataSet(), sourceEncoding, childUri);
         }
       }
       else if (IsBulkData(vr))
@@ -435,20 +437,22 @@
         node["Value"] = Json::arrayValue;
 
         gdcm::SmartPointer<gdcm::SequenceOfItems> seq = it->GetValueAsSQ();
-
-        for (gdcm::SequenceOfItems::SizeType i = 1; i <= seq->GetNumberOfItems(); i++)
+        if (seq.GetPointer() != NULL)
         {
-          Json::Value child;
+          for (gdcm::SequenceOfItems::SizeType i = 1; i <= seq->GetNumberOfItems(); i++)
+          {
+            Json::Value child;
 
-          std::string childUri;
-          if (!bulkUri.empty())
-          {
-            std::string number = boost::lexical_cast<std::string>(i);
-            childUri = bulkUri + std::string(path) + "/" + number + "/";
+            std::string childUri;
+            if (!bulkUri.empty())
+            {
+              std::string number = boost::lexical_cast<std::string>(i);
+              childUri = bulkUri + std::string(path) + "/" + number + "/";
+            }
+
+            DicomToJsonInternal(child, dictionary, file, seq->GetItem(i).GetNestedDataSet(), childUri, sourceEncoding);
+            node["Value"].append(child);
           }
-
-          DicomToJsonInternal(child, dictionary, file, seq->GetItem(i).GetNestedDataSet(), childUri, sourceEncoding);
-          node["Value"].append(child);
         }
       }
       else if (IsBulkData(vr))