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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
708
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Stone of Orthanc
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * the License, or (at your option) any later version.
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 **/
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 #include "BasicFetchingStrategy.h"
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24
1455
30deba7bc8e2 simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1270
diff changeset
25 #include <OrthancException.h>
708
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26
1624
59f95b9ea858 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
27 #include <cassert>
59f95b9ea858 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
28
708
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 namespace OrthancStone
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 {
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 void BasicFetchingStrategy::Schedule(unsigned int item,
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 unsigned int quality)
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 {
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 assert(item < GetItemsCount() &&
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 quality <= maxQuality_);
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 if (nextQuality_[item] <= quality)
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 {
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 content_.push_back(ContentItem(item, quality));
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 }
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 }
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 sorter_(sorter),
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 maxQuality_(maxQuality),
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 position_(0),
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 blockSize_(2)
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 {
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 if (sorter == NULL)
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 {
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 }
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58
1755
1a775f4ee672 added ability to specify initial slice in
bgo@SHARKNADO.localdomain
parents: 1739
diff changeset
59 SetCurrent(initialItem);
708
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 }
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 void BasicFetchingStrategy::SetBlockSize(unsigned int size)
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 {
1571
85e117739eca cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
65 if (size == 0)
708
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 {
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 }
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 blockSize_ = size;
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 }
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 bool BasicFetchingStrategy::GetNext(unsigned int& item,
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 unsigned int& quality)
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 {
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 if (position_ >= content_.size())
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 {
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 return false;
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 }
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 else
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 {
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 item = content_[position_].GetItem();
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 quality = content_[position_].GetQuality();
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 assert(nextQuality_[item] <= quality);
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 nextQuality_[item] = quality + 1;
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 position_ ++;
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 return true;
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 }
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 }
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 void BasicFetchingStrategy::SetCurrent(unsigned int item)
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 {
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 // TODO - This function is O(N) complexity where "N" is the
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 // number of items times the max quality. Could use a LRU index.
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 position_ = 0;
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 std::vector<unsigned int> v;
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 sorter_->Sort(v, item);
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 assert(v.size() == GetItemsCount());
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 if (v.size() == 0)
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 {
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 return;
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 }
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 content_.clear();
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 content_.reserve(v.size() * maxQuality_);
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 Schedule(v.front(), maxQuality_);
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 for (unsigned int q = 0; q <= maxQuality_; q++)
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 {
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 unsigned int start = 1 + q * blockSize_;
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 unsigned int end = start + blockSize_;
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 if (q == maxQuality_ ||
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 end > v.size())
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 {
725
f8d582fc5731 Fixed previous typo
Benjamin Golinvaux <bgo@osimis.io>
parents: 724
diff changeset
125 end = static_cast<int>(v.size());
708
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 }
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 unsigned int a = 0;
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 if (maxQuality_ >= q + 1)
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 {
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 a = maxQuality_ - q - 1;
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 }
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 for (unsigned int j = a; j <= maxQuality_; j++)
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 {
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 for (unsigned int i = start; i < end; i++)
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 {
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 Schedule(v[i], j);
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 }
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 }
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 }
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 }
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 void BasicFetchingStrategy::RecycleFurthest(unsigned int& item)
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 {
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 }
51976977d2d3 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 }