%COMP 256 Assignment 1
%Adrian Ilie

final=getpfmraw('r.pfm');

%show height field as an image
figure;
imagesc(final);colormap(gray(256));

%show height field as a surface
figure;
subplot(1, 2, 1);
surfl(final); shading interp; rotate3d on; colormap(gray(256));

%show height field as a textured surface
[Nx,Ny,Nz] = surfnorm(final);
light = lightdirs(:,1);
C = Nx*light(1)+Ny*light(2)+Nz*light(3);
subplot(1, 2, 2);
surface(1:width,1:height,final,albedo.*C); shading interp; rotate3d on; colormap(gray(256));

%plot p and q
figure;
subplot(1, 2, 1);
mesh(p),title('df/dx');rotate3d on;
subplot(1, 2, 2);
mesh(q),title('df/dy');rotate3d on;

%compare different types of integration
r=integrate(p,q);
figure;
subplot(1, 2, 1);
surfl(r),title('Simple integration'); shading interp; rotate3d on; colormap(gray(256));
subplot(1, 2, 2);
surfl(final),title('Multi-grid integration'); shading interp; rotate3d on; colormap(gray(256));