-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcalc_rot_angles.m
More file actions
145 lines (126 loc) · 5.61 KB
/
calc_rot_angles.m
File metadata and controls
145 lines (126 loc) · 5.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
%**************************************************************************
%
% PROGRAM TITLE calc_rot_angles.m
%
% WRITTEN BY Gregory G. Reiker and Kirk Smith
% DATE WRITTEN August 4, 2011
% WRITTEN FOR Pediatric head modeling project
%
% REVISIONS BY
%
% CALLING SYNTAX
% Use the following syntax:
% [image_center_in, alpha, beta, gamma, nas, par, pal ] = ...
% calc_rot_angles( full_ref_local_file_name ) ;
%
% where
% image_center_in row, column, plane of image center.
% alpha angle of rotation about x.
% beta angle of rotation about y.
% gamma angle of rotation about z.
% nas NAS
% par PAR
% pal PAL
% full_ref_local_file_name name of the text file that
% contains the (x,y,z) coordinates of the
% CT reference points (NAS,PAR,PAL) that define a
% local coordinate system, with the name of the
% directory (folder) where the inputs are located.
%
% PROGRAM DESCRIPTION
% Calculate a Euler angles to align the PAR, PAL, NAS coordinates
% automatically. When applying the rotations, order of execution matters.
% Make sure to follow it. First step is to calculate the rotations in
% degrees. We will use the PAR as the reference.
%
% 8/10/2011 - angles seem to be calculated correctly.
% Shift the PAR point to 0 by subtracting it from both PAL and
% NAS and then calculating new points that way.
%
% FILES
% standard input - not used
% standard output - not used
%
% DEPENDENCIES
% MATLAB (win64) Version 7.12.0.635 (R2011a)
% Image Processing Toolbox Version 7.2 (R2011a)
% Signal Processing Toolbox Version 6.15 (R2011a)
% Statistics Toolbox Version 7.5
%
% Code dependencies are indicated by the level of indent:
% read_ref_landmarks_file
%
% VERSION HISTORY
% Version Date Comment
% ------- --------------- ----------------------------------------
% 1.0 August 4, 2011 Initial release.
%
% COPYRIGHT
%
% Copyright (c) 2011 Washington University in St. Louis
%
% Licensed under the Apache License, Version 2.0 (the "License");
% you may not use this file except in compliance with the License.
% You may obtain a copy of the License at
%
% http://www.apache.org/licenses/LICENSE-2.0
%
% Unless required by applicable law or agreed to in writing, software
% distributed under the License is distributed on an "AS IS" BASIS,
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
% See the License for the specific language governing permissions and
% limitations under the License.
%**************************************************************************
function [image_center_in, alpha, beta, gamma, nas, par, pal ] = ...
calc_rot_angles( full_ref_local_file_name )
% Read in the local coordinates using the read function.
[ref_locals] = read_ref_landmarks_file(full_ref_local_file_name) ;
nas = ref_locals ( 1 , :) ;
par = ref_locals ( 2 , :) ;
pal = ref_locals ( 3 , :) ;
% shift local reference points so par is at origin
nas_or = nas - par ;
pal_or = pal - par ;
par_or = par - par ;
% Use PAR as reference; represented in rcp format for tformarray
% Is above statement rigt?
image_center_in = par;
% Left Handed Analyze coordinate system
% Calculate each of the rotation angles
% recompute points after each rotation in order to get new angles
% rotate about z, positive rotation moves x into y
par_pal_xydist = sqrt((pal_or(1)-par_or(1))^2+(pal_or(2)-par_or(2))^2);
par_nas_xydist = sqrt((nas_or(1)-par_or(1))^2+(nas_or(2)-par_or(2))^2);
gamma = asind((par_or(2)-pal_or(2))/ par_pal_xydist) ;
% Points (nas,pal) move after each rotation and angles must be
% recalculated.
nas_gamma = asind(nas_or(2)/ par_nas_xydist);
nas_rotz = nas_gamma + gamma ;
pal_or(2) = sind(gamma-gamma)* par_pal_xydist;
pal_or(1) = cosd(gamma-gamma)* par_pal_xydist;
nas_or(2) = sind(nas_rotz)* par_nas_xydist;
nas_or(1) = cosd(nas_rotz)* par_nas_xydist;
% rotate about y, positive rotation moves z into x
par_pal_zxdist = sqrt((pal_or(1)-par_or(1))^2+(pal_or(3)-par_or(3))^2);
par_nas_zxdist = sqrt((nas_or(1)-par_or(1))^2+(nas_or(3)-par_or(3))^2);
beta = asind((-1*(par_or(3)-pal_or(3))/ par_pal_zxdist));
% Points (nas,pal) move after each rotation and angles must be
% recalculated.
nas_beta = asind(nas_or(3)/ par_nas_zxdist);
nas_roty = nas_beta - beta ;
pal_or(3) = sind(beta-beta)* par_pal_zxdist;
pal_or(1) = cosd(beta-beta)* par_pal_zxdist;
nas_or(3) = sind(nas_roty)* par_nas_zxdist;
nas_or(1) = cosd(nas_roty)* par_nas_zxdist;
% rotate about x, positive rotation moves y into z
%par_pal_yzdist = sqrt((pal(2)-par(2))^2+(pal(3)-par(3))^2);
par_nas_yzdist = sqrt((nas_or(2)-par_or(2))^2+(nas_or(3)-par_or(3))^2);
alpha = asind((par_or(3)-nas_or(3))/ par_nas_yzdist);
% Points nas moves after rotation and angles must be
% recalculated.
nas_or(3) = sind(alpha-alpha)* par_nas_yzdist;
nas_or(2) = cosd(alpha-alpha)* par_nas_yzdist;
nas = nas_or + par ;
par = par_or + par ;
pal = pal_or + par ;
end