Mercurial > hg > orthanc-stone
annotate Framework/SmartLoader.cpp @ 546:fb7f4a5bdfc0 ct-pet-dose-struct
Merged in dev (pull request #1)
Merge from dev
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Tue, 02 Apr 2019 09:38:50 +0000 |
parents | b70e9be013e4 |
children | 42dadae61fa9 |
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 | |
439 | 5 * Copyright (C) 2017-2019 Osimis S.A., Belgium |
260 | 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" | |
396
ed7146fa2c98
rename ILayerSource as IVolumeSlicer, and OrthancFrameLayerSource as as DicomSeriesVolumeSlicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
395
diff
changeset
|
23 #include "Layers/DicomSeriesVolumeSlicer.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" |
388
20f149669c1f
renamed LayerWidget as SliceViewerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
381
diff
changeset
|
26 #include "Framework/Widgets/SliceViewerWidget.h" |
318
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 { | |
334
c34784e5f299
compatibility fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
330
diff
changeset
|
33 enum CachedSliceStatus |
c34784e5f299
compatibility fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
330
diff
changeset
|
34 { |
c34784e5f299
compatibility fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
330
diff
changeset
|
35 CachedSliceStatus_ScheduledToLoad, |
c34784e5f299
compatibility fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
330
diff
changeset
|
36 CachedSliceStatus_GeometryLoaded, |
c34784e5f299
compatibility fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
330
diff
changeset
|
37 CachedSliceStatus_ImageLoaded |
c34784e5f299
compatibility fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
330
diff
changeset
|
38 }; |
318
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
39 |
401
f1c769b3a5c2
start getting rid of VolumeSlicerBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
396
diff
changeset
|
40 class SmartLoader::CachedSlice : public IVolumeSlicer |
318
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: |
381
19bd222283ae
uncoupling LayerReadyMessage from the creation of the renderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
380
diff
changeset
|
43 class RendererFactory : public LayerReadyMessage::IRendererFactory |
19bd222283ae
uncoupling LayerReadyMessage from the creation of the renderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
380
diff
changeset
|
44 { |
19bd222283ae
uncoupling LayerReadyMessage from the creation of the renderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
380
diff
changeset
|
45 private: |
19bd222283ae
uncoupling LayerReadyMessage from the creation of the renderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
380
diff
changeset
|
46 const CachedSlice& that_; |
19bd222283ae
uncoupling LayerReadyMessage from the creation of the renderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
380
diff
changeset
|
47 |
19bd222283ae
uncoupling LayerReadyMessage from the creation of the renderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
380
diff
changeset
|
48 public: |
19bd222283ae
uncoupling LayerReadyMessage from the creation of the renderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
380
diff
changeset
|
49 RendererFactory(const CachedSlice& that) : |
19bd222283ae
uncoupling LayerReadyMessage from the creation of the renderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
380
diff
changeset
|
50 that_(that) |
19bd222283ae
uncoupling LayerReadyMessage from the creation of the renderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
380
diff
changeset
|
51 { |
19bd222283ae
uncoupling LayerReadyMessage from the creation of the renderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
380
diff
changeset
|
52 } |
19bd222283ae
uncoupling LayerReadyMessage from the creation of the renderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
380
diff
changeset
|
53 |
19bd222283ae
uncoupling LayerReadyMessage from the creation of the renderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
380
diff
changeset
|
54 virtual ILayerRenderer* CreateRenderer() const |
19bd222283ae
uncoupling LayerReadyMessage from the creation of the renderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
380
diff
changeset
|
55 { |
19bd222283ae
uncoupling LayerReadyMessage from the creation of the renderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
380
diff
changeset
|
56 bool isFull = (that_.effectiveQuality_ == SliceImageQuality_FullPng || |
19bd222283ae
uncoupling LayerReadyMessage from the creation of the renderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
380
diff
changeset
|
57 that_.effectiveQuality_ == SliceImageQuality_FullPam); |
19bd222283ae
uncoupling LayerReadyMessage from the creation of the renderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
380
diff
changeset
|
58 |
19bd222283ae
uncoupling LayerReadyMessage from the creation of the renderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
380
diff
changeset
|
59 return FrameRenderer::CreateRenderer(*that_.image_, *that_.slice_, isFull); |
19bd222283ae
uncoupling LayerReadyMessage from the creation of the renderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
380
diff
changeset
|
60 } |
19bd222283ae
uncoupling LayerReadyMessage from the creation of the renderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
380
diff
changeset
|
61 }; |
19bd222283ae
uncoupling LayerReadyMessage from the creation of the renderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
380
diff
changeset
|
62 |
318
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
63 unsigned int sliceIndex_; |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
64 std::auto_ptr<Slice> slice_; |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
65 boost::shared_ptr<Orthanc::ImageAccessor> image_; |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
66 SliceImageQuality effectiveQuality_; |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
67 CachedSliceStatus status_; |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
68 |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
69 public: |
334
c34784e5f299
compatibility fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
330
diff
changeset
|
70 CachedSlice(MessageBroker& broker) : |
401
f1c769b3a5c2
start getting rid of VolumeSlicerBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
396
diff
changeset
|
71 IVolumeSlicer(broker) |
334
c34784e5f299
compatibility fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
330
diff
changeset
|
72 { |
c34784e5f299
compatibility fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
330
diff
changeset
|
73 } |
318
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
74 |
334
c34784e5f299
compatibility fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
330
diff
changeset
|
75 virtual ~CachedSlice() |
c34784e5f299
compatibility fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
330
diff
changeset
|
76 { |
c34784e5f299
compatibility fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
330
diff
changeset
|
77 } |
318
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
78 |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
79 virtual bool GetExtent(std::vector<Vector>& points, |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
80 const CoordinateSystem3D& viewportSlice) |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
81 { |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
82 // TODO: viewportSlice is not used !!!! |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
83 slice_->GetExtent(points); |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
84 return true; |
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 virtual void ScheduleLayerCreation(const CoordinateSystem3D& viewportSlice) |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
88 { |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
89 // TODO: viewportSlice is not used !!!! |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
90 |
330 | 91 // it has already been loaded -> trigger the "layer ready" message immediately otherwise, do nothing now. The LayerReady will be triggered |
396
ed7146fa2c98
rename ILayerSource as IVolumeSlicer, and OrthancFrameLayerSource as as DicomSeriesVolumeSlicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
395
diff
changeset
|
92 // once the VolumeSlicer is ready |
330 | 93 if (status_ == CachedSliceStatus_ImageLoaded) |
94 { | |
95 LOG(WARNING) << "ScheduleLayerCreation for CachedSlice (image is loaded): " << slice_->GetOrthancInstanceId(); | |
381
19bd222283ae
uncoupling LayerReadyMessage from the creation of the renderer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
380
diff
changeset
|
96 |
401
f1c769b3a5c2
start getting rid of VolumeSlicerBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
396
diff
changeset
|
97 RendererFactory factory(*this); |
f1c769b3a5c2
start getting rid of VolumeSlicerBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
396
diff
changeset
|
98 EmitMessage(IVolumeSlicer::LayerReadyMessage(*this, factory, slice_->GetGeometry())); |
330 | 99 } |
100 else | |
101 { | |
102 LOG(WARNING) << "ScheduleLayerCreation for CachedSlice (image is not loaded yet): " << slice_->GetOrthancInstanceId(); | |
103 } | |
318
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
104 } |
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 CachedSlice* Clone() const |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
107 { |
393
e7a494bdd956
removed Messages/MessageType.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
388
diff
changeset
|
108 CachedSlice* output = new CachedSlice(GetBroker()); |
318
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
109 output->sliceIndex_ = sliceIndex_; |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
110 output->slice_.reset(slice_->Clone()); |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
111 output->image_ = image_; |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
112 output->effectiveQuality_ = effectiveQuality_; |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
113 output->status_ = status_; |
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 return output; |
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 |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
118 }; |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
119 |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
120 |
334
c34784e5f299
compatibility fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
330
diff
changeset
|
121 SmartLoader::SmartLoader(MessageBroker& broker, |
c34784e5f299
compatibility fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
330
diff
changeset
|
122 OrthancApiClient& orthancApiClient) : |
260 | 123 IObservable(broker), |
124 IObserver(broker), | |
125 imageQuality_(SliceImageQuality_FullPam), | |
317 | 126 orthancApiClient_(orthancApiClient) |
267 | 127 { |
260 | 128 } |
129 | |
388
20f149669c1f
renamed LayerWidget as SliceViewerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
381
diff
changeset
|
130 void SmartLoader::SetFrameInWidget(SliceViewerWidget& sliceViewer, |
334
c34784e5f299
compatibility fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
330
diff
changeset
|
131 size_t layerIndex, |
c34784e5f299
compatibility fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
330
diff
changeset
|
132 const std::string& instanceId, |
c34784e5f299
compatibility fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
330
diff
changeset
|
133 unsigned int frame) |
260 | 134 { |
262 | 135 // TODO: check if this frame has already been loaded or is already being loaded. |
136 // - if already loaded: create a "clone" that will emit the GeometryReady/ImageReady messages "immediately" | |
137 // (it can not be immediate because Observers needs to register first and this is done after this method returns) | |
396
ed7146fa2c98
rename ILayerSource as IVolumeSlicer, and OrthancFrameLayerSource as as DicomSeriesVolumeSlicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
395
diff
changeset
|
138 // - if currently loading, we need to return an object that will observe the existing VolumeSlicer and forward |
262 | 139 // the messages to its observables |
140 // 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
|
141 |
396
ed7146fa2c98
rename ILayerSource as IVolumeSlicer, and OrthancFrameLayerSource as as DicomSeriesVolumeSlicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
395
diff
changeset
|
142 std::auto_ptr<IVolumeSlicer> layerSource; |
334
c34784e5f299
compatibility fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
330
diff
changeset
|
143 std::string sliceKeyId = instanceId + ":" + boost::lexical_cast<std::string>(frame); |
330 | 144 SmartLoader::CachedSlice* cachedSlice = NULL; |
318
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
145 |
322 | 146 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
|
147 { |
322 | 148 layerSource.reset(cachedSlices_[sliceKeyId]->Clone()); |
330 | 149 cachedSlice = dynamic_cast<SmartLoader::CachedSlice*>(layerSource.get()); |
318
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
150 } |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
151 else |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
152 { |
396
ed7146fa2c98
rename ILayerSource as IVolumeSlicer, and OrthancFrameLayerSource as as DicomSeriesVolumeSlicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
395
diff
changeset
|
153 layerSource.reset(new DicomSeriesVolumeSlicer(IObserver::GetBroker(), orthancApiClient_)); |
ed7146fa2c98
rename ILayerSource as IVolumeSlicer, and OrthancFrameLayerSource as as DicomSeriesVolumeSlicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
395
diff
changeset
|
154 dynamic_cast<DicomSeriesVolumeSlicer*>(layerSource.get())->SetImageQuality(imageQuality_); |
ed7146fa2c98
rename ILayerSource as IVolumeSlicer, and OrthancFrameLayerSource as as DicomSeriesVolumeSlicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
395
diff
changeset
|
155 layerSource->RegisterObserverCallback(new Callable<SmartLoader, IVolumeSlicer::GeometryReadyMessage>(*this, &SmartLoader::OnLayerGeometryReady)); |
ed7146fa2c98
rename ILayerSource as IVolumeSlicer, and OrthancFrameLayerSource as as DicomSeriesVolumeSlicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
395
diff
changeset
|
156 layerSource->RegisterObserverCallback(new Callable<SmartLoader, DicomSeriesVolumeSlicer::FrameReadyMessage>(*this, &SmartLoader::OnFrameReady)); |
ed7146fa2c98
rename ILayerSource as IVolumeSlicer, and OrthancFrameLayerSource as as DicomSeriesVolumeSlicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
395
diff
changeset
|
157 layerSource->RegisterObserverCallback(new Callable<SmartLoader, IVolumeSlicer::LayerReadyMessage>(*this, &SmartLoader::OnLayerReady)); |
ed7146fa2c98
rename ILayerSource as IVolumeSlicer, and OrthancFrameLayerSource as as DicomSeriesVolumeSlicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
395
diff
changeset
|
158 dynamic_cast<DicomSeriesVolumeSlicer*>(layerSource.get())->LoadFrame(instanceId, frame); |
318
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
159 } |
260 | 160 |
318
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
161 // make sure that the widget registers the events before we trigger them |
388
20f149669c1f
renamed LayerWidget as SliceViewerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
381
diff
changeset
|
162 if (sliceViewer.GetLayerCount() == layerIndex) |
318
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
163 { |
388
20f149669c1f
renamed LayerWidget as SliceViewerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
381
diff
changeset
|
164 sliceViewer.AddLayer(layerSource.release()); |
318
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
165 } |
388
20f149669c1f
renamed LayerWidget as SliceViewerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
381
diff
changeset
|
166 else if (sliceViewer.GetLayerCount() > layerIndex) |
318
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
167 { |
388
20f149669c1f
renamed LayerWidget as SliceViewerWidget
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
381
diff
changeset
|
168 sliceViewer.ReplaceLayer(layerIndex, layerSource.release()); |
318
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
169 } |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
170 else |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
171 { |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
172 throw StoneException(ErrorCode_CanOnlyAddOneLayerAtATime); |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
173 } |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
174 |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
175 if (cachedSlice != NULL) |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
176 { |
401
f1c769b3a5c2
start getting rid of VolumeSlicerBase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
396
diff
changeset
|
177 EmitMessage(IVolumeSlicer::GeometryReadyMessage(*cachedSlice)); |
318
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
178 } |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
179 |
260 | 180 } |
181 | |
334
c34784e5f299
compatibility fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
330
diff
changeset
|
182 void SmartLoader::PreloadSlice(const std::string instanceId, |
c34784e5f299
compatibility fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
330
diff
changeset
|
183 unsigned int frame) |
322 | 184 { |
396
ed7146fa2c98
rename ILayerSource as IVolumeSlicer, and OrthancFrameLayerSource as as DicomSeriesVolumeSlicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
395
diff
changeset
|
185 // TODO: reactivate -> need to be able to ScheduleLayerLoading in IVolumeSlicer without calling ScheduleLayerCreation |
330 | 186 return; |
322 | 187 // 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
|
188 |
330 | 189 |
190 | |
322 | 191 // create the slice in the cache with "empty" data |
393
e7a494bdd956
removed Messages/MessageType.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
388
diff
changeset
|
192 boost::shared_ptr<CachedSlice> cachedSlice(new CachedSlice(IObserver::GetBroker())); |
322 | 193 cachedSlice->slice_.reset(new Slice(instanceId, frame)); |
194 cachedSlice->status_ = CachedSliceStatus_ScheduledToLoad; | |
334
c34784e5f299
compatibility fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
330
diff
changeset
|
195 std::string sliceKeyId = instanceId + ":" + boost::lexical_cast<std::string>(frame); |
322 | 196 |
330 | 197 LOG(WARNING) << "Will preload: " << sliceKeyId; |
198 | |
322 | 199 cachedSlices_[sliceKeyId] = boost::shared_ptr<CachedSlice>(cachedSlice); |
200 | |
396
ed7146fa2c98
rename ILayerSource as IVolumeSlicer, and OrthancFrameLayerSource as as DicomSeriesVolumeSlicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
395
diff
changeset
|
201 std::auto_ptr<IVolumeSlicer> layerSource(new DicomSeriesVolumeSlicer(IObserver::GetBroker(), orthancApiClient_)); |
322 | 202 |
396
ed7146fa2c98
rename ILayerSource as IVolumeSlicer, and OrthancFrameLayerSource as as DicomSeriesVolumeSlicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
395
diff
changeset
|
203 dynamic_cast<DicomSeriesVolumeSlicer*>(layerSource.get())->SetImageQuality(imageQuality_); |
ed7146fa2c98
rename ILayerSource as IVolumeSlicer, and OrthancFrameLayerSource as as DicomSeriesVolumeSlicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
395
diff
changeset
|
204 layerSource->RegisterObserverCallback(new Callable<SmartLoader, IVolumeSlicer::GeometryReadyMessage>(*this, &SmartLoader::OnLayerGeometryReady)); |
ed7146fa2c98
rename ILayerSource as IVolumeSlicer, and OrthancFrameLayerSource as as DicomSeriesVolumeSlicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
395
diff
changeset
|
205 layerSource->RegisterObserverCallback(new Callable<SmartLoader, DicomSeriesVolumeSlicer::FrameReadyMessage>(*this, &SmartLoader::OnFrameReady)); |
ed7146fa2c98
rename ILayerSource as IVolumeSlicer, and OrthancFrameLayerSource as as DicomSeriesVolumeSlicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
395
diff
changeset
|
206 layerSource->RegisterObserverCallback(new Callable<SmartLoader, IVolumeSlicer::LayerReadyMessage>(*this, &SmartLoader::OnLayerReady)); |
ed7146fa2c98
rename ILayerSource as IVolumeSlicer, and OrthancFrameLayerSource as as DicomSeriesVolumeSlicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
395
diff
changeset
|
207 dynamic_cast<DicomSeriesVolumeSlicer*>(layerSource.get())->LoadFrame(instanceId, frame); |
322 | 208 |
396
ed7146fa2c98
rename ILayerSource as IVolumeSlicer, and OrthancFrameLayerSource as as DicomSeriesVolumeSlicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
395
diff
changeset
|
209 // keep a ref to the VolumeSlicer until the slice is fully loaded and saved to cache |
ed7146fa2c98
rename ILayerSource as IVolumeSlicer, and OrthancFrameLayerSource as as DicomSeriesVolumeSlicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
395
diff
changeset
|
210 preloadingInstances_[sliceKeyId] = boost::shared_ptr<IVolumeSlicer>(layerSource.release()); |
270 | 211 } |
260 | 212 |
266
c9cf95b49a86
removed OrthancSlicesLoader::ISliceLoaderObserver; now using standard messages instead
am@osimis.io
parents:
262
diff
changeset
|
213 |
322 | 214 // void PreloadStudy(const std::string studyId) |
215 // { | |
216 // /* TODO */ | |
217 // } | |
218 | |
219 // void PreloadSeries(const std::string seriesId) | |
220 // { | |
221 // /* TODO */ | |
222 // } | |
266
c9cf95b49a86
removed OrthancSlicesLoader::ISliceLoaderObserver; now using standard messages instead
am@osimis.io
parents:
262
diff
changeset
|
223 |
c9cf95b49a86
removed OrthancSlicesLoader::ISliceLoaderObserver; now using standard messages instead
am@osimis.io
parents:
262
diff
changeset
|
224 |
396
ed7146fa2c98
rename ILayerSource as IVolumeSlicer, and OrthancFrameLayerSource as as DicomSeriesVolumeSlicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
395
diff
changeset
|
225 void SmartLoader::OnLayerGeometryReady(const IVolumeSlicer::GeometryReadyMessage& message) |
318
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
226 { |
406
5d359b115b29
use of callables in OrthancVolumeImage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
401
diff
changeset
|
227 const DicomSeriesVolumeSlicer& source = |
5d359b115b29
use of callables in OrthancVolumeImage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
401
diff
changeset
|
228 dynamic_cast<const DicomSeriesVolumeSlicer&>(message.GetOrigin()); |
322 | 229 |
230 // save/replace the slice in cache | |
318
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
231 const Slice& slice = source.GetSlice(0); // TODO handle GetSliceCount() |
334
c34784e5f299
compatibility fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
330
diff
changeset
|
232 std::string sliceKeyId = (slice.GetOrthancInstanceId() + ":" + |
c34784e5f299
compatibility fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
330
diff
changeset
|
233 boost::lexical_cast<std::string>(slice.GetFrame())); |
318
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
234 |
330 | 235 LOG(WARNING) << "Geometry ready: " << sliceKeyId; |
236 | |
393
e7a494bdd956
removed Messages/MessageType.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
388
diff
changeset
|
237 boost::shared_ptr<CachedSlice> cachedSlice(new CachedSlice(IObserver::GetBroker())); |
318
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
238 cachedSlice->slice_.reset(slice.Clone()); |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
239 cachedSlice->effectiveQuality_ = source.GetImageQuality(); |
322 | 240 cachedSlice->status_ = CachedSliceStatus_GeometryLoaded; |
318
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
241 |
322 | 242 cachedSlices_[sliceKeyId] = boost::shared_ptr<CachedSlice>(cachedSlice); |
318
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
243 |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
244 // re-emit original Layer message to observers |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
245 EmitMessage(message); |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
246 } |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
247 |
334
c34784e5f299
compatibility fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
330
diff
changeset
|
248 |
396
ed7146fa2c98
rename ILayerSource as IVolumeSlicer, and OrthancFrameLayerSource as as DicomSeriesVolumeSlicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
395
diff
changeset
|
249 void SmartLoader::OnFrameReady(const DicomSeriesVolumeSlicer::FrameReadyMessage& message) |
318
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
250 { |
322 | 251 // save/replace the slice in cache |
395
5f13809f3f76
rename ILayerSource::ImageReadyMessage to OrthancFrameLayerSource::FrameReadyMessage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
393
diff
changeset
|
252 const Slice& slice = message.GetSlice(); |
334
c34784e5f299
compatibility fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
330
diff
changeset
|
253 std::string sliceKeyId = (slice.GetOrthancInstanceId() + ":" + |
c34784e5f299
compatibility fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
330
diff
changeset
|
254 boost::lexical_cast<std::string>(slice.GetFrame())); |
318
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
255 |
330 | 256 LOG(WARNING) << "Image ready: " << sliceKeyId; |
257 | |
393
e7a494bdd956
removed Messages/MessageType.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
388
diff
changeset
|
258 boost::shared_ptr<CachedSlice> cachedSlice(new CachedSlice(IObserver::GetBroker())); |
395
5f13809f3f76
rename ILayerSource::ImageReadyMessage to OrthancFrameLayerSource::FrameReadyMessage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
393
diff
changeset
|
259 cachedSlice->image_.reset(Orthanc::Image::Clone(message.GetFrame())); |
378 | 260 cachedSlice->effectiveQuality_ = message.GetImageQuality(); |
261 cachedSlice->slice_.reset(message.GetSlice().Clone()); | |
322 | 262 cachedSlice->status_ = CachedSliceStatus_ImageLoaded; |
318
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
263 |
322 | 264 cachedSlices_[sliceKeyId] = cachedSlice; |
318
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
265 |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
266 // re-emit original Layer message to observers |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
267 EmitMessage(message); |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
268 } |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
269 |
334
c34784e5f299
compatibility fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
330
diff
changeset
|
270 |
396
ed7146fa2c98
rename ILayerSource as IVolumeSlicer, and OrthancFrameLayerSource as as DicomSeriesVolumeSlicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
395
diff
changeset
|
271 void SmartLoader::OnLayerReady(const IVolumeSlicer::LayerReadyMessage& message) |
318
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
272 { |
406
5d359b115b29
use of callables in OrthancVolumeImage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
401
diff
changeset
|
273 const DicomSeriesVolumeSlicer& source = |
5d359b115b29
use of callables in OrthancVolumeImage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
401
diff
changeset
|
274 dynamic_cast<const DicomSeriesVolumeSlicer&>(message.GetOrigin()); |
5d359b115b29
use of callables in OrthancVolumeImage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
401
diff
changeset
|
275 |
322 | 276 const Slice& slice = source.GetSlice(0); // TODO handle GetSliceCount() ? |
334
c34784e5f299
compatibility fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
330
diff
changeset
|
277 std::string sliceKeyId = (slice.GetOrthancInstanceId() + ":" + |
c34784e5f299
compatibility fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
330
diff
changeset
|
278 boost::lexical_cast<std::string>(slice.GetFrame())); |
322 | 279 |
330 | 280 LOG(WARNING) << "Layer ready: " << sliceKeyId; |
281 | |
322 | 282 // remove the slice from the preloading slices now that it has been fully loaded and it is referenced in the cache |
283 if (preloadingInstances_.find(sliceKeyId) != preloadingInstances_.end()) | |
284 { | |
285 preloadingInstances_.erase(sliceKeyId); | |
286 } | |
287 | |
318
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
288 // re-emit original Layer message to observers |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
289 EmitMessage(message); |
3a4ca166fafa
ImageAccessor refactoring + implemented Image Cache in SmartLoader
am@osimis.io
parents:
317
diff
changeset
|
290 } |
260 | 291 } |