Download CIFTI_read_save/private/fixpos.m from cindyhfls/fcMRI-VAE: direct link, hf CLI and curl.
- Browser
- Download file 1.95 kB
-
https://huggingface.co/cindyhfls/fcMRI-VAE/resolve/f6dfc015f4abc5330bcdd05c23e8a5570aa7b208/CIFTI_read_save/private/fixpos.m
- Command line
-
hf download hf://cindyhfls/fcMRI-VAE@f6dfc015f4abc5330bcdd05c23e8a5570aa7b208/CIFTI_read_save/private/fixpos.m
-
curl -L -o fixpos.m https://huggingface.co/cindyhfls/fcMRI-VAE/resolve/f6dfc015f4abc5330bcdd05c23e8a5570aa7b208/CIFTI_read_save/private/fixpos.m
1.95 kB
| function mesh = fixpos(mesh, recurse) | |
| % FIXPOS helper function to ensure that meshes are described properly | |
| if nargin==1 | |
| recurse = 1; | |
| end | |
| if isa(mesh, 'delaunayTriangulation') | |
| % convert to structure, otherwise the code below won't work properly | |
| ws = warning('off', 'MATLAB:structOnObject'); | |
| mesh = struct(mesh); | |
| warning(ws); | |
| end | |
| if ~isa(mesh, 'struct') | |
| return; | |
| end | |
| if numel(mesh)>1 | |
| % loop over all individual elements | |
| clear tmp | |
| for i=1:numel(mesh) | |
| % this is to prevent an "Subscripted assignment between dissimilar structures" error | |
| tmp(i) = fixpos(mesh(i)); | |
| end | |
| mesh = tmp; | |
| clear tmp | |
| return | |
| end | |
| % convert from MATLAB delaunayTriangulation output to FieldTrip convention | |
| if isfield(mesh, 'Points') && isfield(mesh, 'ConnectivityList') | |
| mesh.pos = mesh.Points; | |
| switch size(mesh.ConnectivityList,2) | |
| case 2 | |
| mesh.edge = mesh.ConnectivityList; | |
| case 3 | |
| mesh.tri = mesh.ConnectivityList; | |
| case 4 | |
| mesh.tet = mesh.ConnectivityList; | |
| case 8 | |
| mesh.hex = mesh.ConnectivityList; | |
| otherwise | |
| error('unsupported ConnectivityList') | |
| end % switch | |
| mesh = rmfield(mesh, {'Points', 'ConnectivityList', 'Constraints'}); | |
| end | |
| % convert from BrainStorm/MNE to FieldTrip convention | |
| if isfield(mesh, 'vertices') && isfield(mesh, 'faces') | |
| mesh.pos = mesh.vertices; | |
| mesh.tri = mesh.faces; | |
| mesh = rmfield(mesh, {'faces', 'vertices'}); | |
| elseif isfield(mesh, 'Vertices') && isfield(mesh, 'Faces') | |
| mesh.pos = mesh.Vertices; | |
| mesh.tri = mesh.Faces; | |
| mesh = rmfield(mesh, {'Faces', 'Vertices'}); | |
| end | |
| % replace pnt by pos | |
| if isfield(mesh, 'pnt') | |
| mesh.pos = mesh.pnt; | |
| mesh = rmfield(mesh, 'pnt'); | |
| end | |
| if recurse<3 | |
| % recurse into substructures, not too deep | |
| fn = fieldnames(mesh); | |
| fn = setdiff(fn, {'cfg'}); % don't recurse into the cfg structure | |
| for i=1:length(fn) | |
| if isstruct(mesh.(fn{i})) | |
| mesh.(fn{i}) = fixpos(mesh.(fn{i}), recurse+1); | |
| end | |
| end | |
| end | |