ctkDicomObjectLocatorCache.cpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. // CTK includes
  17. #include "ctkDicomAppHostingTypes.h"
  18. #include "ctkDicomObjectLocatorCache.h"
  19. class ctkDicomObjectLocatorCachePrivate
  20. {
  21. public:
  22. ctkDicomObjectLocatorCachePrivate();
  23. QHash<QString, ctkDicomAppHosting::ObjectLocator> ObjectLocatorMap;
  24. };
  25. //----------------------------------------------------------------------------
  26. // ctkDicomObjectLocatorCachePrivate methods
  27. //----------------------------------------------------------------------------
  28. ctkDicomObjectLocatorCachePrivate::ctkDicomObjectLocatorCachePrivate()
  29. {
  30. }
  31. //----------------------------------------------------------------------------
  32. // ctkDicomObjectLocatorCache methods
  33. //----------------------------------------------------------------------------
  34. ctkDicomObjectLocatorCache::ctkDicomObjectLocatorCache() : d_ptr(new ctkDicomObjectLocatorCachePrivate())
  35. {
  36. }
  37. //----------------------------------------------------------------------------
  38. ctkDicomObjectLocatorCache::~ctkDicomObjectLocatorCache()
  39. {
  40. }
  41. //----------------------------------------------------------------------------
  42. bool ctkDicomObjectLocatorCache::isCached(const ctkDicomAppHosting::AvailableData& availableData)const
  43. {
  44. Q_D(const ctkDicomObjectLocatorCache);
  45. QList<QString> uuids = d->ObjectLocatorMap.keys();
  46. // Loop over top level object descriptors
  47. foreach(const ctkDicomAppHosting::ObjectDescriptor& objectDescriptor, availableData.objectDescriptors)
  48. {
  49. if (!uuids.contains(objectDescriptor.descriptorUUID))
  50. {
  51. return false;
  52. }
  53. }
  54. // Loop over patients
  55. foreach(const ctkDicomAppHosting::Patient& patient, availableData.patients)
  56. {
  57. // Loop over patient level object descriptors
  58. foreach(const ctkDicomAppHosting::ObjectDescriptor& objectDescriptor, patient.objectDescriptors)
  59. {
  60. if (!uuids.contains(objectDescriptor.descriptorUUID))
  61. {
  62. return false;
  63. }
  64. }
  65. // Loop over studies
  66. foreach(const ctkDicomAppHosting::Study& study, patient.studies)
  67. {
  68. // Loop over study level object descriptors
  69. foreach(const ctkDicomAppHosting::ObjectDescriptor& objectDescriptor, study.objectDescriptors)
  70. {
  71. if (!uuids.contains(objectDescriptor.descriptorUUID))
  72. {
  73. return false;
  74. }
  75. }
  76. // Loop over series
  77. foreach(const ctkDicomAppHosting::Series& series, study.series)
  78. {
  79. // Loop over series level object descriptors
  80. foreach(const ctkDicomAppHosting::ObjectDescriptor& objectDescriptor, series.objectDescriptors)
  81. {
  82. if (!uuids.contains(objectDescriptor.descriptorUUID))
  83. {
  84. return false;
  85. }
  86. }
  87. }
  88. }
  89. }
  90. }
  91. //----------------------------------------------------------------------------
  92. bool ctkDicomObjectLocatorCache::find(const QString& objectUuid,
  93. ctkDicomAppHosting::ObjectLocator& objectLocator)const
  94. {
  95. Q_D(const ctkDicomObjectLocatorCache);
  96. if (!d->ObjectLocatorMap.contains(objectUuid))
  97. {
  98. return false;
  99. }
  100. objectLocator = d->ObjectLocatorMap.value(objectUuid);
  101. return true;
  102. }
  103. //----------------------------------------------------------------------------
  104. void ctkDicomObjectLocatorCache::insert(const QString& objectUuid,
  105. const ctkDicomAppHosting::ObjectLocator& objectLocator)
  106. {
  107. Q_D(ctkDicomObjectLocatorCache);
  108. if(d->ObjectLocatorMap.contains(objectUuid))
  109. {
  110. return;
  111. }
  112. d->ObjectLocatorMap.insert(objectUuid, objectLocator);
  113. }
  114. //----------------------------------------------------------------------------
  115. bool ctkDicomObjectLocatorCache::remove(const QString& objectUuid)
  116. {
  117. Q_D(ctkDicomObjectLocatorCache);
  118. int removed = d->ObjectLocatorMap.remove(objectUuid);
  119. Q_ASSERT(removed > 1);
  120. return (removed == 1);
  121. }
  122. //----------------------------------------------------------------------------
  123. QList<ctkDicomAppHosting::ObjectLocator> ctkDicomObjectLocatorCache::getData(
  124. const QList<QUuid>& objectUUIDs,
  125. const QList<QString>& acceptableTransferSyntaxUIDs,
  126. bool includeBulkData)
  127. {
  128. QList<ctkDicomAppHosting::ObjectLocator> objectLocators;
  129. foreach(const QUuid& uuid, objectUUIDs)
  130. {
  131. ctkDicomAppHosting::ObjectLocator objectLocator;
  132. bool found = this->find(uuid, objectLocator);
  133. if (!found)
  134. {
  135. // What to do .. ? Create an empty objectLocator ...
  136. continue;
  137. }
  138. if (includeBulkData)
  139. {
  140. Q_UNUSED(acceptableTransferSyntaxUIDs);
  141. // Not implemented
  142. }
  143. objectLocators << objectLocator;
  144. }
  145. return objectLocators;
  146. }