function [Vertices Edges Faces VertexCoefficients] = ...
DisplayGamutFromPrimaries(Wavelengths, SpectralPowerPerWavelength, Obs);
% Purpose Calculate the display gamut, in CIE XYZ space, for an input set of
% primaries. This function can handle multi-primary displays, where there
% are four or more primaries.
%
% Description
%
% Wavelengths A row vector whose entries are the wavelengths (in nm) for the
% spectral power density matrix. The wavelengths should be
% evenly spaced.
%
% SpectralPowerPerWavelength A matrix, whose rows are the values for the
% primaries' spectral power densities at the wavelengths
% listed in the first input. Each row gives a density
% for a different primary.
%
% Obs An indicator for either the 2 degree or the 10 degree standard observer.
% This input can be either a string or a number.
%
% Vertices A three-column matrix. Each row gives the three-dimensional
% coordinates of a vertex of the generated zonohedron.
%
% Edges A two-column matrix. Each row gives an edge of the generated
% zonohedron. The entries of the matrix refer to the rows of the
% Vertices matrix. For example, the row [5,7] in the Edges matrix
% means that the zonohedron contains an edge between the 5th and
% 7th rows (each of which is the three-dimensional coordinates of
% a vertex) in the Vertices matrix.
%
% Faces A four-column matrix. Each row gives a face of the generated
% zonohedron. The entries of the matrix refer to the rows of the
% Vertices matrix. For example, the row [5,7,3,2] in the Edges
% matrix means that the zonohedron contains a face whose vertices
% are the 5th, 7th, 3rd, and 2nd rows of the Vertices matrix. The
% vertices are listed in either clockwise or counterclockwise
% order, for easy plotting.
%
% VertexCoefficients Each vertex is a linear combination of the generating vectors.
% The ith row of the matrix VertexCoefficients gives the
% coefficients of the generating vectors for the ith vertex, which
% is given in the ith row of the matrix Vertices.
%
% Author Paul Centore (March 30, 2014)
%
% Copyright 2014 Paul Centore
%
% This file is part of MunsellAndKubelkaMunkToolbox.
%
% MunsellAndKubelkaMunkToolbox is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% MunsellAndKubelkaMunkToolbox is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with MunsellAndKubelkaMunkToolbox. If not, see .
% Calculate the CIE XYZ coordinates of each primary, from its spectral power density
XYZ = SpectralPowerDensityToXYZ(Wavelengths, SpectralPowerPerWavelength, Obs) ;
% A display gamut (in CIE XYZ space) is the zonohedron generated by the primaries. Find
% detailed information about this zonohedron
[Vertices Edges Faces VertexCoefficients] = ConstructPositiveZonohedron(XYZ) ;
DisplayFigure = true ; % A flag for drawing a figure of the gamut
if DisplayFigure
figure
NumberOfFaces = size(Faces,1) ;
for ctr = 1:NumberOfFaces
plot3([Vertices(Faces(ctr,1),1),Vertices(Faces(ctr,2),1),Vertices(Faces(ctr,3),1),...
Vertices(Faces(ctr,4),1),Vertices(Faces(ctr,1),1)], ...
[Vertices(Faces(ctr,1),2),Vertices(Faces(ctr,2),2),Vertices(Faces(ctr,3),2),...
Vertices(Faces(ctr,4),2),Vertices(Faces(ctr,1),2)], ...
[Vertices(Faces(ctr,1),3),Vertices(Faces(ctr,2),3),Vertices(Faces(ctr,3),3),...
Vertices(Faces(ctr,4),3),Vertices(Faces(ctr,1),3)], 'k-')
hold on
end
set(gca, 'dataaspectratio', [1 1 1])
% set(gca, 'xlabel', 'X')
% set(gca, 'ylabel', 'Y')
% set(gca, 'zlabel', 'Z')
set(gca, 'view', [300 25])
end
return;