% 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.

% Reads the geotiff AOI file and converts it into 1D binary buffer
% Input:referencepc~ 3D lidar data with the ground coordinates
% Input:gtAOIpath~ geotiff file
% Input:Semantic_flag~ flag whether there is a specific AOI selected or the entire area is to be used
% Output:1D binary buffer with the pixel locations of the AOI
% Version History
%   2017/03/28  Marc Bosch       Initial version
function AOImask=alignAOImask(referencepc,gtAOIpath,Semantic_flag)

Classbuilding=6;

if Semantic_flag==1
    [aoigt,aoiRef]=geotiffread(gtAOIpath);
    aoiinfo=geotiffinfo(gtAOIpath);
    AOImask=zeros(length(referencepc.x),1);
    [xy]=round(map2pix(aoiinfo.RefMatrix,referencepc.x,referencepc.y));  
    for ij=1:length(referencepc.x)
        AOImask(ij,1)=double(aoigt(xy(ij,1),xy(ij,2)));
    end
else
    AOImask(1:length(referencepc.x),1)=Classbuilding;    
end
