clear

%% demo call for roast()
% basic demo
roast('example/subject1.nii',{'F1',0.3,'P2',0.7,'C5',-0.6,'O2',-0.4},'simulationTag','basicDemo');
close all

% use a different cap
roast('example/subject1.nii',{'G12',1,'J7',-1},'captype','biosemi','simulationTag','tryBiosemi');
close all

% place electrodes at customized locations
roast('example/subject1.nii',{'custom1',0.5,'custom3',-0.5,'Nk1',0.5,'Nk3',-0.5,},'simulationTag','tryCustomizedElec');
close all

% use pad electrode
roast('example/subject1.nii',{'Fp1',1,'FC4',1,'POz',-2},'electype','pad','simulationTag','tryPad');
close all

% control electrode shapes individually
roast('example/subject1.nii',{'Fp1',1,'FC4',1,'POz',-2},'electype',{'disc','pad','ring'},'simulationTag','tryAllShapes');
close all

% control electrode size
roast('example/subject1.nii',{'Fp1',1,'FC4',1,'POz',-2},'electype','pad','elecsize',[45 25 4],'simulationTag','controlSize');
close all

% control electrode size individually
roast('example/subject1.nii',{'Fp1',1,'FC4',1,'POz',-2},'electype',{'disc','pad','ring'},'elecsize',{[8 2],[45 25 4],[5 8 2]},'simulationTag','controlIndividualSize');
close all

% control orientation of pad electrode
roast('example/subject1.nii',{'Fp1',1,'FC4',1,'POz',-2},'electype','pad','elecori','ap','simulationTag','controlPadOri');
close all

% control orientation of pad electrode using customized orientation vector
% (not recommended, code still not perfect)
roast('example/subject1.nii',{'Fp1',1,'FC4',1,'POz',-2},'electype','pad','elecori',[1 1 0],'simulationTag','controlPadOriCustom');
close all

% add T2
roast('example/subject1.nii',{'F1',0.3,'P2',0.7,'C5',-0.6,'O2',-0.4},'T2','example/subject1_T2.nii','simulationTag','addT2');
close all

% turn on resampling
roast('example/subject1.nii',{'F1',0.3,'P2',0.7,'C5',-0.6,'O2',-0.4},'resampling','on','simulationTag','useResample');
close all

% turn on zero-padding
roast('example/MNI152_T1_1mm.nii',{'Exx19',1,'C4',-1},'zeropadding',60,'simulationTag','useZeroPadding');
close all

% control mesh options
roast('example/MNI152_T1_1mm.nii',{'F1',0.3,'P2',0.7,'C5',-0.6,'O2',-0.4},'meshoptions',struct('distbound',0.2,'maxvol',8),'simulationTag','controlMesh');
close all

% control tissue conductivities
roast('example/subject1.nii',{'F1',0.3,'P2',0.7,'C5',-0.6,'O2',-0.4},'conductivities',struct('csf',0.6,'electrode',0.1),'simulationTag','controlConductivity');
close all

% generate lead field for running roast_target()
roast('example/MNI152_T1_1mm.nii','leadField','zeropadding',20,'simulationTag','MNI152leadField');
close all

% generate lead field for running roast_target()
roast('example/subject1.nii','leadField','resampling','on','zeropadding',20,'simulationTag','subj1LeadField');
close all

%% demo call for roast_target()
% basic demo of targeting (max-intensity)
roast_target('example/MNI152_T1_1mm.nii','MNI152leadField',[-48 -8 50],'targetingTag','basicDemo');
close all

% split electrodes for max-intensity targeting
roast_target('example/MNI152_T1_1mm.nii','MNI152leadField',[-48 -8 50],'optType','max-l1per','targetingTag','splitElectrode');
close all

% split electrodes and control exact electrode number for max-intensity targeting
roast_target('example/MNI152_T1_1mm.nii','MNI152leadField',[-48 -8 50],'optType','max-l1per','elecNum',8,'targetingTag','controlElecNumber');
close all

% basic demo of targeting (max-focality, using wls)
roast_target('example/MNI152_T1_1mm.nii','MNI152leadField',[-48 -8 50],'optType','wls-l1','targetingTag','basicDemoFocality');
close all

% basic demo of targeting (max-focality, using lcmv)
roast_target('example/MNI152_T1_1mm.nii','MNI152leadField',[-48 -8 50],'optType','lcmv-l1','targetingTag','basicDemoFocality2');
close all

% reduce k to get more focality
roast_target('example/MNI152_T1_1mm.nii','MNI152leadField',[-48 -8 50],'optType','wls-l1','k',0.01,'targetingTag','usingK');
close all

% 2 targets at the same time
roast_target('example/MNI152_T1_1mm.nii','MNI152leadField',[-48 -8 50;48 -8 50],'optType','wls-l1','k',0.002,'targetingTag','2targets');
close all

% 2 targets at the same time and define orientation for each target
roast_target('example/MNI152_T1_1mm.nii','MNI152leadField',[-48 -8 50;48 -8 50],'optType','wls-l1','k',0.002,'orient',{'right','left'},'targetingTag','2targetsDefineOri');
close all

% use voxel coordinates for target locations
roast_target('example/MNI152_T1_1mm.nii','MNI152leadField',[52 184 72;25 80 72;139 171 72],'coordType','voxel','optType','wls-l1','k',0.002,'targetingTag','3targets');
close all

% customize electric field orientation at each target
roast_target('example/MNI152_T1_1mm.nii','MNI152leadField',[52 184 72;25 80 72;139 171 72],'coordType','voxel','optType','wls-l1','k',0.002,'orient',{'radial-in',[-1 1 1],'posterior'},'targetingTag','3targetsCustomOrient');
close all

% use optimal orientation at the target
roast_target('example/MNI152_T1_1mm.nii','MNI152leadField',[-48 -8 50],'orient','optimal','targetingTag','optimalOri');
close all

%% demo call for reviewRes()
% review results from simulation 'tryCustomizedElec' on subject1, showing all the tissues
reviewRes('example/subject1.nii','tryCustomizedElec','all');
close all

% review results from simulation 'controlPadOri' on subject1, showing only csf
reviewRes('example/subject1.nii','controlPadOri','csf');
close all

% review results from targeting '3targets' on MNI152 head, showing all the tissues
reviewRes('example/MNI152_T1_1mm.nii','MNI152leadField','all',[],'3targets');
close all
