Mercurial > hg > orthanc-stone
annotate Framework/Scene2D/InfoPanelSceneLayer.cpp @ 1165:4d97f532f1e0 broker
fix
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 19 Nov 2019 21:40:25 +0100 |
parents | 434ceeb0bcab |
children | 2d8ab34c8c91 |
rev | line source |
---|---|
584
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 /** |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2 * Stone of Orthanc |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
6 * |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
7 * This program is free software: you can redistribute it and/or |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 * modify it under the terms of the GNU Affero General Public License |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 * as published by the Free Software Foundation, either version 3 of |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 * the License, or (at your option) any later version. |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
11 * |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 * This program is distributed in the hope that it will be useful, but |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 * WITHOUT ANY WARRANTY; without even the implied warranty of |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 * Affero General Public License for more details. |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 * |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 * You should have received a copy of the GNU Affero General Public License |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
19 **/ |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
20 |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
21 |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 #include "InfoPanelSceneLayer.h" |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 #include <Core/Images/Image.h> |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 #include <Core/OrthancException.h> |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 namespace OrthancStone |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
28 { |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 InfoPanelSceneLayer::InfoPanelSceneLayer(const Orthanc::ImageAccessor& texture, |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
30 BitmapAnchor anchor, |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
31 bool isLinearInterpolation) : |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
32 texture_(Orthanc::Image::Clone(texture)), |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
33 anchor_(anchor), |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
34 isLinearInterpolation_(isLinearInterpolation) |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
35 { |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
36 if (texture_->GetFormat() != Orthanc::PixelFormat_RGBA32 && |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
37 texture_->GetFormat() != Orthanc::PixelFormat_RGB24) |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
38 { |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
39 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat); |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
40 } |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
41 } |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
42 |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
43 |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
44 void InfoPanelSceneLayer::ComputeAnchorLocation(int& x, |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
45 int& y, |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
46 BitmapAnchor anchor, |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
47 unsigned int textureWidth, |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
48 unsigned int textureHeight, |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
49 unsigned int canvasWidth, |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
50 unsigned int canvasHeight) |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
51 { |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
52 int tw = static_cast<int>(textureWidth); |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
53 int th = static_cast<int>(textureHeight); |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
54 int cw = static_cast<int>(canvasWidth); |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
55 int ch = static_cast<int>(canvasHeight); |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
56 |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
57 switch (anchor) |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
58 { |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
59 case BitmapAnchor_TopLeft: |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
60 case BitmapAnchor_CenterLeft: |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
61 case BitmapAnchor_BottomLeft: |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
62 x = 0; |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
63 break; |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
64 |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
65 case BitmapAnchor_TopCenter: |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
66 case BitmapAnchor_Center: |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
67 case BitmapAnchor_BottomCenter: |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
68 x = (cw - tw) / 2; |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
69 break; |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
70 |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
71 case BitmapAnchor_TopRight: |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
72 case BitmapAnchor_CenterRight: |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
73 case BitmapAnchor_BottomRight: |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
74 x = cw - tw; |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
75 break; |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
76 |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
77 default: |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
78 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
79 } |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
80 |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
81 switch (anchor) |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
82 { |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
83 case BitmapAnchor_TopLeft: |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
84 case BitmapAnchor_TopCenter: |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
85 case BitmapAnchor_TopRight: |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
86 y = 0; |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
87 break; |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
88 |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
89 case BitmapAnchor_CenterLeft: |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
90 case BitmapAnchor_Center: |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
91 case BitmapAnchor_CenterRight: |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
92 y = (ch - th) / 2; |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
93 break; |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
94 |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
95 case BitmapAnchor_BottomLeft: |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
96 case BitmapAnchor_BottomCenter: |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
97 case BitmapAnchor_BottomRight: |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
98 y = ch - th; |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
99 break; |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
100 |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
101 default: |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
102 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
103 } |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
104 } |
434ceeb0bcab
layers: InfoPanel, Polyline, Texture
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
105 } |