function autoLabels = exampleLidarAutomationAlgorithmFunction(ptCloud)
% autoLabels = exampleLidarAutomationAlgorithmFunction(ptCloud) runs a pretrained 
% Point Pillars Detector to label objects in the input point cloud, ptCloud.The
% predicted labels are returned in autoLabels, a struct array with fields Name, Type,
% and Position.

% Copyright 2023 The MathWorks, Inc.

% One-time initialization of the detector. A one-time initialization saves
% time on subsequent runs.
persistent detector
if isempty(detector)%  % Specify class names.
% Load the pre-trained detector. 
   pretrainedDetector = load('pretrainedPointPillarsDetector.mat','detector');
   detector = pretrainedDetector.detector;

end

% Run the detector on the input point cloud, ptCloud.
 [bboxes,scores,labels] = detect(detector,ptCloud,'Threshold',0.25);
 
% Create and fill the autoLabels struct with the predicted bounding box
% locations. The Name and Type of ROI returned by the automation function
% must match one of the labels defined in the labeling app.
autoLabels = struct('Name',{},'Type',{}, 'Position',{});
for i = 1:size(bboxes,1)
    autoLabels(i).Name = 'object';
    autoLabels(i).Type = labelType.Cuboid;
    autoLabels(i).Position = bboxes(i,:);
end