Mercurial > hg > orthanc-stone
annotate OrthancStone/Sources/Loaders/BasicFetchingStrategy.cpp @ 1716:6aadc7cbb8ea
todo
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 01 Dec 2020 08:58:53 +0100 |
parents | 59f95b9ea858 |
children | 9ac2a65d4172 |
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 | |
1270
2d8ab34c8c91
upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
725
diff
changeset
|
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium |
708 | 6 * |
7 * 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
|
8 * modify it under the terms of the GNU Lesser General Public License |
708 | 9 * as published by the Free Software Foundation, either version 3 of |
10 * the License, or (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, but | |
13 * 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
|
14 * 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
|
15 * Lesser General Public License for more details. |
1596
4fb8fdf03314
removed annoying whitespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1571
diff
changeset
|
16 * |
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
|
17 * 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
|
18 * 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
|
19 * <http://www.gnu.org/licenses/>. |
708 | 20 **/ |
21 | |
22 | |
23 #include "BasicFetchingStrategy.h" | |
24 | |
1455
30deba7bc8e2
simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1270
diff
changeset
|
25 #include <OrthancException.h> |
708 | 26 |
1624 | 27 #include <cassert> |
28 | |
708 | 29 namespace OrthancStone |
30 { | |
31 void BasicFetchingStrategy::Schedule(unsigned int item, | |
32 unsigned int quality) | |
33 { | |
34 assert(item < GetItemsCount() && | |
35 quality <= maxQuality_); | |
36 | |
37 if (nextQuality_[item] <= quality) | |
38 { | |
39 content_.push_back(ContentItem(item, quality)); | |
40 } | |
41 } | |
42 | |
43 | |
44 BasicFetchingStrategy::BasicFetchingStrategy(IFetchingItemsSorter* sorter, // Takes ownership | |
45 unsigned int maxQuality) : | |
46 sorter_(sorter), | |
47 maxQuality_(maxQuality), | |
48 position_(0), | |
49 blockSize_(2) | |
50 { | |
51 if (sorter == NULL) | |
52 { | |
53 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); | |
54 } | |
55 | |
709
7457b4ee1f29
VolumeSeriesOrthancLoader uses a prefetching strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
708
diff
changeset
|
56 nextQuality_.resize(sorter_->GetItemsCount(), 0); // Does not change along calls to "SetCurrent()" |
708 | 57 |
709
7457b4ee1f29
VolumeSeriesOrthancLoader uses a prefetching strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
708
diff
changeset
|
58 SetCurrent(0); |
708 | 59 } |
60 | |
61 | |
62 void BasicFetchingStrategy::SetBlockSize(unsigned int size) | |
63 { | |
1571 | 64 if (size == 0) |
708 | 65 { |
66 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
67 } | |
68 | |
69 blockSize_ = size; | |
70 } | |
71 | |
72 | |
73 bool BasicFetchingStrategy::GetNext(unsigned int& item, | |
74 unsigned int& quality) | |
75 { | |
76 if (position_ >= content_.size()) | |
77 { | |
78 return false; | |
79 } | |
80 else | |
81 { | |
82 item = content_[position_].GetItem(); | |
83 quality = content_[position_].GetQuality(); | |
84 | |
85 assert(nextQuality_[item] <= quality); | |
86 nextQuality_[item] = quality + 1; | |
87 | |
88 position_ ++; | |
89 return true; | |
90 } | |
91 } | |
92 | |
93 | |
94 void BasicFetchingStrategy::SetCurrent(unsigned int item) | |
95 { | |
96 // TODO - This function is O(N) complexity where "N" is the | |
97 // number of items times the max quality. Could use a LRU index. | |
98 | |
99 position_ = 0; | |
100 | |
101 std::vector<unsigned int> v; | |
102 sorter_->Sort(v, item); | |
103 | |
104 assert(v.size() == GetItemsCount()); | |
105 | |
106 if (v.size() == 0) | |
107 { | |
108 return; | |
109 } | |
110 | |
111 content_.clear(); | |
112 content_.reserve(v.size() * maxQuality_); | |
113 | |
114 Schedule(v.front(), maxQuality_); | |
115 | |
116 for (unsigned int q = 0; q <= maxQuality_; q++) | |
117 { | |
118 unsigned int start = 1 + q * blockSize_; | |
119 unsigned int end = start + blockSize_; | |
120 | |
121 if (q == maxQuality_ || | |
122 end > v.size()) | |
123 { | |
725 | 124 end = static_cast<int>(v.size()); |
708 | 125 } |
126 | |
127 unsigned int a = 0; | |
128 if (maxQuality_ >= q + 1) | |
129 { | |
130 a = maxQuality_ - q - 1; | |
131 } | |
132 | |
133 for (unsigned int j = a; j <= maxQuality_; j++) | |
134 { | |
135 for (unsigned int i = start; i < end; i++) | |
136 { | |
137 Schedule(v[i], j); | |
138 } | |
139 } | |
140 } | |
141 } | |
142 | |
143 | |
144 void BasicFetchingStrategy::RecycleFurthest(unsigned int& item) | |
145 { | |
146 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); | |
147 } | |
148 } |