Mercurial > hg > orthanc-stone
annotate OrthancStone/Sources/Toolbox/AffineTransform2D.cpp @ 1653:2e3b2ed239b9
Fixed usage of object cookie
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Mon, 16 Nov 2020 22:17:01 +0100 |
parents | 8563ea5d8ae4 |
children | 9ac2a65d4172 |
rev | line source |
---|---|
409 | 1 /** |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
1270
2d8ab34c8c91
upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1259
diff
changeset
|
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium |
409 | 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:
1554
diff
changeset
|
8 * modify it under the terms of the GNU Lesser General Public License |
409 | 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:
1554
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:
1554
diff
changeset
|
15 * Lesser General Public License for more details. |
409 | 16 * |
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
|
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:
1554
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:
1554
diff
changeset
|
19 * <http://www.gnu.org/licenses/>. |
409 | 20 **/ |
21 | |
22 | |
23 #include "AffineTransform2D.h" | |
24 | |
25 #include "ImageGeometry.h" | |
26 | |
1455
30deba7bc8e2
simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1279
diff
changeset
|
27 #include <Logging.h> |
30deba7bc8e2
simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1279
diff
changeset
|
28 #include <OrthancException.h> |
409 | 29 |
30 namespace OrthancStone | |
31 { | |
32 AffineTransform2D::AffineTransform2D() : | |
33 matrix_(LinearAlgebra::IdentityMatrix(3)) | |
34 { | |
35 } | |
36 | |
37 | |
38 AffineTransform2D::AffineTransform2D(const Matrix& m) | |
39 { | |
40 if (m.size1() != 3 || | |
41 m.size2() != 3) | |
42 { | |
43 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageSize); | |
44 } | |
45 | |
46 if (!LinearAlgebra::IsCloseToZero(m(2, 0)) || | |
47 !LinearAlgebra::IsCloseToZero(m(2, 1)) || | |
48 LinearAlgebra::IsCloseToZero(m(2, 2))) | |
49 { | |
50 LOG(ERROR) << "Cannot setup an AffineTransform2D with perspective effects"; | |
51 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
52 } | |
53 | |
54 matrix_ = m / m(2, 2); | |
55 } | |
56 | |
57 | |
58 void AffineTransform2D::Apply(double& x /* inout */, | |
59 double& y /* inout */) const | |
60 { | |
61 Vector p; | |
62 LinearAlgebra::AssignVector(p, x, y, 1); | |
63 | |
64 Vector q = LinearAlgebra::Product(matrix_, p); | |
65 | |
66 if (!LinearAlgebra::IsNear(q[2], 1.0)) | |
67 { | |
68 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
69 } | |
70 else | |
71 { | |
72 x = q[0]; | |
73 y = q[1]; | |
74 } | |
75 } | |
76 | |
77 | |
78 void AffineTransform2D::Apply(Orthanc::ImageAccessor& target, | |
79 const Orthanc::ImageAccessor& source, | |
80 ImageInterpolation interpolation, | |
81 bool clear) const | |
82 { | |
83 assert(LinearAlgebra::IsNear(matrix_(2, 0), 0) && | |
84 LinearAlgebra::IsNear(matrix_(2, 1), 0) && | |
85 LinearAlgebra::IsNear(matrix_(2, 2), 1)); | |
86 | |
87 ApplyAffineTransform(target, source, | |
88 matrix_(0, 0), matrix_(0, 1), matrix_(0, 2), | |
89 matrix_(1, 0), matrix_(1, 1), matrix_(1, 2), | |
90 interpolation, clear); | |
91 } | |
92 | |
93 | |
574
911297a277c4
AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
94 void AffineTransform2D::ConvertToOpenGLMatrix(float target[16], |
911297a277c4
AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
95 unsigned int canvasWidth, |
911297a277c4
AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
96 unsigned int canvasHeight) const |
911297a277c4
AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
97 { |
911297a277c4
AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
98 const AffineTransform2D t = AffineTransform2D::Combine( |
911297a277c4
AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
99 CreateOpenGLClipspace(canvasWidth, canvasHeight), *this); |
911297a277c4
AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
100 |
911297a277c4
AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
101 const Matrix source = t.GetHomogeneousMatrix(); |
911297a277c4
AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
102 |
911297a277c4
AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
103 if (source.size1() != 3 || |
911297a277c4
AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
104 source.size2() != 3) |
911297a277c4
AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
105 { |
911297a277c4
AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
106 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
911297a277c4
AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
107 } |
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 // "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
|
110 float z = 0; |
911297a277c4
AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
111 |
911297a277c4
AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
112 // 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
|
113 // matrix (3D) for OpenGL. The matrix must be transposed. |
911297a277c4
AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
114 |
911297a277c4
AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
115 target[0] = static_cast<float>(source(0, 0)); |
911297a277c4
AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
116 target[1] = static_cast<float>(source(1, 0)); |
911297a277c4
AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
117 target[2] = 0; |
911297a277c4
AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
118 target[3] = static_cast<float>(source(2, 0)); |
911297a277c4
AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
119 target[4] = static_cast<float>(source(0, 1)); |
911297a277c4
AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
120 target[5] = static_cast<float>(source(1, 1)); |
911297a277c4
AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
121 target[6] = 0; |
911297a277c4
AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
122 target[7] = static_cast<float>(source(2, 1)); |
911297a277c4
AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
123 target[8] = 0; |
911297a277c4
AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
124 target[9] = 0; |
911297a277c4
AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
125 target[10] = -1; |
911297a277c4
AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
126 target[11] = 0; |
911297a277c4
AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
127 target[12] = static_cast<float>(source(0, 2)); |
911297a277c4
AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
128 target[13] = static_cast<float>(source(1, 2)); |
911297a277c4
AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
129 target[14] = -z; |
911297a277c4
AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
130 target[15] = static_cast<float>(source(2, 2)); |
911297a277c4
AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
131 } |
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 |
575
919226caca82
AffineTransform2D::ComputeZoom()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
574
diff
changeset
|
134 double AffineTransform2D::ComputeZoom() const |
919226caca82
AffineTransform2D::ComputeZoom()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
574
diff
changeset
|
135 { |
919226caca82
AffineTransform2D::ComputeZoom()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
574
diff
changeset
|
136 // Compute the length of the (0,0)-(1,1) diagonal (whose |
919226caca82
AffineTransform2D::ComputeZoom()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
574
diff
changeset
|
137 // 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
|
138 // in order to cope with possible anisotropic zooming |
919226caca82
AffineTransform2D::ComputeZoom()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
574
diff
changeset
|
139 |
919226caca82
AffineTransform2D::ComputeZoom()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
574
diff
changeset
|
140 double x1 = 0; |
919226caca82
AffineTransform2D::ComputeZoom()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
574
diff
changeset
|
141 double y1 = 0; |
919226caca82
AffineTransform2D::ComputeZoom()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
574
diff
changeset
|
142 Apply(x1, y1); |
919226caca82
AffineTransform2D::ComputeZoom()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
574
diff
changeset
|
143 |
919226caca82
AffineTransform2D::ComputeZoom()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
574
diff
changeset
|
144 double x2 = 1; |
919226caca82
AffineTransform2D::ComputeZoom()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
574
diff
changeset
|
145 double y2 = 1; |
919226caca82
AffineTransform2D::ComputeZoom()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
574
diff
changeset
|
146 Apply(x2, y2); |
919226caca82
AffineTransform2D::ComputeZoom()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
574
diff
changeset
|
147 |
919226caca82
AffineTransform2D::ComputeZoom()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
574
diff
changeset
|
148 double dx = x2 - x1; |
919226caca82
AffineTransform2D::ComputeZoom()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
574
diff
changeset
|
149 double dy = y2 - y1; |
919226caca82
AffineTransform2D::ComputeZoom()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
574
diff
changeset
|
150 |
919226caca82
AffineTransform2D::ComputeZoom()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
574
diff
changeset
|
151 double zoom = sqrt(dx * dx + dy * dy) / sqrt(2.0); |
919226caca82
AffineTransform2D::ComputeZoom()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
574
diff
changeset
|
152 |
919226caca82
AffineTransform2D::ComputeZoom()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
574
diff
changeset
|
153 if (LinearAlgebra::IsCloseToZero(zoom)) |
919226caca82
AffineTransform2D::ComputeZoom()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
574
diff
changeset
|
154 { |
919226caca82
AffineTransform2D::ComputeZoom()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
574
diff
changeset
|
155 return 1; // Default value if transform is ill-conditioned |
919226caca82
AffineTransform2D::ComputeZoom()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
574
diff
changeset
|
156 } |
919226caca82
AffineTransform2D::ComputeZoom()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
574
diff
changeset
|
157 else |
919226caca82
AffineTransform2D::ComputeZoom()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
574
diff
changeset
|
158 { |
919226caca82
AffineTransform2D::ComputeZoom()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
574
diff
changeset
|
159 return zoom; |
919226caca82
AffineTransform2D::ComputeZoom()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
574
diff
changeset
|
160 } |
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 |
409 | 164 AffineTransform2D AffineTransform2D::Invert(const AffineTransform2D& a) |
165 { | |
166 AffineTransform2D t; | |
167 LinearAlgebra::InvertMatrix(t.matrix_, a.matrix_); | |
168 return t; | |
169 } | |
170 | |
171 | |
172 AffineTransform2D AffineTransform2D::Combine(const AffineTransform2D& a, | |
173 const AffineTransform2D& b) | |
174 { | |
175 return AffineTransform2D(LinearAlgebra::Product(a.GetHomogeneousMatrix(), | |
176 b.GetHomogeneousMatrix())); | |
177 } | |
178 | |
179 | |
180 AffineTransform2D AffineTransform2D::Combine(const AffineTransform2D& a, | |
181 const AffineTransform2D& b, | |
182 const AffineTransform2D& c) | |
183 { | |
184 return AffineTransform2D(LinearAlgebra::Product(a.GetHomogeneousMatrix(), | |
185 b.GetHomogeneousMatrix(), | |
186 c.GetHomogeneousMatrix())); | |
187 } | |
188 | |
189 | |
190 AffineTransform2D AffineTransform2D::Combine(const AffineTransform2D& a, | |
191 const AffineTransform2D& b, | |
192 const AffineTransform2D& c, | |
193 const AffineTransform2D& d) | |
194 { | |
195 return AffineTransform2D(LinearAlgebra::Product(a.GetHomogeneousMatrix(), | |
196 b.GetHomogeneousMatrix(), | |
197 c.GetHomogeneousMatrix(), | |
198 d.GetHomogeneousMatrix())); | |
199 } | |
200 | |
1025
7912de3a15e0
AffineTransform2D::Combine with 5 args
Alain Mazy <alain@mazy.be>
parents:
575
diff
changeset
|
201 AffineTransform2D AffineTransform2D::Combine(const AffineTransform2D& a, |
7912de3a15e0
AffineTransform2D::Combine with 5 args
Alain Mazy <alain@mazy.be>
parents:
575
diff
changeset
|
202 const AffineTransform2D& b, |
7912de3a15e0
AffineTransform2D::Combine with 5 args
Alain Mazy <alain@mazy.be>
parents:
575
diff
changeset
|
203 const AffineTransform2D& c, |
7912de3a15e0
AffineTransform2D::Combine with 5 args
Alain Mazy <alain@mazy.be>
parents:
575
diff
changeset
|
204 const AffineTransform2D& d, |
7912de3a15e0
AffineTransform2D::Combine with 5 args
Alain Mazy <alain@mazy.be>
parents:
575
diff
changeset
|
205 const AffineTransform2D& e) |
7912de3a15e0
AffineTransform2D::Combine with 5 args
Alain Mazy <alain@mazy.be>
parents:
575
diff
changeset
|
206 { |
7912de3a15e0
AffineTransform2D::Combine with 5 args
Alain Mazy <alain@mazy.be>
parents:
575
diff
changeset
|
207 return AffineTransform2D(LinearAlgebra::Product(a.GetHomogeneousMatrix(), |
7912de3a15e0
AffineTransform2D::Combine with 5 args
Alain Mazy <alain@mazy.be>
parents:
575
diff
changeset
|
208 b.GetHomogeneousMatrix(), |
7912de3a15e0
AffineTransform2D::Combine with 5 args
Alain Mazy <alain@mazy.be>
parents:
575
diff
changeset
|
209 c.GetHomogeneousMatrix(), |
7912de3a15e0
AffineTransform2D::Combine with 5 args
Alain Mazy <alain@mazy.be>
parents:
575
diff
changeset
|
210 d.GetHomogeneousMatrix(), |
7912de3a15e0
AffineTransform2D::Combine with 5 args
Alain Mazy <alain@mazy.be>
parents:
575
diff
changeset
|
211 e.GetHomogeneousMatrix())); |
7912de3a15e0
AffineTransform2D::Combine with 5 args
Alain Mazy <alain@mazy.be>
parents:
575
diff
changeset
|
212 } |
409 | 213 |
214 AffineTransform2D AffineTransform2D::CreateOffset(double dx, | |
215 double dy) | |
216 { | |
217 AffineTransform2D t; | |
218 t.matrix_(0, 2) = dx; | |
219 t.matrix_(1, 2) = dy; | |
220 | |
221 return t; | |
222 } | |
223 | |
224 | |
225 AffineTransform2D AffineTransform2D::CreateScaling(double sx, | |
226 double sy) | |
227 { | |
228 AffineTransform2D t; | |
229 t.matrix_(0, 0) = sx; | |
230 t.matrix_(1, 1) = sy; | |
231 | |
232 return t; | |
233 } | |
234 | |
235 | |
236 AffineTransform2D AffineTransform2D::CreateRotation(double angle) | |
237 { | |
238 double cosine = cos(angle); | |
239 double sine = sin(angle); | |
240 | |
241 AffineTransform2D t; | |
242 t.matrix_(0, 0) = cosine; | |
243 t.matrix_(0, 1) = -sine; | |
244 t.matrix_(1, 0) = sine; | |
245 t.matrix_(1, 1) = cosine; | |
246 | |
247 return t; | |
248 } | |
574
911297a277c4
AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
249 |
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
|
250 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
|
251 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
|
252 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
|
253 { |
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 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
|
255 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
|
256 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
|
257 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
|
258 ); |
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 } |
574
911297a277c4
AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
260 |
911297a277c4
AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
261 AffineTransform2D AffineTransform2D::CreateOpenGLClipspace(unsigned int canvasWidth, |
911297a277c4
AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
262 unsigned int canvasHeight) |
911297a277c4
AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
263 { |
911297a277c4
AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
264 AffineTransform2D t; |
911297a277c4
AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
265 t.matrix_(0, 0) = 2.0 / static_cast<double>(canvasWidth); |
911297a277c4
AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
266 t.matrix_(0, 2) = -1.0; |
911297a277c4
AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
267 t.matrix_(1, 1) = -2.0 / static_cast<double>(canvasHeight); |
911297a277c4
AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
268 t.matrix_(1, 2) = 1.0; |
911297a277c4
AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
269 |
911297a277c4
AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
270 return t; |
911297a277c4
AffineTransform2D::ConvertToOpenGLMatrix()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
271 } |
1554
6d14ed6163b1
flip x/y in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
272 |
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 AffineTransform2D AffineTransform2D::CreateFlip(bool flipX, |
6d14ed6163b1
flip x/y in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
275 bool flipY, |
6d14ed6163b1
flip x/y in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
276 unsigned int width, |
6d14ed6163b1
flip x/y in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
277 unsigned int height) |
6d14ed6163b1
flip x/y in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
278 { |
6d14ed6163b1
flip x/y in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
279 AffineTransform2D t; |
6d14ed6163b1
flip x/y in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
280 t.matrix_(0, 0) = (flipX ? -1 : 1); |
6d14ed6163b1
flip x/y in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
281 t.matrix_(0, 2) = (flipX ? width : 0); |
6d14ed6163b1
flip x/y in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
282 t.matrix_(1, 1) = (flipY ? -1 : 1); |
6d14ed6163b1
flip x/y in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
283 t.matrix_(1, 2) = (flipY ? height : 0); |
6d14ed6163b1
flip x/y in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
284 |
6d14ed6163b1
flip x/y in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
285 return t; |
6d14ed6163b1
flip x/y in Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
286 } |
409 | 287 } |