function configs = coverageConfig(sensors,positions,orientations)
%COVERAGECONFIG returns configurations used by a coverage plotter.
%   configs = coverageConfig(sensors) returns sensor and emitter
%   configuration structures from a list of sensors and emitters.
%
%   configs = coverageConfig(sensors,positions,orientations) allows you to
%   specify the position and orientation of the platform on which each
%   sensor or emitter is mounted.
%   
%   Inputs:
%           sensors          Sensors or emitters, specified as a sensor or
%                            emitter object, or an N-element cell array of
%                            sensor and emitter objects.
%           positions        Cartesian positions of sensors or emitters'
%                            platforms, specified as an N-by-3 matrix of
%                            scalars. The ith row is the [x, y, z]
%                            Cartesian coordinates of the ith sensor or
%                            emitter.
%           orientations     Orientations of sensors or emitters' platforms,
%                            specified as an N-by-1 vector of quaternions.
%                            The ith quaternion in the vector represents
%                            the rotation from the global or scenario frame
%                            to the ith sensor or emitter's platform frame.
%
%   Outputs: 
%           configs          An array of configuration structures.  The
%                            fields are listed <a href="matlab:help fusion.internal.interfaces.DataStructures/coverageConfigStruct">here</a>.
%
%   % Example
%   % -------
%   radar = monostaticRadarSensor(1,'Rotator');
%   emitter = radarEmitter(2);
%   % radar config in the platform frame
%   cfg = coverageConfig({radar, emitter});
%   disp(cfg);
%   % radar config in a global frame
%   cfg2 = coverageConfig({radar, emitter},[1000 0 0 ; 0 1000 0])
%   disp(cfg2);
%
%   See also coveragePlotter, theaterPlot.

%   Copyright 2019-2020 The MathWorks, Inc.

% validate inputs
narginchk(1,3)
validateattributes(sensors,{'cell'},{},mfilename,'sensors');
numSensors = numel(sensors);
if nargin < 2
    positions = zeros(numSensors,3);
else % validate number of positions matches number of sensors
    validateattributes(positions,{'numeric'},{'nrows',numSensors},mfilename,'positions');
end
if nargin < 3
    orientations = repmat(quaternion(1,0,0,0),numSensors,1);
else
    validateattributes(orientations,{'quaternion'},{'nrows',numSensors},mfilename,'orientations');
end

% Create output
configTemplate = fusion.internal.interfaces.DataStructures.coverageConfigStruct;
configs = repmat(configTemplate,numSensors,1);

% Fill in output values
for i=1:numSensors
    sensor = sensors{i};
    if ~isa(sensor,'fusion.internal.remotesensors.ScanningMount') ...
            && ~isa(sensor,'monostaticLidarSensor') ...
            && ~isa(sensor,'matlabshared.tracking.internal.fusion.EmissionsRadarDataGenerator')
        error(message('shared_radarfusion:coverageConfig:InvalidInput','coverageConfig'));
    end
    configs(i) = sensors{i}.coverageConfig(positions(i,:),orientations(i));
end
end
