annotate OrthancStone/Sources/Scene2D/Internals/CairoInfoPanelRenderer.cpp @ 1675:6fa05252b085

don't load low-quality image if the parsed dicom file is cached by the oracle
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 23 Nov 2020 18:09:14 +0100
parents 8563ea5d8ae4
children 9ac2a65d4172
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
597
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Stone of Orthanc
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
1270
2d8ab34c8c91 upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 889
diff changeset
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium
597
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * the License, or (at your option) any later version.
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 **/
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 #include "CairoInfoPanelRenderer.h"
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 #include "../InfoPanelSceneLayer.h"
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 namespace OrthancStone
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 {
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 namespace Internals
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 {
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 void CairoInfoPanelRenderer::Update(const ISceneLayer& layer)
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 {
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 const InfoPanelSceneLayer& l = dynamic_cast<const InfoPanelSceneLayer&>(layer);
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 texture_.Copy(l.GetTexture(), true);
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 anchor_ = l.GetAnchor();
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 }
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 {
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 int dx, dy;
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 InfoPanelSceneLayer::ComputeAnchorLocation(
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 cairo_t* cr = target_.GetCairoContext();
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 cairo_save(cr);
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
85e117739eca cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
83 // first translation (directly written in `t`)
85e117739eca cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
84 cairo_matrix_t t;
85e117739eca cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
85 cairo_matrix_init_identity(&t);
85e117739eca cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
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
85e117739eca cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
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
85e117739eca cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
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
85e117739eca cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
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
85e117739eca cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
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
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 cairo_set_source_surface(cr, texture_.GetObject(), 0, 0);
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 if (isLinearInterpolation_)
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 {
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 cairo_pattern_set_filter(cairo_get_source(cr), CAIRO_FILTER_BILINEAR);
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 }
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 else
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 {
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 cairo_pattern_set_filter(cairo_get_source(cr), CAIRO_FILTER_NEAREST);
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 }
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 cairo_paint(cr);
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 cairo_restore(cr);
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 }
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 }
9e51fb773bbd CairoCompositor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 }