function Disp_3Dmeshes_characteristicleaves(colines,colbkg,opt);
%Program to make figures of 3D leaves as meshes.
%The program has to be run as Disp_3Dbestfitshape(colines,colbkg,opt); 
%where colines is the line color, colbkg is the background color, 
%and opt = 1 overrides the chosen line color to display lines based on z-value (i.e. leaf height). 
%If not input parameters are provided, default values are used to show a black grid on a grey background.
%Examples:
%>> Disp_3Dmeshes_characteristicleaves([0 0 0],[0.7 0.7 0.7],0);
%>> Disp_3Dmeshes_characteristicleaves([0 0 0],[1 1 1],1);
%Next program to run: Makemovie_3Dmeshes


days=7:19;

close all
if nargin<3
    colines=[0 0 0];
    colbkg=[0.7 0.7 0.7];
    opt=0;
end
Pathname=uigetdir(cd,'Select main project folder in  which all shape results and figures are stored');
load([Pathname '\3D surface and figures\Mean3Dsurface.mat']);

resdir='Figures of characteristic leaves as 3D meshes';
if ~exist([Pathname '\' resdir],'dir')
    mkdir(Pathname,resdir);
end
Pathname=[Pathname '\' resdir];

% PathName=uigetdir(pwd,'Select folder in  which to save mean grids');
cd(Pathname)

%days=input('days to display? e.g. 7:19');
fignum=0;
for t=days(1):days(end)
    fignum=fignum+1;
    
    figure;
    set(gca,'Color',colbkg);
    set(gcf,'Color',colbkg);
    hold on,
    h=plot3([Mode_outlineZ{t}(:,1);Mode_outlineZ{t}(1,1)],[Mode_outlineZ{t}(:,2);Mode_outlineZ{t}(1,2)],[Mode_outlineZ{t}(:,3);Mode_outlineZ{t}(1,3)],'LineWidth',1);
    set(h,'Color',colines);
    if opt==0
        drawgrid1(leaf_XIg{t},leaf_YIg{t},Mode_leaf_ZIg{t},colines);
    elseif opt==1
        h=mesh(leaf_XIg{t},leaf_YIg{t},Mode_leaf_ZIg{t});
        set(h,'FaceColor','none')
    else
         h=surf(leaf_XIg{t},leaf_YIg{t},Mode_leaf_ZIg{t});
    end
    axis equal
    saveas(gcf,['FigureDAS' num2str(t)],'fig');
end

disp(['Figures of characteristic leaves as 3D meshes have been saved in:' Pathname]);
