Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
8e6d19e
Option to change MRI fids to match digitized ones
Moo-Marc Feb 20, 2022
6631b47
Merge remote-tracking branch 'upstream/master' into Coordinates
Moo-Marc Feb 20, 2022
c40c8fe
can repeat new option by using remove first
Moo-Marc Feb 20, 2022
c3894ba
debugging
Moo-Marc Feb 20, 2022
b95846e
add option to process_refine
Moo-Marc Feb 20, 2022
cf5a141
improved report
Moo-Marc Feb 20, 2022
19fa381
improved scalp surface fit
Moo-Marc Feb 25, 2022
02f02d4
wip head surface & fit head points
Moo-Marc Mar 2, 2022
f126672
Merge remote-tracking branch 'upstream/master' into Coordinates
Moo-Marc Mar 22, 2022
6192ca5
Merge branch 'master' into Coordinates
Moo-Marc May 29, 2022
f09944c
threshold input for tess_isohead
Moo-Marc Jun 2, 2022
22864f7
Merge remote-tracking branch 'upstream/master' into Coordinates
Moo-Marc Jun 9, 2022
d3211ab
Merge remote-tracking branch 'upstream/master' into Coordinates
Moo-Marc Jun 16, 2022
8e862f9
Merge branch 'Coordinates' of github.com:Moo-Marc/brainstorm3 into Co…
Moo-Marc Jun 16, 2022
8846b76
Merge remote-tracking branch 'upstream/master' into Coordinates
Moo-Marc Jul 19, 2022
c778b8a
head shape from spatial gradient threshold
Moo-Marc Aug 9, 2022
529fb44
small fix for old pos files
Moo-Marc Aug 9, 2022
5931718
cleanup
Moo-Marc Aug 9, 2022
9db6c9e
Merge branch 'HeadPoints' into Coordinates
Moo-Marc Aug 9, 2022
6133b7f
Fix indentation
ftadel Aug 10, 2022
8f967a9
Recompute distance dynamically
ftadel Aug 10, 2022
31e3177
Added popup menu for color-coded dots
ftadel Aug 10, 2022
b2b4a7a
wip, head points as patch
Moo-Marc Aug 10, 2022
7a4cbed
Further head point modifications, merged with Francois' changes
Moo-Marc Aug 10, 2022
2e8bc09
cleanup
Moo-Marc Aug 10, 2022
517f509
Merge branch 'HeadPoints' into Coordinates
Moo-Marc Aug 11, 2022
34ef50b
Merge remote-tracking branch 'upstream/master' into Coordinates
Moo-Marc Aug 11, 2022
74e02da
Enforce target (0,0,0) only when the axes are visible
ftadel Aug 12, 2022
89a9b98
Disabling camera target at (0,0,0)
ftadel Aug 12, 2022
f510e90
Get rid of normr
ftadel Aug 12, 2022
382ca44
Moved popup menu to Channel submenu (Figure is independent from the d…
ftadel Aug 12, 2022
9faac45
colorbar fix
Moo-Marc Aug 31, 2022
bd2b22a
Merge branch 'HeadPoints' into Coordinates
Moo-Marc Sep 1, 2022
9e6f026
Merge remote-tracking branch 'upstream/master' into Coordinates
Moo-Marc Nov 7, 2022
90b4dac
tweaks to manual registration figure, head points distance coloring
Moo-Marc Nov 18, 2022
fb08e81
Merge branch 'master' into Coordinates
Moo-Marc Nov 18, 2022
a91ac60
fix head point distance coloring & add manual registration reset button
Moo-Marc Nov 18, 2022
ea3ea6d
small code cleaning
Moo-Marc Nov 18, 2022
e8ceedb
undo adding head points as figure surface
Moo-Marc Nov 22, 2022
97bef91
Merge remote-tracking branch 'upstream/master' into Coordinates
Moo-Marc Nov 22, 2022
811e941
Merge branch 'HeadPoints' into Coordinates and further fixes
Moo-Marc Nov 25, 2022
af062b3
minor fix to adjust coordinates scs option
Moo-Marc Nov 28, 2022
242f9d5
compat fix
Moo-Marc Nov 28, 2022
be59842
wip exporting registration to BIDS
Moo-Marc Dec 2, 2022
9f3be2b
wip coregistration
Moo-Marc Jan 16, 2023
e9d0e46
adding coregistration export for BIDS
Moo-Marc Sep 27, 2023
301a489
Merge branch 'master' into Coordinates
Moo-Marc Sep 27, 2023
6ab9794
fix apply digitized fids to MRI
Moo-Marc Sep 27, 2023
ca6c152
coregistration branch cleanup
Moo-Marc Sep 27, 2023
11b54bc
wip export coregistration to BIDS
Moo-Marc Jan 13, 2025
ef9fc51
wip coregistration create head surface
Moo-Marc Jan 23, 2025
a01cd68
Merge master, BUT NOT channel_align_manual which will have to be merg…
Moo-Marc Jan 23, 2025
c65fc7e
wip coregistration add SurfaceSmooth
Moo-Marc Jan 23, 2025
bb47718
wip SurfaceSmooth
Moo-Marc Jan 25, 2025
c91dd96
wip coregistration head surface
Moo-Marc Jan 28, 2025
3ccf61d
wip coregistration head surface
Moo-Marc Jan 29, 2025
2f5a36b
wip coregistration head surface clean
Moo-Marc Jan 29, 2025
4c54a28
wip coregistration
Moo-Marc Feb 2, 2025
45f747b
wip coregistration interactive view histogram
Moo-Marc Feb 4, 2025
685286d
wip coregistration small fixes
Feb 4, 2025
99d7b67
Merge branch 'Coordinates' of github.com:Moo-Marc/brainstorm3 into Co…
Moo-Marc Feb 4, 2025
9d4f02c
wip coregistration interactive view histogram
Moo-Marc Feb 4, 2025
3513e93
bugfix in mri histogram bglevel check
Moo-Marc Feb 4, 2025
9e4cefe
fix in mri histogram bglevel check
Moo-Marc Feb 4, 2025
03eba9b
fix gradient method of thresholding MRI for head surface
Moo-Marc Feb 11, 2025
b5190f4
wip save coregistration
Moo-Marc Mar 25, 2025
a22ec5d
coregistration
Moo-Marc Jul 7, 2025
7f8d50e
Merge branch 'master' into Coordinates
Moo-Marc Jul 7, 2025
218c18d
coregistration wip bug fix
Moo-Marc Jul 8, 2025
32cf80b
Merge branch 'master' into Coordinates
Moo-Marc Jul 8, 2025
13fae4c
coregistration fixes
Moo-Marc Jul 24, 2025
7cdb8cf
Import BIDS, minimal fix for IntendedFor containing array or BIDS URI…
Moo-Marc Jul 24, 2025
940ff7e
Merge branch 'BidsUri' into Coordinates
Moo-Marc Jul 25, 2025
3851ae9
wip save coregistration
Moo-Marc Aug 5, 2025
6e7f0fc
minor comment additions
Moo-Marc Sep 12, 2025
866e6c2
bids coreg, skip saving mri if no change
Moo-Marc Sep 22, 2025
2433ebf
Merge branch 'master' into Coordinates
Moo-Marc Sep 22, 2025
ef9e11f
save coregistration per study, & bug fixes
Moo-Marc Dec 3, 2025
ace58db
save coregistration dry run option
Moo-Marc Dec 3, 2025
4eb928d
save coreg minor fix
Moo-Marc Dec 5, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
138 changes: 138 additions & 0 deletions toolbox/anatomy/CalcVertexNormals.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
function [VertexNormals,VertexArea,FaceNormals,FaceArea]=CalcVertexNormals(FV,FaceNormals) % ,up,vp
% Very slightly modified for efficiency and convenience, and added normr. Marc L.
%% Summary
%Author: Itzik Ben Shabat
%Last Update: July 2014

%summary: CalcVertexNormals calculates the normals and voronoi areas at each vertex
%INPUT:
%FV - triangle mesh in face vertex structure
%N - face normals
%OUTPUT -
%VertexNormals - [Nv X 3] matrix of normals at each vertex
%Avertex - [NvX1] voronoi area at each vertex
%Acorner - [NfX3] slice of the voronoi area at each face corner

%% Code

if nargin < 2 || isempty(FaceNormals)
[FaceNormals, FaceArea] = CalcFaceNormals(FV);
end

% disp('Calculating vertex normals... Please wait');
% Get all edge vectors
e0=FV.Vertices(FV.Faces(:,3),:)-FV.Vertices(FV.Faces(:,2),:);
e1=FV.Vertices(FV.Faces(:,1),:)-FV.Vertices(FV.Faces(:,3),:);
e2=FV.Vertices(FV.Faces(:,2),:)-FV.Vertices(FV.Faces(:,1),:);
% Normalize edge vectors
% e0_norm=normr(e0);
% e1_norm=normr(e1);
% e2_norm=normr(e2);

%normalization procedure
%calculate face Area
%edge lengths
de0=sqrt(e0(:,1).^2+e0(:,2).^2+e0(:,3).^2);
de1=sqrt(e1(:,1).^2+e1(:,2).^2+e1(:,3).^2);
de2=sqrt(e2(:,1).^2+e2(:,2).^2+e2(:,3).^2);
l2=[de0.^2 de1.^2 de2.^2];

%using ew to calulate the cot of the angles for the voronoi area
%calculation. ew is the triangle barycenter, I later check if its inside or
%outide the triangle
ew=[l2(:,1).*(l2(:,2)+l2(:,3)-l2(:,1)) l2(:,2).*(l2(:,3)+l2(:,1)-l2(:,2)) l2(:,3).*(l2(:,1)+l2(:,2)-l2(:,3))];

s=(de0+de1+de2)/2;
%Af - face area vector
FaceArea=sqrt(max(0, s.*(s-de0).*(s-de1).*(s-de2)));%herons formula for triangle area, could have also used 0.5*norm(cross(e0,e1))
% if any(~Af) || any(~FaceArea)
% error('Degenerate faces.');
% end

%calculate weights
Acorner=zeros(size(FV.Faces,1),3);
VertexArea=zeros(size(FV.Vertices,1),1);

% Calculate Vertice Normals
VertexNormals=zeros([size(FV.Vertices,1) 3]);

% up=zeros([size(FV.Vertices,1) 3]);
% vp=zeros([size(FV.Vertices,1) 3]);
for i=1:size(FV.Faces,1)
%Calculate weights according to N.Max [1999]

wfv1=FaceArea(i)/(de1(i)^2*de2(i)^2);
wfv2=FaceArea(i)/(de0(i)^2*de2(i)^2);
wfv3=FaceArea(i)/(de1(i)^2*de0(i)^2);

VertexNormals(FV.Faces(i,1),:)=VertexNormals(FV.Faces(i,1),:)+wfv1*FaceNormals(i,:);
VertexNormals(FV.Faces(i,2),:)=VertexNormals(FV.Faces(i,2),:)+wfv2*FaceNormals(i,:);
VertexNormals(FV.Faces(i,3),:)=VertexNormals(FV.Faces(i,3),:)+wfv3*FaceNormals(i,:);
%Calculate areas for weights according to Meyer et al. [2002]
%check if the tringle is obtuse, right or acute

if ew(i,1)<=0
Acorner(i,2)=-0.25*l2(i,3)*FaceArea(i)/(e0(i,:)*e2(i,:)');
Acorner(i,3)=-0.25*l2(i,2)*FaceArea(i)/(e0(i,:)*e1(i,:)');
Acorner(i,1)=FaceArea(i)-Acorner(i,2)-Acorner(i,3);
elseif ew(i,2)<=0
Acorner(i,3)=-0.25*l2(i,1)*FaceArea(i)/(e1(i,:)*e0(i,:)');
Acorner(i,1)=-0.25*l2(i,3)*FaceArea(i)/(e1(i,:)*e2(i,:)');
Acorner(i,2)=FaceArea(i)-Acorner(i,1)-Acorner(i,3);
elseif ew(i,3)<=0
Acorner(i,1)=-0.25*l2(i,2)*FaceArea(i)/(e2(i,:)*e1(i,:)');
Acorner(i,2)=-0.25*l2(i,1)*FaceArea(i)/(e2(i,:)*e0(i,:)');
Acorner(i,3)=FaceArea(i)-Acorner(i,1)-Acorner(i,2);
else
ewscale=0.5*FaceArea(i)/(ew(i,1)+ew(i,2)+ew(i,3));
Acorner(i,1)=ewscale*(ew(i,2)+ew(i,3));
Acorner(i,2)=ewscale*(ew(i,1)+ew(i,3));
Acorner(i,3)=ewscale*(ew(i,2)+ew(i,1));
end
VertexArea(FV.Faces(i,1))=VertexArea(FV.Faces(i,1))+Acorner(i,1);
VertexArea(FV.Faces(i,2))=VertexArea(FV.Faces(i,2))+Acorner(i,2);
VertexArea(FV.Faces(i,3))=VertexArea(FV.Faces(i,3))+Acorner(i,3);

% %Calculate initial coordinate system
% up(FV.Faces(i,1),:)=e2_norm(i,:);
% up(FV.Faces(i,2),:)=e0_norm(i,:);
% up(FV.Faces(i,3),:)=e1_norm(i,:);
end
VertexNormals=normr(VertexNormals);

% %Calculate initial vertex coordinate system
% for i=1:size(FV.Vertices,1)
% up(i,:)=cross(up(i,:),VertexNormals(i,:));
% up(i,:)=up(i,:)/norm(up(i,:));
% vp(i,:)=cross(VertexNormals(i,:),up(i,:));
% end

% disp('Finished Calculating vertex normals');
end


function [FaceNormals, FaceArea]=CalcFaceNormals(FV)
%% Summary
%Author: Itzik Ben Shabat
%Last Update: July 2014

%CalcFaceNormals recives a list of vrtexes and Faces in FV structure
% and calculates the normal at each face and returns it as FaceNormals
%INPUT:
%FV - face-vertex data structure containing a list of Vertices and a list of Faces
%OUTPUT:
%FaceNormals - an nX3 matrix (n = number of Faces) containng the norml at each face
%% Code
% Get all edge vectors
e0=FV.Vertices(FV.Faces(:,3),:)-FV.Vertices(FV.Faces(:,2),:);
e1=FV.Vertices(FV.Faces(:,1),:)-FV.Vertices(FV.Faces(:,3),:);
% Calculate normal of face
FaceNormalsA=cross(e0,e1);
FaceArea = sqrt(sum(FaceNormalsA.^2, 2)) / 2;
FaceNormals=normr(FaceNormalsA);
end

function V = normr(V)
V = bsxfun(@rdivide, V, sqrt(sum(V.^2, 2)));
end

Loading