Procházet zdrojové kódy

Add ctkDicomObjectLocatorCache

This object maintains a cache of objectDescriptors and their
associated object locators.
Jean-Christophe Fillion-Robin před 14 roky
rodič
revize
59e21246b3

+ 1 - 0
Plugins/org.commontk.dah.core/CMakeLists.txt

@@ -11,6 +11,7 @@ SET(PLUGIN_SRCS
   ctkDicomExchangeInterface.h
   ctkDicomExchangeService.cpp
   ctkDicomHostInterface.h
+  ctkDicomObjectLocatorCache.cpp
   ctkExchangeSoapMessageProcessor.cpp
   ctkSimpleSoapClient.cpp
   ctkSimpleSoapServer.cpp

+ 166 - 0
Plugins/org.commontk.dah.core/ctkDicomObjectLocatorCache.cpp

@@ -0,0 +1,166 @@
+/*=========================================================================
+
+  Library:   CTK
+
+  Copyright (c) Kitware Inc.
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+      http://www.commontk.org/LICENSE
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+=========================================================================*/
+
+// Qt includes
+#include <QHash>
+
+// CTK includes
+#include "ctkDicomAppHostingTypes.h"
+#include "ctkDicomObjectLocatorCache.h"
+
+class ctkDicomObjectLocatorCachePrivate
+{
+public:
+  ctkDicomObjectLocatorCachePrivate();
+
+  QHash<QString, ctkDicomAppHosting::ObjectLocator> ObjectLocatorMap;
+};
+
+//----------------------------------------------------------------------------
+// ctkDicomObjectLocatorCachePrivate methods
+
+//----------------------------------------------------------------------------
+ctkDicomObjectLocatorCachePrivate::ctkDicomObjectLocatorCachePrivate()
+{
+}
+
+//----------------------------------------------------------------------------
+// ctkDicomObjectLocatorCache methods
+
+//----------------------------------------------------------------------------
+ctkDicomObjectLocatorCache::ctkDicomObjectLocatorCache() : d_ptr(new ctkDicomObjectLocatorCachePrivate())
+{
+}
+
+//----------------------------------------------------------------------------
+ctkDicomObjectLocatorCache::~ctkDicomObjectLocatorCache()
+{
+}
+
+//----------------------------------------------------------------------------
+bool ctkDicomObjectLocatorCache::isCached(const ctkDicomAppHosting::AvailableData& availableData)const
+{
+  Q_D(const ctkDicomObjectLocatorCache);
+  QList<QString> uuids = d->ObjectLocatorMap.keys();
+  // Loop over top level object descriptors
+  foreach(const ctkDicomAppHosting::ObjectDescriptor& objectDescriptor, availableData.objectDescriptors)
+    {
+    if (!uuids.contains(objectDescriptor.descriptorUUID))
+      {
+      return false;
+      }
+    }
+  // Loop over patients
+  foreach(const ctkDicomAppHosting::Patient& patient, availableData.patients)
+    {
+    // Loop over patient level object descriptors
+    foreach(const ctkDicomAppHosting::ObjectDescriptor& objectDescriptor, patient.objectDescriptors)
+      {
+      if (!uuids.contains(objectDescriptor.descriptorUUID))
+        {
+        return false;
+        }
+      }
+    // Loop over studies
+    foreach(const ctkDicomAppHosting::Study& study, patient.studies)
+      {
+      // Loop over study level object descriptors
+      foreach(const ctkDicomAppHosting::ObjectDescriptor& objectDescriptor, study.objectDescriptors)
+        {
+        if (!uuids.contains(objectDescriptor.descriptorUUID))
+          {
+          return false;
+          }
+        }
+      // Loop over series
+      foreach(const ctkDicomAppHosting::Series& series, study.series)
+        {
+        // Loop over series level object descriptors
+        foreach(const ctkDicomAppHosting::ObjectDescriptor& objectDescriptor, series.objectDescriptors)
+          {
+          if (!uuids.contains(objectDescriptor.descriptorUUID))
+            {
+            return false;
+            }
+          }
+        }
+      }
+    }
+}
+
+//----------------------------------------------------------------------------
+bool ctkDicomObjectLocatorCache::find(const QString& objectUuid,
+                                         ctkDicomAppHosting::ObjectLocator& objectLocator)const
+{
+  Q_D(const ctkDicomObjectLocatorCache);
+  if (!d->ObjectLocatorMap.contains(objectUuid))
+    {
+    return false;
+    }
+  objectLocator = d->ObjectLocatorMap.value(objectUuid);
+  return true;
+}
+
+//----------------------------------------------------------------------------
+void ctkDicomObjectLocatorCache::insert(const QString& objectUuid,
+                                        const ctkDicomAppHosting::ObjectLocator& objectLocator)
+{
+  Q_D(ctkDicomObjectLocatorCache);
+  if(d->ObjectLocatorMap.contains(objectUuid))
+    {
+    return;
+    }
+  d->ObjectLocatorMap.insert(objectUuid, objectLocator);
+}
+
+//----------------------------------------------------------------------------
+bool ctkDicomObjectLocatorCache::remove(const QString& objectUuid)
+{
+  Q_D(ctkDicomObjectLocatorCache);
+  int removed = d->ObjectLocatorMap.remove(objectUuid);
+  Q_ASSERT(removed > 1);
+  return (removed == 1);
+}
+
+//----------------------------------------------------------------------------
+QList<ctkDicomAppHosting::ObjectLocator> ctkDicomObjectLocatorCache::getData(
+  const QList<QUuid>& objectUUIDs,
+  const QList<QString>& acceptableTransferSyntaxUIDs,
+  bool includeBulkData)
+{
+  QList<ctkDicomAppHosting::ObjectLocator> objectLocators;
+  foreach(const QUuid& uuid, objectUUIDs)
+    {
+    ctkDicomAppHosting::ObjectLocator objectLocator;
+    bool found = this->find(uuid, objectLocator);
+    if (!found)
+      {
+      // What to do .. ? Create an empty objectLocator ...
+      continue;
+      }
+    if (includeBulkData)
+      {
+      Q_UNUSED(acceptableTransferSyntaxUIDs);
+      // Not implemented
+      }
+    objectLocators << objectLocator;
+    }
+  return objectLocators;
+}

+ 62 - 0
Plugins/org.commontk.dah.core/ctkDicomObjectLocatorCache.h

@@ -0,0 +1,62 @@
+/*=========================================================================
+
+  Library:   CTK
+
+  Copyright (c) Kitware Inc.
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+      http://www.commontk.org/LICENSE
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+=========================================================================*/
+
+#ifndef CTKDICOMEXCHANGEIMPL_H
+#define CTKDICOMEXCHANGEIMPL_H
+
+// Qt includes
+#include <QScopedPointer>
+
+// CTK includes
+#include "ctkDicomAppHostingTypes.h"
+#include <org_commontk_dah_core_Export.h>
+
+class ctkDicomObjectLocatorCachePrivate;
+
+/**
+  *
+  */
+class org_commontk_dah_core_EXPORT ctkDicomObjectLocatorCache
+{
+
+public:
+
+  ctkDicomObjectLocatorCache();
+  virtual ~ctkDicomObjectLocatorCache();
+
+  bool isCached(const ctkDicomAppHosting::AvailableData& availableData)const;
+
+  bool find(const QString& objectUuid, ctkDicomAppHosting::ObjectLocator& objectLocator)const;
+
+  void insert(const QString& objectUuid, const ctkDicomAppHosting::ObjectLocator& objectLocator);
+
+  bool remove(const QString& objectUuid);
+
+  QList<ctkDicomAppHosting::ObjectLocator> getData(
+    const QList<QUuid>& objectUUIDs,
+    const QList<QString>& acceptableTransferSyntaxUIDs,
+    bool includeBulkData);
+
+private:
+  Q_DECLARE_PRIVATE(ctkDicomObjectLocatorCache)
+  const QScopedPointer<ctkDicomObjectLocatorCachePrivate> d_ptr;
+};
+
+#endif // CTKDICOMEXCHANGEIMPL_H