function rok_evaluation_full_latex_table (evaluationData, lines)
    % ROK_EVALUATION_FULL_LATEX_TABLE (evaluationData, lines)
    %
    % Creates LaTeX source for table.
    %
    % Input:
    %  - evaluationData = structure produced by evaluation routine. Must
    %    contain the following fields: 'confusionMatrix' (confusion matrix 
    %    of (N+1)x(N+1) dimension - each object/detection, plus phantom and 
    %    missing detections), 'precision' (1xN array of precision values)
    %    and 'recall' (1xN array of recall values) where N is number of
    %    objects
    %  - lines = whether to print additional horizontal and vertical lines
    %    or not
    %
    % See also: ROK_EVALUATION_FULL_CREATE, ROK_EVALUATION_FULL_UPDATE,
    % ROK_EVALUATION_FULL_DISPLAY
    %    
    % Copyright (C) 2012, Rok Mandeljc <rok.mandeljc@fe.uni-lj.si>
    
    % Extract data...
    numIds = size(evaluationData.counterAssigned, 2);
    
    diagElements = diag(evaluationData.counterAssigned)';
    
    precision = diagElements ./ evaluationData.counterDetections;
    recall = diagElements ./ evaluationData.counterGround;
    
    confusionMatrix = evaluationData.counterAssigned;
    phantoms = evaluationData.counterFp;
    missing = evaluationData.counterFn;
    
    overallPrecision = sum(diagElements) / sum(evaluationData.counterDetections);
    overallRecall = sum(diagElements) / sum(evaluationData.counterGround);
    
    % Begin tabular
    fprintf('\\begin{tabular}{cc');
    for p = 1:numIds,
        fprintf('c');
    end
    fprintf('ccc}\n');
    
    fprintf('\\cline{%d-%d}\n', 3, 3+numIds+2);

    % Header
    fprintf('\\multicolumn{2}{c|}{}\t&\t');
    fprintf('\\multicolumn{%d}{c}{\\textbf{DETECTIONS}}\t&\t', numIds);
    fprintf('\\multicolumn{1}{|c||}{\\multirow{2}{*}{\\textbf{Missing}}}\t&\t');
    fprintf('\\multicolumn{1}{|c|}{\\multirow{2}{*}{\\textbf{Precision}}}\t&\t');
    fprintf('\\multicolumn{1}{|c|}{\\multirow{2}{*}{\\textbf{Recall}}}\t \\\\ \n');
    
    fprintf('\\cline{%d-%d}\n', 3, 3+numIds-1);

    fprintf('\\multicolumn{2}{c|}{}\t&\t');
    for p = 1:numIds,
        if lines,
            fprintf('\\multicolumn{1}{|c|}{\\textbf{\\#%d}}\t&\t', p);
        else
            fprintf('\\textbf{\\#%d}\t&\t', p);
        end
    end
    fprintf('\\multicolumn{1}{|c||}{}\t&\t');
    fprintf('\\multicolumn{1}{|c|}{}\t&\t');
    fprintf('\\multicolumn{1}{|c|}{}\t \\\\ \n');

    fprintf('\\cline{%d-%d}\n', 1, 2+numIds+3);

    % Detection rows
    for p = 1:numIds,
        % First column is different1
        if p == 1,
            fprintf('\\multicolumn{1}{|c|}{\\multirow{%d}{*}{\\rotatebox{90}{\\textbf{PERSON}}}}\t&\t', numIds)
        else
            fprintf('\\multicolumn{1}{|c|}{}\t&\t');
        end
        
        fprintf('\\multicolumn{1}{|c|}{\\textbf{\\#%d}}\t&\t', p);
        
        % Detection fields
        for r = 1:numIds,
            % Diagonal elements are bold
            if r == p,
                fieldText = sprintf('\\textbf{%d}', confusionMatrix(p,r));
            else
                fieldText = sprintf('%d', confusionMatrix(p,r));
            end
            
            if lines,
                fprintf('\\multicolumn{1}{|c|}{%s}\t&\t', fieldText);
            else
                fprintf('%s\t&\t', fieldText);
            end
        end
        fprintf('\\multicolumn{1}{|c||}{%d}\t&\t', missing(p));
        fprintf('\\multicolumn{1}{|c|}{%.2f}\t&\t', precision(p));
        fprintf('\\multicolumn{1}{|c|}{%.2f}\t \\\\ \n', recall(p));

        if lines,
            fprintf('\\cline{%d-%d}\n', 2, 2+numIds+3);
        end
    end

    fprintf('\\cline{%d-%d}\n', 1, 2+numIds+3);

    % Phantoms
    fprintf('\\multicolumn{2}{|c|}{\\textbf{Phantom}}\t&\t');
    if lines,
        fprintf('\\multicolumn{1}{|c|}{%d}\t&\t', phantoms);
    else
        fprintf('%d\t&\t', phantoms);
    end
    fprintf('\\multicolumn{1}{|c}{}\t&\t');
    
    % Overall precision and recall
    fprintf('\\multicolumn{1}{|c|}{\\textbf{%.2f}}\t&\t', overallPrecision);
    fprintf('\\multicolumn{1}{|c|}{\\textbf{%.2f}}\t \\\\ \n', overallRecall);
    
    
    fprintf('\\cline{%d-%d}\n', 1, 2+numIds);
    fprintf('\\cline{%d-%d}\n', 2+numIds+2, 2+numIds+3);
    
    % End tabular
    fprintf('\\end{tabular}\n');
end