%% SCRIPT FOR CREATING QUALITY CONTROL OVERLAY PICTURES
% File Directories

% The Meshmonked Obj Files
MappedFiles='D:\Files\Meshmonked\';

%The original Obj files before Meshmonk
OriginalFiles='D:\Files\Original\';

%Meshmonk Matlab folder
addpath(genpath('C:\Users\Simpl\Documents\GitHub\meshmonk\matlab\')) % change this to the correct path on your computer

%Folder to save images into
ImageFolder='D:\Files\QualityControlPics\';

%list all files
objs = dir(strcat(MappedFiles,'*.obj'));

%% Visualize Each Overlay and save as image

for f= 1:numel(objs)
     targetName = objs(f).name
     Mapped=shape3D;
     Mapped.importWavefront(targetName, MappedFiles);

     Mapped.ViewMode='wireframe';
     Mapped.ColorMode='single';
     Mapped.SingleColor=[0 0 0.4];

     targetName2=targetName(3:end);
     Original=shape3D;
     Original.importWavefront(targetName2, OriginalFiles);

     Original.ViewMode='solid';
     Original.SingleColor=[0.7 0.7 0.7];
     Original.ColorMode='single';
     Original.Alpha=0.8;

     %Visualize
     v=viewer(Original);
     v.SceneLightVisible = true;
     v.SceneLightLinked = true;
     v.BackgroundColor = [1,1,1];
     viewer(Mapped,v);

     %Save
     print(v.Figure,[ImageFolder targetName(1:end-4) '_Front'],'-dpng','-r300');

     %Left Side (values may need to be adjusted)
     v.CameraPosition=[1.077296101646526e+03,35.480581752175640,4.076149065073416e+02];
     v.CameraTarget=[3.535343499999996,4.760998000000004,-4.122390745000001];
     v.CameraUpVector=[-0.005364480267767,0.998154867111451,-0.060482093326684];
     v.CameraViewAngle=6.096435787673356;
     v.CamProjection='orthographic';
     v.SceneLightVisible = true;
     v.SceneLightLinked = true;

     print(v.Figure,[ImageFolder targetName(1:end-4) '_Left'],'-dpng','-r300');

     %Right Side (values may need to be adjusted)
     v.CameraPosition=[-1.002235149331587e+03,10.475409171185557,5.542919014827785e+02];
     v.CameraTarget=[3.535343499999996,4.760998000000004,-4.122390745000001];
     v.CameraUpVector=[-0.010944254043582,0.999491781197852,-0.029939983656888];
     v.CameraViewAngle=6.096435787673356;
     v.CamProjection='orthographic';
     v.SceneLightVisible = true;
     v.SceneLightLinked = true;

     print(v.Figure,[ImageFolder targetName(1:end-4) '_Right'],'-dpng','-r300');
     close all
end



