comparison Framework/Loaders/OrthancSeriesVolumeProgressiveLoader.h @ 1337:b1396be5aa27 broker

Moved the fixed loaders back from the dead
author Benjamin Golinvaux <bgo@osimis.io>
date Fri, 03 Apr 2020 16:13:06 +0200
parents
children 556b4bc19118
comparison
equal deleted inserted replaced
1334:04055b6b9e2c 1337:b1396be5aa27
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-2020 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 #pragma once
23
24 #include "../../Loaders/IFetchingItemsSorter.h"
25 #include "../../Loaders/IFetchingStrategy.h"
26 #include "../../Messages/IObservable.h"
27 #include "../../Messages/ObserverBase.h"
28 #include "../../Oracle/GetOrthancImageCommand.h"
29 #include "../../Oracle/GetOrthancWebViewerJpegCommand.h"
30 #include "../../Oracle/IOracle.h"
31 #include "../../Oracle/OrthancRestApiCommand.h"
32 #include "../../Toolbox/SlicesSorter.h"
33 #include "../../Volumes/DicomVolumeImage.h"
34 #include "../../Volumes/IVolumeSlicer.h"
35
36 #include "../Volumes/IGeometryProvider.h"
37
38
39 #include <boost/shared_ptr.hpp>
40
41 namespace OrthancStone
42 {
43 /**
44 This class is used to manage the progressive loading of a volume that
45 is stored in a Dicom series.
46 */
47 class OrthancSeriesVolumeProgressiveLoader :
48 public OrthancStone::ObserverBase<OrthancSeriesVolumeProgressiveLoader>,
49 public OrthancStone::IObservable,
50 public OrthancStone::IVolumeSlicer,
51 public IGeometryProvider
52 {
53 private:
54 static const unsigned int QUALITY_00 = 0;
55 static const unsigned int QUALITY_01 = 1;
56 static const unsigned int QUALITY_02 = 2;
57
58 class ExtractedSlice;
59
60 /** Helper class internal to OrthancSeriesVolumeProgressiveLoader */
61 class SeriesGeometry : public boost::noncopyable
62 {
63 private:
64 void CheckSlice(size_t index,
65 const OrthancStone::DicomInstanceParameters& reference) const;
66
67 void CheckVolume() const;
68
69 void Clear();
70
71 void CheckSliceIndex(size_t index) const;
72
73 std::unique_ptr<OrthancStone::VolumeImageGeometry> geometry_;
74 std::vector<OrthancStone::DicomInstanceParameters*> slices_;
75 std::vector<uint64_t> slicesRevision_;
76
77 public:
78 ~SeriesGeometry()
79 {
80 Clear();
81 }
82
83 void ComputeGeometry(OrthancStone::SlicesSorter& slices);
84
85 virtual bool HasGeometry() const
86 {
87 return geometry_.get() != NULL;
88 }
89
90 virtual const OrthancStone::VolumeImageGeometry& GetImageGeometry() const;
91
92 const OrthancStone::DicomInstanceParameters& GetSliceParameters(size_t index) const;
93
94 uint64_t GetSliceRevision(size_t index) const;
95
96 void IncrementSliceRevision(size_t index);
97 };
98
99 void ScheduleNextSliceDownload();
100
101 void LoadGeometry(const OrthancStone::OrthancRestApiCommand::SuccessMessage& message);
102
103 void SetSliceContent(unsigned int sliceIndex,
104 const Orthanc::ImageAccessor& image,
105 unsigned int quality);
106
107 void LoadBestQualitySliceContent(const OrthancStone::GetOrthancImageCommand::SuccessMessage& message);
108
109 void LoadJpegSliceContent(const OrthancStone::GetOrthancWebViewerJpegCommand::SuccessMessage& message);
110
111 OrthancStone::ILoadersContext& loadersContext_;
112 bool active_;
113 bool progressiveQuality_;
114 unsigned int simultaneousDownloads_;
115 SeriesGeometry seriesGeometry_;
116 boost::shared_ptr<OrthancStone::DicomVolumeImage> volume_;
117 std::unique_ptr<OrthancStone::IFetchingItemsSorter::IFactory> sorter_;
118 std::unique_ptr<OrthancStone::IFetchingStrategy> strategy_;
119 std::vector<unsigned int> slicesQuality_;
120 bool volumeImageReadyInHighQuality_;
121
122 OrthancSeriesVolumeProgressiveLoader(
123 OrthancStone::ILoadersContext& loadersContext,
124 boost::shared_ptr<OrthancStone::DicomVolumeImage> volume,
125 bool progressiveQuality);
126
127 public:
128 ORTHANC_STONE_DEFINE_ORIGIN_MESSAGE(__FILE__, __LINE__, VolumeImageReadyInHighQuality, OrthancSeriesVolumeProgressiveLoader);
129
130 /**
131 See doc for the progressiveQuality_ field
132 */
133 static boost::shared_ptr<OrthancSeriesVolumeProgressiveLoader> Create(
134 OrthancStone::ILoadersContext& context,
135 boost::shared_ptr<OrthancStone::DicomVolumeImage> volume,
136 bool progressiveQuality = false);
137
138 virtual ~OrthancSeriesVolumeProgressiveLoader();
139
140 void SetSimultaneousDownloads(unsigned int count);
141
142 bool IsVolumeImageReadyInHighQuality() const
143 {
144 return volumeImageReadyInHighQuality_;
145 }
146
147 void LoadSeries(const std::string& seriesId);
148
149 /**
150 This getter is used by clients that do not receive the geometry through
151 subscribing, for instance if they are created or listening only AFTER the
152 "geometry loaded" message is broadcast
153 */
154 bool HasGeometry() const ORTHANC_OVERRIDE
155 {
156 return seriesGeometry_.HasGeometry();
157 }
158
159 /**
160 Same remark as HasGeometry
161 */
162 const OrthancStone::VolumeImageGeometry& GetImageGeometry() const ORTHANC_OVERRIDE
163 {
164 return seriesGeometry_.GetImageGeometry();
165 }
166
167 /**
168 When a slice is requested, the strategy algorithm (that defines the
169 sequence of resources to be loaded from the server) is modified to
170 take into account this request (this is done in the ExtractedSlice ctor)
171 */
172 virtual IExtractedSlice*
173 ExtractSlice(const OrthancStone::CoordinateSystem3D& cuttingPlane) ORTHANC_OVERRIDE;
174 };
175 }