function [ hrms,hrms_uncertainty, vrms,vrms_uncertainty ] = vector_metrics_run( data_filename, aoi_filename, bldg_filename, road_filename, params )

%% Read in AOI
if(~isempty(aoi_filename))
    [~,~,ext] = fileparts(aoi_filename);
    switch(ext)
        case '.kml'
            disp('Read AOI KML');
            aoi = loadKML(aoi_filename, []);
            
        otherwise
            error('Unknown AOI extension: %s', ext(2:end));
    end
else
    aoi = [];
end


%% Read in data
assert(~isempty(data_filename));
[~,~,ext] = fileparts(data_filename);
switch(ext)
    case '.las'
        disp('Read point cloud');
        ref_pc = lasdata(data_filename);
        dem_struct = demGenerate(ref_pc, aoi, params.dem);
        
    case '.tif'
        disp('Read DSM');
        [data,R] = geotiffread(data_filename);
        dem_struct = dem2struct(data, R, aoi, params.dem);
        
    otherwise
        error('Unknown DATA extension: %s', ext(2:end));
end
if(params.dem.display)
    displayVectors(1, dem_struct.max_dem, dem_struct, [], []);
end


%% Read in building vectors
if(~isempty(bldg_filename))
    [~,~,ext] = fileparts(bldg_filename);
    switch(ext)
        case '.shp'
            disp('Read building shapefile');
            buildings = loadShapeFile(bldg_filename, dem_struct.boundary, params.vectors);
            
        case '.kml'
            disp('Read building KML');
            buildings = loadKML(bldg_filename, dem_struct.boundary);
            
        case '.tif'
            disp('Read building raster image');
            buildings = loadRasterVectors(bldg_filename, dem_struct.boundary, params.vectors);
            
        case '.mat'
            disp('Load building MAT file');
            load(bldg_filename);
            
        otherwise
            error('Unknown BUILDING extension: %s', ext(2:end));
    end
    
    buildings = vectorClip(buildings,dem_struct.boundary,true);
    
    if(params.dem.display)
        displayVectors(1, [], dem_struct, buildings, 'r');
    end
else
    buildings = [];
end


%% Read in road vectors
if(~isempty(road_filename))
    [~,~,ext] = fileparts(road_filename);
    switch(ext)
        case '.shp'
            disp('Read road shapefile');
            roads = loadShapeFile(road_filename, dem_struct.boundary, params.vectors);
            
        case '.kml'
            disp('Read road KML');
            roads = loadKML(road_filename, dem_struct.boundary);
            
        otherwise
            error('Unknown ROAD extension: %s', ext(2:end));
    end
    
    roads = vectorClip(roads,dem_struct.boundary,false);
    
    if(params.dem.display)
        displayVectors(1, [], dem_struct, roads, 'b');
    end
else
    roads = [];
end


%% Create edge mask
if(~isempty(buildings))
    dem_struct = demEdges(dem_struct, params.dem);
    
    if(params.dem.display)
        displayVectors(2, dem_struct.edges, dem_struct, [], []);
    end
end


%% Calculate HRMS
if(~isempty(buildings))
    [hrms,hrms_uncertainty] = calculateHRMS(buildings, dem_struct, params.hrms);
else
    hrms = 0;
    hrms_uncertainty = 0;
end


%% Calculate VRMS
if(~isempty(roads))
    [vrms,vrms_uncertainty] = calculateVRMS(roads, dem_struct, params.vrms);
else
    vrms = 0;
    vrms_uncertainty = 0;
end


end

