
% set up atlas to read subjects
SD_atlas = CreateDefaultAtlasParm('lh');                %left hemisphere ('lh') or right hemisphere ('rh')
sbj_parms = SD_atlas.parms;

sbj_parms.SUBJECTS_DIR = fullfile('..','..','example_surfaces'); % directory that contains subjects
sbj_parms.subject_cell = {'simple_surface1', 'simple_surface2'}; 
sbj_parms.surf_filename = 'sphere';
sbj_parms.data_filename_cell = {'sulc'};
sbj_parms.uniform_meshes = {'ic3.tri'};

SD_atlas.parms = sbj_parms;

% read subjects
sbj_parms.SUBJECT = sbj_parms.subject_cell{1};
fixed_sphere = MARS2_readSbjMesh(sbj_parms);

sbj_parms.SUBJECT = sbj_parms.subject_cell{2};
moving_sphere = MARS2_readSbjMesh(sbj_parms);

% set up parameters
reg_parms = CreateDefaultRegParms;
reg_parms.iter = [15];                     
reg_parms.smooth_displacement_iter = [10]; 
reg_parms.smooth_velocity = 0;                                                    
reg_parms.final_unfold = 0; 
reg_parms.meshes{1} = MARS_readUniformMesh(SD_atlas.parms.uniform_mesh_dir, 'ic3.tri');
reg_parms.verbose = 1;
reg_parms.minimal_verbosity = 0;

% register
parms = SD_registerPairOfSpheres(fixed_sphere, moving_sphere, SD_atlas, reg_parms);

% save warped subject
sbjWarp = parms.sbjWarp;
save_path = fullfile(sbj_parms.SUBJECTS_DIR, sbj_parms.subject_cell{1}, 'surf', 'lh.output');
if(SD_atlas.parms.flipFacesBool)
    write_surf(sbjWarp.curr_vertices', int32(transpose([fixed_sphere.faces(3, :); fixed_sphere.faces(2, :); fixed_sphere.faces(1, :)]) - 1), save_path);
else
    write_surf(sbjWarp.curr_vertices', int32(fixed_sphere.faces' - 1), save_path);
end