%Oct. 20, 2003, Longin Jan Latecki, latecki@temple.edu
%cluster visualization in 3D obtained by PCA
%cluster is a row verctor that contains cluster index in each entry
%based on the program by Venugupal Rajagupal vrajagop@temple.edu

function showcluster(cluster,inputFileName)
datas=load(inputFileName);

noclusters=max(cluster); %this gives the number of clusters


[m, s, d] = normalize(datas, [], []);    %normalize the dataset
[datas, proj] = pca(d, [], 3);     %Extracting the principal components from the dataset


color = ['ok','vr','+g','+r','+c','+m','+y';'xk','xb','xg','xr','xc','xm','xy']; 
figure

cl = 0;
cl=datas(find(cluster == 1),:); size(cl,1);            %Plotting 3D output for both clusters and centroids 
    plot3(cl(:,1),cl(:,2),cl(:,3),'*'); hold
    
    j = 1; k = 1;
    for i=2:noclusters
        if i == 8 
            j = 2; k = 1;
        end
        cl=datas(find(cluster == i),:); size(cl,1);
        plot3(cl(:,1),cl(:,2),cl(:,3),[color(j,k) color(j,k+1)]);
        k=k+2;
    end
    
%     for i=1:noclusters
%         cl=datas(vi,:);
%         plot3(cl(:,1),cl(:,2),cl(:,3),'ob');
%     end
    rotate3d
title('Cluster visualization in 3D obtained by PCA from distances')