\documentclass[a2,landscape]{sciposter}
\setmargins[1cm]

\usepackage{csvsimple}	% for marker and target positions
\usepackage{readarray}	% for key=value settings file

\usepackage{siunitx}
\sisetup{detect-all,group-digits=integer}

\usepackage{ifthen}

\usepackage{tikz}
\usepackage{xfp}

% much of the poster setup is read from the file validationSetup.txt.
% read setup
\readarraysepchar{=}
\readdef{validationSetup.txt}{\fileData}
\readarray*\fileData\setupInfo[-,2]
% turn each key into its own command
% NB: this provides \distance, \markerPosFile and \targetPosFile,
% amongst others
\newcounter{keyCount}
\setcounter{keyCount}{0}%
\whiledo{\value{keyCount} < \setupInfoROWS}{%
    \stepcounter{keyCount}%
    \typeout{\arabic{keyCount}: \setupInfo[\arabic{keyCount},1] -> \setupInfo[\arabic{keyCount},2]}
    \expandafter\xdef\csname \setupInfo[\arabic{keyCount},1]\endcsname{%
        \setupInfo[\arabic{keyCount},2]}%
}
\def\markerSideCm{\markerSide\step}
\def\markerFilename#1{all-markers/#1.png}
\def\targetRadCm{.5*\targetDiameter\step}

\makeatletter
\def\convertto#1#2{\strip@pt\dimexpr #2*65536/\number\dimexpr 1#1}
\makeatother

\newlength{\step}
\ifthenelse{\equal{\mode}{deg}}{%
    % convert 1 deg at viewing distance to cm
    % 2*tan(angle/2)*distance
    \pgfmathparse{(2*tan(.5)*\distance)}
    \edef\gridFac{\pgfmathresult}
    \setlength{\step}{\gridFac cm}
    \def\gridAnnot{Grid: \SI{\gridCols}{\degree} x \SI{\gridRows}{\degree}}
}
{ % else
    % cm mode, hopefully. emit warning if not
    \ifthenelse{\equal{\mode}{cm}}{}
    { % else, mode is not cm
        \GenericError{}{mode is not set to deg or cm, but \mode. Unsupported}
    }
    % all user-provides measures are in cm, so step is simply 1cm
    \setlength{\step}{1cm}
    \def\gridAnnot{Grid: \SI{\gridCols}{\centi\meter} x \SI{\gridRows}{\centi\meter}}
}

% setup gaze targets
\tikzset{
    % https://tex.stackexchange.com/a/290508
    clip even odd rule/.code={\pgfseteorule},
    invclip/.style={
        clip,insert path=
        [clip even odd rule]{
            [reset cm](-\maxdimen,-\maxdimen)rectangle(\maxdimen,\maxdimen)
        }
    }
}
\newcommand{\gazeTarget}[3]
{
    \ifthenelse{\equal{\targetType}{Tobii}}{%
        \ifthenelse{\equal{\useExactTobiiSize}{1}}{%
        % exact size specifications of Tobii calibration target
            \fill[white] (#1-27.25mm,#2-27.25mm) rectangle (#1+27.25mm,#2+27.25mm);
            \fill[#3]    (#1,#2) circle (21.5mm);
            \fill[white] (#1,#2) circle (11.5mm);
            \fill[#3]    (#1,#2) circle (1.5mm);
        }
        { % else
            % instead, something defined in visual angle that looks good
            \fill[white] (#1-\targetRadCm,#2-\targetRadCm) rectangle (#1+\targetRadCm,#2+\targetRadCm);
            \fill[#3]    (#1,#2) circle (\targetRadCm);
            \fill[white] (#1,#2) circle (.535*\targetRadCm);
            \fill[#3]    (#1,#2) circle (.0698*\targetRadCm);
        }
    }{}
    \ifthenelse{\equal{\targetType}{Thaler}}{%
        \fill[white]    (#1,#2) circle (\targetRadCm);
        \begin{scope}
            % draw circle, clipping away a cross from it
            \begin{pgfinterruptboundingbox}
                \path[invclip]
                (#1-1.1*\targetRadCm,#2-.25*\targetRadCm) --
                (#1+1.1*\targetRadCm,#2-.25*\targetRadCm) --
                (#1+1.1*\targetRadCm,#2+.25*\targetRadCm) --
                (#1-1.1*\targetRadCm,#2+.25*\targetRadCm);
                \path[invclip]
                (#1-.25*\targetRadCm,#2-1.1*\targetRadCm) --
                (#1+.25*\targetRadCm,#2-1.1*\targetRadCm) --
                (#1+.25*\targetRadCm,#2+1.1*\targetRadCm) --
                (#1-.25*\targetRadCm,#2+1.1*\targetRadCm);
            \end{pgfinterruptboundingbox}
            \fill[#3] (#1,#2) circle (\targetRadCm);
        \end{scope}
        \fill[#3]    (#1,#2) circle (.25*\targetRadCm);
    }{}
}


\begin{document}

\centering
\begin{tikzpicture}[
        draw,color=black!30,yscale=-1
    ]
    \if\showGrid1
        \draw[step=\step, line width=3pt] (0cm,0cm) grid (\step*\gridCols,\step*\gridRows);
    \fi

\csvreader{\markerPosFile}{ID=\ID, x=\x, y=\y, rotation_angle=\rotang}%
{
    \coordinate (m) at (
    \x*\step,
    \y*\step
    );

    \node[inner sep=0pt] (m2) at (m)			{\includegraphics[width=\markerSideCm,angle=\rotang,origin=c]{\markerFilename{\ID}}};
};


\csvreader{\targetPosFile}{ID=\ID, x=\x, y=\y, color=\tColor}%
{
    \gazeTarget{\x*\step}{\y*\step}{\tColor};
};


    % annotations
    \if\showAnnotations1
        \newcounter{mycounter}
        \newlength{\mycounterl}
        \if\showGrid1
            \node[left] at (-0\step, 1\step-0.5\step)     { 1 };
            \node[left] at (-0\step, \fpeval{floor(\gridRows)}\step-0.5\step) { \fpeval{floor(\gridRows)} };

            \node[] at (1\step-0.5\step    ,-0.5\step) { 1 };
            \node[] at (\fpeval{floor(\gridCols)}\step-0.5\step,-0.5\step) { \fpeval{floor(\gridCols)} };

            \setcounter{mycounter}{-1}
            \setlength{\mycounterl}{\value{mycounter}cm}
            \node[right] at (0,\gridRows\step-\mycounterl) {
                \gridAnnot
            };
            \addtocounter{mycounter}{-1}
            \setlength{\mycounterl}{\value{mycounter}cm}

            \node[right] at (0,\gridRows\step-\mycounterl) {
                Cell: \SI{\convertto{cm}{\step}}{\centi\meter} x
                      \SI{\convertto{cm}{\step}}{\centi\meter}
            };
            \addtocounter{mycounter}{-1}
            \setlength{\mycounterl}{\value{mycounter}cm}

            \ifthenelse{\equal{\mode}{deg}}{%
                \node[right] at (0,\gridRows\step-\mycounterl) {
                    1 cell = \SI{1}{\degree} at \SI{\distance}{\centi\meter}
                };
            \addtocounter{mycounter}{-1}
            \setlength{\mycounterl}{\value{mycounter}cm}
            }

                \node[right] at (0,\gridRows\step-\mycounterl) {
                    Markers are \markerSide x\markerSide~cells, which is
                    \convertto{cm}{\markerSideCm}x\SI{\convertto{cm}{\markerSideCm}}{\centi\meter}
                };
        \else
            \setcounter{mycounter}{-1}
            \setlength{\mycounterl}{\value{mycounter}cm}

            \node[right] at (0,\gridRows\step-\mycounterl) {
                Markers are
                \convertto{cm}{\markerSideCm}x\SI{\convertto{cm}{\markerSideCm}}{\centi\meter}
            };
        \fi
    \fi


\end{tikzpicture}

\end{document}
