comparison Framework/Deprecated/Radiography/RadiographyScene.h @ 1398:c5403d52078c

moved Radiography into Deprecated
author Alain Mazy <alain@mazy.be>
date Wed, 29 Apr 2020 20:43:09 +0200
parents Framework/Radiography/RadiographyScene.h@6ea4062c1a0d
children 30deba7bc8e2
comparison
equal deleted inserted replaced
1397:1c2d065ba372 1398:c5403d52078c
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 "RadiographyLayer.h"
25 #include "../Messages/ObserverBase.h"
26 #include "../Deprecated/Toolbox/DicomFrameConverter.h"
27 #include "../Deprecated/Toolbox/OrthancApiClient.h"
28 #include "../StoneEnumerations.h"
29 #include "Core/Images/Image.h"
30 #include "Core/Images/ImageProcessing.h"
31
32 #include "../Scene2D/Scene2D.h"
33
34 namespace OrthancStone
35 {
36 class RadiographyDicomLayer;
37
38 class RadiographyScene :
39 public ObserverBase<RadiographyScene>,
40 public IObservable
41 {
42 friend class RadiographySceneGeometryReader;
43 public:
44 class GeometryChangedMessage : public OriginMessage<RadiographyScene>
45 {
46 ORTHANC_STONE_MESSAGE(__FILE__, __LINE__);
47
48 private:
49 RadiographyLayer& layer_;
50
51 public:
52 GeometryChangedMessage(const RadiographyScene& origin,
53 RadiographyLayer& layer) :
54 OriginMessage(origin),
55 layer_(layer)
56 {
57 }
58
59 RadiographyLayer& GetLayer() const
60 {
61 return layer_;
62 }
63 };
64
65 class ContentChangedMessage : public OriginMessage<RadiographyScene>
66 {
67 ORTHANC_STONE_MESSAGE(__FILE__, __LINE__);
68
69 private:
70 RadiographyLayer& layer_;
71
72 public:
73 ContentChangedMessage(const RadiographyScene& origin,
74 RadiographyLayer& layer) :
75 OriginMessage(origin),
76 layer_(layer)
77 {
78 }
79
80 RadiographyLayer& GetLayer() const
81 {
82 return layer_;
83 }
84 };
85
86 class LayerEditedMessage : public OriginMessage<RadiographyScene>
87 {
88 ORTHANC_STONE_MESSAGE(__FILE__, __LINE__);
89
90 private:
91 const RadiographyLayer& layer_;
92
93 public:
94 LayerEditedMessage(const RadiographyScene& origin,
95 const RadiographyLayer& layer) :
96 OriginMessage(origin),
97 layer_(layer)
98 {
99 }
100
101 const RadiographyLayer& GetLayer() const
102 {
103 return layer_;
104 }
105 };
106
107 class LayerRemovedMessage : public OriginMessage<RadiographyScene>
108 {
109 ORTHANC_STONE_MESSAGE(__FILE__, __LINE__);
110
111 private:
112 size_t& layerIndex_;
113
114 public:
115 LayerRemovedMessage(const RadiographyScene& origin,
116 size_t& layerIndex) :
117 OriginMessage(origin),
118 layerIndex_(layerIndex)
119 {
120 }
121
122 size_t& GetLayerIndex() const
123 {
124 return layerIndex_;
125 }
126 };
127
128
129 ORTHANC_STONE_DEFINE_ORIGIN_MESSAGE(__FILE__, __LINE__, WindowingChangedMessage, RadiographyScene);
130
131
132 class LayerAccessor : public boost::noncopyable
133 {
134 private:
135 RadiographyScene& scene_;
136 size_t index_;
137 RadiographyLayer* layer_;
138
139 public:
140 LayerAccessor(RadiographyScene& scene,
141 size_t index);
142
143 LayerAccessor(RadiographyScene& scene,
144 double x,
145 double y);
146
147 void Invalidate()
148 {
149 layer_ = NULL;
150 }
151
152 bool IsValid() const
153 {
154 return layer_ != NULL;
155 }
156
157 RadiographyScene& GetScene() const;
158
159 size_t GetIndex() const;
160
161 RadiographyLayer& GetLayer() const;
162 };
163
164
165 protected:
166 typedef std::map<size_t, RadiographyLayer*> Layers;
167
168 size_t nextLayerIndex_;
169 bool hasWindowing_;
170 float windowingCenter_;
171 float windowingWidth_;
172 Layers layers_;
173
174 public:
175 RadiographyLayer& RegisterLayer(RadiographyLayer* layer);
176
177 protected:
178 virtual void _RegisterLayer(RadiographyLayer* layer);
179 virtual void _OnLayerRemoved() {}
180
181 void SetLayerIndex(RadiographyLayer* layer, size_t index)
182 {
183 layer->SetIndex(index);
184 }
185
186 virtual void OnTagsReceived(const Deprecated::OrthancApiClient::BinaryResponseReadyMessage& message);
187
188 virtual void OnFrameReceived(const Deprecated::OrthancApiClient::BinaryResponseReadyMessage& message);
189
190 void OnDicomExported(const Deprecated::OrthancApiClient::JsonResponseReadyMessage& message);
191
192 void OnDicomWebReceived(const Deprecated::IWebService::HttpRequestSuccessMessage& message);
193
194 virtual void OnLayerEdited(const RadiographyLayer::LayerEditedMessage& message);
195
196 public:
197 RadiographyScene();
198
199 virtual ~RadiographyScene();
200
201 virtual size_t GetApproximateMemoryUsage() const;
202
203 bool GetWindowing(float& center,
204 float& width) const;
205
206 void GetWindowingWithDefault(float& center,
207 float& width) const;
208
209 virtual void SetWindowing(float center,
210 float width);
211
212 RadiographyPhotometricDisplayMode GetPreferredPhotomotricDisplayMode() const;
213
214 RadiographyLayer& LoadText(const std::string& utf8,
215 const std::string& font,
216 unsigned int fontSize,
217 uint8_t foreground,
218 RadiographyLayer::Geometry* geometry,
219 bool isCenterGeometry);
220
221 RadiographyLayer& UpdateText(size_t layerIndex,
222 const std::string& font,
223 const std::string& utf8,
224 unsigned int fontSize,
225 uint8_t foreground);
226
227 RadiographyLayer& LoadTestBlock(unsigned int width,
228 unsigned int height,
229 RadiographyLayer::Geometry* geometry);
230
231 RadiographyLayer& LoadMask(const std::vector<Orthanc::ImageProcessing::ImagePoint>& corners,
232 const RadiographyDicomLayer& dicomLayer,
233 float foreground,
234 RadiographyLayer::Geometry* geometry);
235
236 RadiographyLayer& LoadAlphaBitmap(Orthanc::ImageAccessor* bitmap, // takes ownership
237 RadiographyLayer::Geometry* geometry);
238
239 virtual RadiographyLayer& LoadDicomImage(Orthanc::ImageAccessor* dicomImage, // takes ownership
240 const std::string& instance,
241 unsigned int frame,
242 Deprecated::DicomFrameConverter* converter, // takes ownership
243 RadiographyPhotometricDisplayMode preferredPhotometricDisplayMode,
244 RadiographyLayer::Geometry* geometry);
245
246 virtual RadiographyLayer& LoadDicomFrame(Deprecated::OrthancApiClient& orthanc,
247 const std::string& instance,
248 unsigned int frame,
249 bool httpCompression,
250 RadiographyLayer::Geometry* geometry); // pass NULL if you want default geometry
251
252 RadiographyLayer& LoadDicomWebFrame(Deprecated::IWebService& web);
253
254 void RemoveLayer(size_t layerIndex);
255
256 RadiographyLayer& GetLayer(size_t layerIndex);
257
258 const RadiographyLayer& GetLayer(size_t layerIndex) const;
259
260 template <typename TypeLayer>
261 TypeLayer* GetTypedLayer(size_t indexOfType = 0)
262 {
263 std::vector<size_t> layerIndexes;
264 GetLayersIndexes(layerIndexes);
265
266 size_t count = 0;
267
268 for (size_t i = 0; i < layerIndexes.size(); ++i)
269 {
270 TypeLayer* typedLayer = dynamic_cast<TypeLayer*>(layers_[layerIndexes[i]]);
271 if (typedLayer != NULL)
272 {
273 if (count == indexOfType)
274 {
275 return typedLayer;
276 }
277 count++;
278 }
279 }
280
281 return NULL;
282 }
283
284 void GetLayersIndexes(std::vector<size_t>& output) const;
285
286 virtual Extent2D GetSceneExtent(bool minimal) const;
287
288 virtual void Render(Orthanc::ImageAccessor& buffer,
289 const AffineTransform2D& viewTransform,
290 ImageInterpolation interpolation,
291 bool applyWindowing) const;
292
293 bool LookupLayer(size_t& index /* out */,
294 double x,
295 double y) const;
296
297 void DrawBorder(CairoContext& context,
298 unsigned int layer,
299 double zoom);
300
301 void GetRange(float& minValue,
302 float& maxValue) const;
303
304 void ExportToScene2D(Scene2D& output) const;
305
306 // Export using PAM is faster than using PNG, but requires Orthanc
307 // core >= 1.4.3
308 void ExportDicom(Deprecated::OrthancApiClient& orthanc,
309 const Orthanc::DicomMap& dicom,
310 const std::string& parentOrthancId,
311 double pixelSpacingX,
312 double pixelSpacingY,
313 bool invert,
314 bool autoCrop,
315 ImageInterpolation interpolation,
316 bool usePam);
317
318 void ExportDicom(Deprecated::OrthancApiClient& orthanc,
319 const Json::Value& dicomTags,
320 const std::string& parentOrthancId,
321 double pixelSpacingX,
322 double pixelSpacingY,
323 bool invert,
324 bool autoCrop,
325 ImageInterpolation interpolation,
326 bool usePam);
327
328 void ExportToCreateDicomRequest(Json::Value& createDicomRequestContent,
329 const Json::Value& dicomTags,
330 const std::string& parentOrthancId,
331 double pixelSpacingX,
332 double pixelSpacingY,
333 bool invert,
334 bool autoCrop,
335 ImageInterpolation interpolation,
336 bool usePam);
337
338 Orthanc::Image* ExportToCreateDicomRequestAndImage(Json::Value& createDicomRequestContent,
339 const Json::Value& dicomTags,
340 const std::string& parentOrthancId,
341 double pixelSpacingX,
342 double pixelSpacingY,
343 bool invert,
344 bool autoCrop,
345 ImageInterpolation interpolation);
346
347 Orthanc::Image* ExportToImage(double pixelSpacingX,
348 double pixelSpacingY,
349 ImageInterpolation interpolation,
350 bool autoCrop,
351 bool applyWindowing)
352 {
353 return ExportToImage(pixelSpacingX, pixelSpacingY, interpolation, false, 0, autoCrop, applyWindowing);
354 }
355
356 Orthanc::Image* ExportToImage(double pixelSpacingX,
357 double pixelSpacingY,
358 ImageInterpolation interpolation,
359 bool invert,
360 int64_t maxValue /* for inversion */,
361 bool autoCrop,
362 bool applyWindowing);
363
364 void ExtractLayerFromRenderedScene(Orthanc::ImageAccessor& layer,
365 const Orthanc::ImageAccessor& renderedScene,
366 size_t layerIndex,
367 bool isCropped,
368 ImageInterpolation interpolation);
369 };
370 }