Skip to content

Commit

Permalink
ENH - allow for 3-param (or 6-param) parameters for transformation
Browse files Browse the repository at this point in the history
schoffelen committed Feb 5, 2024
1 parent b525618 commit 54411c8
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions utilities/ft_transform_geometry.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function [output] = ft_transform_geometry(transform, input)
function [output] = ft_transform_geometry(transform, input, method)

% FT_TRANSFORM_GEOMETRY applies a homogeneous coordinate transformation to a
% structure with geometric information, for example a volume conduction model for the
@@ -9,7 +9,12 @@
% [output] = ft_transform_geometry(transform, input)
% where the transform should be a 4x4 homogeneous transformation matrix and the input
% data structure can be any of the FieldTrip data structures that describes
% geometrical data.
% geometrical data, or
% [output] = ft_transform_geometry(transform, input, method)
% where the transform contains a set of parameters that can be converted into a 4x4
% homogeneous transformation matrix, using one of the supported methods:
% 'rotate', 'scale', 'translate', 'rigidbody'. All methods require a 3-element vector
% as parameters, apart from rigidbody, which requires 6 parameters.
%
% The units of the transformation matrix must be the same as the units in which the
% geometric object is expressed.
@@ -48,7 +53,7 @@
%
% See also FT_WARP_APPLY, FT_HEADCOORDINATES, FT_SCALINGFACTOR

% Copyright (C) 2011-2022, Jan-Mathijs Schoffelen and Robert Oostenveld
% Copyright (C) 2011-2024, Jan-Mathijs Schoffelen and Robert Oostenveld
%
% This file is part of FieldTrip, see http://www.fieldtriptoolbox.org
% for the documentation and details.
@@ -68,6 +73,30 @@
%
% $Id: ft_transform_geometry.m$

siz = size(transform);
if isequal(siz, [4 4])
% this is OK
else
% check whether the method has been specified, and to be consistent with
% the input transform parameters, and create the transformation matrix
if nargin<3
ft_error('the first input argument is not a transformation matrix, hence a ''method'' should be specified');
end
switch method
case {'scale' 'translate' 'rotate'}
if numel(transform)~=3
ft_error('the number of transformation parameters should be 3');
end
case 'rigidbody'
if ~isequal(siz, [1 6]) && ~isequal(siz, [6 1])
ft_error('the transformation parameters should contain six elements in a vector');
end
otherwise
ft_error('unsupported method');
end
transform = feval(method, transform);
end

% determine the rotation matrix
rotation = eye(4);
rotation(1:3,1:3) = transform(1:3,1:3);

0 comments on commit 54411c8

Please sign in to comment.