Created
November 27, 2017 11:28
-
-
Save behinger/a7c7a0a0c35091a42c5d360d46ae97a3 to your computer and use it in GitHub Desktop.
A tool to recalibrate targets when it was forgotten where the target where ;)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function hitlistIncremental = manualCalibTool(calibtargets,fixlist1,fixlist2) | |
if nargin < 1 | |
% dummy variables with some noise in case of no input | |
[xx, yy] = meshgrid(1:5,1:2); | |
xx = xx(:); | |
yy = yy(:); | |
calibtargets = [xx yy]; | |
fixlist1 = [xx yy]; | |
fixlist2 = [xx yy]; | |
fixlist1 = fixlist1+ 0.3*randn(size(fixlist1)); | |
fixlist2 = fixlist2+ 0.3*randn(size(fixlist2)); | |
end | |
% define some colors | |
cfg.targetColor = [0 0 0]; | |
cfg.targetColorActive = [1 0 0]; | |
cfg.fixColor = [0 0.5 0]; | |
cfg.fixColorSelected = [0 1 0]; | |
cfg.fixColorNotSelected = [0.8 0.8 0.8]; | |
hitlistIncremental =[]; | |
targetIndex= 1; | |
fixlist = [fixlist1 fixlist2]; | |
fighandle = figure; | |
% plot each point separately to get separate color values (could be made | |
% with scatter as well, but more involved) | |
hTarget = []; | |
for t = 1:size(calibtargets,1) | |
hTarget(t) = plot(calibtargets(t,1),calibtargets(t,2),'xk','HitTest','off'); | |
hold all | |
end | |
% after calib, now the fixations | |
hFix = []; | |
for f= 1:length(fixlist) | |
hFix(f,1) = plot(fixlist(f,1),fixlist(f,2),'og','HitTest','off'); | |
hFix(f,2) = plot(fixlist(f,3),fixlist(f,4),'og','HitTest','off'); | |
end | |
% set(gca,'xlim',[0 11],'ylim',[0 6]) | |
% | |
set(gca,'ButtonDownFcn', {@buttondown}); | |
activateNextTarget() | |
recolorFixations() | |
function [] = buttondown(~,hit) | |
if hit.Button == 1 | |
if targetIndex > length(hTarget) | |
warning('you reached the end, not doing anything. Close figure to finish') | |
return | |
end | |
%left | |
hitlist = zeros(size(fixlist,1),1); | |
if ~isempty(hitlistIncremental) | |
hitlist(hitlistIncremental(:,1)) = hitlistIncremental(:,2); | |
end | |
hitindex = find(hitlist == 0); | |
fixsublist = fixlist(hitindex,:); | |
hitXY = hit.IntersectionPoint(1:2); | |
dist1 = pdist2(hitXY,fixsublist(:,[1 2])); | |
dist2 = pdist2(hitXY,fixsublist(:,[3 4])); | |
[d1,i1] = min(dist1); | |
[d2,i2] = min(dist2); | |
if d1<d2 | |
hitlistIncremental(end+1,:) = [hitindex(i1),1]; | |
else | |
hitlistIncremental(end+1,:) = [hitindex(i2),2]; | |
end | |
recolorFixations() | |
targetIndex = targetIndex + 1; | |
activateNextTarget() | |
elseif hit.Button == 3 | |
%right click | |
targetIndex = max(1,targetIndex - 1); | |
if ~isempty(hitlistIncremental) | |
hitlistIncremental(end,:) = []; | |
end | |
recolorFixations() | |
activateNextTarget() | |
end | |
end | |
function activateNextTarget() | |
set(hTarget,'Color',cfg.targetColor); | |
if targetIndex > length(hTarget) | |
warning('you reached the end,no target anymore') | |
else | |
set(hTarget(targetIndex),'Color',cfg.targetColorActive); | |
end | |
end | |
function recolorFixations() | |
hitlist = zeros(size(fixlist,1),1); | |
if ~isempty(hitlistIncremental) | |
hitlist(hitlistIncremental(:,1)) = hitlistIncremental(:,2); | |
end | |
for f = 1:length(hFix) | |
if hitlist(f) == 0 | |
set(hFix(f,1:2),'Color',cfg.fixColor); | |
else | |
set(hFix(f,hitlist(f)),'Color',cfg.fixColorSelected); | |
set(hFix(f,2 - hitlist(f) + 1),'Color',cfg.fixColorNotSelected); | |
end | |
end | |
end | |
waitfor(fighandle) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment