changeset 1788:6a2d507ef064 worklists

getting rid of opaque data structures
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 18 Nov 2015 16:11:28 +0100
parents 1b1d5470233f
children bdcc1dba4a53
files OrthancServer/DicomDirWriter.cpp OrthancServer/DicomInstanceToStore.cpp OrthancServer/Internals/FindScp.cpp OrthancServer/ParsedDicomFile.cpp OrthancServer/ParsedDicomFile.h
diffstat 5 files changed, 35 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/DicomDirWriter.cpp	Wed Nov 18 15:50:32 2015 +0100
+++ b/OrthancServer/DicomDirWriter.cpp	Wed Nov 18 16:11:28 2015 +0100
@@ -527,7 +527,7 @@
       path = directory + '\\' + filename;
     }
 
-    DcmFileFormat& fileFormat = *reinterpret_cast<DcmFileFormat*>(dicom.GetDcmtkObject());
+    DcmFileFormat& fileFormat = dicom.GetDcmtkObject();
 
     DcmDirectoryRecord* instance;
     bool isNewInstance = pimpl_->CreateResource(instance, ResourceType_Instance, fileFormat, filename.c_str(), path.c_str());
--- a/OrthancServer/DicomInstanceToStore.cpp	Wed Nov 18 15:50:32 2015 +0100
+++ b/OrthancServer/DicomInstanceToStore.cpp	Wed Nov 18 16:11:28 2015 +0100
@@ -41,12 +41,6 @@
 
 namespace Orthanc
 {
-  static DcmDataset& GetDataset(ParsedDicomFile& file)
-  {
-    return *reinterpret_cast<DcmFileFormat*>(file.GetDcmtkObject())->getDataset();
-  }
-
-
   void DicomInstanceToStore::AddMetadata(ResourceType level,
                                          MetadataType metadata,
                                          const std::string& value)
@@ -75,7 +69,8 @@
       {
         // Serialize the parsed DICOM file
         buffer_.Allocate();
-        if (!FromDcmtkBridge::SaveToMemoryBuffer(buffer_.GetContent(), GetDataset(parsed_.GetContent())))
+        if (!FromDcmtkBridge::SaveToMemoryBuffer(buffer_.GetContent(), 
+                                                 *parsed_.GetContent().GetDcmtkObject().getDataset()))
         {
           LOG(ERROR) << "Unable to serialize a DICOM file to a memory buffer";
           throw OrthancException(ErrorCode_InternalError);
@@ -103,13 +98,15 @@
     if (!summary_.HasContent())
     {
       summary_.Allocate();
-      FromDcmtkBridge::Convert(summary_.GetContent(), GetDataset(parsed_.GetContent()));
+      FromDcmtkBridge::Convert(summary_.GetContent(), 
+                               *parsed_.GetContent().GetDcmtkObject().getDataset());
     }
     
     if (!json_.HasContent())
     {
       json_.Allocate();
-      FromDcmtkBridge::ToJson(json_.GetContent(), GetDataset(parsed_.GetContent()), 
+      FromDcmtkBridge::ToJson(json_.GetContent(), 
+                              *parsed_.GetContent().GetDcmtkObject().getDataset(),
                               DicomToJsonFormat_Full, 
                               DicomToJsonFlags_Default,
                               256 /* max string length */);
--- a/OrthancServer/Internals/FindScp.cpp	Wed Nov 18 15:50:32 2015 +0100
+++ b/OrthancServer/Internals/FindScp.cpp	Wed Nov 18 16:11:28 2015 +0100
@@ -133,10 +133,9 @@
           {
             if (data.worklistHandler_ != NULL)
             {
-              // TODO
-              /*std::auto_ptr<ParsedDicomFile> query(ParsedDicomFile::CreateFromDcmtkDataset(requestIdentifiers));
-              DicomWorklistAnswers a;
-              data.worklistHandler_->Handle(a, *query, *data.remoteIp_, *data.remoteAet_);*/
+              ParsedDicomFile query(*requestIdentifiers);
+              data.noCroppingOfResults_ = data.worklistHandler_->Handle(data.answers_, query,
+                                                                        *data.remoteIp_, *data.remoteAet_);
               ok = true;
             }
             else
@@ -188,11 +187,10 @@
         // There are pending results that are still to be sent
         response->DimseStatus = STATUS_Pending;
 
-        void* obj = data.answers_.GetAnswer(responseCount - 1).GetDcmtkObject();
-        DcmFileFormat* fileFormat = static_cast<DcmFileFormat*>(obj);
-        assert(fileFormat != NULL);
+        DcmFileFormat& fileFormat = data.answers_.GetAnswer(responseCount - 1).GetDcmtkObject();
 
-        *responseIdentifiers = new DcmDataset(*fileFormat->getDataset());
+        // TODO Is there a way to avoid this copy?
+        *responseIdentifiers = new DcmDataset(*fileFormat.getDataset());
       }
       else if (data.noCroppingOfResults_)
       {
--- a/OrthancServer/ParsedDicomFile.cpp	Wed Nov 18 15:50:32 2015 +0100
+++ b/OrthancServer/ParsedDicomFile.cpp	Wed Nov 18 16:11:28 2015 +0100
@@ -863,15 +863,27 @@
   }
 
 
+  ParsedDicomFile::ParsedDicomFile(DcmDataset& dicom) : pimpl_(new PImpl)
+  {
+    pimpl_->file_.reset(new DcmFileFormat(&dicom));
+  }
+
+
+  ParsedDicomFile::ParsedDicomFile(DcmFileFormat& dicom) : pimpl_(new PImpl)
+  {
+    pimpl_->file_.reset(new DcmFileFormat(dicom));
+  }
+
+
   ParsedDicomFile::~ParsedDicomFile()
   {
     delete pimpl_;
   }
 
 
-  void* ParsedDicomFile::GetDcmtkObject()
+  DcmFileFormat& ParsedDicomFile::GetDcmtkObject()
   {
-    return pimpl_->file_.get();
+    return *pimpl_->file_.get();
   }
 
 
--- a/OrthancServer/ParsedDicomFile.h	Wed Nov 18 15:50:32 2015 +0100
+++ b/OrthancServer/ParsedDicomFile.h	Wed Nov 18 16:11:28 2015 +0100
@@ -39,6 +39,9 @@
 #include "../Core/Images/ImageBuffer.h"
 #include "../Core/IDynamicObject.h"
 
+class DcmDataset;
+class DcmFileFormat;
+
 namespace Orthanc
 {
   class ParsedDicomFile : public IDynamicObject
@@ -68,9 +71,13 @@
 
     ParsedDicomFile(const std::string& content);
 
+    ParsedDicomFile(DcmDataset& dicom);
+
+    ParsedDicomFile(DcmFileFormat& dicom);
+
     ~ParsedDicomFile();
 
-    void* GetDcmtkObject();
+    DcmFileFormat& GetDcmtkObject();
 
     ParsedDicomFile* Clone();