annotate OrthancStone/Sources/Toolbox/AffineTransform2D.cpp @ 2069:5956d7357098 deep-learning

macro ORTHANC_HAS_WASM_SIMD has to be manually defined
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 19 May 2023 17:00:17 +0200
parents e8b9a2ba1df1
children 07964689cb0b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
409
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Stone of Orthanc
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
1871
7053b8a0aaec upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1870
diff changeset
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium
7053b8a0aaec upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1870
diff changeset
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
409
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 *
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * 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: 1554
diff changeset
9 * modify it under the terms of the GNU Lesser General Public License
409
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * as published by the Free Software Foundation, either version 3 of
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * the License, or (at your option) any later version.
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 *
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful, but
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * 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: 1554
diff changeset
15 * 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: 1554
diff changeset
16 * Lesser General Public License for more details.
409
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 *
1598
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1554
diff changeset
18 * 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: 1554
diff changeset
19 * 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: 1554
diff changeset
20 * <http://www.gnu.org/licenses/>.
409
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 **/
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #include "AffineTransform2D.h"
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #include "ImageGeometry.h"
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27
1455
30deba7bc8e2 simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1279
diff changeset
28 #include <Logging.h>
30deba7bc8e2 simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1279
diff changeset
29 #include <OrthancException.h>
409
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 namespace OrthancStone
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 {
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 AffineTransform2D::AffineTransform2D() :
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 matrix_(LinearAlgebra::IdentityMatrix(3))
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 {
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 }
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 AffineTransform2D::AffineTransform2D(const Matrix& m)
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 {
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 if (m.size1() != 3 ||
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 m.size2() != 3)
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 {
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageSize);
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 }
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 if (!LinearAlgebra::IsCloseToZero(m(2, 0)) ||
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 !LinearAlgebra::IsCloseToZero(m(2, 1)) ||
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 LinearAlgebra::IsCloseToZero(m(2, 2)))
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 {
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 LOG(ERROR) << "Cannot setup an AffineTransform2D with perspective effects";
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 }
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 matrix_ = m / m(2, 2);
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 }
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 void AffineTransform2D::Apply(double& x /* inout */,
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 double& y /* inout */) const
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 {
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 Vector p;
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 LinearAlgebra::AssignVector(p, x, y, 1);
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 Vector q = LinearAlgebra::Product(matrix_, p);
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 if (!LinearAlgebra::IsNear(q[2], 1.0))
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 {
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 }
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 else
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 {
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 x = q[0];
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 y = q[1];
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 }
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 }
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 void AffineTransform2D::Apply(Orthanc::ImageAccessor& target,
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 const Orthanc::ImageAccessor& source,
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 ImageInterpolation interpolation,
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 bool clear) const
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 {
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 assert(LinearAlgebra::IsNear(matrix_(2, 0), 0) &&
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 LinearAlgebra::IsNear(matrix_(2, 1), 0) &&
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 LinearAlgebra::IsNear(matrix_(2, 2), 1));
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 ApplyAffineTransform(target, source,
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 matrix_(0, 0), matrix_(0, 1), matrix_(0, 2),
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 matrix_(1, 0), matrix_(1, 1), matrix_(1, 2),
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 interpolation, clear);
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 }
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94
574
911297a277c4 AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
95 void AffineTransform2D::ConvertToOpenGLMatrix(float target[16],
911297a277c4 AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
96 unsigned int canvasWidth,
911297a277c4 AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
97 unsigned int canvasHeight) const
911297a277c4 AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
98 {
911297a277c4 AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
99 const AffineTransform2D t = AffineTransform2D::Combine(
911297a277c4 AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
100 CreateOpenGLClipspace(canvasWidth, canvasHeight), *this);
911297a277c4 AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
101
911297a277c4 AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
102 const Matrix source = t.GetHomogeneousMatrix();
911297a277c4 AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
103
911297a277c4 AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
104 if (source.size1() != 3 ||
911297a277c4 AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
105 source.size2() != 3)
911297a277c4 AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
106 {
911297a277c4 AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
107 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
911297a277c4 AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
108 }
911297a277c4 AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
109
911297a277c4 AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
110 // "z" must be in the [-1,1] range, otherwise the texture does not show up
911297a277c4 AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
111 float z = 0;
911297a277c4 AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
112
911297a277c4 AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
113 // Embed the 3x3 affine transform of the 2D plane into a 4x4
911297a277c4 AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
114 // matrix (3D) for OpenGL. The matrix must be transposed.
911297a277c4 AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
115
911297a277c4 AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
116 target[0] = static_cast<float>(source(0, 0));
911297a277c4 AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
117 target[1] = static_cast<float>(source(1, 0));
911297a277c4 AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
118 target[2] = 0;
911297a277c4 AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
119 target[3] = static_cast<float>(source(2, 0));
911297a277c4 AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
120 target[4] = static_cast<float>(source(0, 1));
911297a277c4 AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
121 target[5] = static_cast<float>(source(1, 1));
911297a277c4 AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
122 target[6] = 0;
911297a277c4 AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
123 target[7] = static_cast<float>(source(2, 1));
911297a277c4 AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
124 target[8] = 0;
911297a277c4 AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
125 target[9] = 0;
911297a277c4 AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
126 target[10] = -1;
911297a277c4 AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
127 target[11] = 0;
911297a277c4 AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
128 target[12] = static_cast<float>(source(0, 2));
911297a277c4 AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
129 target[13] = static_cast<float>(source(1, 2));
911297a277c4 AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
130 target[14] = -z;
911297a277c4 AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
131 target[15] = static_cast<float>(source(2, 2));
911297a277c4 AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
132 }
911297a277c4 AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
133
911297a277c4 AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
134
575
919226caca82 AffineTransform2D::ComputeZoom()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 574
diff changeset
135 double AffineTransform2D::ComputeZoom() const
919226caca82 AffineTransform2D::ComputeZoom()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 574
diff changeset
136 {
919226caca82 AffineTransform2D::ComputeZoom()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 574
diff changeset
137 // Compute the length of the (0,0)-(1,1) diagonal (whose
919226caca82 AffineTransform2D::ComputeZoom()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 574
diff changeset
138 // length is sqrt(2)) instead of the (0,0)-(1,0) unit segment,
919226caca82 AffineTransform2D::ComputeZoom()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 574
diff changeset
139 // in order to cope with possible anisotropic zooming
919226caca82 AffineTransform2D::ComputeZoom()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 574
diff changeset
140
919226caca82 AffineTransform2D::ComputeZoom()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 574
diff changeset
141 double x1 = 0;
919226caca82 AffineTransform2D::ComputeZoom()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 574
diff changeset
142 double y1 = 0;
919226caca82 AffineTransform2D::ComputeZoom()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 574
diff changeset
143 Apply(x1, y1);
919226caca82 AffineTransform2D::ComputeZoom()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 574
diff changeset
144
919226caca82 AffineTransform2D::ComputeZoom()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 574
diff changeset
145 double x2 = 1;
919226caca82 AffineTransform2D::ComputeZoom()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 574
diff changeset
146 double y2 = 1;
919226caca82 AffineTransform2D::ComputeZoom()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 574
diff changeset
147 Apply(x2, y2);
919226caca82 AffineTransform2D::ComputeZoom()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 574
diff changeset
148
919226caca82 AffineTransform2D::ComputeZoom()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 574
diff changeset
149 double dx = x2 - x1;
919226caca82 AffineTransform2D::ComputeZoom()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 574
diff changeset
150 double dy = y2 - y1;
919226caca82 AffineTransform2D::ComputeZoom()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 574
diff changeset
151
919226caca82 AffineTransform2D::ComputeZoom()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 574
diff changeset
152 double zoom = sqrt(dx * dx + dy * dy) / sqrt(2.0);
919226caca82 AffineTransform2D::ComputeZoom()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 574
diff changeset
153
919226caca82 AffineTransform2D::ComputeZoom()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 574
diff changeset
154 if (LinearAlgebra::IsCloseToZero(zoom))
919226caca82 AffineTransform2D::ComputeZoom()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 574
diff changeset
155 {
919226caca82 AffineTransform2D::ComputeZoom()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 574
diff changeset
156 return 1; // Default value if transform is ill-conditioned
919226caca82 AffineTransform2D::ComputeZoom()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 574
diff changeset
157 }
919226caca82 AffineTransform2D::ComputeZoom()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 574
diff changeset
158 else
919226caca82 AffineTransform2D::ComputeZoom()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 574
diff changeset
159 {
919226caca82 AffineTransform2D::ComputeZoom()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 574
diff changeset
160 return zoom;
919226caca82 AffineTransform2D::ComputeZoom()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 574
diff changeset
161 }
919226caca82 AffineTransform2D::ComputeZoom()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 574
diff changeset
162 }
919226caca82 AffineTransform2D::ComputeZoom()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 574
diff changeset
163
919226caca82 AffineTransform2D::ComputeZoom()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 574
diff changeset
164
409
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 AffineTransform2D AffineTransform2D::Invert(const AffineTransform2D& a)
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 {
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 AffineTransform2D t;
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 LinearAlgebra::InvertMatrix(t.matrix_, a.matrix_);
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 return t;
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 }
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 AffineTransform2D AffineTransform2D::Combine(const AffineTransform2D& a,
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 const AffineTransform2D& b)
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 {
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 return AffineTransform2D(LinearAlgebra::Product(a.GetHomogeneousMatrix(),
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 b.GetHomogeneousMatrix()));
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 }
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 AffineTransform2D AffineTransform2D::Combine(const AffineTransform2D& a,
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 const AffineTransform2D& b,
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 const AffineTransform2D& c)
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 {
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 return AffineTransform2D(LinearAlgebra::Product(a.GetHomogeneousMatrix(),
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 b.GetHomogeneousMatrix(),
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 c.GetHomogeneousMatrix()));
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 }
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 AffineTransform2D AffineTransform2D::Combine(const AffineTransform2D& a,
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 const AffineTransform2D& b,
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 const AffineTransform2D& c,
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 const AffineTransform2D& d)
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 {
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 return AffineTransform2D(LinearAlgebra::Product(a.GetHomogeneousMatrix(),
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 b.GetHomogeneousMatrix(),
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 c.GetHomogeneousMatrix(),
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 d.GetHomogeneousMatrix()));
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 }
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201
1025
7912de3a15e0 AffineTransform2D::Combine with 5 args
Alain Mazy <alain@mazy.be>
parents: 575
diff changeset
202 AffineTransform2D AffineTransform2D::Combine(const AffineTransform2D& a,
7912de3a15e0 AffineTransform2D::Combine with 5 args
Alain Mazy <alain@mazy.be>
parents: 575
diff changeset
203 const AffineTransform2D& b,
7912de3a15e0 AffineTransform2D::Combine with 5 args
Alain Mazy <alain@mazy.be>
parents: 575
diff changeset
204 const AffineTransform2D& c,
7912de3a15e0 AffineTransform2D::Combine with 5 args
Alain Mazy <alain@mazy.be>
parents: 575
diff changeset
205 const AffineTransform2D& d,
7912de3a15e0 AffineTransform2D::Combine with 5 args
Alain Mazy <alain@mazy.be>
parents: 575
diff changeset
206 const AffineTransform2D& e)
7912de3a15e0 AffineTransform2D::Combine with 5 args
Alain Mazy <alain@mazy.be>
parents: 575
diff changeset
207 {
7912de3a15e0 AffineTransform2D::Combine with 5 args
Alain Mazy <alain@mazy.be>
parents: 575
diff changeset
208 return AffineTransform2D(LinearAlgebra::Product(a.GetHomogeneousMatrix(),
7912de3a15e0 AffineTransform2D::Combine with 5 args
Alain Mazy <alain@mazy.be>
parents: 575
diff changeset
209 b.GetHomogeneousMatrix(),
7912de3a15e0 AffineTransform2D::Combine with 5 args
Alain Mazy <alain@mazy.be>
parents: 575
diff changeset
210 c.GetHomogeneousMatrix(),
7912de3a15e0 AffineTransform2D::Combine with 5 args
Alain Mazy <alain@mazy.be>
parents: 575
diff changeset
211 d.GetHomogeneousMatrix(),
7912de3a15e0 AffineTransform2D::Combine with 5 args
Alain Mazy <alain@mazy.be>
parents: 575
diff changeset
212 e.GetHomogeneousMatrix()));
7912de3a15e0 AffineTransform2D::Combine with 5 args
Alain Mazy <alain@mazy.be>
parents: 575
diff changeset
213 }
409
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 AffineTransform2D AffineTransform2D::CreateOffset(double dx,
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 double dy)
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217 {
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 AffineTransform2D t;
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 t.matrix_(0, 2) = dx;
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 t.matrix_(1, 2) = dy;
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 return t;
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 }
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 AffineTransform2D AffineTransform2D::CreateScaling(double sx,
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227 double sy)
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 {
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 AffineTransform2D t;
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 t.matrix_(0, 0) = sx;
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 t.matrix_(1, 1) = sy;
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233 return t;
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 }
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 AffineTransform2D AffineTransform2D::CreateRotation(double angle)
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238 {
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 double cosine = cos(angle);
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240 double sine = sin(angle);
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242 AffineTransform2D t;
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243 t.matrix_(0, 0) = cosine;
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244 t.matrix_(0, 1) = -sine;
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245 t.matrix_(1, 0) = sine;
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246 t.matrix_(1, 1) = cosine;
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248 return t;
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 }
574
911297a277c4 AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
250
1259
69177b10e2b9 various fixes for RadiographyScene: support text layers outside the dicom layer, fix background in this case + extract dicom from rendered scene
Alain Mazy <alain@mazy.be>
parents: 1025
diff changeset
251 AffineTransform2D AffineTransform2D::CreateRotation(double angle, // CW rotation
69177b10e2b9 various fixes for RadiographyScene: support text layers outside the dicom layer, fix background in this case + extract dicom from rendered scene
Alain Mazy <alain@mazy.be>
parents: 1025
diff changeset
252 double cx, // rotation center
69177b10e2b9 various fixes for RadiographyScene: support text layers outside the dicom layer, fix background in this case + extract dicom from rendered scene
Alain Mazy <alain@mazy.be>
parents: 1025
diff changeset
253 double cy) // rotation center
69177b10e2b9 various fixes for RadiographyScene: support text layers outside the dicom layer, fix background in this case + extract dicom from rendered scene
Alain Mazy <alain@mazy.be>
parents: 1025
diff changeset
254 {
69177b10e2b9 various fixes for RadiographyScene: support text layers outside the dicom layer, fix background in this case + extract dicom from rendered scene
Alain Mazy <alain@mazy.be>
parents: 1025
diff changeset
255 return Combine(
69177b10e2b9 various fixes for RadiographyScene: support text layers outside the dicom layer, fix background in this case + extract dicom from rendered scene
Alain Mazy <alain@mazy.be>
parents: 1025
diff changeset
256 CreateOffset(cx, cy),
69177b10e2b9 various fixes for RadiographyScene: support text layers outside the dicom layer, fix background in this case + extract dicom from rendered scene
Alain Mazy <alain@mazy.be>
parents: 1025
diff changeset
257 CreateRotation(angle),
69177b10e2b9 various fixes for RadiographyScene: support text layers outside the dicom layer, fix background in this case + extract dicom from rendered scene
Alain Mazy <alain@mazy.be>
parents: 1025
diff changeset
258 CreateOffset(-cx, -cy)
69177b10e2b9 various fixes for RadiographyScene: support text layers outside the dicom layer, fix background in this case + extract dicom from rendered scene
Alain Mazy <alain@mazy.be>
parents: 1025
diff changeset
259 );
69177b10e2b9 various fixes for RadiographyScene: support text layers outside the dicom layer, fix background in this case + extract dicom from rendered scene
Alain Mazy <alain@mazy.be>
parents: 1025
diff changeset
260 }
574
911297a277c4 AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
261
911297a277c4 AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
262 AffineTransform2D AffineTransform2D::CreateOpenGLClipspace(unsigned int canvasWidth,
911297a277c4 AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
263 unsigned int canvasHeight)
911297a277c4 AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
264 {
911297a277c4 AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
265 AffineTransform2D t;
911297a277c4 AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
266 t.matrix_(0, 0) = 2.0 / static_cast<double>(canvasWidth);
911297a277c4 AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
267 t.matrix_(0, 2) = -1.0;
911297a277c4 AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
268 t.matrix_(1, 1) = -2.0 / static_cast<double>(canvasHeight);
911297a277c4 AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
269 t.matrix_(1, 2) = 1.0;
911297a277c4 AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
270
911297a277c4 AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
271 return t;
911297a277c4 AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
272 }
1554
6d14ed6163b1 flip x/y in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
273
6d14ed6163b1 flip x/y in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
274
6d14ed6163b1 flip x/y in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
275 AffineTransform2D AffineTransform2D::CreateFlip(bool flipX,
6d14ed6163b1 flip x/y in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
276 bool flipY,
6d14ed6163b1 flip x/y in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
277 unsigned int width,
6d14ed6163b1 flip x/y in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
278 unsigned int height)
6d14ed6163b1 flip x/y in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
279 {
1882
4e80b8afd0da numpy in rendering plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1871
diff changeset
280 if (width == 0 ||
4e80b8afd0da numpy in rendering plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1871
diff changeset
281 height == 0)
4e80b8afd0da numpy in rendering plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1871
diff changeset
282 {
4e80b8afd0da numpy in rendering plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1871
diff changeset
283 return AffineTransform2D(); // Identity
4e80b8afd0da numpy in rendering plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1871
diff changeset
284 }
4e80b8afd0da numpy in rendering plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1871
diff changeset
285 else
4e80b8afd0da numpy in rendering plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1871
diff changeset
286 {
4e80b8afd0da numpy in rendering plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1871
diff changeset
287 AffineTransform2D t;
4e80b8afd0da numpy in rendering plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1871
diff changeset
288 t.matrix_(0, 0) = (flipX ? -1 : 1);
4e80b8afd0da numpy in rendering plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1871
diff changeset
289 t.matrix_(0, 2) = (flipX ? width : 0);
4e80b8afd0da numpy in rendering plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1871
diff changeset
290 t.matrix_(1, 1) = (flipY ? -1 : 1);
4e80b8afd0da numpy in rendering plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1871
diff changeset
291 t.matrix_(1, 2) = (flipY ? height : 0);
1554
6d14ed6163b1 flip x/y in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
292
1882
4e80b8afd0da numpy in rendering plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1871
diff changeset
293 return t;
4e80b8afd0da numpy in rendering plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1871
diff changeset
294 }
1554
6d14ed6163b1 flip x/y in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
295 }
1989
e8b9a2ba1df1 Added left/right rotation buttons
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1882
diff changeset
296
e8b9a2ba1df1 Added left/right rotation buttons
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1882
diff changeset
297
e8b9a2ba1df1 Added left/right rotation buttons
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1882
diff changeset
298 AffineTransform2D AffineTransform2D::CreateFlipX()
e8b9a2ba1df1 Added left/right rotation buttons
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1882
diff changeset
299 {
e8b9a2ba1df1 Added left/right rotation buttons
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1882
diff changeset
300 AffineTransform2D t;
e8b9a2ba1df1 Added left/right rotation buttons
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1882
diff changeset
301 t.matrix_(0, 0) = -1;
e8b9a2ba1df1 Added left/right rotation buttons
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1882
diff changeset
302 t.matrix_(1, 1) = 1;
e8b9a2ba1df1 Added left/right rotation buttons
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1882
diff changeset
303 return t;
e8b9a2ba1df1 Added left/right rotation buttons
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1882
diff changeset
304 }
e8b9a2ba1df1 Added left/right rotation buttons
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1882
diff changeset
305
e8b9a2ba1df1 Added left/right rotation buttons
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1882
diff changeset
306
e8b9a2ba1df1 Added left/right rotation buttons
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1882
diff changeset
307 AffineTransform2D AffineTransform2D::CreateFlipY()
e8b9a2ba1df1 Added left/right rotation buttons
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1882
diff changeset
308 {
e8b9a2ba1df1 Added left/right rotation buttons
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1882
diff changeset
309 AffineTransform2D t;
e8b9a2ba1df1 Added left/right rotation buttons
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1882
diff changeset
310 t.matrix_(0, 0) = 1;
e8b9a2ba1df1 Added left/right rotation buttons
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1882
diff changeset
311 t.matrix_(1, 1) = -1;
e8b9a2ba1df1 Added left/right rotation buttons
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1882
diff changeset
312 return t;
e8b9a2ba1df1 Added left/right rotation buttons
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1882
diff changeset
313 }
409
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
314 }