%Figure for flattening and representation
%Figure 2

%example of flatening process
i=4;
vol=F{i};
surf=isosurface(vol,0.505); 
 
  [amyg,sphere,amygsphere]=CREATEenclosedamyg2(vol,surf); %slightly modified from surfstats
  stream=LAPLACE3Dsmooth(amygsphere,amyg,-sphere); %from surfstats
  sphere=isosurface(amyg,0.505);
  
 
 ha = tight_subplot(3,5,[.01 .01],[.01 .01],[.01 .01]); %like subplot, but with less space between figures
%A 
        
      
        
   axes(ha(1));
   
    
       figure_wire2(sphere,'yellow')
    axis off 
    
     alpha=1
    sphere=LAPLACEcontour(stream,sphere, 1 - 2*alpha/5); % from surfstats
    sphere=REGULARIZEarea2(sphere, 0.8); %slightly modified from surfstats
     axes(ha(2));
    figure_wire2(sphere,'yellow')
    axis off 

     alpha=2
    sphere=LAPLACEcontour(stream,sphere, 1 - 2*alpha/5); % from surfstats
    sphere=REGULARIZEarea2(sphere, 0.8); %slightly modified from surfstats
     axes(ha(3));
    figure_wire2(sphere,'yellow')
    axis off 
    
    alpha=3
    sphere=LAPLACEcontour(stream,sphere, 1 - 2*alpha/5); % from surfstats
    sphere=REGULARIZEarea2(sphere, 0.8); %slightly modified from surfstats
     axes(ha(6));
    figure_wire2(sphere,'yellow')
    axis off 
    
    alpha=4
    sphere=LAPLACEcontour(stream,sphere, 1 - 2*alpha/5); % from surfstats
    sphere=REGULARIZEarea2(sphere, 0.8); %slightly modified from surfstats
     axes(ha(7));
    figure_wire2(sphere,'yellow')
    axis off 
    
    alpha=5
    sphere=LAPLACEcontour(stream,sphere, 1 - 2*alpha/5); % from surfstats
    sphere=REGULARIZEarea2(sphere, 0.8); %slightly modified from surfstats
     axes(ha(8));
    figure_wire2(sphere,'yellow')
    axis off 
    
    
    %C

k=1;
    
    
for n=[1, 2, 8, 15,30]
[surf_smooth, fourier]=SPHARMsmooth2(isosurface(amyg,0.505),sphere,n,0); %from surfstats
axes(ha(k+10));
figure_wire2(surf_smooth,'yellow')
axis off 
k=k+1;
end

%B
    
    %spherical angles
[theta varphi]=EULERangles(sphere);
surf=isosurface(amyg,0.505);
axes(ha(4));
figure_trimesh3(surf,theta)
axis off 
axes(ha(9));
figure_trimesh3(surf,varphi)
axis off 


load('unitsphere2562.mat')
[theta varphi]=EULERangles(sphere);
axes(ha(5));
figure_trimesh4(sphere,theta)
axis off 
axes(ha(10));
figure_trimesh4(sphere,varphi)
    axis off 
    


  