Mercurial > hg > orthanc-stone
comparison Framework/Toolbox/AffineTransform2D.cpp @ 575:919226caca82
AffineTransform2D::ComputeZoom()
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 19 Apr 2019 09:08:15 +0200 |
parents | 911297a277c4 |
children | 7912de3a15e0 |
comparison
equal
deleted
inserted
replaced
574:911297a277c4 | 575:919226caca82 |
---|---|
128 target[14] = -z; | 128 target[14] = -z; |
129 target[15] = static_cast<float>(source(2, 2)); | 129 target[15] = static_cast<float>(source(2, 2)); |
130 } | 130 } |
131 | 131 |
132 | 132 |
133 double AffineTransform2D::ComputeZoom() const | |
134 { | |
135 // Compute the length of the (0,0)-(1,1) diagonal (whose | |
136 // length is sqrt(2)) instead of the (0,0)-(1,0) unit segment, | |
137 // in order to cope with possible anisotropic zooming | |
138 | |
139 double x1 = 0; | |
140 double y1 = 0; | |
141 Apply(x1, y1); | |
142 | |
143 double x2 = 1; | |
144 double y2 = 1; | |
145 Apply(x2, y2); | |
146 | |
147 double dx = x2 - x1; | |
148 double dy = y2 - y1; | |
149 | |
150 double zoom = sqrt(dx * dx + dy * dy) / sqrt(2.0); | |
151 | |
152 if (LinearAlgebra::IsCloseToZero(zoom)) | |
153 { | |
154 return 1; // Default value if transform is ill-conditioned | |
155 } | |
156 else | |
157 { | |
158 return zoom; | |
159 } | |
160 } | |
161 | |
162 | |
133 AffineTransform2D AffineTransform2D::Invert(const AffineTransform2D& a) | 163 AffineTransform2D AffineTransform2D::Invert(const AffineTransform2D& a) |
134 { | 164 { |
135 AffineTransform2D t; | 165 AffineTransform2D t; |
136 LinearAlgebra::InvertMatrix(t.matrix_, a.matrix_); | 166 LinearAlgebra::InvertMatrix(t.matrix_, a.matrix_); |
137 return t; | 167 return t; |