Skip to content

Commit e110cf9

Browse files
ENH - added quaternion as transformation type to ft_warp_apply
1 parent 2a61f47 commit e110cf9

File tree

10 files changed

+400
-28
lines changed

10 files changed

+400
-28
lines changed

bin/synchronize-private.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2319,6 +2319,17 @@ ARRAY+=(private/ptriprojn.m)
23192319
ARRAY+=(utilities/private/ptriprojn.m)
23202320
sync ${ARRAY[*]}
23212321

2322+
################################################################################
2323+
# quaternion.m
2324+
2325+
ARRAY=()
2326+
ARRAY+=(fileio/private/quaternion.m)
2327+
ARRAY+=(inverse/private/quaternion.m)
2328+
ARRAY+=(plotting/private/quaternion.m)
2329+
ARRAY+=(private/quaternion.m)
2330+
ARRAY+=(utilities/private/quaternion.m)
2331+
sync ${ARRAY[*]}
2332+
23222333
################################################################################
23232334
# randomseed.m
23242335

fileio/private/ft_warp_apply.m

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,15 @@
4343
% VG: [1x1 struct]
4444
% flags: [1x1 struct]
4545
%
46-
% If any other method is selected, it is assumed that it specifies
47-
% the name of an auxiliary function that will, when given the input
48-
% parameter vector M, return an 4x4 homogenous transformation
49-
% matrix. Supplied functions in the warping toolbox are translate,
50-
% rotate, scale, rigidbody, globalrescale, traditional, affine,
51-
% perspective.
46+
% If any other method is selected, it is assumed that it specifies the name of an
47+
% auxiliary function that will, when given the input parameter vector M, return an
48+
% 4x4 homogenous transformation matrix. Supplied functions are 'translate', 'rotate',
49+
% 'scale', 'rigidbody', 'globalrescale', 'traditional', 'affine', 'perspective',
50+
% 'quaternion'.
5251
%
5352
% See also FT_WARP_OPTIM, FT_WARP_ERROR
5453

55-
% Copyright (C) 2000-2013, Robert Oostenveld
54+
% Copyright (C) 2000-2016, Robert Oostenveld
5655
%
5756
% This file is part of FieldTrip, see http://www.fieldtriptoolbox.org
5857
% for the documentation and details.

fileio/private/quaternion.m

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
function [H] = quaternion(q)
2+
3+
% QUATERNION returns the homogenous coordinate transformation matrix corresponding to
4+
% a coordinate transformation described by 7 quaternion parameters.
5+
%
6+
% Use as
7+
% [H] = quaternion(Q)
8+
% where
9+
% Q [q0, q1, q2, q3, q4, q5, q6] vector with parameters
10+
% H corresponding homogenous transformation matrix
11+
%
12+
% See Elekta/Neuromag MaxFilter manual version 2.2, section "D2 Coordinate Matching",
13+
% page 77 for more details and
14+
% https://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation#Conversion_to_and_from_the_matrix_representation
15+
16+
% Copyright (C) 2016, Robert Oostenveld
17+
%
18+
% This program is free software; you can redistribute it and/or modify
19+
% it under the terms of the GNU General Public License as published by
20+
% the Free Software Foundation; either version 2 of the License, or
21+
% (at your option) any later version.
22+
%
23+
% This program is distributed in the hope that it will be useful,
24+
% but WITHOUT ANY WARRANTY; without even the implied warranty of
25+
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26+
% GNU General Public License for more details.
27+
%
28+
% You should have received a copy of the GNU General Public License
29+
% along with this program; if not, write to the Free Software
30+
% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31+
32+
% This file is part of FieldTrip, see http://www.fieldtriptoolbox.org
33+
% for the documentation and details.
34+
%
35+
% FieldTrip is free software: you can redistribute it and/or modify
36+
% it under the terms of the GNU General Public License as published by
37+
% the Free Software Foundation, either version 3 of the License, or
38+
% (at your option) any later version.
39+
%
40+
% FieldTrip is distributed in the hope that it will be useful,
41+
% but WITHOUT ANY WARRANTY; without even the implied warranty of
42+
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
43+
% GNU General Public License for more details.
44+
%
45+
% You should have received a copy of the GNU General Public License
46+
% along with FieldTrip. If not, see <http://www.gnu.org/licenses/>.
47+
%
48+
% $Id$
49+
50+
if numel(q)~=7
51+
error('incorrect input vector');
52+
end
53+
54+
% all of these quaternions are zero-offset in the original equation, but one-offset in the MATLAB vector
55+
q0 = q(0+1);
56+
q1 = q(1+1);
57+
q2 = q(2+1);
58+
q3 = q(3+1);
59+
q4 = q(4+1);
60+
q5 = q(5+1);
61+
q6 = q(6+1);
62+
63+
R = [
64+
q0^2+q1^2-q2^2-q3^2 2*(q1*q2-q0*q3) 2*(q1*q3+q0*q2)
65+
2*(q1*q2+q0*q3) q0^2+q2^2-q1^2-q3^2 2*(q2*q3-q0*q1)
66+
2*(q1*q3-q0*q2) 2*(q2*q3+q0*q1) q0^2+q3^2-q1^2-q2^2
67+
];
68+
69+
T = [q4 q5 q6]';
70+
71+
H = eye(4,4);
72+
H(1:3,1:3) = R;
73+
H(1:3,4) = T;

forward/private/ft_warp_apply.m

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,15 @@
4343
% VG: [1x1 struct]
4444
% flags: [1x1 struct]
4545
%
46-
% If any other method is selected, it is assumed that it specifies
47-
% the name of an auxiliary function that will, when given the input
48-
% parameter vector M, return an 4x4 homogenous transformation
49-
% matrix. Supplied functions in the warping toolbox are translate,
50-
% rotate, scale, rigidbody, globalrescale, traditional, affine,
51-
% perspective.
46+
% If any other method is selected, it is assumed that it specifies the name of an
47+
% auxiliary function that will, when given the input parameter vector M, return an
48+
% 4x4 homogenous transformation matrix. Supplied functions are 'translate', 'rotate',
49+
% 'scale', 'rigidbody', 'globalrescale', 'traditional', 'affine', 'perspective',
50+
% 'quaternion'.
5251
%
5352
% See also FT_WARP_OPTIM, FT_WARP_ERROR
5453

55-
% Copyright (C) 2000-2013, Robert Oostenveld
54+
% Copyright (C) 2000-2016, Robert Oostenveld
5655
%
5756
% This file is part of FieldTrip, see http://www.fieldtriptoolbox.org
5857
% for the documentation and details.

inverse/private/quaternion.m

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
function [H] = quaternion(q)
2+
3+
% QUATERNION returns the homogenous coordinate transformation matrix corresponding to
4+
% a coordinate transformation described by 7 quaternion parameters.
5+
%
6+
% Use as
7+
% [H] = quaternion(Q)
8+
% where
9+
% Q [q0, q1, q2, q3, q4, q5, q6] vector with parameters
10+
% H corresponding homogenous transformation matrix
11+
%
12+
% See Elekta/Neuromag MaxFilter manual version 2.2, section "D2 Coordinate Matching",
13+
% page 77 for more details and
14+
% https://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation#Conversion_to_and_from_the_matrix_representation
15+
16+
% Copyright (C) 2016, Robert Oostenveld
17+
%
18+
% This program is free software; you can redistribute it and/or modify
19+
% it under the terms of the GNU General Public License as published by
20+
% the Free Software Foundation; either version 2 of the License, or
21+
% (at your option) any later version.
22+
%
23+
% This program is distributed in the hope that it will be useful,
24+
% but WITHOUT ANY WARRANTY; without even the implied warranty of
25+
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26+
% GNU General Public License for more details.
27+
%
28+
% You should have received a copy of the GNU General Public License
29+
% along with this program; if not, write to the Free Software
30+
% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31+
32+
% This file is part of FieldTrip, see http://www.fieldtriptoolbox.org
33+
% for the documentation and details.
34+
%
35+
% FieldTrip is free software: you can redistribute it and/or modify
36+
% it under the terms of the GNU General Public License as published by
37+
% the Free Software Foundation, either version 3 of the License, or
38+
% (at your option) any later version.
39+
%
40+
% FieldTrip is distributed in the hope that it will be useful,
41+
% but WITHOUT ANY WARRANTY; without even the implied warranty of
42+
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
43+
% GNU General Public License for more details.
44+
%
45+
% You should have received a copy of the GNU General Public License
46+
% along with FieldTrip. If not, see <http://www.gnu.org/licenses/>.
47+
%
48+
% $Id$
49+
50+
if numel(q)~=7
51+
error('incorrect input vector');
52+
end
53+
54+
% all of these quaternions are zero-offset in the original equation, but one-offset in the MATLAB vector
55+
q0 = q(0+1);
56+
q1 = q(1+1);
57+
q2 = q(2+1);
58+
q3 = q(3+1);
59+
q4 = q(4+1);
60+
q5 = q(5+1);
61+
q6 = q(6+1);
62+
63+
R = [
64+
q0^2+q1^2-q2^2-q3^2 2*(q1*q2-q0*q3) 2*(q1*q3+q0*q2)
65+
2*(q1*q2+q0*q3) q0^2+q2^2-q1^2-q3^2 2*(q2*q3-q0*q1)
66+
2*(q1*q3-q0*q2) 2*(q2*q3+q0*q1) q0^2+q3^2-q1^2-q2^2
67+
];
68+
69+
T = [q4 q5 q6]';
70+
71+
H = eye(4,4);
72+
H(1:3,1:3) = R;
73+
H(1:3,4) = T;

plotting/private/ft_warp_apply.m

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,15 @@
4343
% VG: [1x1 struct]
4444
% flags: [1x1 struct]
4545
%
46-
% If any other method is selected, it is assumed that it specifies
47-
% the name of an auxiliary function that will, when given the input
48-
% parameter vector M, return an 4x4 homogenous transformation
49-
% matrix. Supplied functions in the warping toolbox are translate,
50-
% rotate, scale, rigidbody, globalrescale, traditional, affine,
51-
% perspective.
46+
% If any other method is selected, it is assumed that it specifies the name of an
47+
% auxiliary function that will, when given the input parameter vector M, return an
48+
% 4x4 homogenous transformation matrix. Supplied functions are 'translate', 'rotate',
49+
% 'scale', 'rigidbody', 'globalrescale', 'traditional', 'affine', 'perspective',
50+
% 'quaternion'.
5251
%
5352
% See also FT_WARP_OPTIM, FT_WARP_ERROR
5453

55-
% Copyright (C) 2000-2013, Robert Oostenveld
54+
% Copyright (C) 2000-2016, Robert Oostenveld
5655
%
5756
% This file is part of FieldTrip, see http://www.fieldtriptoolbox.org
5857
% for the documentation and details.

plotting/private/quaternion.m

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
function [H] = quaternion(q)
2+
3+
% QUATERNION returns the homogenous coordinate transformation matrix corresponding to
4+
% a coordinate transformation described by 7 quaternion parameters.
5+
%
6+
% Use as
7+
% [H] = quaternion(Q)
8+
% where
9+
% Q [q0, q1, q2, q3, q4, q5, q6] vector with parameters
10+
% H corresponding homogenous transformation matrix
11+
%
12+
% See Elekta/Neuromag MaxFilter manual version 2.2, section "D2 Coordinate Matching",
13+
% page 77 for more details and
14+
% https://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation#Conversion_to_and_from_the_matrix_representation
15+
16+
% Copyright (C) 2016, Robert Oostenveld
17+
%
18+
% This program is free software; you can redistribute it and/or modify
19+
% it under the terms of the GNU General Public License as published by
20+
% the Free Software Foundation; either version 2 of the License, or
21+
% (at your option) any later version.
22+
%
23+
% This program is distributed in the hope that it will be useful,
24+
% but WITHOUT ANY WARRANTY; without even the implied warranty of
25+
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26+
% GNU General Public License for more details.
27+
%
28+
% You should have received a copy of the GNU General Public License
29+
% along with this program; if not, write to the Free Software
30+
% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31+
32+
% This file is part of FieldTrip, see http://www.fieldtriptoolbox.org
33+
% for the documentation and details.
34+
%
35+
% FieldTrip is free software: you can redistribute it and/or modify
36+
% it under the terms of the GNU General Public License as published by
37+
% the Free Software Foundation, either version 3 of the License, or
38+
% (at your option) any later version.
39+
%
40+
% FieldTrip is distributed in the hope that it will be useful,
41+
% but WITHOUT ANY WARRANTY; without even the implied warranty of
42+
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
43+
% GNU General Public License for more details.
44+
%
45+
% You should have received a copy of the GNU General Public License
46+
% along with FieldTrip. If not, see <http://www.gnu.org/licenses/>.
47+
%
48+
% $Id$
49+
50+
if numel(q)~=7
51+
error('incorrect input vector');
52+
end
53+
54+
% all of these quaternions are zero-offset in the original equation, but one-offset in the MATLAB vector
55+
q0 = q(0+1);
56+
q1 = q(1+1);
57+
q2 = q(2+1);
58+
q3 = q(3+1);
59+
q4 = q(4+1);
60+
q5 = q(5+1);
61+
q6 = q(6+1);
62+
63+
R = [
64+
q0^2+q1^2-q2^2-q3^2 2*(q1*q2-q0*q3) 2*(q1*q3+q0*q2)
65+
2*(q1*q2+q0*q3) q0^2+q2^2-q1^2-q3^2 2*(q2*q3-q0*q1)
66+
2*(q1*q3-q0*q2) 2*(q2*q3+q0*q1) q0^2+q3^2-q1^2-q2^2
67+
];
68+
69+
T = [q4 q5 q6]';
70+
71+
H = eye(4,4);
72+
H(1:3,1:3) = R;
73+
H(1:3,4) = T;

private/quaternion.m

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
function [H] = quaternion(q)
2+
3+
% QUATERNION returns the homogenous coordinate transformation matrix corresponding to
4+
% a coordinate transformation described by 7 quaternion parameters.
5+
%
6+
% Use as
7+
% [H] = quaternion(Q)
8+
% where
9+
% Q [q0, q1, q2, q3, q4, q5, q6] vector with parameters
10+
% H corresponding homogenous transformation matrix
11+
%
12+
% See Elekta/Neuromag MaxFilter manual version 2.2, section "D2 Coordinate Matching",
13+
% page 77 for more details and
14+
% https://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation#Conversion_to_and_from_the_matrix_representation
15+
16+
% Copyright (C) 2016, Robert Oostenveld
17+
%
18+
% This program is free software; you can redistribute it and/or modify
19+
% it under the terms of the GNU General Public License as published by
20+
% the Free Software Foundation; either version 2 of the License, or
21+
% (at your option) any later version.
22+
%
23+
% This program is distributed in the hope that it will be useful,
24+
% but WITHOUT ANY WARRANTY; without even the implied warranty of
25+
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26+
% GNU General Public License for more details.
27+
%
28+
% You should have received a copy of the GNU General Public License
29+
% along with this program; if not, write to the Free Software
30+
% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31+
32+
% This file is part of FieldTrip, see http://www.fieldtriptoolbox.org
33+
% for the documentation and details.
34+
%
35+
% FieldTrip is free software: you can redistribute it and/or modify
36+
% it under the terms of the GNU General Public License as published by
37+
% the Free Software Foundation, either version 3 of the License, or
38+
% (at your option) any later version.
39+
%
40+
% FieldTrip is distributed in the hope that it will be useful,
41+
% but WITHOUT ANY WARRANTY; without even the implied warranty of
42+
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
43+
% GNU General Public License for more details.
44+
%
45+
% You should have received a copy of the GNU General Public License
46+
% along with FieldTrip. If not, see <http://www.gnu.org/licenses/>.
47+
%
48+
% $Id$
49+
50+
if numel(q)~=7
51+
error('incorrect input vector');
52+
end
53+
54+
% all of these quaternions are zero-offset in the original equation, but one-offset in the MATLAB vector
55+
q0 = q(0+1);
56+
q1 = q(1+1);
57+
q2 = q(2+1);
58+
q3 = q(3+1);
59+
q4 = q(4+1);
60+
q5 = q(5+1);
61+
q6 = q(6+1);
62+
63+
R = [
64+
q0^2+q1^2-q2^2-q3^2 2*(q1*q2-q0*q3) 2*(q1*q3+q0*q2)
65+
2*(q1*q2+q0*q3) q0^2+q2^2-q1^2-q3^2 2*(q2*q3-q0*q1)
66+
2*(q1*q3-q0*q2) 2*(q2*q3+q0*q1) q0^2+q3^2-q1^2-q2^2
67+
];
68+
69+
T = [q4 q5 q6]';
70+
71+
H = eye(4,4);
72+
H(1:3,1:3) = R;
73+
H(1:3,4) = T;

0 commit comments

Comments
 (0)