Mercurial > hg > orthanc-stone
annotate OrthancStone/Sources/Loaders/BasicFetchingStrategy.cpp @ 2146:743fa9c74443 dicom-sr tip
integration mainline->dicom-sr
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 16 Aug 2024 18:09:53 +0200 |
parents | 16c01cc201e7 |
children |
rev | line source |
---|---|
708 | 1 /** |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
2124
16c01cc201e7
updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2114
diff
changeset
|
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium |
2114
c23eef785569
update year to 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2077
diff
changeset
|
6 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
708 | 7 * |
8 * This program is free software: you can redistribute it and/or | |
1598
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
9 * modify it under the terms of the GNU Lesser General Public License |
708 | 10 * as published by the Free Software Foundation, either version 3 of |
11 * the License, or (at your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, but | |
14 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
1598
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
16 * Lesser General Public License for more details. |
1596
4fb8fdf03314
removed annoying whitespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1571
diff
changeset
|
17 * |
1598
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
18 * You should have received a copy of the GNU Lesser General Public |
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
19 * License along with this program. If not, see |
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
20 * <http://www.gnu.org/licenses/>. |
708 | 21 **/ |
22 | |
23 | |
24 #include "BasicFetchingStrategy.h" | |
25 | |
1455
30deba7bc8e2
simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1270
diff
changeset
|
26 #include <OrthancException.h> |
708 | 27 |
1624 | 28 #include <cassert> |
29 | |
708 | 30 namespace OrthancStone |
31 { | |
32 void BasicFetchingStrategy::Schedule(unsigned int item, | |
33 unsigned int quality) | |
34 { | |
35 assert(item < GetItemsCount() && | |
36 quality <= maxQuality_); | |
37 | |
38 if (nextQuality_[item] <= quality) | |
39 { | |
40 content_.push_back(ContentItem(item, quality)); | |
41 } | |
42 } | |
43 | |
44 | |
45 BasicFetchingStrategy::BasicFetchingStrategy(IFetchingItemsSorter* sorter, // Takes ownership | |
1755
1a775f4ee672
added ability to specify initial slice in
bgo@SHARKNADO.localdomain
parents:
1739
diff
changeset
|
46 unsigned int maxQuality, |
1a775f4ee672
added ability to specify initial slice in
bgo@SHARKNADO.localdomain
parents:
1739
diff
changeset
|
47 unsigned int initialItem) : |
708 | 48 sorter_(sorter), |
49 maxQuality_(maxQuality), | |
50 position_(0), | |
51 blockSize_(2) | |
52 { | |
53 if (sorter == NULL) | |
54 { | |
55 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); | |
56 } | |
57 | |
709
7457b4ee1f29
VolumeSeriesOrthancLoader uses a prefetching strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
708
diff
changeset
|
58 nextQuality_.resize(sorter_->GetItemsCount(), 0); // Does not change along calls to "SetCurrent()" |
708 | 59 |
1755
1a775f4ee672
added ability to specify initial slice in
bgo@SHARKNADO.localdomain
parents:
1739
diff
changeset
|
60 SetCurrent(initialItem); |
708 | 61 } |
62 | |
63 | |
64 void BasicFetchingStrategy::SetBlockSize(unsigned int size) | |
65 { | |
1571 | 66 if (size == 0) |
708 | 67 { |
68 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
69 } | |
70 | |
71 blockSize_ = size; | |
72 } | |
73 | |
74 | |
75 bool BasicFetchingStrategy::GetNext(unsigned int& item, | |
76 unsigned int& quality) | |
77 { | |
78 if (position_ >= content_.size()) | |
79 { | |
80 return false; | |
81 } | |
82 else | |
83 { | |
84 item = content_[position_].GetItem(); | |
85 quality = content_[position_].GetQuality(); | |
86 | |
87 assert(nextQuality_[item] <= quality); | |
88 nextQuality_[item] = quality + 1; | |
89 | |
90 position_ ++; | |
91 return true; | |
92 } | |
93 } | |
94 | |
95 | |
96 void BasicFetchingStrategy::SetCurrent(unsigned int item) | |
97 { | |
98 // TODO - This function is O(N) complexity where "N" is the | |
99 // number of items times the max quality. Could use a LRU index. | |
100 | |
101 position_ = 0; | |
102 | |
103 std::vector<unsigned int> v; | |
104 sorter_->Sort(v, item); | |
105 | |
106 assert(v.size() == GetItemsCount()); | |
107 | |
108 if (v.size() == 0) | |
109 { | |
110 return; | |
111 } | |
112 | |
113 content_.clear(); | |
114 content_.reserve(v.size() * maxQuality_); | |
115 | |
116 Schedule(v.front(), maxQuality_); | |
117 | |
118 for (unsigned int q = 0; q <= maxQuality_; q++) | |
119 { | |
120 unsigned int start = 1 + q * blockSize_; | |
121 unsigned int end = start + blockSize_; | |
122 | |
123 if (q == maxQuality_ || | |
124 end > v.size()) | |
125 { | |
725 | 126 end = static_cast<int>(v.size()); |
708 | 127 } |
128 | |
129 unsigned int a = 0; | |
130 if (maxQuality_ >= q + 1) | |
131 { | |
132 a = maxQuality_ - q - 1; | |
133 } | |
134 | |
135 for (unsigned int j = a; j <= maxQuality_; j++) | |
136 { | |
137 for (unsigned int i = start; i < end; i++) | |
138 { | |
139 Schedule(v[i], j); | |
140 } | |
141 } | |
142 } | |
143 } | |
144 | |
145 | |
146 void BasicFetchingStrategy::RecycleFurthest(unsigned int& item) | |
147 { | |
148 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); | |
149 } | |
150 } |