% lecture 01
% Moo K. Chung mkchung@wisc.edu
% 
% AMYGDALA SHAPE MODELING

% reading ANALYZE 7.5 file
header=analyze75info('left_amygdala.hdr')
vol=analyze75read(header);

% image dimension
size(vol)

% volume of the left amygdala
sum(sum(sum(vol)))

% marching cubes algorithm
surf = isosurface(vol) 

% mesh visualization
figure_wire(surf, 'yellow')


% mesh data structure

% 1270 nodes
size(surf.vertices)   

coord=surf.vertices;

% the coordinates of the 500-th node
coord(500,:)


% 2536 faces
size(surf.faces)



% EXERCISE: compute the total length of edges

tri=surf.faces;

% the 1200-th triangle consists of vertices 532, 636 and 632.
tri(1200,:)

% the coordinates of nodes in the 1200-th triangle
coord(tri(1200,:),:)

edge=[];
for i=1:2536
    p=coord(tri(i,:),:); % the coordinates of the node in the i-th coordinate
    edge12=sqrt(sum((p(1,:)-p(2,:)).^2));  %  edge length between point p(1,:) and p(2,:)  
    edge13=sqrt(sum((p(1,:)-p(3,:)).^2));
    edge23=sqrt(sum((p(2,:)-p(3,:)).^2));
    edge(i)=edge12+edge13+edge23;
end;
sum(edge)/2  % Each edge was shared by two triangles so the edge lengh was computed twice.



% HW1: Compute the total surface area of the left amygdala. 
%      Provide the MATLAB code as a proof.


% HW2: For a normal population, does amygdala volume incrase 
%      or decrease with age? Discusss the problem with the 
%      sufficient number of references.





