function result = handleIgnoreFilter(bnd, optionStruct)
% handle options to ignore proper particle identification
%
% Particles that are non-convex or too small are estimated by a simple
%   circle to return a dummy result.
%
% THIS IS NO USER FUNCTION

% 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/>.

%% handle ignore cases
flagIgnore = 0;
if optionStruct.minConvexity && ...
        bnd.convexity < optionStruct.minConvexity
    flagIgnore = 1;
end
if optionStruct.minDiameter && ...
        bnd.meanWidthHull < optionStruct.minDiameter
    flagIgnore = 2;
end
if optionStruct.maxSphericity && ...
        bnd.sphericity > optionStruct.maxSphericity
    flagIgnore = 3;
end
if optionStruct.maxSphericity2 && ...
        bnd.sphericity2 > optionStruct.maxSphericity2
    flagIgnore = 4;
end
if optionStruct.maxAngleGap && ...
        bnd.largestAngleGap > optionStruct.maxAngleGap
    flagIgnore = 5;
end
if optionStruct.minBrightFraction && ~isfield(bnd, 'brightFraction')
    error('elk:bnd:inputError', ['If bright fraction from image shall ' ...
        'be checked, you must provide the image for obtainBnd']); 
end
if optionStruct.minBrightFraction && isfield(bnd, 'brightFraction') && ...
        bnd.brightFraction < optionStruct.minBrightFraction
    flagIgnore = 6;
end
if flagIgnore
    result = bnd;
    % shape data
    result.hrep.A = [];
    result.hrep.h = [];
    result.vrep.V = [0 0];
    result.lambda = mean(bnd.polarDistance);
    % additional data
    result.circumfence = 2*pi*result.lambda;
    result.meanWidth = 2*result.lambda;
    result.roughness = max(bnd.polarDistance) - min(bnd.polarDistance);
    result.squareRoughness = inf;
    result.flagIgnore = flagIgnore;
else
    result = [];
end