%% preparation
% add the path of iso2mesh to matlab path list...
%add the full path to .../iso2mesh/bin directory % to windows/Linux/Unix PATH environment variable
clear;clc;


%% load the sample data
a_left=load('data_left.mat');% left hippocampus data
a_right=load('data_right.mat');

TrSet_left=cell2mat(struct2cell(a_left)); % TrSet.mat contains left hippocampus of Training set patient%rat_head.mat
TrSet_right=cell2mat(struct2cell(a_right));
NoofEigVals=30; %Fixed; Could vary 

NoofPatients=size(TrSet_left,1);

EigValsRlogRatio=zeros((NoofPatients),(NoofEigVals-2));
EigValsLlogRatio=zeros((NoofPatients),(NoofEigVals-2));

% volimage is a volumetric image such as an X-ray or MRI image
%% perform mesh generation
for index=1:NoofPatients
     
    volimageL=squeeze(TrSet_left(index,:,:,:));
    volimageR=squeeze(TrSet_right(index,:,:,:));
    
    [nodeL,faceL,~,~]=vol2surf(volimageL>0.05,1:size(volimageL,1),1:size(volimageL,2),1:size(volimageL,3),0.1,1,'simplify');
    [A_L,C_L] = FEM(nodeL,faceL); [V_L, D_L] = eigs(C_L,A_L,NoofEigVals,'sm');
    temp=diag(D_L); temp(1)=[];    
    temp=log(temp);temp(1)=[]; 
    EigValsLlogRatio(index,:)=temp;
    clear temp
    
    [nodeR,faceR,~,~]=vol2surf(volimageR>0.05,1:size(volimageR,1),1:size(volimageR,2),1:size(volimageR,3),0.15,4,'simplify');
    [A_R,C_R] = FEM(nodeR,faceR); [V_R, D_R] = eigs(C_R,A_R,NoofEigVals,'sm');
    temp=diag(D_R);    temp(1)=[];
    temp=log(temp);temp(1)=[]; 
    EigValsRlogRatio(index,:)=temp;
    
end
EigValsLlogRatio
EigValsRlogRatio


% 