% Copyright 2017 The Johns Hopkins University Applied Physics Laboratory.
% Licensed under the MIT License. See LICENSE.txt in the project root for full license information.

%main function of PCS metrics
%Input:meshinput1~ data structure containing the input mesh
%Input:referencepcpath ~ path of ground truth data location
%Input:gtAOIpath~ path of AOI mask location
%pointspacing: desired point spacing to compute metrics (should be point
%spacing of ground truth for best results)
%Input:registration_done~ flag that indicates if input data has been already registered wtr to lidar data
%Input:visualflag~ flag to generate figures
%Input:fid~ file descriptor for writing metric summary reports
%Output:outmesh~ data structure containing all metric results
function [outmesh] = PCSmetric_run(meshinput1,referencepcpath,gtAOIpath,pointspacing,registration_done,visualflag,fid)
% Main script to run PCS metrics code.
%
% Assumes compile is happening from pipelinePCS directory.
%
% Version History
%   2017/03/28  Marc Bosch       Initial version
%
%Where is the code being executed from?
WorkingDir = mfilename('fullpath');
WorkingDir = fileparts(WorkingDir);
currentDir=pwd;

warning('off','all')
addpath(genpath([currentDir '/3rdparty'])) 
addpath(genpath([currentDir '/Registration']))

%Compile mex files
%listmexfiles=dir(['./*mexw64']);
ext = mexext;
if length(dir([WorkingDir '/*' ext]))~=6 
    fprintf('Compiling mex files...\n');
    cd(WorkingDir)
    PCSmetric_compile;
    cd(currentDir)
end

%Configuration
results_verbose=1; 
Surfacemetrics=0;% set to 1 to calculate dihedral angle and geometric laplacian errors

%read lidar data and triangulate (if only point cloud is passed)
fprintf('Reading Lidar data and creating mesh...\n');
referencepcpath=get_fullpath(referencepcpath);
if ~isempty(gtAOIpath)
    gtAOIpath=get_fullpath(gtAOIpath);
end
meshreference=get_referencedata(referencepcpath,gtAOIpath,pointspacing,Surfacemetrics);


%visualflag=1;
%repeat steps in case registration hasn't been done yet
if registration_done~=1
    pathinputpc = meshinput1.pathinputpc;
    referencepcpath = meshreference.referencepcpath;
    gtAOIpath = meshreference.gtAOIpath;
    curdir=cd;
    fprintf('Reading Lidar data and creating mesh...\n');
    [a,b,c]=fileparts(referencepcpath);

    cd(a)
    referencepcpath=which([b c]);
    cd(curdir)
    meshreference=get_referencedata(referencepcpath,gtAOIpath,pointspacing,Surfacemetrics)
    fprintf('Reading solution data and creating mesh...\n');
    [a,b,c]=fileparts(pathinputpc);
    cd(a)
    pathinputpc=which([b c]);
    cd(curdir)
    meshinput1=get_inputdata(pathinputpc,gtAOIpath,pointspacing);
  
  
    %perform registration
    node_xyz=meshinput1.node_xyz;
    inputfilename=meshinput1.filenameLAS;
    [filenameLAS_registered,XYZoffset, registeredpc] = ...
        XYZregistration(inputfilename,meshreference.referencepcpath,node_xyz);

    %read registered data 
    meshinput1.node_xyz(1,:) = registeredpc.x;
    meshinput1.node_xyz(2,:) = registeredpc.y;
    meshinput1.node_xyz(3,:) = registeredpc.z;
    
    
end

%compute PCS metrics
tic;
meshreferenceori=meshreference;
[meshreference,meshinput1]=error_curvature(meshreferenceori,meshinput1, ...
    meshreferenceori.pointspacing,visualflag,Surfacemetrics);
toc;
%write out results
fprintf(fid,'\n\n');
fprintf(fid,'-------------------\n');
    fprintf(fid,'Metrics Summary:\n');
    fprintf(fid,'-------------------\n');
    fprintf(fid,'Mean Curvature Error (Full site):%f\n',meshinput1.errormeancurvature);
    fprintf(fid,'Gaussian Curvature Error (Full site):%f\n',meshinput1.errorgaussiancurvature);
    fprintf(fid,'Max Curvature Error (Full site):%f\n',meshinput1.errormaxcurvature);
    fprintf(fid,'Min Curvature Error (Full site):%f\n',meshinput1.errormincurvature);
    fprintf(fid,'Geometric Laplacian Error (Full site):%f\n',meshinput1.errorGL);
    fprintf(fid,'Dihedral Angle Error (Full site):%f\n',meshinput1.errorDA);
    fprintf(fid,'z-error RMS (Full site):%f\n',meshinput1.errorRMS);
    fprintf(fid,'z-error RMS without (Lidar) edges regions (Full site):%f\n',meshinput1.errorRMSwoEdges);
    fprintf(fid,'z-error RMS on (Lidar) edges only regions (Full site):%f\n',meshinput1.errorRMSonEdges);
    fprintf(fid,'z-completeness (Full site):%f\n',meshinput1.errorCOMP);
    fprintf(fid,'-------------------\n');
    fprintf(fid,'Mean Curvature Error (AOI site):%f\n',meshinput1.errormeancurvatureAOI);
    fprintf(fid,'Gaussian Curvature Error (AOI site):%f\n',meshinput1.errorgaussiancurvatureAOI);
    fprintf(fid,'Max Curvature Error (AOI site):%f\n',meshinput1.errormaxcurvatureAOI);
    fprintf(fid,'Min Curvature Error (AOI site):%f\n',meshinput1.errormincurvatureAOI);
    fprintf(fid,'Geometric Laplacian Error (AOI site):%f\n',meshinput1.errorGLAOI);
    fprintf(fid,'Dihedral Angle Error (AOI site):%f\n',meshinput1.errorDAAOI);
    fprintf(fid,'z-error RMS (AOI site):%f\n',meshinput1.errorRMSAOI);
    fprintf(fid,'z-completeness (AOI site):%f\n',meshinput1.errorCOMPAOI);
    fprintf(fid,'-------------------\n');
    fprintf(fid,'Error Distribution \n');
    fprintf(fid,'-------------------\n');
    fprintf(fid,'Gaussian Curvature Error Distribution (Full site):[%f,%f,%f,%f,%f,%f]\n',...
        meshinput1.errorKprofile(1),meshinput1.errorKprofile(2),meshinput1.errorKprofile(3),...
        meshinput1.errorKprofile(4),meshinput1.errorKprofile(5),meshinput1.errorKprofile(6));
    fprintf(fid,'Mean Curvature Error Distribution (Full site):[%f,%f,%f,%f,%f,%f]\n',...
        meshinput1.errorHprofile(1),meshinput1.errorHprofile(2),meshinput1.errorHprofile(3),...
        meshinput1.errorHprofile(4),meshinput1.errorHprofile(5),meshinput1.errorHprofile(6));
    fprintf(fid,'Max Curvature Error Distribution (Full site):[%f,%f,%f,%f,%f,%f]\n',...
        meshinput1.errorCmaxprofile(1),meshinput1.errorCmaxprofile(2),meshinput1.errorCmaxprofile(3),...
        meshinput1.errorCmaxprofile(4),meshinput1.errorCmaxprofile(5),meshinput1.errorCmaxprofile(6));
    fprintf(fid,'Min Curvature Error Distribution (Full site):[%f,%f,%f,%f,%f,%f]\n',...
        meshinput1.errorCminprofile(1),meshinput1.errorCminprofile(2),meshinput1.errorCminprofile(3),...
        meshinput1.errorCminprofile(4),meshinput1.errorCminprofile(5),meshinput1.errorCminprofile(6));
    fprintf(fid,'Geometric Laplacian Error Distribution (Full site):[%f,%f,%f,%f,%f,%f]\n',...
        meshinput1.errorGLprofile(1),meshinput1.errorGLprofile(2),meshinput1.errorGLprofile(3),...
        meshinput1.errorGLprofile(4),meshinput1.errorGLprofile(5),meshinput1.errorGLprofile(6));
    fprintf(fid,'Dihedral Angle Error Distribution (Full site):[%f,%f,%f,%f,%f,%f]\n',...
        meshinput1.errorDiAnprofile(1),meshinput1.errorDiAnprofile(2),meshinput1.errorDiAnprofile(3),...
        meshinput1.errorDiAnprofile(4),meshinput1.errorDiAnprofile(5),meshinput1.errorDiAnprofile(6));
    fprintf(fid,'Gaussian Curvature Error Distribution without (Lidar) edge regions (Full site):[%f,%f,%f,%f,%f,%f]\n',...
        meshinput1.errorKprofilewoedges(1),meshinput1.errorKprofilewoedges(2),meshinput1.errorKprofilewoedges(3),...
        meshinput1.errorKprofilewoedges(4),meshinput1.errorKprofilewoedges(5),meshinput1.errorKprofilewoedges(6));
    fprintf(fid,'Mean Curvature Error Distribution without (Lidar) edge regions (Full site):[%f,%f,%f,%f,%f,%f]\n',...
        meshinput1.errorHprofilewoedges(1),meshinput1.errorHprofilewoedges(2),meshinput1.errorHprofilewoedges(3),...
        meshinput1.errorHprofilewoedges(4),meshinput1.errorHprofilewoedges(5),meshinput1.errorHprofilewoedges(6));
    fprintf(fid,'Max Curvature Error Distribution without (Lidar) edge regions (Full site):[%f,%f,%f,%f,%f,%f]\n',...
        meshinput1.errorCmaxprofilewoedges(1),meshinput1.errorCmaxprofilewoedges(2),meshinput1.errorCmaxprofilewoedges(3),...
        meshinput1.errorCmaxprofilewoedges(4),meshinput1.errorCmaxprofilewoedges(5),meshinput1.errorCmaxprofilewoedges(6));
    fprintf(fid,'Min Curvature Error Distribution without (Lidar) edge regions (Full site):[%f,%f,%f,%f,%f,%f]\n',...
        meshinput1.errorCminprofilewoedges(1),meshinput1.errorCminprofilewoedges(2),meshinput1.errorCminprofilewoedges(3),...
        meshinput1.errorCminprofilewoedges(4),meshinput1.errorCminprofilewoedges(5),meshinput1.errorCminprofilewoedges(6));
    fprintf(fid,'Dihedral Angle Error Distribution without (Lidar) edge regions (Full site):[%f,%f,%f,%f,%f,%f]\n',...
        meshinput1.errorDiAnprofilewoedges(1),meshinput1.errorDiAnprofilewoedges(2),meshinput1.errorDiAnprofilewoedges(3),...
        meshinput1.errorDiAnprofilewoedges(4),meshinput1.errorDiAnprofilewoedges(5),meshinput1.errorDiAnprofilewoedges(6));
    fprintf(fid,'Geometric Laplacian Error Distribution without (Lidar) edge regions (Full site):[%f,%f,%f,%f,%f,%f]\n',...
        meshinput1.errorGLprofilewoedges(1),meshinput1.errorGLprofilewoedges(2),meshinput1.errorGLprofilewoedges(3),...
        meshinput1.errorGLprofilewoedges(4),meshinput1.errorGLprofilewoedges(5),meshinput1.errorGLprofilewoedges(6));
    fprintf(fid,'Cumulative Accuracy (Full site):[%f,%f,%f,%f,%f,%f]\n',...
        meshinput1.errorZPERC(1),meshinput1.errorZPERC(2),meshinput1.errorZPERC(3),...
        meshinput1.errorZPERC(4),meshinput1.errorZPERC(5),meshinput1.errorZPERC(6));
    fprintf(fid,'Completeness Percentile (Full site):[%f,%f,%f,%f,%f,%f]\n',...
        meshinput1.errorCUMUL(1),meshinput1.errorCUMUL(2),meshinput1.errorCUMUL(3),...
        meshinput1.errorCUMUL(4),meshinput1.errorCUMUL(5),meshinput1.errorCUMUL(6));
    fprintf(fid,'-------------------\n');
    fprintf(fid,'Gaussian curvature Error Distribution(AOI site):[%f,%f,%f,%f,%f,%f]\n',...
        meshinput1.errorKAOIprofile(1),meshinput1.errorKAOIprofile(2),meshinput1.errorKAOIprofile(3),...
        meshinput1.errorKAOIprofile(4),meshinput1.errorKAOIprofile(5),meshinput1.errorKAOIprofile(6));
    fprintf(fid,'Mean curvature Error Distribution(AOI site):[%f,%f,%f,%f,%f,%f]\n',...
        meshinput1.errorHAOIprofile(1),meshinput1.errorHAOIprofile(2),meshinput1.errorHAOIprofile(3),...
        meshinput1.errorHAOIprofile(4),meshinput1.errorHAOIprofile(5),meshinput1.errorHAOIprofile(6));
    fprintf(fid,'Max curvature (Error DistributionAOI site):[%f,%f,%f,%f,%f,%f]\n',...
        meshinput1.errorCmaxAOIprofile(1),meshinput1.errorCmaxAOIprofile(2),meshinput1.errorCmaxAOIprofile(3),...
        meshinput1.errorCmaxAOIprofile(4),meshinput1.errorCmaxAOIprofile(5),meshinput1.errorCmaxAOIprofile(6));
    fprintf(fid,'Min curvature Distribution(AOI site):[%f,%f,%f,%f,%f,%f]\n',...
        meshinput1.errorCminAOIprofile(1),meshinput1.errorCminAOIprofile(2),meshinput1.errorCminAOIprofile(3),...
        meshinput1.errorCminAOIprofile(4),meshinput1.errorCminAOIprofile(5),meshinput1.errorCminAOIprofile(6));
    fprintf(fid,'Geometric Laplacian Error Distribution(AOI site):[%f,%f,%f,%f,%f,%f]\n',...
        meshinput1.errorGLAOIprofile(1),meshinput1.errorGLAOIprofile(2),meshinput1.errorGLAOIprofile(3),...
        meshinput1.errorGLAOIprofile(4),meshinput1.errorGLAOIprofile(5),meshinput1.errorGLAOIprofile(6));
    fprintf(fid,'Dihedral angle Error Distribution(AOI site):[%f,%f,%f,%f,%f,%f]\n',...
        meshinput1.errorDiAnAOIprofile(1),meshinput1.errorDiAnAOIprofile(2),meshinput1.errorDiAnAOIprofile(3),...
        meshinput1.errorDiAnAOIprofile(4),meshinput1.errorDiAnAOIprofile(5),meshinput1.errorDiAnAOIprofile(6));
    fprintf(fid,'Completeness Percentile (AOI site):[%f,%f,%f,%f,%f,%f]\n',...
        meshinput1.errorCUMULAOI(1),meshinput1.errorCUMULAOI(2),meshinput1.errorCUMULAOI(3),...
        meshinput1.errorCUMULAOI(4),meshinput1.errorCUMULAOI(5),meshinput1.errorCUMULAOI(6));
    fprintf(fid,'Cumulative Accuracy (AOI site):[%f,%f,%f,%f,%f,%f]\n',...
        meshinput1.errorZPERCAOI(1),meshinput1.errorZPERCAOI(2),meshinput1.errorZPERCAOI(3),...
        meshinput1.errorZPERCAOI(4),meshinput1.errorZPERCAOI(5),meshinput1.errorZPERCAOI(6));

%fclose(fid);
if results_verbose==1
    fprintf('-------------------\n');
    fprintf('Metrics Summary:\n');
    fprintf('-------------------\n');
    fprintf('Mean Curvature Error (Full site):%f\n',meshinput1.errormeancurvature);
    fprintf('Gaussian Curvature Error (Full site):%f\n',meshinput1.errorgaussiancurvature);
    fprintf('Max Curvature Error (Full site):%f\n',meshinput1.errormaxcurvature);
    fprintf('Min Curvature Error (Full site):%f\n',meshinput1.errormincurvature);
    fprintf('Geometric Laplacian Error (Full site):%f\n',meshinput1.errorGL);
    fprintf('Dihedral Angle Error (Full site):%f\n',meshinput1.errorDA);
    fprintf('z-error RMS (Full site):%f\n',meshinput1.errorRMS);
    fprintf('z-error RMS without (Lidar) edges regions (Full site):%f\n',meshinput1.errorRMSwoEdges);
    fprintf('z-error RMS on (Lidar) edges only regions (Full site):%f\n',meshinput1.errorRMSonEdges);
    fprintf('z-completeness (Full site):%f\n',meshinput1.errorCOMP);
    fprintf('-------------------\n');
    fprintf('Mean Curvature Error (AOI site):%f\n',meshinput1.errormeancurvatureAOI);
    fprintf('Gaussian Curvature Error (AOI site):%f\n',meshinput1.errorgaussiancurvatureAOI);
    fprintf('Max Curvature Error (AOI site):%f\n',meshinput1.errormaxcurvatureAOI);
    fprintf('Min Curvature Error (AOI site):%f\n',meshinput1.errormincurvatureAOI);
    fprintf('Geometric Laplacian Error (AOI site):%f\n',meshinput1.errorGLAOI);
    fprintf('Dihedral Angle Error (AOI site):%f\n',meshinput1.errorDAAOI);
    fprintf('z-error RMS (AOI site):%f\n',meshinput1.errorRMSAOI);
    fprintf('z-completeness (AOI site):%f\n',meshinput1.errorCOMPAOI);
    fprintf('-------------------\n');
    fprintf('Error Distribution \n');
    fprintf('-------------------\n');
    fprintf('Gaussian Curvature Error Distribution (Full site):[%f,%f,%f,%f,%f,%f]\n',...
        meshinput1.errorKprofile(1),meshinput1.errorKprofile(2),meshinput1.errorKprofile(3),...
        meshinput1.errorKprofile(4),meshinput1.errorKprofile(5),meshinput1.errorKprofile(6));
    fprintf('Mean Curvature Error Distribution (Full site):[%f,%f,%f,%f,%f,%f]\n',...
        meshinput1.errorHprofile(1),meshinput1.errorHprofile(2),meshinput1.errorHprofile(3),...
        meshinput1.errorHprofile(4),meshinput1.errorHprofile(5),meshinput1.errorHprofile(6));
    fprintf('Max Curvature Error Distribution (Full site):[%f,%f,%f,%f,%f,%f]\n',...
        meshinput1.errorCmaxprofile(1),meshinput1.errorCmaxprofile(2),meshinput1.errorCmaxprofile(3),...
        meshinput1.errorCmaxprofile(4),meshinput1.errorCmaxprofile(5),meshinput1.errorCmaxprofile(6));
    fprintf('Min Curvature Error Distribution (Full site):[%f,%f,%f,%f,%f,%f]\n',...
        meshinput1.errorCminprofile(1),meshinput1.errorCminprofile(2),meshinput1.errorCminprofile(3),...
        meshinput1.errorCminprofile(4),meshinput1.errorCminprofile(5),meshinput1.errorCminprofile(6));
    fprintf('Geometric Laplacian Error Distribution (Full site):[%f,%f,%f,%f,%f,%f]\n',...
        meshinput1.errorGLprofile(1),meshinput1.errorGLprofile(2),meshinput1.errorGLprofile(3),...
        meshinput1.errorGLprofile(4),meshinput1.errorGLprofile(5),meshinput1.errorGLprofile(6));
    fprintf('Dihedral Angle Error Distribution (Full site):[%f,%f,%f,%f,%f,%f]\n',...
        meshinput1.errorDiAnprofile(1),meshinput1.errorDiAnprofile(2),meshinput1.errorDiAnprofile(3),...
        meshinput1.errorDiAnprofile(4),meshinput1.errorDiAnprofile(5),meshinput1.errorDiAnprofile(6));
    fprintf('Gaussian Curvature Error Distribution without (Lidar) edge regions (Full site):[%f,%f,%f,%f,%f,%f]\n',...
        meshinput1.errorKprofilewoedges(1),meshinput1.errorKprofilewoedges(2),meshinput1.errorKprofilewoedges(3),...
        meshinput1.errorKprofilewoedges(4),meshinput1.errorKprofilewoedges(5),meshinput1.errorKprofilewoedges(6));
    fprintf('Mean Curvature Error Distribution without (Lidar) edge regions (Full site):[%f,%f,%f,%f,%f,%f]\n',...
        meshinput1.errorHprofilewoedges(1),meshinput1.errorHprofilewoedges(2),meshinput1.errorHprofilewoedges(3),...
        meshinput1.errorHprofilewoedges(4),meshinput1.errorHprofilewoedges(5),meshinput1.errorHprofilewoedges(6));
    fprintf('Max Curvature Error Distribution without (Lidar) edge regions (Full site):[%f,%f,%f,%f,%f,%f]\n',...
        meshinput1.errorCmaxprofilewoedges(1),meshinput1.errorCmaxprofilewoedges(2),meshinput1.errorCmaxprofilewoedges(3),...
        meshinput1.errorCmaxprofilewoedges(4),meshinput1.errorCmaxprofilewoedges(5),meshinput1.errorCmaxprofilewoedges(6));
    fprintf('Min Curvature Error Distribution without (Lidar) edge regions (Full site):[%f,%f,%f,%f,%f,%f]\n',...
        meshinput1.errorCminprofilewoedges(1),meshinput1.errorCminprofilewoedges(2),meshinput1.errorCminprofilewoedges(3),...
        meshinput1.errorCminprofilewoedges(4),meshinput1.errorCminprofilewoedges(5),meshinput1.errorCminprofilewoedges(6));
    fprintf('Dihedral Angle Error Distribution without (Lidar) edge regions (Full site):[%f,%f,%f,%f,%f,%f]\n',...
        meshinput1.errorDiAnprofilewoedges(1),meshinput1.errorDiAnprofilewoedges(2),meshinput1.errorDiAnprofilewoedges(3),...
        meshinput1.errorDiAnprofilewoedges(4),meshinput1.errorDiAnprofilewoedges(5),meshinput1.errorDiAnprofilewoedges(6));
    fprintf('Geometric Laplacian Error Distribution without (Lidar) edge regions (Full site):[%f,%f,%f,%f,%f,%f]\n',...
        meshinput1.errorGLprofilewoedges(1),meshinput1.errorGLprofilewoedges(2),meshinput1.errorGLprofilewoedges(3),...
        meshinput1.errorGLprofilewoedges(4),meshinput1.errorGLprofilewoedges(5),meshinput1.errorGLprofilewoedges(6));
    fprintf('Cumulative Accuracy (Full site):[%f,%f,%f,%f,%f,%f]\n',...
        meshinput1.errorZPERC(1),meshinput1.errorZPERC(2),meshinput1.errorZPERC(3),...
        meshinput1.errorZPERC(4),meshinput1.errorZPERC(5),meshinput1.errorZPERC(6));
    fprintf('Completeness Percentile (Full site):[%f,%f,%f,%f,%f,%f]\n',...
        meshinput1.errorCUMUL(1),meshinput1.errorCUMUL(2),meshinput1.errorCUMUL(3),...
        meshinput1.errorCUMUL(4),meshinput1.errorCUMUL(5),meshinput1.errorCUMUL(6));
    fprintf('-------------------\n');
    fprintf('Gaussian curvature Error Distribution(AOI site):[%f,%f,%f,%f,%f,%f]\n',...
        meshinput1.errorKAOIprofile(1),meshinput1.errorKAOIprofile(2),meshinput1.errorKAOIprofile(3),...
        meshinput1.errorKAOIprofile(4),meshinput1.errorKAOIprofile(5),meshinput1.errorKAOIprofile(6));
    fprintf('Mean curvature Error Distribution(AOI site):[%f,%f,%f,%f,%f,%f]\n',...
        meshinput1.errorHAOIprofile(1),meshinput1.errorHAOIprofile(2),meshinput1.errorHAOIprofile(3),...
        meshinput1.errorHAOIprofile(4),meshinput1.errorHAOIprofile(5),meshinput1.errorHAOIprofile(6));
    fprintf('Max curvature (Error DistributionAOI site):[%f,%f,%f,%f,%f,%f]\n',...
        meshinput1.errorCmaxAOIprofile(1),meshinput1.errorCmaxAOIprofile(2),meshinput1.errorCmaxAOIprofile(3),...
        meshinput1.errorCmaxAOIprofile(4),meshinput1.errorCmaxAOIprofile(5),meshinput1.errorCmaxAOIprofile(6));
    fprintf('Min curvature Distribution(AOI site):[%f,%f,%f,%f,%f,%f]\n',...
        meshinput1.errorCminAOIprofile(1),meshinput1.errorCminAOIprofile(2),meshinput1.errorCminAOIprofile(3),...
        meshinput1.errorCminAOIprofile(4),meshinput1.errorCminAOIprofile(5),meshinput1.errorCminAOIprofile(6));
    fprintf('Geometric Laplacian Error Distribution(AOI site):[%f,%f,%f,%f,%f,%f]\n',...
        meshinput1.errorGLAOIprofile(1),meshinput1.errorGLAOIprofile(2),meshinput1.errorGLAOIprofile(3),...
        meshinput1.errorGLAOIprofile(4),meshinput1.errorGLAOIprofile(5),meshinput1.errorGLAOIprofile(6));
    fprintf('Dihedral angle Error Distribution(AOI site):[%f,%f,%f,%f,%f,%f]\n',...
        meshinput1.errorDiAnAOIprofile(1),meshinput1.errorDiAnAOIprofile(2),meshinput1.errorDiAnAOIprofile(3),...
        meshinput1.errorDiAnAOIprofile(4),meshinput1.errorDiAnAOIprofile(5),meshinput1.errorDiAnAOIprofile(6));
    fprintf('Completeness Percentile (AOI site):[%f,%f,%f,%f,%f,%f]\n',...
        meshinput1.errorCUMULAOI(1),meshinput1.errorCUMULAOI(2),meshinput1.errorCUMULAOI(3),...
        meshinput1.errorCUMULAOI(4),meshinput1.errorCUMULAOI(5),meshinput1.errorCUMULAOI(6));
    fprintf('Cumulative Accuracy (AOI site):[%f,%f,%f,%f,%f,%f]\n',...
        meshinput1.errorZPERCAOI(1),meshinput1.errorZPERCAOI(2),meshinput1.errorZPERCAOI(3),...
        meshinput1.errorZPERCAOI(4),meshinput1.errorZPERCAOI(5),meshinput1.errorZPERCAOI(6));
end
outmesh=meshinput1;
