comparison Framework/Deprecated/Radiography/RadiographyLayer.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/RadiographyLayer.h@379c00958553
children
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 <algorithm>
25
26 #include "../Toolbox/AffineTransform2D.h"
27 #include "../Toolbox/Extent2D.h"
28 #include "../Wrappers/CairoContext.h"
29 #include "../Messages/IMessage.h"
30 #include "../Messages/IObservable.h"
31
32 namespace OrthancStone
33 {
34 class RadiographyScene;
35
36 enum RadiographyControlPointType
37 {
38 RadiographyControlPointType_TopLeftCorner = 0,
39 RadiographyControlPointType_TopRightCorner = 1,
40 RadiographyControlPointType_BottomRightCorner = 2,
41 RadiographyControlPointType_BottomLeftCorner = 3
42 };
43
44 enum RadiographyPhotometricDisplayMode
45 {
46 RadiographyPhotometricDisplayMode_Default,
47
48 RadiographyPhotometricDisplayMode_Monochrome1,
49 RadiographyPhotometricDisplayMode_Monochrome2
50 };
51
52
53 struct ControlPoint
54 {
55 double x;
56 double y;
57 size_t index;
58
59 ControlPoint(double x, double y, size_t index)
60 : x(x),
61 y(y),
62 index(index)
63 {}
64
65 ControlPoint()
66 : x(0),
67 y(0),
68 index(std::numeric_limits<size_t>::max())
69 {}
70 };
71
72 class RadiographyLayer : public IObservable
73 {
74 friend class RadiographyScene;
75
76 public:
77 ORTHANC_STONE_DEFINE_ORIGIN_MESSAGE(__FILE__, __LINE__, LayerEditedMessage, RadiographyLayer);
78
79 class Geometry
80 {
81 bool hasCrop_;
82 unsigned int cropX_;
83 unsigned int cropY_;
84 unsigned int cropWidth_;
85 unsigned int cropHeight_;
86 bool flipVertical_;
87 bool flipHorizontal_;
88 double panX_;
89 double panY_;
90 double angle_;
91 bool resizeable_;
92 double pixelSpacingX_;
93 double pixelSpacingY_;
94
95 public:
96 Geometry();
97
98 void ResetCrop()
99 {
100 hasCrop_ = false;
101 }
102
103 void SetCrop(unsigned int x,
104 unsigned int y,
105 unsigned int width,
106 unsigned int height)
107 {
108 hasCrop_ = true;
109 cropX_ = x;
110 cropY_ = y;
111 cropWidth_ = width;
112 cropHeight_ = height;
113 }
114
115 bool HasCrop() const
116 {
117 return hasCrop_;
118 }
119
120 void GetCrop(unsigned int& x,
121 unsigned int& y,
122 unsigned int& width,
123 unsigned int& height) const;
124
125 void SetAngle(double angle)
126 {
127 angle_ = angle;
128 }
129
130 double GetAngle() const
131 {
132 return angle_;
133 }
134
135 void SetPan(double x,
136 double y)
137 {
138 panX_ = x;
139 panY_ = y;
140 }
141
142 double GetPanX() const
143 {
144 return panX_;
145 }
146
147 double GetPanY() const
148 {
149 return panY_;
150 }
151
152 bool IsResizeable() const
153 {
154 return resizeable_;
155 }
156
157 void SetResizeable(bool resizeable)
158 {
159 resizeable_ = resizeable;
160 }
161
162 void SetPixelSpacing(double x,
163 double y)
164 {
165 pixelSpacingX_ = x;
166 pixelSpacingY_ = y;
167 }
168
169 double GetPixelSpacingX() const
170 {
171 return pixelSpacingX_;
172 }
173
174 double GetPixelSpacingY() const
175 {
176 return pixelSpacingY_;
177 }
178
179 void SetFlipVertical(bool flip) // mirrors image around an horizontal axis (note: flip is applied before the rotation !)
180 {
181 flipVertical_ = flip;
182 }
183
184 void SetFlipHorizontal(bool flip) // mirrors image around a vertical axis (note: flip is applied before the rotation !)
185 {
186 flipHorizontal_ = flip;
187 }
188
189 bool GetFlipVertical() const
190 {
191 return flipVertical_;
192 }
193
194 bool GetFlipHorizontal() const
195 {
196 return flipHorizontal_;
197 }
198
199 double GetScalingX() const
200 {
201 return (flipHorizontal_ ? - pixelSpacingX_: pixelSpacingX_);
202 }
203
204 double GetScalingY() const
205 {
206 return (flipVertical_ ? - pixelSpacingY_: pixelSpacingY_);
207 }
208 };
209
210 private:
211 size_t index_;
212 bool hasSize_;
213 unsigned int width_;
214 unsigned int height_;
215 AffineTransform2D transform_;
216 AffineTransform2D transformInverse_;
217 Geometry geometry_;
218 RadiographyPhotometricDisplayMode prefferedPhotometricDisplayMode_;
219 const RadiographyScene& scene_;
220
221 protected:
222 void SetPreferredPhotomotricDisplayMode(RadiographyPhotometricDisplayMode prefferedPhotometricDisplayMode);
223
224 private:
225 void UpdateTransform();
226
227 void AddToExtent(Extent2D& extent,
228 double x,
229 double y) const;
230
231 void SetIndex(size_t index)
232 {
233 index_ = index;
234 }
235
236 bool Contains(double x,
237 double y) const;
238
239 void DrawBorders(CairoContext& context,
240 double zoom);
241
242 public:
243 RadiographyLayer(const RadiographyScene& scene);
244
245 virtual ~RadiographyLayer()
246 {
247 }
248
249 virtual const AffineTransform2D& GetTransform() const
250 {
251 return transform_;
252 }
253
254 virtual const AffineTransform2D& GetTransformInverse() const
255 {
256 return transformInverse_;
257 }
258
259 size_t GetIndex() const
260 {
261 return index_;
262 }
263
264 const RadiographyScene& GetScene() const
265 {
266 return scene_;
267 }
268
269 const Geometry& GetGeometry() const
270 {
271 return geometry_;
272 }
273
274 void SetGeometry(const Geometry& geometry);
275
276 void ResetCrop();
277
278 void SetCrop(unsigned int x, // those are pixel coordinates/size
279 unsigned int y,
280 unsigned int width,
281 unsigned int height);
282
283 void SetCrop(const Extent2D& sceneExtent)
284 {
285 Extent2D imageCrop;
286
287 {
288 double x = sceneExtent.GetX1();
289 double y = sceneExtent.GetY1();
290 GetTransformInverse().Apply(x, y);
291 imageCrop.AddPoint(x, y);
292 }
293
294 {
295 double x = sceneExtent.GetX2();
296 double y = sceneExtent.GetY2();
297 GetTransformInverse().Apply(x, y);
298 imageCrop.AddPoint(x, y);
299 }
300
301 SetCrop(static_cast<unsigned int>(std::max(0.0, std::floor(imageCrop.GetX1()))),
302 static_cast<unsigned int>(std::max(0.0, std::floor(imageCrop.GetY1()))),
303 std::min(width_, static_cast<unsigned int>(std::ceil(imageCrop.GetWidth()))),
304 std::min(height_, static_cast<unsigned int>(std::ceil(imageCrop.GetHeight())))
305 );
306 }
307
308
309 void GetCrop(unsigned int& x,
310 unsigned int& y,
311 unsigned int& width,
312 unsigned int& height) const;
313
314 void SetAngle(double angle);
315
316 void SetPan(double x,
317 double y);
318
319 void SetFlipVertical(bool flip); // mirrors image around an horizontal axis (note: flip is applied before the rotation !)
320
321 void SetFlipHorizontal(bool flip); // mirrors image around a vertical axis (note: flip is applied before the rotation !)
322
323 void SetResizeable(bool resizeable)
324 {
325 geometry_.SetResizeable(resizeable);
326 }
327
328 void SetSize(unsigned int width,
329 unsigned int height,
330 bool emitLayerEditedEvent = true);
331
332 bool HasSize() const
333 {
334 return hasSize_;
335 }
336
337 unsigned int GetWidth() const
338 {
339 return width_;
340 }
341
342 unsigned int GetHeight() const
343 {
344 return height_;
345 }
346
347 virtual Extent2D GetSceneExtent(bool minimal) const;
348
349 virtual bool GetPixel(unsigned int& imageX,
350 unsigned int& imageY,
351 double sceneX,
352 double sceneY) const;
353
354 void SetPixelSpacing(double x,
355 double y,
356 bool emitLayerEditedEvent = true);
357
358 void GetCenter(double& centerX,
359 double& centerY) const;
360
361 virtual void GetControlPoint(ControlPoint& cpScene /* out in scene coordinates */,
362 size_t index) const;
363
364 virtual size_t GetControlPointCount() const;
365
366 bool LookupControlPoint(ControlPoint& cpScene /* out */,
367 double x,
368 double y,
369 double zoom,
370 double viewportDistance) const;
371
372 virtual bool GetDefaultWindowing(float& center,
373 float& width) const = 0;
374
375 RadiographyPhotometricDisplayMode GetPreferredPhotomotricDisplayMode() const
376 {
377 return prefferedPhotometricDisplayMode_;
378 }
379
380 virtual void Render(Orthanc::ImageAccessor& buffer,
381 const AffineTransform2D& viewTransform,
382 ImageInterpolation interpolation,
383 float windowCenter,
384 float windowWidth,
385 bool applyWindowing) const = 0;
386
387 virtual bool GetRange(float& minValue,
388 float& maxValue) const = 0;
389
390 virtual size_t GetApproximateMemoryUsage() const // this is used to limit the number of scenes loaded in RAM when resources are limited (we actually only count the size used by the images, not the C structs)
391 {
392 return 0;
393 }
394 };
395 }