File: iViewXDriftCorrection.m

package info (click to toggle)
psychtoolbox-3 3.0.19.14.dfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 86,796 kB
  • sloc: ansic: 176,245; cpp: 20,103; objc: 5,393; sh: 2,753; python: 1,397; php: 384; makefile: 193; java: 113
file content (109 lines) | stat: -rw-r--r-- 3,414 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
function [result, ivx]=iViewXDriftCorrection(ivx, pos)

% driftcorrection routine of iViewX toolbox
% could also double as driftcorrection with a single point?
result=1;
absdcpos=[];
try

    if ~exist('ivx', 'var') || isempty(ivx)
        txt=[ mfilename ' requires a structure with iViewX default values as input.'];
        error(txt);
    end

    if 1==exist('pos', 'var') && ~isempty(pos)
        % if pos is supplied, we take the default value, but we first do
        % some checks
        if size(pos,1)==1 && size(pos,2)==2
            if 1==IsInRect(pos(1,1), pos(1,2), Screen('Rect', ivx.window))
                absdcpos=pos;
            else
                fprintf([mfilename ':supplied driftcorrection position is outside window, using default instead.\n']);
            end
        else
            fprintf([mfilename ':something is wrong with the supplied driftcorrection position, using default instead.\n']);
        end
    end

    if isempty(absdcpos)
        % we take default value if no value is found yet
        if ~isfield(ivx, 'absDCPos') || isempty(ivx.absDCPos) || size(ivx.absDCPos,1)~=1 || size(ivx.absCalPos,2)~=2
            txt=[ mfilename ': something is wrong with default driftcorrection point pixel values.'];
            error(txt);
        else
            absdcpos=ivx.absDCPos(1,:);
        end
    end

%     Screen('FillRect',ivx.window, ivx.backgroundColour);
%     Screen('Flip',ivx.window);
    iViewX('erasescreen', ivx);
    fprintf('Driftcorrection at position (%d, %d).\n', absdcpos(1,1), absdcpos(1,2));

    pointShown=zeros(1,size(absdcpos,1));
    nPointsShown=0;

    i=0;
    while 1
        [keyIsDown,secs,keyCode] = KbCheck;
        if keyCode(ivx.modifierKey) && keyCode(ivx.breakKey),
            result=-1;
            ivx.stop=1;
            break;
        end
        if keyCode(ivx.breakKey),
            result=-1;
            break;
        end
        % determine next point
        if ivx.orderedCalibration==1
            i=i+1;
        else
            while 1
                k=randperm(size(absdcpos,1));
                if pointShown(k(1))==0
                    i=k(1);
                    break;
                end
                drawnow; % enables ctrl-c break?
            end
        end
        iViewX('drawcalibrationpoint', ivx, [absdcpos(i,1), absdcpos(i,2)]);
        pointShown(i)=1;
        nPointsShown=nPointsShown+1;

        % here we should probably send some information to the tracker about the
        % present point
        tEnd=GetSecs+ivx.calPaceSecs;
        while GetSecs<tEnd
            [keyIsDown,secs,keyCode] = KbCheck;
            if keyCode(ivx.modifierKey) && keyCode(ivx.breakKey),
                ivx.stop=1;
                result=-1;
                break;
            end
            if keyCode(ivx.breakKey),
                result=-1;
                break;
            end
        end

        if nPointsShown==size(absdcpos,1)
            break;
        end
    end
%     Screen('FillRect',ivx.window, ivx.backgroundColour);
%     Screen('Flip',ivx.window);
    iViewX('erasescreen', ivx);
    WaitSecs(ivx.calExtraTimeSecs);

    fprintf('\nEnd of driftcorrection.\n');
catch
    %this "catch" section executes in case of an error in the "try" section
    %above.  Importantly, it closes the onscreen window if its open.

    Screen('CloseAll');
    rethrow(lasterror);
end %try..catch..