Mercurial > hg > orthanc-stone
annotate OrthancStone/Sources/Scene2D/Internals/CairoInfoPanelRenderer.cpp @ 1801:64dad1d7aca4
renamed subclass
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 20 May 2021 13:23:59 +0200 |
parents | 9ac2a65d4172 |
children | 3889ae96d2e9 |
rev | line source |
---|---|
597 | 1 /** |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
1739
9ac2a65d4172
upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium |
597 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
1598
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
8 * modify it under the terms of the GNU Lesser General Public License |
597 | 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 | |
1598
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
15 * Lesser General Public License for more details. |
1596
4fb8fdf03314
removed annoying whitespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1571
diff
changeset
|
16 * |
1598
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
17 * You should have received a copy of the GNU Lesser General Public |
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
18 * License along with this program. If not, see |
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
19 * <http://www.gnu.org/licenses/>. |
597 | 20 **/ |
21 | |
22 | |
23 #include "CairoInfoPanelRenderer.h" | |
24 | |
25 #include "../InfoPanelSceneLayer.h" | |
26 | |
27 namespace OrthancStone | |
28 { | |
29 namespace Internals | |
30 { | |
31 void CairoInfoPanelRenderer::Update(const ISceneLayer& layer) | |
32 { | |
33 const InfoPanelSceneLayer& l = dynamic_cast<const InfoPanelSceneLayer&>(layer); | |
34 | |
35 texture_.Copy(l.GetTexture(), true); | |
36 anchor_ = l.GetAnchor(); | |
37 isLinearInterpolation_ = l.IsLinearInterpolation(); | |
1325
be17fed8c7c5
Added flag in InfoPanelSceneLayer to
Benjamin Golinvaux <bgo@osimis.io>
parents:
1270
diff
changeset
|
38 applySceneRotation_ = l.ShouldApplySceneRotation(); |
597 | 39 } |
40 | |
888
6e888cf6a48b
renderers now have access to canvas width/height
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
597
diff
changeset
|
41 void CairoInfoPanelRenderer::Render(const AffineTransform2D& transform, |
6e888cf6a48b
renderers now have access to canvas width/height
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
597
diff
changeset
|
42 unsigned int canvasWidth, |
6e888cf6a48b
renderers now have access to canvas width/height
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
597
diff
changeset
|
43 unsigned int canvasHeight) |
597 | 44 { |
45 int dx, dy; | |
46 InfoPanelSceneLayer::ComputeAnchorLocation( | |
47 dx, dy, anchor_, texture_.GetWidth(), texture_.GetHeight(), | |
888
6e888cf6a48b
renderers now have access to canvas width/height
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
597
diff
changeset
|
48 canvasWidth, canvasHeight); |
597 | 49 |
50 cairo_t* cr = target_.GetCairoContext(); | |
51 cairo_save(cr); | |
52 | |
1325
be17fed8c7c5
Added flag in InfoPanelSceneLayer to
Benjamin Golinvaux <bgo@osimis.io>
parents:
1270
diff
changeset
|
53 if (applySceneRotation_) |
be17fed8c7c5
Added flag in InfoPanelSceneLayer to
Benjamin Golinvaux <bgo@osimis.io>
parents:
1270
diff
changeset
|
54 { |
be17fed8c7c5
Added flag in InfoPanelSceneLayer to
Benjamin Golinvaux <bgo@osimis.io>
parents:
1270
diff
changeset
|
55 // the transformation is as follows: |
be17fed8c7c5
Added flag in InfoPanelSceneLayer to
Benjamin Golinvaux <bgo@osimis.io>
parents:
1270
diff
changeset
|
56 // - originally, the image is aligned so that its top left corner |
be17fed8c7c5
Added flag in InfoPanelSceneLayer to
Benjamin Golinvaux <bgo@osimis.io>
parents:
1270
diff
changeset
|
57 // is at 0,0 |
be17fed8c7c5
Added flag in InfoPanelSceneLayer to
Benjamin Golinvaux <bgo@osimis.io>
parents:
1270
diff
changeset
|
58 // - first, we translate the image by -w/2,-h/2 |
be17fed8c7c5
Added flag in InfoPanelSceneLayer to
Benjamin Golinvaux <bgo@osimis.io>
parents:
1270
diff
changeset
|
59 // - then we rotate it, so that the next rotation will make the |
be17fed8c7c5
Added flag in InfoPanelSceneLayer to
Benjamin Golinvaux <bgo@osimis.io>
parents:
1270
diff
changeset
|
60 // image rotate around its center. |
be17fed8c7c5
Added flag in InfoPanelSceneLayer to
Benjamin Golinvaux <bgo@osimis.io>
parents:
1270
diff
changeset
|
61 // - then, we translate the image by +w/2,+h/2 to put it |
be17fed8c7c5
Added flag in InfoPanelSceneLayer to
Benjamin Golinvaux <bgo@osimis.io>
parents:
1270
diff
changeset
|
62 // back in place |
be17fed8c7c5
Added flag in InfoPanelSceneLayer to
Benjamin Golinvaux <bgo@osimis.io>
parents:
1270
diff
changeset
|
63 // - the fourth and last transform is the one that brings the |
be17fed8c7c5
Added flag in InfoPanelSceneLayer to
Benjamin Golinvaux <bgo@osimis.io>
parents:
1270
diff
changeset
|
64 // image to its desired anchored location. |
be17fed8c7c5
Added flag in InfoPanelSceneLayer to
Benjamin Golinvaux <bgo@osimis.io>
parents:
1270
diff
changeset
|
65 |
be17fed8c7c5
Added flag in InfoPanelSceneLayer to
Benjamin Golinvaux <bgo@osimis.io>
parents:
1270
diff
changeset
|
66 int32_t halfWidth = |
be17fed8c7c5
Added flag in InfoPanelSceneLayer to
Benjamin Golinvaux <bgo@osimis.io>
parents:
1270
diff
changeset
|
67 static_cast<int32_t>(0.5 * texture_.GetWidth()); |
be17fed8c7c5
Added flag in InfoPanelSceneLayer to
Benjamin Golinvaux <bgo@osimis.io>
parents:
1270
diff
changeset
|
68 |
be17fed8c7c5
Added flag in InfoPanelSceneLayer to
Benjamin Golinvaux <bgo@osimis.io>
parents:
1270
diff
changeset
|
69 int32_t halfHeight = |
be17fed8c7c5
Added flag in InfoPanelSceneLayer to
Benjamin Golinvaux <bgo@osimis.io>
parents:
1270
diff
changeset
|
70 static_cast<int32_t>(0.5 * texture_.GetHeight()); |
be17fed8c7c5
Added flag in InfoPanelSceneLayer to
Benjamin Golinvaux <bgo@osimis.io>
parents:
1270
diff
changeset
|
71 |
be17fed8c7c5
Added flag in InfoPanelSceneLayer to
Benjamin Golinvaux <bgo@osimis.io>
parents:
1270
diff
changeset
|
72 const Matrix& sceneTransformM = transform.GetHomogeneousMatrix(); |
be17fed8c7c5
Added flag in InfoPanelSceneLayer to
Benjamin Golinvaux <bgo@osimis.io>
parents:
1270
diff
changeset
|
73 Matrix r; |
be17fed8c7c5
Added flag in InfoPanelSceneLayer to
Benjamin Golinvaux <bgo@osimis.io>
parents:
1270
diff
changeset
|
74 Matrix q; |
be17fed8c7c5
Added flag in InfoPanelSceneLayer to
Benjamin Golinvaux <bgo@osimis.io>
parents:
1270
diff
changeset
|
75 LinearAlgebra::RQDecomposition3x3(r, q, sceneTransformM); |
be17fed8c7c5
Added flag in InfoPanelSceneLayer to
Benjamin Golinvaux <bgo@osimis.io>
parents:
1270
diff
changeset
|
76 |
be17fed8c7c5
Added flag in InfoPanelSceneLayer to
Benjamin Golinvaux <bgo@osimis.io>
parents:
1270
diff
changeset
|
77 // first, put the scene rotation in a cairo matrix |
be17fed8c7c5
Added flag in InfoPanelSceneLayer to
Benjamin Golinvaux <bgo@osimis.io>
parents:
1270
diff
changeset
|
78 cairo_matrix_t m; |
be17fed8c7c5
Added flag in InfoPanelSceneLayer to
Benjamin Golinvaux <bgo@osimis.io>
parents:
1270
diff
changeset
|
79 cairo_matrix_init( |
be17fed8c7c5
Added flag in InfoPanelSceneLayer to
Benjamin Golinvaux <bgo@osimis.io>
parents:
1270
diff
changeset
|
80 &m, q(0, 0), q(1, 0), q(0, 1), q(1, 1), q(0, 2), q(1, 2)); |
597 | 81 |
1325
be17fed8c7c5
Added flag in InfoPanelSceneLayer to
Benjamin Golinvaux <bgo@osimis.io>
parents:
1270
diff
changeset
|
82 // now let's build the transform piece by piece |
1571 | 83 // first translation (directly written in `t`) |
84 cairo_matrix_t t; | |
85 cairo_matrix_init_identity(&t); | |
86 cairo_matrix_translate(&t, -halfWidth, -halfHeight); | |
1325
be17fed8c7c5
Added flag in InfoPanelSceneLayer to
Benjamin Golinvaux <bgo@osimis.io>
parents:
1270
diff
changeset
|
87 |
be17fed8c7c5
Added flag in InfoPanelSceneLayer to
Benjamin Golinvaux <bgo@osimis.io>
parents:
1270
diff
changeset
|
88 // then the rotation |
1571 | 89 cairo_matrix_multiply(&t, &t, &m); |
1325
be17fed8c7c5
Added flag in InfoPanelSceneLayer to
Benjamin Golinvaux <bgo@osimis.io>
parents:
1270
diff
changeset
|
90 |
be17fed8c7c5
Added flag in InfoPanelSceneLayer to
Benjamin Golinvaux <bgo@osimis.io>
parents:
1270
diff
changeset
|
91 // then the second translation |
be17fed8c7c5
Added flag in InfoPanelSceneLayer to
Benjamin Golinvaux <bgo@osimis.io>
parents:
1270
diff
changeset
|
92 { |
be17fed8c7c5
Added flag in InfoPanelSceneLayer to
Benjamin Golinvaux <bgo@osimis.io>
parents:
1270
diff
changeset
|
93 cairo_matrix_t translation2; |
be17fed8c7c5
Added flag in InfoPanelSceneLayer to
Benjamin Golinvaux <bgo@osimis.io>
parents:
1270
diff
changeset
|
94 cairo_matrix_init_translate(&translation2, halfWidth, halfHeight); |
1571 | 95 cairo_matrix_multiply(&t, &t, &m); |
1325
be17fed8c7c5
Added flag in InfoPanelSceneLayer to
Benjamin Golinvaux <bgo@osimis.io>
parents:
1270
diff
changeset
|
96 } |
be17fed8c7c5
Added flag in InfoPanelSceneLayer to
Benjamin Golinvaux <bgo@osimis.io>
parents:
1270
diff
changeset
|
97 |
be17fed8c7c5
Added flag in InfoPanelSceneLayer to
Benjamin Golinvaux <bgo@osimis.io>
parents:
1270
diff
changeset
|
98 // then the last translation |
be17fed8c7c5
Added flag in InfoPanelSceneLayer to
Benjamin Golinvaux <bgo@osimis.io>
parents:
1270
diff
changeset
|
99 { |
be17fed8c7c5
Added flag in InfoPanelSceneLayer to
Benjamin Golinvaux <bgo@osimis.io>
parents:
1270
diff
changeset
|
100 cairo_matrix_t translation3; |
be17fed8c7c5
Added flag in InfoPanelSceneLayer to
Benjamin Golinvaux <bgo@osimis.io>
parents:
1270
diff
changeset
|
101 cairo_matrix_init_translate(&translation3, dx, dy); |
1571 | 102 cairo_matrix_multiply(&t, &t, &translation3); |
1325
be17fed8c7c5
Added flag in InfoPanelSceneLayer to
Benjamin Golinvaux <bgo@osimis.io>
parents:
1270
diff
changeset
|
103 } |
1571 | 104 cairo_transform(cr, &t); |
1325
be17fed8c7c5
Added flag in InfoPanelSceneLayer to
Benjamin Golinvaux <bgo@osimis.io>
parents:
1270
diff
changeset
|
105 } |
be17fed8c7c5
Added flag in InfoPanelSceneLayer to
Benjamin Golinvaux <bgo@osimis.io>
parents:
1270
diff
changeset
|
106 else |
be17fed8c7c5
Added flag in InfoPanelSceneLayer to
Benjamin Golinvaux <bgo@osimis.io>
parents:
1270
diff
changeset
|
107 { |
be17fed8c7c5
Added flag in InfoPanelSceneLayer to
Benjamin Golinvaux <bgo@osimis.io>
parents:
1270
diff
changeset
|
108 cairo_matrix_t t; |
be17fed8c7c5
Added flag in InfoPanelSceneLayer to
Benjamin Golinvaux <bgo@osimis.io>
parents:
1270
diff
changeset
|
109 cairo_matrix_init_identity(&t); |
be17fed8c7c5
Added flag in InfoPanelSceneLayer to
Benjamin Golinvaux <bgo@osimis.io>
parents:
1270
diff
changeset
|
110 cairo_matrix_translate(&t, dx, dy); |
be17fed8c7c5
Added flag in InfoPanelSceneLayer to
Benjamin Golinvaux <bgo@osimis.io>
parents:
1270
diff
changeset
|
111 cairo_transform(cr, &t); |
be17fed8c7c5
Added flag in InfoPanelSceneLayer to
Benjamin Golinvaux <bgo@osimis.io>
parents:
1270
diff
changeset
|
112 } |
597 | 113 cairo_set_operator(cr, CAIRO_OPERATOR_OVER); |
114 cairo_set_source_surface(cr, texture_.GetObject(), 0, 0); | |
115 | |
116 if (isLinearInterpolation_) | |
117 { | |
118 cairo_pattern_set_filter(cairo_get_source(cr), CAIRO_FILTER_BILINEAR); | |
119 } | |
120 else | |
121 { | |
122 cairo_pattern_set_filter(cairo_get_source(cr), CAIRO_FILTER_NEAREST); | |
123 } | |
124 | |
125 cairo_paint(cr); | |
126 | |
127 cairo_restore(cr); | |
128 } | |
129 } | |
130 } |