
%% Hexagon Example, Section 3 of the paper barcodes&walls
clear

%% We define a point cloud by giving explicitly the coordinates of the points

point_cloud=[-1,1;1,1;1,2;-1,2;0,3;0,0]

%% We draw a figure with the above points, with the shape of an hexagon
f=figure()
%scatter(point_cloud(:,1),point_cloud(:,2),'.')
%scatter(point_cloud(:,1),point_cloud(:,2),30,'r','filled')
scatter(point_cloud(:,1),point_cloud(:,2),'MarkerEdgeColor',[0 .5 .5],...
              'MarkerFaceColor',[0 .7 .7],...
              'LineWidth',1.5)
axis([-2.5,2.5,-1,4])
saveas(f,'Hexagon.png')
%axis equal

%% these are the parameters needed to the computation of persistent homology

% the max degree of the homology groups
max_dimension = 3;
% the max value of the proximity parameter epsilon
max_filtration_value = 4;
% the number of divisions of the interval
num_divisions = 100;



%% Now we create a Vietoris-Rips complex, which takes as input the above point cloud
stream=api.Plex4.createVietorisRipsStream(point_cloud,max_dimension,max_filtration_value,num_divisions);
num_simplices = stream.getSize()

%% We call the library with the persistence algorithm, here over Z/2Z
persistence = api.Plex4.getModularSimplicialAlgorithm(max_dimension, 2);

%% This command compute the barcodes
intervals= persistence.computeIntervals(stream);


%% Finally we plot the results
options.filename = 'Hexagon Barcodes 2';
options.max_filtration_value = max_filtration_value;
options.max_dimension = max_dimension - 1;
%options.file_format = 'pdf'
%options.side_by_side = true;
options.caption='Hexagon Barcodes';
plot_barcodes(intervals, options);

