changeset 4507:b4c58795f3a8

widening the use of DicomTransferSyntax enum
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 11 Feb 2021 09:33:48 +0100
parents ac69c9f76c71
children 8f9090b137f1
files OrthancFramework/Sources/DicomParsing/MemoryBufferTranscoder.cpp OrthancFramework/Sources/DicomParsing/ParsedDicomFile.cpp OrthancFramework/Sources/DicomParsing/ParsedDicomFile.h OrthancFramework/UnitTestsSources/FromDcmtkTests.cpp OrthancServer/Plugins/Engine/OrthancPlugins.cpp OrthancServer/Sources/DicomInstanceToStore.cpp OrthancServer/Sources/DicomInstanceToStore.h OrthancServer/Sources/LuaScripting.cpp OrthancServer/Sources/OrthancRestApi/OrthancRestApi.cpp OrthancServer/Sources/ServerContext.cpp OrthancServer/Sources/ServerIndex.cpp OrthancServer/Sources/ServerIndex.h OrthancServer/UnitTestsSources/ServerIndexTests.cpp
diffstat 13 files changed, 104 insertions(+), 82 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancFramework/Sources/DicomParsing/MemoryBufferTranscoder.cpp	Wed Feb 10 17:01:44 2021 +0100
+++ b/OrthancFramework/Sources/DicomParsing/MemoryBufferTranscoder.cpp	Thu Feb 11 09:33:48 2021 +0100
@@ -43,9 +43,8 @@
 
     std::string s;
     DicomTransferSyntax a, b;
-    if (!const_cast<const ParsedDicomFile&>(parsed).LookupTransferSyntax(s) ||
+    if (!const_cast<const ParsedDicomFile&>(parsed).LookupTransferSyntax(b) ||
         !FromDcmtkBridge::LookupOrthancTransferSyntax(a, parsed.GetDcmtkObject()) ||
-        !LookupTransferSyntax(b, s) ||
         a != b ||
         allowedSyntaxes.find(a) == allowedSyntaxes.end())
     {
--- a/OrthancFramework/Sources/DicomParsing/ParsedDicomFile.cpp	Wed Feb 10 17:01:44 2021 +0100
+++ b/OrthancFramework/Sources/DicomParsing/ParsedDicomFile.cpp	Thu Feb 11 09:33:48 2021 +0100
@@ -1683,38 +1683,9 @@
   }
 
 
-  bool ParsedDicomFile::LookupTransferSyntax(std::string& result) const
+  bool ParsedDicomFile::LookupTransferSyntax(DicomTransferSyntax& result) const
   {
-#if 0
-    // This was the implementation in Orthanc <= 1.6.1
-
-    // TODO - Shouldn't "dataset.getCurrentXfer()" be used instead of
-    // using the meta header?
-    const char* value = NULL;
-
-    if (GetDcmtkObjectConst().getMetaInfo() != NULL &&
-        GetDcmtkObjectConst().getMetaInfo()->findAndGetString(DCM_TransferSyntaxUID, value).good() &&
-        value != NULL)
-    {
-      result.assign(value);
-      return true;
-    }
-    else
-    {
-      return false;
-    }
-#else
-    DicomTransferSyntax s;
-    if (FromDcmtkBridge::LookupOrthancTransferSyntax(s, GetDcmtkObjectConst()))
-    {
-      result.assign(GetTransferSyntaxUid(s));
-      return true;
-    }
-    else
-    {
-      return false;
-    }
-#endif
+    return FromDcmtkBridge::LookupOrthancTransferSyntax(result, GetDcmtkObjectConst());
   }
 
 
@@ -1787,6 +1758,20 @@
   {
     return const_cast<const ParsedDicomFile&>(*this).LookupTransferSyntax(result);
   }
+  
+  bool ParsedDicomFile::LookupTransferSyntax(std::string& result) const
+  {
+    DicomTransferSyntax s;
+    if (LookupTransferSyntax(s))
+    {
+      result = GetTransferSyntaxUid(s);
+      return true;
+    }
+    else
+    {
+      return false;
+    }
+  }
 
   bool ParsedDicomFile::GetTagValue(std::string& value,
                                     const DicomTag& tag)
--- a/OrthancFramework/Sources/DicomParsing/ParsedDicomFile.h	Wed Feb 10 17:01:44 2021 +0100
+++ b/OrthancFramework/Sources/DicomParsing/ParsedDicomFile.h	Thu Feb 11 09:33:48 2021 +0100
@@ -111,6 +111,7 @@
     void Apply(ITagVisitor& visitor);
     ParsedDicomFile* Clone(bool keepSopInstanceUid);
     bool LookupTransferSyntax(std::string& result);
+    bool LookupTransferSyntax(std::string& result) const;
     bool GetTagValue(std::string& value,
                      const DicomTag& tag);
 #endif
@@ -264,7 +265,7 @@
                              unsigned int maxTagLength,
                              const std::set<DicomTag>& ignoreTagLength) const;
 
-    bool LookupTransferSyntax(std::string& result) const;
+    bool LookupTransferSyntax(DicomTransferSyntax& result) const;
 
     bool LookupPhotometricInterpretation(PhotometricInterpretation& result) const;
 
--- a/OrthancFramework/UnitTestsSources/FromDcmtkTests.cpp	Wed Feb 10 17:01:44 2021 +0100
+++ b/OrthancFramework/UnitTestsSources/FromDcmtkTests.cpp	Thu Feb 11 09:33:48 2021 +0100
@@ -385,15 +385,17 @@
   f.ReplacePlainString(DICOM_TAG_SOP_INSTANCE_UID, "Toto");  // (*)
   f.ReplacePlainString(DICOM_TAG_SOP_CLASS_UID, "Tata");  // (**)
 
-  std::string s;
-  ASSERT_TRUE(f.LookupTransferSyntax(s));
+  DicomTransferSyntax syntax;
+  ASSERT_TRUE(f.LookupTransferSyntax(syntax));
   // The default transfer syntax depends on the OS endianness
-  ASSERT_TRUE(s == GetTransferSyntaxUid(DicomTransferSyntax_LittleEndianExplicit) ||
-              s == GetTransferSyntaxUid(DicomTransferSyntax_BigEndianExplicit));
+  ASSERT_TRUE(syntax == DicomTransferSyntax_LittleEndianExplicit ||
+              syntax == DicomTransferSyntax_BigEndianExplicit);
 
   ASSERT_THROW(f.Replace(DICOM_TAG_ACCESSION_NUMBER, std::string("Accession"),
                          false, DicomReplaceMode_ThrowIfAbsent, ""), OrthancException);
   f.Replace(DICOM_TAG_ACCESSION_NUMBER, std::string("Accession"), false, DicomReplaceMode_IgnoreIfAbsent, "");
+
+  std::string s;
   ASSERT_FALSE(f.GetTagValue(s, DICOM_TAG_ACCESSION_NUMBER));
   f.Replace(DICOM_TAG_ACCESSION_NUMBER, std::string("Accession"), false, DicomReplaceMode_InsertIfAbsent, "");
   ASSERT_TRUE(f.GetTagValue(s, DICOM_TAG_ACCESSION_NUMBER));
--- a/OrthancServer/Plugins/Engine/OrthancPlugins.cpp	Wed Feb 10 17:01:44 2021 +0100
+++ b/OrthancServer/Plugins/Engine/OrthancPlugins.cpp	Thu Feb 11 09:33:48 2021 +0100
@@ -2933,10 +2933,9 @@
       case _OrthancPluginService_GetInstanceSimplifiedJson:
       {
         Json::Value dicomAsJson;
-        OrthancConfiguration::DefaultDicomDatasetToJson(dicomAsJson, instance.GetParsedDicomFile());
+        instance.GetDicomAsJson(dicomAsJson);
         
         std::string s;
-
         if (service == _OrthancPluginService_GetInstanceJson)
         {
           Toolbox::WriteStyledJson(s, dicomAsJson);
@@ -2958,13 +2957,16 @@
 
       case _OrthancPluginService_GetInstanceTransferSyntaxUid:   // New in Orthanc 1.6.1
       {
-        std::string s;
-        if (!instance.LookupTransferSyntax(s))
+        DicomTransferSyntax s;
+        if (instance.LookupTransferSyntax(s))
         {
-          s.clear();
+          *p.resultStringToFree = CopyString(GetTransferSyntaxUid(s));
+        }
+        else
+        {
+          *p.resultStringToFree = CopyString("");
         }
         
-        *p.resultStringToFree = CopyString(s);
         return;
       }
 
@@ -2973,7 +2975,7 @@
         return;
 
       case _OrthancPluginService_GetInstanceFramesCount:  // New in Orthanc 1.7.0
-        *p.resultInt64 = instance.GetParsedDicomFile().GetFramesCount();
+        *p.resultInt64 = instance.GetFramesCount();
         return;
         
       default:
@@ -3081,7 +3083,7 @@
     switch (service)
     {
       case _OrthancPluginService_GetInstanceFramesCount:
-        *p.targetUint32 = instance.GetParsedDicomFile().GetFramesCount();
+        *p.targetUint32 = instance.GetFramesCount();
         return;
         
       case _OrthancPluginService_GetInstanceRawFrame:
@@ -3127,10 +3129,7 @@
 
         p.targetBuffer->data = NULL;
         p.targetBuffer->size = 0;
-        
-        std::string serialized;
-        instance.GetParsedDicomFile().SaveToMemoryBuffer(serialized);
-        CopyToMemoryBuffer(*p.targetBuffer, serialized);
+        CopyToMemoryBuffer(*p.targetBuffer, instance.GetBufferData(), instance.GetBufferSize());
         return;
       }
 
@@ -3142,9 +3141,8 @@
         }
         
         Json::Value json;
-        instance.GetParsedDicomFile().DatasetToJson(
-          json, Plugins::Convert(p.format), 
-          static_cast<DicomToJsonFlags>(p.flags), p.maxStringLength);
+        instance.DatasetToJson(json, Plugins::Convert(p.format), 
+                               static_cast<DicomToJsonFlags>(p.flags), p.maxStringLength);
 
         std::string s;
         Toolbox::WriteFastJson(s, json);
--- a/OrthancServer/Sources/DicomInstanceToStore.cpp	Wed Feb 10 17:01:44 2021 +0100
+++ b/OrthancServer/Sources/DicomInstanceToStore.cpp	Thu Feb 11 09:33:48 2021 +0100
@@ -267,7 +267,7 @@
     }
 
 
-    bool LookupTransferSyntax(std::string& result)
+    bool LookupTransferSyntax(DicomTransferSyntax& result)
     {
       DicomMap header;
       if (DicomMap::ParseDicomMetaInformation(header, GetBufferData(), GetBufferSize()))
@@ -277,8 +277,7 @@
             !value->IsBinary() &&
             !value->IsNull())
         {
-          result = Toolbox::StripSpaces(value->GetContent());
-          return true;
+          return ::Orthanc::LookupTransferSyntax(result, Toolbox::StripSpaces(value->GetContent()));
         }
       }
       else
@@ -286,12 +285,7 @@
         // This is a DICOM file without a proper meta-header. Fallback
         // to DCMTK, which will fully parse the dataset to retrieve
         // the transfer syntax. Added in Orthanc 1.8.2.
-        std::string transferSyntax;
-        if (GetParsedDicomFile().LookupTransferSyntax(transferSyntax))
-        {
-          result = Toolbox::StripSpaces(transferSyntax);
-          return true;
-        }
+        return GetParsedDicomFile().LookupTransferSyntax(result);
       }
 
       return false;
@@ -377,7 +371,7 @@
   }
 
 
-  bool DicomInstanceToStore::LookupTransferSyntax(std::string& result) const
+  bool DicomInstanceToStore::LookupTransferSyntax(DicomTransferSyntax& result) const
   {
     return const_cast<PImpl&>(*pimpl_).LookupTransferSyntax(result);
   }
@@ -392,4 +386,32 @@
   {
     return const_cast<PImpl&>(*pimpl_).GetParsedDicomFile();
   }
+
+  void DicomInstanceToStore::GetSummary(DicomMap& summary) const
+  {
+    OrthancConfiguration::DefaultExtractDicomSummary(summary, GetParsedDicomFile());
+  }
+
+  void DicomInstanceToStore::GetDicomAsJson(Json::Value& dicomAsJson) const
+  {
+    OrthancConfiguration::DefaultDicomDatasetToJson(dicomAsJson, GetParsedDicomFile());
+  }
+
+  void DicomInstanceToStore::DatasetToJson(Json::Value& target, 
+                                           DicomToJsonFormat format,
+                                           DicomToJsonFlags flags,
+                                           unsigned int maxStringLength) const
+  {
+    return GetParsedDicomFile().DatasetToJson(target, format, flags, maxStringLength);
+  }
+
+  unsigned int DicomInstanceToStore::GetFramesCount() const
+  {
+    return GetParsedDicomFile().GetFramesCount();
+  }
+    
+  ImageAccessor* DicomInstanceToStore::DecodeFrame(unsigned int frame) const
+  {
+    return GetParsedDicomFile().DecodeFrame(frame);
+  }
 }
--- a/OrthancServer/Sources/DicomInstanceToStore.h	Wed Feb 10 17:01:44 2021 +0100
+++ b/OrthancServer/Sources/DicomInstanceToStore.h	Thu Feb 11 09:33:48 2021 +0100
@@ -41,6 +41,7 @@
 
 namespace Orthanc
 {
+  class ImageAccessor;
   class ParsedDicomFile;
 
   class DicomInstanceToStore : public boost::noncopyable
@@ -80,10 +81,23 @@
 
     size_t GetBufferSize() const;
 
-    bool LookupTransferSyntax(std::string& result) const;
+    bool LookupTransferSyntax(DicomTransferSyntax& result) const;
 
     bool HasPixelData() const;
 
     ParsedDicomFile& GetParsedDicomFile() const;
+
+    void GetSummary(DicomMap& summary) const;
+
+    void GetDicomAsJson(Json::Value& dicomAsJson) const;
+
+    void DatasetToJson(Json::Value& target, 
+                       DicomToJsonFormat format,
+                       DicomToJsonFlags flags,
+                       unsigned int maxStringLength) const;
+
+    unsigned int GetFramesCount() const;
+    
+    ImageAccessor* DecodeFrame(unsigned int frame) const;
   };
 }
--- a/OrthancServer/Sources/LuaScripting.cpp	Wed Feb 10 17:01:44 2021 +0100
+++ b/OrthancServer/Sources/LuaScripting.cpp	Thu Feb 11 09:33:48 2021 +0100
@@ -879,10 +879,10 @@
       Json::Value info = Json::objectValue;
       info["HasPixelData"] = instance.HasPixelData();
 
-      std::string s;
+      DicomTransferSyntax s;
       if (instance.LookupTransferSyntax(s))
       {
-        info["TransferSyntaxUID"] = s;
+        info["TransferSyntaxUID"] = GetTransferSyntaxUid(s);
       }
 
       call.PushJson(info);
--- a/OrthancServer/Sources/OrthancRestApi/OrthancRestApi.cpp	Wed Feb 10 17:01:44 2021 +0100
+++ b/OrthancServer/Sources/OrthancRestApi/OrthancRestApi.cpp	Thu Feb 11 09:33:48 2021 +0100
@@ -71,7 +71,7 @@
     SetupResourceAnswer(result, instanceId, ResourceType_Instance, status);
 
     DicomMap summary;
-    OrthancConfiguration::DefaultExtractDicomSummary(summary, instance.GetParsedDicomFile());
+    instance.GetSummary(summary);
 
     DicomInstanceHasher hasher(summary);
     result["ParentPatient"] = hasher.HashPatient();
--- a/OrthancServer/Sources/ServerContext.cpp	Wed Feb 10 17:01:44 2021 +0100
+++ b/OrthancServer/Sources/ServerContext.cpp	Thu Feb 11 09:33:48 2021 +0100
@@ -517,21 +517,22 @@
     hasPixelDataOffset = DicomStreamReader::LookupPixelDataOffset(
       pixelDataOffset, dicom.GetBufferData(), dicom.GetBufferSize());
 
-    std::string transferSyntax;
+    DicomTransferSyntax transferSyntax;
     bool hasTransferSyntax = dicom.LookupTransferSyntax(transferSyntax);
-        
+    
     DicomMap summary;
-    OrthancConfiguration::DefaultExtractDicomSummary(summary, dicom.GetParsedDicomFile());
+    dicom.GetSummary(summary);
 
     try
     {
       MetricsRegistry::Timer timer(GetMetricsRegistry(), "orthanc_store_dicom_duration_ms");
       StorageAccessor accessor(area_, GetMetricsRegistry());
 
-      resultPublicId = dicom.GetParsedDicomFile().GetHasher().HashInstance();
+      DicomInstanceHasher hasher(summary);
+      resultPublicId = hasher.HashInstance();
 
       Json::Value dicomAsJson;
-      OrthancConfiguration::DefaultDicomDatasetToJson(dicomAsJson, dicom.GetParsedDicomFile());
+      dicom.GetDicomAsJson(dicomAsJson);
       
       Json::Value simplifiedTags;
       Toolbox::SimplifyDicomAsJson(simplifiedTags, dicomAsJson, DicomToJsonFormat_Human);
@@ -684,8 +685,7 @@
       bool transcode = false;
 
       DicomTransferSyntax sourceSyntax;
-      if (!FromDcmtkBridge::LookupOrthancTransferSyntax(
-            sourceSyntax, dicom.GetParsedDicomFile().GetDcmtkObject()) ||
+      if (!dicom.LookupTransferSyntax(sourceSyntax) ||
           sourceSyntax == ingestTransferSyntax_)
       {
         // Don't transcode if the incoming DICOM is already in the proper transfer syntax
@@ -1684,7 +1684,7 @@
       std::unique_ptr<ImageAccessor> decoded;
       try
       {
-        decoded.reset(dicom.GetParsedDicomFile().DecodeFrame(frameIndex));
+        decoded.reset(dicom.DecodeFrame(frameIndex));
       }
       catch (OrthancException& e)
       {
@@ -1723,7 +1723,7 @@
 
     if (builtinDecoderTranscoderOrder_ == BuiltinDecoderTranscoderOrder_After)
     {
-      return dicom.GetParsedDicomFile().DecodeFrame(frameIndex);
+      return dicom.DecodeFrame(frameIndex);
     }
     else
     {
--- a/OrthancServer/Sources/ServerIndex.cpp	Wed Feb 10 17:01:44 2021 +0100
+++ b/OrthancServer/Sources/ServerIndex.cpp	Thu Feb 11 09:33:48 2021 +0100
@@ -761,7 +761,7 @@
                                  const DicomInstanceOrigin& origin,
                                  bool overwrite,
                                  bool hasTransferSyntax,
-                                 const std::string& transferSyntax,
+                                 DicomTransferSyntax transferSyntax,
                                  bool hasPixelDataOffset,
                                  uint64_t pixelDataOffset)
   {
@@ -946,7 +946,8 @@
         {
           // New in Orthanc 1.2.0
           SetInstanceMetadata(content, instanceMetadata, instanceId,
-                              MetadataType_Instance_TransferSyntax, transferSyntax);
+                              MetadataType_Instance_TransferSyntax,
+                              GetTransferSyntaxUid(transferSyntax));
         }
 
         {
@@ -2532,10 +2533,10 @@
       }
 
       {
-        std::string s;
+        DicomTransferSyntax s;
         if (dicom.LookupTransferSyntax(s))
         {
-          db_.SetMetadata(instance, MetadataType_Instance_TransferSyntax, s);
+          db_.SetMetadata(instance, MetadataType_Instance_TransferSyntax, GetTransferSyntaxUid(s));
         }
       }
 
--- a/OrthancServer/Sources/ServerIndex.h	Wed Feb 10 17:01:44 2021 +0100
+++ b/OrthancServer/Sources/ServerIndex.h	Thu Feb 11 09:33:48 2021 +0100
@@ -145,7 +145,7 @@
                       const DicomInstanceOrigin& origin,
                       bool overwrite,
                       bool hasTransferSyntax,
-                      const std::string& transferSyntax,
+                      DicomTransferSyntax transferSyntax,
                       bool hasPixelDataOffset,
                       uint64_t pixelDataOffset);
 
--- a/OrthancServer/UnitTestsSources/ServerIndexTests.cpp	Wed Feb 10 17:01:44 2021 +0100
+++ b/OrthancServer/UnitTestsSources/ServerIndexTests.cpp	Thu Feb 11 09:33:48 2021 +0100
@@ -736,7 +736,7 @@
       DicomMap summary;
       OrthancConfiguration::DefaultExtractDicomSummary(summary, toStore.GetParsedDicomFile());
 
-      std::string transferSyntax;
+      DicomTransferSyntax transferSyntax;
       bool hasTransferSyntax = dicom.LookupTransferSyntax(transferSyntax);
       ASSERT_EQ(StoreStatus_Success, index.Store(
                   instanceMetadata, summary, attachments, toStore.GetMetadata(),