function seMatrix = scaleToReal(seMatrix, dec, zerotol)
% scale input matrix of hC-vectors to some real geometry
%
% THIS FUNCTION IS NO USER FUNCTION.

% The elk-library: convex geometry applied to crystallization modeling.
%   Copyright (C) 2012 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/>.

%% info
% This scaling preserves the position and scales the polytope to the mean
%   width of 1. This is beneficial for S-representation with these SEs.
%   From the sum of the lambda-vector, one can directly read the mean width
%   and, hence, extrapolate a particle size!

hrep.A = dec.A;
for iSe = 1:size(seMatrix, 1)
    % old scaling
    % This scaling preserves the position but ensures that one facet 
    %   exactly touches the unit sphere while the distance of all other 
    %   facets to the origin will be smaller than 1 so that they intersect 
    %   the unit sphere.

%       seMatrix(iSe, :) = seMatrix(iSe, :) / ...
%           max(seMatrix(iSe, :)*dec.mappingReducedToFull');

    % mean width scaling:
    hrep.h = dec.mappingReducedToFull*seMatrix(iSe, :)';
    %! DEV: the following line is not according to the intentions for
    %       zerotol but is necessary to get results for the decomposition.
    %       Even though, this solution is not nice it is quite valid scince
    %       crystal poloytopes are always centered at x0=[0 0 0].
    hrep.h(abs(hrep.h) < sqrt(zerotol) & hrep.h < 0) = 0;
    %/
    
    seMatrix(iSe, :) = seMatrix(iSe, :) / computeMeanWidthHrep(hrep, zerotol);
end