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