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