function lamMatrix = convertHcToLamFromDec(hcMatrix, dec)
% convert hC-vectors to lambda-vectors 
%
% Syntax: lamMatrix = convertHcToLamFromDec(hcMatrix, dec)
%
% The hC-vectors in the columns of hcMatrix are converted to the scalar
%   coefficients of a minkowski sum of the structuring elements such that
%   lamMatrix has dec.nS rows and the same number of columns like hcMatrix.
%
% See also: obtainDec

% The elk-library: convex geometry applied to crystallization modeling.
%   Copyright (C) 2013 Alexander Reinhold
%
% This program 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.
%
% This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.

zerotol = elkZerotol;

%! Dev: Invalid vectors are not yet covered!
%/

lamMatrix = zeros(size(dec.se, 1), size(hcMatrix, 2));
for iSimplex = 1:length(dec.simplexPartition)
    thisFilterMatrix = dec.simplexPartition{iSimplex}.A*hcMatrix;
    thisFilterVector = sum(thisFilterMatrix < zerotol, 1) == dec.nC;
    
    lamMatrix(dec.simplexPartition{iSimplex}.seIndexVector, ...
              thisFilterVector) = ...
        dec.simplexPartition{iSimplex}.mappingHcToLam * ...
        hcMatrix(:, thisFilterVector);
end