function varargout = getTrackPositions(tracks, arg1)
% getTrackPositions   Returns the track positions and position covariances
%   positions = getTrackPositions(TRACKS, MODEL) returns an MxD
%   matrix of track positions. M is the number of tracks and D is the
%   dimension of each track position.
%   TRACKS is an M-element array of objectTrack objects or structures with
%   equivalent fields. Tracks must have a State  field, specified as an N
%   element vector. 
%   MODEL must be one of the following names:
%       "constvel"  - The constant velocity model as defined in the 
%                     constvel function.
%       "constacc"  - The constant acceleration model as defined in the 
%                     constacc function.
%       "constturn" - The constant turn rate model as defined in the 
%                     constturn function.
%       "singer"    - The Singer acceleration model as defined in the 
%                     singer function.
%
%   positions = getTrackPositions(tracks, positionSelector) returns an MxD
%   matrix of track positions, where each row represents the position of a
%   track. The position selector, positionSelector, must be a DxN binary
%   matrix, with 1 in the elements that correspond to the position elements
%   in the state.
%
%   [..., positionCovariances] = getTrackPositions(...)   in addition,
%   returns the position covariance matrices as a DxDxM array, where 
%   positionCovariances(:,:,k) is the position covariance of the k-th
%   track. To use this syntax, Tracks must have a StateCovariance field,
%   specified as an NxN matrix.
%
%   An example of a selector matrix: if the state is [x;vx;y;vy], which
%   represents a 2D constant velocity motion. N=4, D=2 and:
%   positionSelector = [1 0 0 0; 0 0 1 0];
%
%   Example: Extract Position From a 2D Constant Velocity Track
%   -----------------------------------------------------------
%   tracks = struct('TrackID', 1, 'UpdateTime', 2.1, 'State', [10;1;40;-1], ...
%		'StateCovariance', diag([1,3,1,3]), 'IsConfirmed', true, ...
%		'IsCoasted', false, 'ObjectClassID', 0, 'ObjectAttributes', struct)
%   
%   % Get the position vector and position covariance using a model name
%   [position, positionCovariance] = getTrackPositions(tracks, 'constvel')
%
%   % Get the position vector and position covariance using a selector
%   positionSelector = [1 0 0 0; 0 0 1 0]
%   [position, positionCovariance] = getTrackPositions(tracks, positionSelector)
%
%   See also: getTrackVelocities

% Copyright 2016-2022 The MathWorks, Inc.

%#codegen

arguments
    tracks {matlabshared.tracking.internal.fusion.mustBeTracks}
    arg1
end

nargoutchk(0,2);

if isnumeric(arg1)
    [varargout{1:nargout}] = matlabshared.tracking.internal.fusion.getTrackPosVel(tracks, arg1, mfilename, 'positionSelector');
else
    [varargout{1:nargout}] = matlabshared.tracking.internal.fusion.trackPosVelModel(tracks, arg1, mfilename, true);
end