Mercurial > hg > orthanc-stone
annotate OrthancStone/Resources/Computations/ComputeShearOnSlice.py @ 1715:1952162474c3
A few æsthetic changes in the text body
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Tue, 01 Dec 2020 08:31:16 +0100 |
parents | 8563ea5d8ae4 |
children | 9ac2a65d4172 |
rev | line source |
---|---|
191
46cb2eedc2e0
ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 #!/usr/bin/python |
46cb2eedc2e0
ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2 |
1589
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
3 # Stone of Orthanc |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
4 # Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
5 # Department, University Hospital of Liege, Belgium |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
6 # Copyright (C) 2017-2020 Osimis S.A., Belgium |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
7 # |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
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:
1589
diff
changeset
|
9 # modify it under the terms of the GNU Lesser General Public License |
1589
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
10 # as published by the Free Software Foundation, either version 3 of |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
11 # the License, or (at your option) any later version. |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
12 # |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
13 # This program is distributed in the hope that it will be useful, but |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
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:
1589
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:
1589
diff
changeset
|
16 # Lesser General Public License for more details. |
1589
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
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:
1589
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:
1589
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:
1589
diff
changeset
|
20 # <http://www.gnu.org/licenses/>. |
1589
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
21 |
8c5f9864545f
adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
22 |
191
46cb2eedc2e0
ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 from sympy import * |
46cb2eedc2e0
ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 import pprint |
46cb2eedc2e0
ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 |
46cb2eedc2e0
ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 init_printing(use_unicode=True) |
46cb2eedc2e0
ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 |
46cb2eedc2e0
ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
28 |
46cb2eedc2e0
ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 # Setup "T * S * M_shear" (Equation A.16) |
46cb2eedc2e0
ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
30 |
46cb2eedc2e0
ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
31 ex, ey, ew = symbols('ex ey ew') |
46cb2eedc2e0
ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
32 sx, sy = symbols('sx, sy') |
46cb2eedc2e0
ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
33 ti, tj = symbols('ti tj') |
46cb2eedc2e0
ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
34 |
46cb2eedc2e0
ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
35 T = Matrix([[ 1, 0, 0, ti ], |
46cb2eedc2e0
ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
36 [ 0, 1, 0, tj ], |
46cb2eedc2e0
ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
37 [ 0, 0, 1, 0 ], |
46cb2eedc2e0
ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
38 [ 0, 0, 0, 1 ]]) |
46cb2eedc2e0
ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
39 |
46cb2eedc2e0
ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
40 # Equation (A.15), if "sx == sy == f" |
46cb2eedc2e0
ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
41 S = Matrix([[ sx, 0, 0, 0 ], |
46cb2eedc2e0
ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
42 [ 0, sy, 0, 0 ], |
46cb2eedc2e0
ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
43 [ 0, 0, 1, 0 ], |
46cb2eedc2e0
ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
44 [ 0, 0, 0, 1 ]]) |
46cb2eedc2e0
ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
45 |
46cb2eedc2e0
ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
46 # MM_shear, in Equation (A.14) |
46cb2eedc2e0
ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
47 M = Matrix([[ 1, 0, ex, 0 ], |
46cb2eedc2e0
ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
48 [ 0, 1, ey, 0 ], |
46cb2eedc2e0
ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
49 [ 0, 0, 1, 0 ], |
46cb2eedc2e0
ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
50 [ 0, 0, ew, 1 ]]) |
46cb2eedc2e0
ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
51 |
46cb2eedc2e0
ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
52 |
46cb2eedc2e0
ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
53 x, y, z, w = symbols('x y z w') |
46cb2eedc2e0
ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
54 p = Matrix([ x, y, z, w ]) |
46cb2eedc2e0
ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
55 |
46cb2eedc2e0
ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
56 print("\nT =" % T) |
46cb2eedc2e0
ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
57 pprint.pprint(T); |
46cb2eedc2e0
ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
58 |
46cb2eedc2e0
ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
59 print("\nS =" % T) |
46cb2eedc2e0
ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
60 pprint.pprint(S); |
46cb2eedc2e0
ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
61 |
46cb2eedc2e0
ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
62 print("\nM'_shear =" % T) |
46cb2eedc2e0
ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
63 pprint.pprint(M); |
46cb2eedc2e0
ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
64 |
46cb2eedc2e0
ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
65 print("\nGeneral form of a Lacroute's shear matrix (Equation A.16): T * S * M'_shear =") |
46cb2eedc2e0
ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
66 pprint.pprint(T * S * M); |
46cb2eedc2e0
ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
67 |
46cb2eedc2e0
ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
68 print("\nHence, alternative parametrization:") |
46cb2eedc2e0
ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
69 a11, a13, a14, a22, a23, a24, a43 = symbols('a11 a13 a14 a22 a23 a24 a43') |
46cb2eedc2e0
ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
70 |
46cb2eedc2e0
ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
71 A = Matrix([[ a11, 0, a13, a14 ], |
46cb2eedc2e0
ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
72 [ 0, a22, a23, a24 ], |
46cb2eedc2e0
ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
73 [ 0, 0, 1, 0 ], |
46cb2eedc2e0
ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
74 [ 0, 0, a43, 1 ]]) |
46cb2eedc2e0
ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
75 pprint.pprint(A); |
46cb2eedc2e0
ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
76 |
46cb2eedc2e0
ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
77 v = A * p |
46cb2eedc2e0
ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
78 v = v.subs(w, 1) |
46cb2eedc2e0
ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
79 |
46cb2eedc2e0
ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
80 print("\nAction of Lacroute's shear matrix A on plane z (taking w=1):\n%s\n" % v) |
46cb2eedc2e0
ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
81 |
46cb2eedc2e0
ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
82 print('Output x\' = %s\n' % (v[0]/v[3])) |
46cb2eedc2e0
ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
83 print('Output y\' = %s\n' % (v[1]/v[3])) |
46cb2eedc2e0
ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
84 print('Output z\' = %s\n' % (v[2]/v[3])) |