Mercurial > hg > orthanc-stone
annotate OrthancStone/Sources/Loaders/BasicFetchingStrategy.cpp @ 1779:9ab251c03eda
unit test VolumeRendering.TextureCorners
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 14 May 2021 10:01:20 +0200 |
parents | 1a775f4ee672 |
children | 3889ae96d2e9 |
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 | |
1739
9ac2a65d4172
upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1624
diff
changeset
|
5 * Copyright (C) 2017-2021 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 | |
1755
1a775f4ee672
added ability to specify initial slice in
bgo@SHARKNADO.localdomain
parents:
1739
diff
changeset
|
45 unsigned int maxQuality, |
1a775f4ee672
added ability to specify initial slice in
bgo@SHARKNADO.localdomain
parents:
1739
diff
changeset
|
46 unsigned int initialItem) : |
708 | 47 sorter_(sorter), |
48 maxQuality_(maxQuality), | |
49 position_(0), | |
50 blockSize_(2) | |
51 { | |
52 if (sorter == NULL) | |
53 { | |
54 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); | |
55 } | |
56 | |
709
7457b4ee1f29
VolumeSeriesOrthancLoader uses a prefetching strategy
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
708
diff
changeset
|
57 nextQuality_.resize(sorter_->GetItemsCount(), 0); // Does not change along calls to "SetCurrent()" |
708 | 58 |
1755
1a775f4ee672
added ability to specify initial slice in
bgo@SHARKNADO.localdomain
parents:
1739
diff
changeset
|
59 SetCurrent(initialItem); |
708 | 60 } |
61 | |
62 | |
63 void BasicFetchingStrategy::SetBlockSize(unsigned int size) | |
64 { | |
1571 | 65 if (size == 0) |
708 | 66 { |
67 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
68 } | |
69 | |
70 blockSize_ = size; | |
71 } | |
72 | |
73 | |
74 bool BasicFetchingStrategy::GetNext(unsigned int& item, | |
75 unsigned int& quality) | |
76 { | |
77 if (position_ >= content_.size()) | |
78 { | |
79 return false; | |
80 } | |
81 else | |
82 { | |
83 item = content_[position_].GetItem(); | |
84 quality = content_[position_].GetQuality(); | |
85 | |
86 assert(nextQuality_[item] <= quality); | |
87 nextQuality_[item] = quality + 1; | |
88 | |
89 position_ ++; | |
90 return true; | |
91 } | |
92 } | |
93 | |
94 | |
95 void BasicFetchingStrategy::SetCurrent(unsigned int item) | |
96 { | |
97 // TODO - This function is O(N) complexity where "N" is the | |
98 // number of items times the max quality. Could use a LRU index. | |
99 | |
100 position_ = 0; | |
101 | |
102 std::vector<unsigned int> v; | |
103 sorter_->Sort(v, item); | |
104 | |
105 assert(v.size() == GetItemsCount()); | |
106 | |
107 if (v.size() == 0) | |
108 { | |
109 return; | |
110 } | |
111 | |
112 content_.clear(); | |
113 content_.reserve(v.size() * maxQuality_); | |
114 | |
115 Schedule(v.front(), maxQuality_); | |
116 | |
117 for (unsigned int q = 0; q <= maxQuality_; q++) | |
118 { | |
119 unsigned int start = 1 + q * blockSize_; | |
120 unsigned int end = start + blockSize_; | |
121 | |
122 if (q == maxQuality_ || | |
123 end > v.size()) | |
124 { | |
725 | 125 end = static_cast<int>(v.size()); |
708 | 126 } |
127 | |
128 unsigned int a = 0; | |
129 if (maxQuality_ >= q + 1) | |
130 { | |
131 a = maxQuality_ - q - 1; | |
132 } | |
133 | |
134 for (unsigned int j = a; j <= maxQuality_; j++) | |
135 { | |
136 for (unsigned int i = start; i < end; i++) | |
137 { | |
138 Schedule(v[i], j); | |
139 } | |
140 } | |
141 } | |
142 } | |
143 | |
144 | |
145 void BasicFetchingStrategy::RecycleFurthest(unsigned int& item) | |
146 { | |
147 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); | |
148 } | |
149 } |