function triplets = make_material_triplets(mtype, varargin)
% function triplets = make_material_triplets(mtype, varargin)
%
% make a library of possible material triplets
%
% in 
% mtype		'bone', 'water', 'air'
%                (optionally can be a cell array of several)
%
% options
% ntype      'bone', 'iodine'
%                 unrealistic material combination
%
% out
% triplets   array of possible material triplets
%
% Yong Long, the University of Michigan

if ~nargin, help(mfilename), error(mfilename), return, end
if isnumeric(mtype) && length(mtype) > 1
	mtype = num2cell(mtype);
end

arg.ntype = [];
arg = vararg_pair(arg, varargin);

if ~iscell(mtype)
	mtype = {mtype};
end

triplets_all = nchoosek(mtype, 3); 

if ~isempty(arg.ntype)
    % delete impossible material-type combination
    notype = arg.ntype;
    norow = size(notype, 2);
    for nr = 1 : norow
        nonum = length(notype(nr,:));
        ntri = 1;    
        for t = 1 :  size(triplets_all, 1) %loop over triplet materials
            noflg = zeros(nonum, 1);
            ttype = triplets_all(t, :);        
            for i = 1 : 3 
                for j = 1 : nonum
                    if isequal(ttype{i}, notype{nr,j})
                        noflg(j) = 1;
                    end
                end
            end
            if sum(noflg) ~= nonum
                triplets(ntri, :) = ttype;
                ntri = ntri + 1;
            end
        end
        triplets_all = triplets;
    end
    triplets = triplets(1:ntri-1, :);
else
    triplets = triplets_all;
end