% go to the sample data folder inside iso2mesh
datapath=[fileparts(which('s2m')) filesep 'sample'];

fprintf(1,'loading segmented brain image...\n');
for i=1:256
    brain(:,:,i)=imread([datapath filesep 'brain_seg.tif'],i);
end
fprintf(1,'loading complete\n');
brain=uint8(brain);     %% <- cgalmesh requires the volume to be in uint8 format


%% create a brain mesh in 1 line

density=20; %%<- Hands-on hints: change this value (not too small)
maxvol=200; %%<- Hands-on hints: change this value (not too small)

% this can take about a min on a laptop
tic
[node,elem,face]=v2m(brain,[],density,maxvol,'cgalmesh');
toc

%% Plot the results
figure;
plotmesh(node,elem,'x>90');
