Mercurial > hg > orthanc-stone
annotate Framework/SmartLoader.cpp @ 330:7a364e44fbb4 am-2
renamed SetDefaultView in FitContent
author | am@osimis.io |
---|---|
date | Wed, 17 Oct 2018 12:45:52 +0200 |
parents | a902a07769d4 |
children | c34784e5f299 |
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" |
330 | 29 #include "Core/Logging.h" |
260 | 30 |
31 namespace OrthancStone | |
32 { | |
318
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
33 enum CachedSliceStatus |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
34 { |
322 | 35 CachedSliceStatus_ScheduledToLoad, |
36 CachedSliceStatus_GeometryLoaded, | |
37 CachedSliceStatus_ImageLoaded | |
318
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 |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
40 class SmartLoader::CachedSlice : public LayerSourceBase |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
41 { |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
42 public: |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
43 unsigned int sliceIndex_; |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
44 std::auto_ptr<Slice> slice_; |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
45 boost::shared_ptr<Orthanc::ImageAccessor> image_; |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
46 SliceImageQuality effectiveQuality_; |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
47 CachedSliceStatus status_; |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
48 |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
49 public: |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
50 |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
51 CachedSlice(MessageBroker& broker) |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
52 : LayerSourceBase(broker) |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
53 {} |
330 | 54 virtual ~CachedSlice() {} |
318
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
55 |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
56 virtual bool GetExtent(std::vector<Vector>& points, |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
57 const CoordinateSystem3D& viewportSlice) |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
58 { |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
59 // TODO: viewportSlice is not used !!!! |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
60 slice_->GetExtent(points); |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
61 return true; |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
62 } |
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 virtual void ScheduleLayerCreation(const CoordinateSystem3D& viewportSlice) |
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 // TODO: viewportSlice is not used !!!! |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
67 |
330 | 68 // it has already been loaded -> trigger the "layer ready" message immediately otherwise, do nothing now. The LayerReady will be triggered |
69 // once the LayerSource is ready | |
70 if (status_ == CachedSliceStatus_ImageLoaded) | |
71 { | |
72 LOG(WARNING) << "ScheduleLayerCreation for CachedSlice (image is loaded): " << slice_->GetOrthancInstanceId(); | |
73 bool isFull = (effectiveQuality_ == SliceImageQuality_FullPng || effectiveQuality_ == SliceImageQuality_FullPam); | |
74 std::auto_ptr<Orthanc::ImageAccessor> accessor(new Orthanc::ImageAccessor()); | |
75 image_->GetReadOnlyAccessor(*accessor); | |
76 LayerSourceBase::NotifyLayerReady(FrameRenderer::CreateRenderer(accessor.release(), *slice_, isFull), | |
77 slice_->GetGeometry(), false); | |
78 } | |
79 else | |
80 { | |
81 LOG(WARNING) << "ScheduleLayerCreation for CachedSlice (image is not loaded yet): " << slice_->GetOrthancInstanceId(); | |
82 } | |
318
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
83 } |
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 CachedSlice* Clone() const |
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 CachedSlice* output = new CachedSlice(broker_); |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
88 output->sliceIndex_ = sliceIndex_; |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
89 output->slice_.reset(slice_->Clone()); |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
90 output->image_ = image_; |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
91 output->effectiveQuality_ = effectiveQuality_; |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
92 output->status_ = status_; |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
93 |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
94 return output; |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
95 } |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
96 |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
97 }; |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
98 |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
99 |
317 | 100 SmartLoader::SmartLoader(MessageBroker& broker, OrthancApiClient& orthancApiClient) : |
260 | 101 IObservable(broker), |
102 IObserver(broker), | |
103 imageQuality_(SliceImageQuality_FullPam), | |
317 | 104 orthancApiClient_(orthancApiClient) |
267 | 105 { |
260 | 106 } |
107 | |
318
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
108 void SmartLoader::SetFrameInWidget(LayerWidget& layerWidget, size_t layerIndex, const std::string& instanceId, unsigned int frame) |
260 | 109 { |
262 | 110 // TODO: check if this frame has already been loaded or is already being loaded. |
111 // - if already loaded: create a "clone" that will emit the GeometryReady/ImageReady messages "immediately" | |
112 // (it can not be immediate because Observers needs to register first and this is done after this method returns) | |
113 // - if currently loading, we need to return an object that will observe the existing LayerSource and forward | |
114 // the messages to its observables | |
115 // 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
|
116 |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
117 std::auto_ptr<ILayerSource> layerSource; |
322 | 118 std::string sliceKeyId = instanceId + ":" + std::to_string(frame); |
330 | 119 SmartLoader::CachedSlice* cachedSlice = NULL; |
318
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
120 |
322 | 121 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
|
122 { |
322 | 123 layerSource.reset(cachedSlices_[sliceKeyId]->Clone()); |
330 | 124 cachedSlice = dynamic_cast<SmartLoader::CachedSlice*>(layerSource.get()); |
318
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 else |
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 layerSource.reset(new OrthancFrameLayerSource(IObserver::broker_, orthancApiClient_)); |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
129 dynamic_cast<OrthancFrameLayerSource*>(layerSource.get())->SetImageQuality(imageQuality_); |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
130 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
|
131 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
|
132 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
|
133 dynamic_cast<OrthancFrameLayerSource*>(layerSource.get())->LoadFrame(instanceId, frame); |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
134 } |
260 | 135 |
318
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
136 // 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
|
137 if (layerWidget.GetLayerCount() == layerIndex) |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
138 { |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
139 layerWidget.AddLayer(layerSource.release()); |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
140 } |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
141 else if (layerWidget.GetLayerCount() > layerIndex) |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
142 { |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
143 layerWidget.ReplaceLayer(layerIndex, layerSource.release()); |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
144 } |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
145 else |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
146 { |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
147 throw StoneException(ErrorCode_CanOnlyAddOneLayerAtATime); |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
148 } |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
149 |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
150 if (cachedSlice != NULL) |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
151 { |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
152 cachedSlice->NotifyGeometryReady(); |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
153 } |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
154 |
260 | 155 } |
156 | |
322 | 157 void SmartLoader::PreloadSlice(const std::string instanceId, unsigned int frame) |
158 { | |
330 | 159 // TODO: reactivate -> need to be able to ScheduleLayerLoading in ILayerSource without calling ScheduleLayerCreation |
160 return; | |
322 | 161 // 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
|
162 |
330 | 163 |
164 | |
322 | 165 // create the slice in the cache with "empty" data |
166 boost::shared_ptr<CachedSlice> cachedSlice(new CachedSlice(IObserver::broker_)); | |
167 cachedSlice->slice_.reset(new Slice(instanceId, frame)); | |
168 cachedSlice->status_ = CachedSliceStatus_ScheduledToLoad; | |
169 std::string sliceKeyId = instanceId + ":" + std::to_string(frame); | |
170 | |
330 | 171 LOG(WARNING) << "Will preload: " << sliceKeyId; |
172 | |
322 | 173 cachedSlices_[sliceKeyId] = boost::shared_ptr<CachedSlice>(cachedSlice); |
174 | |
175 std::auto_ptr<ILayerSource> layerSource(new OrthancFrameLayerSource(IObserver::broker_, orthancApiClient_)); | |
176 | |
177 dynamic_cast<OrthancFrameLayerSource*>(layerSource.get())->SetImageQuality(imageQuality_); | |
178 layerSource->RegisterObserverCallback(new Callable<SmartLoader, ILayerSource::GeometryReadyMessage>(*this, &SmartLoader::OnLayerGeometryReady)); | |
179 layerSource->RegisterObserverCallback(new Callable<SmartLoader, ILayerSource::ImageReadyMessage>(*this, &SmartLoader::OnImageReady)); | |
180 layerSource->RegisterObserverCallback(new Callable<SmartLoader, ILayerSource::LayerReadyMessage>(*this, &SmartLoader::OnLayerReady)); | |
181 dynamic_cast<OrthancFrameLayerSource*>(layerSource.get())->LoadFrame(instanceId, frame); | |
182 | |
183 // keep a ref to the LayerSource until the slice is fully loaded and saved to cache | |
184 preloadingInstances_[sliceKeyId] = boost::shared_ptr<ILayerSource>(layerSource.release()); | |
270 | 185 } |
260 | 186 |
266
c9cf95b49a86
removed OrthancSlicesLoader::ISliceLoaderObserver; now using standard messages instead
am@osimis.io
parents:
262
diff
changeset
|
187 |
322 | 188 // void PreloadStudy(const std::string studyId) |
189 // { | |
190 // /* TODO */ | |
191 // } | |
192 | |
193 // void PreloadSeries(const std::string seriesId) | |
194 // { | |
195 // /* TODO */ | |
196 // } | |
266
c9cf95b49a86
removed OrthancSlicesLoader::ISliceLoaderObserver; now using standard messages instead
am@osimis.io
parents:
262
diff
changeset
|
197 |
c9cf95b49a86
removed OrthancSlicesLoader::ISliceLoaderObserver; now using standard messages instead
am@osimis.io
parents:
262
diff
changeset
|
198 |
318
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
199 void SmartLoader::OnLayerGeometryReady(const ILayerSource::GeometryReadyMessage& message) |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
200 { |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
201 OrthancFrameLayerSource& source = dynamic_cast<OrthancFrameLayerSource&>(message.origin_); |
322 | 202 |
203 // save/replace the slice in cache | |
318
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
204 const Slice& slice = source.GetSlice(0); // TODO handle GetSliceCount() |
322 | 205 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
|
206 |
330 | 207 LOG(WARNING) << "Geometry ready: " << sliceKeyId; |
208 | |
322 | 209 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
|
210 cachedSlice->slice_.reset(slice.Clone()); |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
211 cachedSlice->effectiveQuality_ = source.GetImageQuality(); |
322 | 212 cachedSlice->status_ = CachedSliceStatus_GeometryLoaded; |
318
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
213 |
322 | 214 cachedSlices_[sliceKeyId] = boost::shared_ptr<CachedSlice>(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::OnImageReady(const ILayerSource::ImageReadyMessage& message) |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
221 { |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
222 OrthancFrameLayerSource& source = dynamic_cast<OrthancFrameLayerSource&>(message.origin_); |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
223 |
322 | 224 // save/replace the slice in cache |
318
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
225 const Slice& slice = source.GetSlice(0); // TODO handle GetSliceCount() ? |
322 | 226 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
|
227 |
330 | 228 LOG(WARNING) << "Image ready: " << sliceKeyId; |
229 | |
318
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
230 boost::shared_ptr<CachedSlice> cachedSlice(new CachedSlice(IObserver::broker_)); |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
231 cachedSlice->image_ = message.image_; |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
232 cachedSlice->effectiveQuality_ = message.imageQuality_; |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
233 cachedSlice->slice_.reset(message.slice_.Clone()); |
322 | 234 cachedSlice->status_ = CachedSliceStatus_ImageLoaded; |
318
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
235 |
322 | 236 cachedSlices_[sliceKeyId] = cachedSlice; |
318
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
237 |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
238 // re-emit original Layer message to observers |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
239 EmitMessage(message); |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
240 } |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
241 |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
242 void SmartLoader::OnLayerReady(const ILayerSource::LayerReadyMessage& message) |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
243 { |
322 | 244 OrthancFrameLayerSource& source = dynamic_cast<OrthancFrameLayerSource&>(message.origin_); |
245 const Slice& slice = source.GetSlice(0); // TODO handle GetSliceCount() ? | |
246 std::string sliceKeyId = slice.GetOrthancInstanceId() + ":" + std::to_string(slice.GetFrame()); | |
247 | |
330 | 248 LOG(WARNING) << "Layer ready: " << sliceKeyId; |
249 | |
322 | 250 // remove the slice from the preloading slices now that it has been fully loaded and it is referenced in the cache |
251 if (preloadingInstances_.find(sliceKeyId) != preloadingInstances_.end()) | |
252 { | |
253 preloadingInstances_.erase(sliceKeyId); | |
254 } | |
255 | |
318
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
256 // re-emit original Layer message to observers |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
257 EmitMessage(message); |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
258 } |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
259 |
260 | 260 } |