Mercurial > hg > orthanc-stone
comparison Framework/Loaders/SeriesThumbnailsLoader.h @ 1381:f4a06ad1580b
Branch broker is now the new default
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Wed, 22 Apr 2020 14:05:47 +0200 |
parents | 0ca50d275b9a |
children | 9cbc6d21ae89 |
comparison
equal
deleted
inserted
replaced
1375:4431ffdcc2a4 | 1381:f4a06ad1580b |
---|---|
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 "../Oracle/GetOrthancImageCommand.h" | |
25 #include "../Oracle/HttpCommand.h" | |
26 #include "../Oracle/OracleCommandExceptionMessage.h" | |
27 #include "../Oracle/OrthancRestApiCommand.h" | |
28 #include "DicomSource.h" | |
29 #include "ILoaderFactory.h" | |
30 #include "OracleScheduler.h" | |
31 | |
32 | |
33 namespace OrthancStone | |
34 { | |
35 enum SeriesThumbnailType | |
36 { | |
37 SeriesThumbnailType_NotLoaded = 1, // The remote server cannot decode this image | |
38 SeriesThumbnailType_Unsupported = 2, // The remote server cannot decode this image | |
39 SeriesThumbnailType_Pdf = 3, | |
40 SeriesThumbnailType_Video = 4, | |
41 SeriesThumbnailType_Image = 5 | |
42 }; | |
43 | |
44 | |
45 class SeriesThumbnailsLoader : | |
46 public IObservable, | |
47 public ObserverBase<SeriesThumbnailsLoader> | |
48 { | |
49 private: | |
50 class Thumbnail : public boost::noncopyable | |
51 { | |
52 private: | |
53 SeriesThumbnailType type_; | |
54 std::string image_; | |
55 std::string mime_; | |
56 | |
57 public: | |
58 Thumbnail(const std::string& image, | |
59 const std::string& mime); | |
60 | |
61 Thumbnail(SeriesThumbnailType type); | |
62 | |
63 SeriesThumbnailType GetType() const | |
64 { | |
65 return type_; | |
66 } | |
67 | |
68 const std::string& GetImage() const | |
69 { | |
70 return image_; | |
71 } | |
72 | |
73 const std::string& GetMime() const | |
74 { | |
75 return mime_; | |
76 } | |
77 }; | |
78 | |
79 public: | |
80 class ThumbnailLoadedMessage : public OriginMessage<SeriesThumbnailsLoader> | |
81 { | |
82 ORTHANC_STONE_MESSAGE(__FILE__, __LINE__); | |
83 | |
84 private: | |
85 const DicomSource& source_; | |
86 const std::string& studyInstanceUid_; | |
87 const std::string& seriesInstanceUid_; | |
88 const Thumbnail& thumbnail_; | |
89 | |
90 public: | |
91 ThumbnailLoadedMessage(const SeriesThumbnailsLoader& origin, | |
92 const DicomSource& source, | |
93 const std::string& studyInstanceUid, | |
94 const std::string& seriesInstanceUid, | |
95 const Thumbnail& thumbnail) : | |
96 OriginMessage(origin), | |
97 source_(source), | |
98 studyInstanceUid_(studyInstanceUid), | |
99 seriesInstanceUid_(seriesInstanceUid), | |
100 thumbnail_(thumbnail) | |
101 { | |
102 } | |
103 | |
104 const DicomSource& GetDicomSource() const | |
105 { | |
106 return source_; | |
107 } | |
108 | |
109 SeriesThumbnailType GetType() const | |
110 { | |
111 return thumbnail_.GetType(); | |
112 } | |
113 | |
114 const std::string& GetStudyInstanceUid() const | |
115 { | |
116 return studyInstanceUid_; | |
117 } | |
118 | |
119 const std::string& GetSeriesInstanceUid() const | |
120 { | |
121 return seriesInstanceUid_; | |
122 } | |
123 | |
124 const std::string& GetEncodedImage() const | |
125 { | |
126 return thumbnail_.GetImage(); | |
127 } | |
128 | |
129 const std::string& GetMime() const | |
130 { | |
131 return thumbnail_.GetMime(); | |
132 } | |
133 }; | |
134 | |
135 private: | |
136 class Handler; | |
137 class DicomWebSopClassHandler; | |
138 class DicomWebThumbnailHandler; | |
139 class ThumbnailInformation; | |
140 class OrthancSopClassHandler; | |
141 class SelectOrthancInstanceHandler; | |
142 | |
143 // Maps a "Series Instance UID" to a thumbnail | |
144 typedef std::map<std::string, Thumbnail*> Thumbnails; | |
145 | |
146 ILoadersContext& context_; | |
147 Thumbnails thumbnails_; | |
148 int priority_; | |
149 unsigned int width_; | |
150 unsigned int height_; | |
151 | |
152 void AcquireThumbnail(const DicomSource& source, | |
153 const std::string& studyInstanceUid, | |
154 const std::string& seriesInstanceUid, | |
155 Thumbnail* thumbnail /* takes ownership */); | |
156 | |
157 void Schedule(IOracleCommand* command); | |
158 | |
159 void Handle(const HttpCommand::SuccessMessage& message); | |
160 | |
161 void Handle(const OrthancRestApiCommand::SuccessMessage& message); | |
162 | |
163 void Handle(const GetOrthancImageCommand::SuccessMessage& message); | |
164 | |
165 void Handle(const OracleCommandExceptionMessage& message); | |
166 | |
167 SeriesThumbnailsLoader(ILoadersContext& context, | |
168 int priority); | |
169 | |
170 public: | |
171 class Factory : public ILoaderFactory | |
172 { | |
173 private: | |
174 int priority_; | |
175 | |
176 public: | |
177 Factory() : | |
178 priority_(0) | |
179 { | |
180 } | |
181 | |
182 void SetPriority(int priority) | |
183 { | |
184 priority_ = priority; | |
185 } | |
186 | |
187 virtual boost::shared_ptr<IObserver> Create(ILoadersContext::ILock& context); | |
188 }; | |
189 | |
190 | |
191 virtual ~SeriesThumbnailsLoader() | |
192 { | |
193 Clear(); | |
194 } | |
195 | |
196 void SetThumbnailSize(unsigned int width, | |
197 unsigned int height); | |
198 | |
199 void Clear(); | |
200 | |
201 SeriesThumbnailType GetSeriesThumbnail(std::string& image, | |
202 std::string& mime, | |
203 const std::string& seriesInstanceUid) const; | |
204 | |
205 void ScheduleLoadThumbnail(const DicomSource& source, | |
206 const std::string& patientId, | |
207 const std::string& studyInstanceUid, | |
208 const std::string& seriesInstanceUid); | |
209 }; | |
210 } |