ctkDicomObjectLocatorCache.cpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) Kitware Inc.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.commontk.org/LICENSE
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. =========================================================================*/
  14. // Qt includes
  15. #include <QHash>
  16. #include <QUuid>
  17. // CTK includes
  18. #include "ctkDicomAppHostingTypes.h"
  19. #include "ctkDicomObjectLocatorCache.h"
  20. class ctkDicomObjectLocatorCachePrivate
  21. {
  22. public:
  23. ctkDicomObjectLocatorCachePrivate();
  24. QHash<QString, ctkDicomAppHosting::ObjectLocator> ObjectLocatorMap;
  25. };
  26. //----------------------------------------------------------------------------
  27. // ctkDicomObjectLocatorCachePrivate methods
  28. //----------------------------------------------------------------------------
  29. ctkDicomObjectLocatorCachePrivate::ctkDicomObjectLocatorCachePrivate()
  30. {
  31. }
  32. //----------------------------------------------------------------------------
  33. // ctkDicomObjectLocatorCache methods
  34. //----------------------------------------------------------------------------
  35. ctkDicomObjectLocatorCache::ctkDicomObjectLocatorCache() : d_ptr(new ctkDicomObjectLocatorCachePrivate())
  36. {
  37. }
  38. //----------------------------------------------------------------------------
  39. ctkDicomObjectLocatorCache::~ctkDicomObjectLocatorCache()
  40. {
  41. }
  42. //----------------------------------------------------------------------------
  43. bool ctkDicomObjectLocatorCache::isCached(const ctkDicomAppHosting::AvailableData& availableData)const
  44. {
  45. Q_D(const ctkDicomObjectLocatorCache);
  46. QList<QString> uuids = d->ObjectLocatorMap.keys();
  47. // Loop over top level object descriptors
  48. foreach(const ctkDicomAppHosting::ObjectDescriptor& objectDescriptor, availableData.objectDescriptors)
  49. {
  50. if (!uuids.contains(objectDescriptor.descriptorUUID))
  51. {
  52. return false;
  53. }
  54. }
  55. // Loop over patients
  56. foreach(const ctkDicomAppHosting::Patient& patient, availableData.patients)
  57. {
  58. // Loop over patient level object descriptors
  59. foreach(const ctkDicomAppHosting::ObjectDescriptor& objectDescriptor, patient.objectDescriptors)
  60. {
  61. if (!uuids.contains(objectDescriptor.descriptorUUID))
  62. {
  63. return false;
  64. }
  65. }
  66. // Loop over studies
  67. foreach(const ctkDicomAppHosting::Study& study, patient.studies)
  68. {
  69. // Loop over study level object descriptors
  70. foreach(const ctkDicomAppHosting::ObjectDescriptor& objectDescriptor, study.objectDescriptors)
  71. {
  72. if (!uuids.contains(objectDescriptor.descriptorUUID))
  73. {
  74. return false;
  75. }
  76. }
  77. // Loop over series
  78. foreach(const ctkDicomAppHosting::Series& series, study.series)
  79. {
  80. // Loop over series level object descriptors
  81. foreach(const ctkDicomAppHosting::ObjectDescriptor& objectDescriptor, series.objectDescriptors)
  82. {
  83. if (!uuids.contains(objectDescriptor.descriptorUUID))
  84. {
  85. return false;
  86. }
  87. }
  88. }
  89. }
  90. }
  91. }
  92. //----------------------------------------------------------------------------
  93. bool ctkDicomObjectLocatorCache::find(const QString& objectUuid,
  94. ctkDicomAppHosting::ObjectLocator& objectLocator)const
  95. {
  96. Q_D(const ctkDicomObjectLocatorCache);
  97. if (!d->ObjectLocatorMap.contains(objectUuid))
  98. {
  99. return false;
  100. }
  101. objectLocator = d->ObjectLocatorMap.value(objectUuid);
  102. return true;
  103. }
  104. //----------------------------------------------------------------------------
  105. void ctkDicomObjectLocatorCache::insert(const QString& objectUuid,
  106. const ctkDicomAppHosting::ObjectLocator& objectLocator)
  107. {
  108. Q_D(ctkDicomObjectLocatorCache);
  109. if(d->ObjectLocatorMap.contains(objectUuid))
  110. {
  111. return;
  112. }
  113. d->ObjectLocatorMap.insert(objectUuid, objectLocator);
  114. }
  115. //----------------------------------------------------------------------------
  116. bool ctkDicomObjectLocatorCache::remove(const QString& objectUuid)
  117. {
  118. Q_D(ctkDicomObjectLocatorCache);
  119. int removed = d->ObjectLocatorMap.remove(objectUuid);
  120. Q_ASSERT(removed > 1);
  121. return (removed == 1);
  122. }
  123. //----------------------------------------------------------------------------
  124. QList<ctkDicomAppHosting::ObjectLocator> ctkDicomObjectLocatorCache::getData(
  125. const QList<QUuid>& objectUUIDs,
  126. const QList<QString>& acceptableTransferSyntaxUIDs,
  127. bool includeBulkData)
  128. {
  129. QList<ctkDicomAppHosting::ObjectLocator> objectLocators;
  130. foreach(const QUuid& uuid, objectUUIDs)
  131. {
  132. ctkDicomAppHosting::ObjectLocator objectLocator;
  133. bool found = this->find(uuid, objectLocator);
  134. if (!found)
  135. {
  136. // What to do .. ? Create an empty objectLocator ...
  137. continue;
  138. }
  139. if (includeBulkData)
  140. {
  141. Q_UNUSED(acceptableTransferSyntaxUIDs);
  142. // Not implemented
  143. }
  144. objectLocators << objectLocator;
  145. }
  146. return objectLocators;
  147. }