comparison OrthancStone/Sources/Loaders/SeriesThumbnailsLoader.h @ 1512:244ad1e4e76a

reorganization of folders
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 07 Jul 2020 16:21:02 +0200
parents Framework/Loaders/SeriesThumbnailsLoader.h@121d01aa328e
children 85e117739eca
comparison
equal deleted inserted replaced
1511:9dfeee74c1e6 1512:244ad1e4e76a
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 "../OrthancStone.h"
25
26 #if !defined(ORTHANC_ENABLE_DCMTK)
27 # error Macro ORTHANC_ENABLE_DCMTK must be defined
28 #endif
29
30
31 #include "../Oracle/GetOrthancImageCommand.h"
32 #include "../Oracle/HttpCommand.h"
33 #include "../Oracle/OracleCommandExceptionMessage.h"
34 #include "../Oracle/OrthancRestApiCommand.h"
35 #include "DicomSource.h"
36 #include "ILoaderFactory.h"
37 #include "OracleScheduler.h"
38
39
40 namespace OrthancStone
41 {
42 enum SeriesThumbnailType
43 {
44 SeriesThumbnailType_NotLoaded = 1, // The remote server cannot decode this image
45 SeriesThumbnailType_Unsupported = 2, // The remote server cannot decode this image
46 SeriesThumbnailType_Pdf = 3,
47 SeriesThumbnailType_Video = 4,
48 SeriesThumbnailType_Image = 5
49 };
50
51
52 class SeriesThumbnailsLoader :
53 public IObservable,
54 public ObserverBase<SeriesThumbnailsLoader>
55 {
56 private:
57 class Thumbnail : public boost::noncopyable
58 {
59 private:
60 SeriesThumbnailType type_;
61 std::string image_;
62 std::string mime_;
63
64 public:
65 Thumbnail(const std::string& image,
66 const std::string& mime);
67
68 Thumbnail(SeriesThumbnailType type);
69
70 SeriesThumbnailType GetType() const
71 {
72 return type_;
73 }
74
75 const std::string& GetImage() const
76 {
77 return image_;
78 }
79
80 const std::string& GetMime() const
81 {
82 return mime_;
83 }
84 };
85
86 public:
87 class SuccessMessage : public OriginMessage<SeriesThumbnailsLoader>
88 {
89 ORTHANC_STONE_MESSAGE(__FILE__, __LINE__);
90
91 private:
92 const DicomSource& source_;
93 const std::string& studyInstanceUid_;
94 const std::string& seriesInstanceUid_;
95 const Thumbnail& thumbnail_;
96
97 public:
98 SuccessMessage(const SeriesThumbnailsLoader& origin,
99 const DicomSource& source,
100 const std::string& studyInstanceUid,
101 const std::string& seriesInstanceUid,
102 const Thumbnail& thumbnail) :
103 OriginMessage(origin),
104 source_(source),
105 studyInstanceUid_(studyInstanceUid),
106 seriesInstanceUid_(seriesInstanceUid),
107 thumbnail_(thumbnail)
108 {
109 }
110
111 const DicomSource& GetDicomSource() const
112 {
113 return source_;
114 }
115
116 SeriesThumbnailType GetType() const
117 {
118 return thumbnail_.GetType();
119 }
120
121 const std::string& GetStudyInstanceUid() const
122 {
123 return studyInstanceUid_;
124 }
125
126 const std::string& GetSeriesInstanceUid() const
127 {
128 return seriesInstanceUid_;
129 }
130
131 const std::string& GetEncodedImage() const
132 {
133 return thumbnail_.GetImage();
134 }
135
136 const std::string& GetMime() const
137 {
138 return thumbnail_.GetMime();
139 }
140
141 Orthanc::ImageAccessor* DecodeImage() const;
142 };
143
144 private:
145 class Handler;
146 class DicomWebSopClassHandler;
147 class DicomWebThumbnailHandler;
148 class ThumbnailInformation;
149 class OrthancSopClassHandler;
150 class SelectOrthancInstanceHandler;
151
152 #if ORTHANC_ENABLE_DCMTK == 1
153 class SelectDicomWebInstanceHandler;
154 #endif
155
156 // Maps a "Series Instance UID" to a thumbnail
157 typedef std::map<std::string, Thumbnail*> Thumbnails;
158
159 ILoadersContext& context_;
160 Thumbnails thumbnails_;
161 int priority_;
162 unsigned int width_;
163 unsigned int height_;
164 std::set<std::string> scheduledSeries_;
165
166 void AcquireThumbnail(const DicomSource& source,
167 const std::string& studyInstanceUid,
168 const std::string& seriesInstanceUid,
169 Thumbnail* thumbnail /* takes ownership */);
170
171 void Schedule(IOracleCommand* command);
172
173 void Handle(const HttpCommand::SuccessMessage& message);
174
175 void Handle(const OrthancRestApiCommand::SuccessMessage& message);
176
177 void Handle(const GetOrthancImageCommand::SuccessMessage& message);
178
179 #if ORTHANC_ENABLE_DCMTK == 1
180 void Handle(const ParseDicomSuccessMessage& message);
181 #endif
182
183 void Handle(const OracleCommandExceptionMessage& message);
184
185 SeriesThumbnailsLoader(ILoadersContext& context,
186 int priority);
187
188 public:
189 class Factory : public ILoaderFactory
190 {
191 private:
192 int priority_;
193
194 public:
195 Factory() :
196 priority_(0)
197 {
198 }
199
200 void SetPriority(int priority)
201 {
202 priority_ = priority;
203 }
204
205 virtual boost::shared_ptr<IObserver> Create(ILoadersContext::ILock& context)
206 {
207 return SeriesThumbnailsLoader::Create(context, priority_);
208 }
209 };
210
211
212 virtual ~SeriesThumbnailsLoader()
213 {
214 Clear();
215 }
216
217
218 static boost::shared_ptr<SeriesThumbnailsLoader> Create(ILoadersContext::ILock& context,
219 int priority);
220
221 void SetThumbnailSize(unsigned int width,
222 unsigned int height);
223
224 void Clear();
225
226 SeriesThumbnailType GetSeriesThumbnail(std::string& image,
227 std::string& mime,
228 const std::string& seriesInstanceUid) const;
229
230 void ScheduleLoadThumbnail(const DicomSource& source,
231 const std::string& patientId,
232 const std::string& studyInstanceUid,
233 const std::string& seriesInstanceUid);
234
235 bool IsScheduledSeries(const std::string& seriesInstanceUid) const
236 {
237 return scheduledSeries_.find(seriesInstanceUid) != scheduledSeries_.end();
238 }
239 };
240 }