Mercurial > hg > orthanc-stone
annotate Framework/SmartLoader.cpp @ 322:a902a07769d4 am-2
wip: preload slice
author | am@osimis.io |
---|---|
date | Mon, 15 Oct 2018 22:43:02 +0200 |
parents | 3a4ca166fafa |
children | 7a364e44fbb4 |
rev | line source |
---|---|
260 | 1 /** |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium | |
6 * | |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU Affero General Public License | |
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 | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Affero General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Affero General Public License | |
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 **/ | |
20 | |
21 | |
22 #include "SmartLoader.h" | |
23 #include "Layers/OrthancFrameLayerSource.h" | |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
299
diff
changeset
|
24 #include "Messages/MessageForwarder.h" |
318
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
25 #include "Core/Images/Image.h" |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
26 #include "Framework/Widgets/LayerWidget.h" |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
27 #include "Framework/StoneException.h" |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
28 #include "Framework/Layers/FrameRenderer.h" |
260 | 29 |
30 namespace OrthancStone | |
31 { | |
318
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
32 enum CachedSliceStatus |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
33 { |
322 | 34 CachedSliceStatus_ScheduledToLoad, |
35 CachedSliceStatus_GeometryLoaded, | |
36 CachedSliceStatus_ImageLoaded | |
318
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
37 }; |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
38 |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
39 class SmartLoader::CachedSlice : public LayerSourceBase |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
40 { |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
41 public: |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
42 unsigned int sliceIndex_; |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
43 std::auto_ptr<Slice> slice_; |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
44 boost::shared_ptr<Orthanc::ImageAccessor> image_; |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
45 SliceImageQuality effectiveQuality_; |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
46 CachedSliceStatus status_; |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
47 |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
48 public: |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
49 |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
50 CachedSlice(MessageBroker& broker) |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
51 : LayerSourceBase(broker) |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
52 {} |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
53 |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
54 virtual bool GetExtent(std::vector<Vector>& points, |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
55 const CoordinateSystem3D& viewportSlice) |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
56 { |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
57 // TODO: viewportSlice is not used !!!! |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
58 slice_->GetExtent(points); |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
59 return true; |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
60 } |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
61 |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
62 virtual void ScheduleLayerCreation(const CoordinateSystem3D& viewportSlice) |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
63 { |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
64 // TODO: viewportSlice is not used !!!! |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
65 |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
66 // it has already been loaded -> trigger the "layer ready" message immediately |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
67 bool isFull = (effectiveQuality_ == SliceImageQuality_FullPng || effectiveQuality_ == SliceImageQuality_FullPam); |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
68 std::auto_ptr<Orthanc::ImageAccessor> accessor(new Orthanc::ImageAccessor()); |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
69 image_->GetReadOnlyAccessor(*accessor); |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
70 LayerSourceBase::NotifyLayerReady(FrameRenderer::CreateRenderer(accessor.release(), *slice_, isFull), |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
71 slice_->GetGeometry(), false); |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
72 } |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
73 |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
74 CachedSlice* Clone() const |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
75 { |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
76 CachedSlice* output = new CachedSlice(broker_); |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
77 output->sliceIndex_ = sliceIndex_; |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
78 output->slice_.reset(slice_->Clone()); |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
79 output->image_ = image_; |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
80 output->effectiveQuality_ = effectiveQuality_; |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
81 output->status_ = status_; |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
82 |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
83 return output; |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
84 } |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
85 |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
86 }; |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
87 |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
88 |
317 | 89 SmartLoader::SmartLoader(MessageBroker& broker, OrthancApiClient& orthancApiClient) : |
260 | 90 IObservable(broker), |
91 IObserver(broker), | |
92 imageQuality_(SliceImageQuality_FullPam), | |
317 | 93 orthancApiClient_(orthancApiClient) |
267 | 94 { |
260 | 95 } |
96 | |
318
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
97 void SmartLoader::SetFrameInWidget(LayerWidget& layerWidget, size_t layerIndex, const std::string& instanceId, unsigned int frame) |
260 | 98 { |
262 | 99 // TODO: check if this frame has already been loaded or is already being loaded. |
100 // - if already loaded: create a "clone" that will emit the GeometryReady/ImageReady messages "immediately" | |
101 // (it can not be immediate because Observers needs to register first and this is done after this method returns) | |
102 // - if currently loading, we need to return an object that will observe the existing LayerSource and forward | |
103 // the messages to its observables | |
104 // in both cases, we must be carefull about objects lifecycle !!! | |
318
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
105 |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
106 std::auto_ptr<ILayerSource> layerSource; |
322 | 107 std::string sliceKeyId = instanceId + ":" + std::to_string(frame); |
318
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
108 |
322 | 109 if (cachedSlices_.find(sliceKeyId) != cachedSlices_.end()) // && cachedSlices_[sliceKeyId]->status_ == CachedSliceStatus_Loaded) |
318
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
110 { |
322 | 111 layerSource.reset(cachedSlices_[sliceKeyId]->Clone()); |
318
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
112 } |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
113 else |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
114 { |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
115 layerSource.reset(new OrthancFrameLayerSource(IObserver::broker_, orthancApiClient_)); |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
116 dynamic_cast<OrthancFrameLayerSource*>(layerSource.get())->SetImageQuality(imageQuality_); |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
117 layerSource->RegisterObserverCallback(new Callable<SmartLoader, ILayerSource::GeometryReadyMessage>(*this, &SmartLoader::OnLayerGeometryReady)); |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
118 layerSource->RegisterObserverCallback(new Callable<SmartLoader, ILayerSource::ImageReadyMessage>(*this, &SmartLoader::OnImageReady)); |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
119 layerSource->RegisterObserverCallback(new Callable<SmartLoader, ILayerSource::LayerReadyMessage>(*this, &SmartLoader::OnLayerReady)); |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
120 dynamic_cast<OrthancFrameLayerSource*>(layerSource.get())->LoadFrame(instanceId, frame); |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
121 } |
260 | 122 |
318
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
123 // make sure that the widget registers the events before we trigger them |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
124 if (layerWidget.GetLayerCount() == layerIndex) |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
125 { |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
126 layerWidget.AddLayer(layerSource.release()); |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
127 } |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
128 else if (layerWidget.GetLayerCount() > layerIndex) |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
129 { |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
130 layerWidget.ReplaceLayer(layerIndex, layerSource.release()); |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
131 } |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
132 else |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
133 { |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
134 throw StoneException(ErrorCode_CanOnlyAddOneLayerAtATime); |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
135 } |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
136 |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
137 SmartLoader::CachedSlice* cachedSlice = dynamic_cast<SmartLoader::CachedSlice*>(layerSource.get()); |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
138 if (cachedSlice != NULL) |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
139 { |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
140 cachedSlice->NotifyGeometryReady(); |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
141 } |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
142 |
260 | 143 } |
144 | |
322 | 145 void SmartLoader::PreloadSlice(const std::string instanceId, unsigned int frame) |
146 { | |
147 // TODO: check if it is already in the cache | |
318
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
148 |
322 | 149 // create the slice in the cache with "empty" data |
150 boost::shared_ptr<CachedSlice> cachedSlice(new CachedSlice(IObserver::broker_)); | |
151 cachedSlice->slice_.reset(new Slice(instanceId, frame)); | |
152 cachedSlice->status_ = CachedSliceStatus_ScheduledToLoad; | |
153 std::string sliceKeyId = instanceId + ":" + std::to_string(frame); | |
154 | |
155 cachedSlices_[sliceKeyId] = boost::shared_ptr<CachedSlice>(cachedSlice); | |
156 | |
157 std::auto_ptr<ILayerSource> layerSource(new OrthancFrameLayerSource(IObserver::broker_, orthancApiClient_)); | |
158 | |
159 dynamic_cast<OrthancFrameLayerSource*>(layerSource.get())->SetImageQuality(imageQuality_); | |
160 layerSource->RegisterObserverCallback(new Callable<SmartLoader, ILayerSource::GeometryReadyMessage>(*this, &SmartLoader::OnLayerGeometryReady)); | |
161 layerSource->RegisterObserverCallback(new Callable<SmartLoader, ILayerSource::ImageReadyMessage>(*this, &SmartLoader::OnImageReady)); | |
162 layerSource->RegisterObserverCallback(new Callable<SmartLoader, ILayerSource::LayerReadyMessage>(*this, &SmartLoader::OnLayerReady)); | |
163 dynamic_cast<OrthancFrameLayerSource*>(layerSource.get())->LoadFrame(instanceId, frame); | |
164 | |
165 // keep a ref to the LayerSource until the slice is fully loaded and saved to cache | |
166 preloadingInstances_[sliceKeyId] = boost::shared_ptr<ILayerSource>(layerSource.release()); | |
270 | 167 } |
260 | 168 |
266
c9cf95b49a86
removed OrthancSlicesLoader::ISliceLoaderObserver; now using standard messages instead
am@osimis.io
parents:
262
diff
changeset
|
169 |
322 | 170 // void PreloadStudy(const std::string studyId) |
171 // { | |
172 // /* TODO */ | |
173 // } | |
174 | |
175 // void PreloadSeries(const std::string seriesId) | |
176 // { | |
177 // /* TODO */ | |
178 // } | |
266
c9cf95b49a86
removed OrthancSlicesLoader::ISliceLoaderObserver; now using standard messages instead
am@osimis.io
parents:
262
diff
changeset
|
179 |
c9cf95b49a86
removed OrthancSlicesLoader::ISliceLoaderObserver; now using standard messages instead
am@osimis.io
parents:
262
diff
changeset
|
180 |
318
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
181 void SmartLoader::OnLayerGeometryReady(const ILayerSource::GeometryReadyMessage& message) |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
182 { |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
183 OrthancFrameLayerSource& source = dynamic_cast<OrthancFrameLayerSource&>(message.origin_); |
322 | 184 |
185 // save/replace the slice in cache | |
318
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
186 const Slice& slice = source.GetSlice(0); // TODO handle GetSliceCount() |
322 | 187 std::string sliceKeyId = slice.GetOrthancInstanceId() + ":" + std::to_string(slice.GetFrame()); |
318
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
188 |
322 | 189 boost::shared_ptr<CachedSlice> cachedSlice(new CachedSlice(IObserver::broker_)); |
318
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
190 cachedSlice->slice_.reset(slice.Clone()); |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
191 cachedSlice->effectiveQuality_ = source.GetImageQuality(); |
322 | 192 cachedSlice->status_ = CachedSliceStatus_GeometryLoaded; |
318
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
193 |
322 | 194 cachedSlices_[sliceKeyId] = boost::shared_ptr<CachedSlice>(cachedSlice); |
318
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
195 |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
196 // re-emit original Layer message to observers |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
197 EmitMessage(message); |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
198 } |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
199 |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
200 void SmartLoader::OnImageReady(const ILayerSource::ImageReadyMessage& message) |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
201 { |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
202 OrthancFrameLayerSource& source = dynamic_cast<OrthancFrameLayerSource&>(message.origin_); |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
203 |
322 | 204 // save/replace the slice in cache |
318
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
205 const Slice& slice = source.GetSlice(0); // TODO handle GetSliceCount() ? |
322 | 206 std::string sliceKeyId = slice.GetOrthancInstanceId() + ":" + std::to_string(slice.GetFrame()); |
318
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
207 |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
208 boost::shared_ptr<CachedSlice> cachedSlice(new CachedSlice(IObserver::broker_)); |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
209 cachedSlice->image_ = message.image_; |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
210 cachedSlice->effectiveQuality_ = message.imageQuality_; |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
211 cachedSlice->slice_.reset(message.slice_.Clone()); |
322 | 212 cachedSlice->status_ = CachedSliceStatus_ImageLoaded; |
318
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
213 |
322 | 214 cachedSlices_[sliceKeyId] = cachedSlice; |
318
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
215 |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
216 // re-emit original Layer message to observers |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
217 EmitMessage(message); |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
218 } |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
219 |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
220 void SmartLoader::OnLayerReady(const ILayerSource::LayerReadyMessage& message) |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
221 { |
322 | 222 OrthancFrameLayerSource& source = dynamic_cast<OrthancFrameLayerSource&>(message.origin_); |
223 const Slice& slice = source.GetSlice(0); // TODO handle GetSliceCount() ? | |
224 std::string sliceKeyId = slice.GetOrthancInstanceId() + ":" + std::to_string(slice.GetFrame()); | |
225 | |
226 // remove the slice from the preloading slices now that it has been fully loaded and it is referenced in the cache | |
227 if (preloadingInstances_.find(sliceKeyId) != preloadingInstances_.end()) | |
228 { | |
229 preloadingInstances_.erase(sliceKeyId); | |
230 } | |
231 | |
318
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
232 // re-emit original Layer message to observers |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
233 EmitMessage(message); |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
234 } |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
235 |
260 | 236 } |