-
Notifications
You must be signed in to change notification settings - Fork 2
/
FractControllerAcuityVernier.j
171 lines (143 loc) · 7.22 KB
/
FractControllerAcuityVernier.j
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/*
This file is part of FrACT10, a vision test battery.
Copyright © 2021 Michael Bach, [email protected], <https://michaelbach.de>
FractControllerAcuityVernier.j
Created by Bach on 14.08.2017.
*/
@import "FractControllerAcuity.j"
@implementation FractControllerAcuityVernier: FractControllerAcuity {
float offsetVernierMinimalArcSec, offsetVernierMaximalArcSec;
}
- (void) modifyThresholderStimulus {[self modifyThresholderStimulusWithBonus];}
- (void) modifyDeviceStimulus {}
- (CPString) composeExportString {return [self acuityComposeExportString];}
- (float) stimDeviceunitsFromThresholderunits: (float) tPest { //console.info("FractControllerAcuityVernier>stimDeviceunitsFromThresholderunits");
gStrokeMinimal = [MiscSpace pixelFromDegree: offsetVernierMinimalArcSec / 60.0 / 60.0];
gStrokeMaximal = [MiscSpace pixelFromDegree: offsetVernierMaximalArcSec / 60.0 / 60.0];
const c1 = gStrokeMinimal;
const c2 = -Math.log(gStrokeMinimal / gStrokeMaximal);
const deviceVal = c1 * Math.exp(tPest * c2); //trace("Vernier.pest2native, tPest:", tPest, "native=", nativeVal);
if ([Misc areNearlyEqual: deviceVal and: gStrokeMaximal]) {
if (!isBonusTrial) {
rangeLimitStatus = kRangeLimitValueAtCeiling; //console.info("max shift size!")
}
} else {
if ([Misc areNearlyEqual: deviceVal and: gStrokeMinimal]) {
rangeLimitStatus = kRangeLimitValueAtFloor; //console.info("min shift size!");
} else {
rangeLimitStatus = kRangeLimitOk;
}
}
return deviceVal;
}
- (float) stimThresholderunitsFromDeviceunits: (float) d {
gStrokeMinimal = [MiscSpace pixelFromDegree: offsetVernierMinimalArcSec / 60.0 / 60.0];
gStrokeMaximal = [MiscSpace pixelFromDegree: offsetVernierMaximalArcSec / 60.0 / 60.0];
const c1 = gStrokeMinimal;
const c2 = -Math.log(gStrokeMinimal / gStrokeMaximal);
const retVal = Math.log(d / c1) / c2;
return retVal;
}
//Draw a vertical line with gaussian profile. x-position (floating point) approximated by center of gravity on discrete raster
- (void) drawLineGaussProfileVerticalAtX: (float) x0 y0: (float) y0 y1: (float) y1 sigma: (float) sigma { //console.info("FractControllerAcuityVernier>>DrawLineGaussianProfileVertical ", x0, y0, y1);
const ix0 = Math.round(x0);
const iSigma = Math.round(Math.max(5, Math.min(sigma * 4, 30))); //trace(sigma, iSigma);
CGContextSetLineWidth(cgc, 1);
const backGray = [MiscLight upperLuminanceFromContrastMilsn: [MiscLight contrastMichelsonPercentFromWeberPercent: [Settings contrastAcuityWeber]]];
const cnt = [Settings contrastAcuityWeber] / 100;
for (let ix = ix0 - iSigma; ix <= ix0 + iSigma; ix++) {
const gaussValue = Math.exp(-Math.pow(x0 - ix, 2) / sigma);
const grayValue = [MiscLight devicegrayFromLuminance: backGray - cnt * gaussValue];
CGContextSetStrokeColor(cgc, [CPColor colorWithWhite: grayValue alpha: 1]);
CGContextBeginPath(cgc);
CGContextMoveToPoint(cgc, ix, y0);
CGContextAddLineToPoint(cgc, ix, y1);
CGContextStrokePath(cgc);
}
}
- (void) drawVernierAtX: (float) xCent y: (float) yCent vLength: (float) vLength sigma: (float) sigma gapHeight: (float) gapHeight offsetSize: (float) offsetSize offsetIsTopRight: (BOOL) offsetIsTopRight { //console.info("FractControllerAcuityVernier>drawVernierAtX", offsetSize);
xCent += (Math.random() < 0.5 ? 1 : -1) + 2 * (2 * Math.random() - 1);
const theSign = offsetIsTopRight ? +1 : -1;
const xPos0 = xCent + theSign * offsetSize / 2, xPos1 = xCent - theSign * offsetSize / 2;
const vLength2 = vLength / 2;
switch([Settings vernierType]) {
case 1: // 3 bars
// lower
let yTemp = yCent + vLength2 + gapHeight;
[self drawLineGaussProfileVerticalAtX: xPos0 y0: yTemp y1: yTemp + vLength sigma: sigma];
// middle
[self drawLineGaussProfileVerticalAtX: xPos1 y0: yCent - vLength2 y1: yCent + vLength2 sigma: sigma];
// upper
yTemp = yCent - vLength2 - gapHeight;
[self drawLineGaussProfileVerticalAtX: xPos0 y0: yTemp y1: yTemp - vLength sigma: sigma];
break;
default: // case 0, 2 bars
const gapHeight2 = gapHeight / 2;
// lower
[self drawLineGaussProfileVerticalAtX: xPos0 y0: yCent + gapHeight2 y1: yCent + gapHeight2 + vLength sigma: sigma];
// upper
[self drawLineGaussProfileVerticalAtX: xPos1 y0: yCent - gapHeight2 y1: yCent - gapHeight2 - vLength sigma: sigma];
break;
}
}
- (void) drawStimulusInRect: (CGRect) dirtyRect forView: (FractView) fractView { //console.info("FractControllerAcuityVernier>drawStimulusInRect");
trialInfoString = [self acuityComposeTrialInfoString];
[self prepareDrawing];
switch(state) {
case kStateDrawBack: break;
case kStateDrawFore: //console.info("kStateDrawFore");
[self drawVernierAtX: 0 y: 0
vLength: [MiscSpace pixelFromDegree: [Settings vernierLength] / 60.0]
sigma: [MiscSpace pixelFromDegree: [Settings vernierWidth] / 60.0]
gapHeight: [MiscSpace pixelFromDegree: [Settings vernierGap] / 60.0]
offsetSize: stimStrengthInDeviceunits
offsetIsTopRight: [alternativesGenerator currentAlternative] != 0]
break;
default: break;
}
if ([Settings enableTouchControls] && (!responseButtonsAdded)) {
const sze = 50, sze2 = sze / 2;
[self buttonCenteredAtX: viewWidth-sze2 y: 0 size: sze title: "6"];
[self buttonCenteredAtX: sze2 y: 0 size: sze title: "4"];
[self buttonCenteredAtX: viewWidth - sze2 y: viewHeight2 - sze2 size: sze title: "Ø"];
}
CGContextRestoreGState(cgc);
[super drawStimulusInRect: dirtyRect];
}
- (void) runStart { //console.info("FractControllerAcuityVernier>runStart");
[self setCurrentTestResultUnit: "arcsec"];
nAlternatives = 2; nTrials = [Settings nTrials02];
offsetVernierMinimalArcSec = 0.5; offsetVernierMaximalArcSec = 3000.0;
[super runStart];
}
- (void) runEnd { //console.info("FractControllerAcuityVernier>runEnd");
if (iTrial < nTrials) { //premature end
[self setResultString: @"Aborted"];
} else {
[self setResultString: [self composeResultString]];
}
[super runEnd];
}
- (int) responseNumberFromChar: (CPString) keyChar { //console.info("FractControllerAcuityVernier>responseNumberFromChar: ", keyChar);
switch (keyChar) {
case CPLeftArrowFunctionKey: return 4;
case CPRightArrowFunctionKey: return 0;
case "6": return 0;
case "4": return 4;
}
return -2;// 0, 4: valid; -1: ignore; -2: invalid
}
- (float) resultValue4Export {
return Math.round([self reportFromNative: stimStrengthInDeviceunits] * 10) / 10;
}
- (CPString) composeResultString {
const rslt = [self resultValue4Export];
const dcs = rslt > 100 ? 0 : 1;
let s = "Vernier threshold" + [self rangeStatusIndicatorStringInverted: YES];
s += [Misc stringFromNumber: rslt decimals: dcs localised: YES] + " arcsec";
return s;
}
- (float) reportFromNative: (float) t {
return ([MiscSpace degreeFromPixel: t] * 60.0 * 60.0);
}
@end