image thumbnail

eogui – a software to analyze electro-oculogram (EOG) recordings

by

 

10 Aug 2011 (Updated )

detects blinks and saccadic eye movements in EOG recordings

threshold.m
function ret=threshold(parameter,varargin)
%   erzeugt in einem Koordiantensystem ein Treshold objekt (Linien)
%   welches sich via Maus ndern lt
%
%   threshold('init',.3,'click_object()');  
%       init = erzeuge das objekt
%       .3 = threshold init wert
%       'cli...' = callback fkt 
%
%   remove, entfernt das Objekt wieder
%   update, setzt neuen Wert
%   getValue, gibt aktuellen Wert zurck
% $Id: threshold.m 6 2004-12-13 12:28:39Z maik $

global THRESHOLD_GCA;

handle=THRESHOLD_GCA;



switch (parameter)
    case 'init'
        THRESHOLD_GCA=gca;
        handle=THRESHOLD_GCA;
        if isappdata(handle,'threshhold_value') 
            return;
        end
        initval=abs(varargin{1});

        zer=0;
        if(nargin==4)            
            zer=varargin{3};
        end
        
        
        setappdata(handle,'threshhold_value',initval);
        initval=varargin{1};
        % zeichnet threshold
        x=get(handle,'XLim');
        threshholdl1=line([x(1) x(2)],[zer+initval zer+initval],'ButtonDownFcn','threshold(''buttondown'')');
        threshholdl2=line([x(1) x(2)],[zer-initval zer-initval],'ButtonDownFcn','threshold(''buttondown'')');
        setappdata(handle,'threshholdl1',threshholdl1);
        setappdata(handle,'threshholdl2',threshholdl2);
        setappdata(handle,'threshhold_zerro',zer);
        setappdata(handle,'threshhold_Pointer',get(gcf,'Pointer'));
        
        if(nargin>2)
            setappdata(handle,'threshholdcallback',varargin{2});
        end
       
        % hnge in Motion ein
        setappdata(handle,'threshhold_WindowButtonMotionFcn',get(gcf,'WindowButtonMotionFcn'));
        set(gcf,'WindowButtonMotionFcn','threshold(''move'')');
                       
        
    case 'update'
        if ~isappdata(handle,'threshhold_value')  
            return;
        end
                            
        initval=abs(varargin{1});
        setappdata(handle,'threshhold_value',initval);
        
        zer=getappdata(handle,'threshhold_zerro');
        
        set(getappdata(handle,'threshholdl1'),'YData',[zer+initval zer+initval]);
        set(getappdata(handle,'threshholdl2'),'YData',[zer-initval zer-initval]);
        
        if isappdata(handle,'threshholdcallback')       
            eval(getappdata(handle,'threshholdcallback'));
        end
        
        
                               
    case 'remove'
        if ~isappdata(handle,'threshhold_value') 
            return;
        end
        
        set(gcf,'WindowButtonMotionFcn',getappdata(handle,'threshhold_WindowButtonMotionFcn'));
        rmappdata(handle,'threshhold_WindowButtonMotionFcn')
        
        delete(getappdata(handle,'threshholdl1'));
        delete(getappdata(handle,'threshholdl2'));
        rmappdata(handle,'threshhold_value');
        rmappdata(handle,'threshholdl1');
        rmappdata(handle,'threshholdl2');
        rmappdata(handle,'threshhold_zerro');
        rmappdata(handle,'threshhold_Pointer')
        
        
        if isappdata(handle,'threshholdcallback')
            rmappdata(handle,'threshholdcallback');
        end
              
    case 'buttondown'
        
        % Mauszeiger ndern
        %setappdata(handle,'threshhold_Pointer',get(gcf,'Pointer'));
        %set(gcf,'Pointer','Top');
        
        % sichere alte Funtionen
        setappdata(handle,'threshhold_WindowButtonUpFcn',get(gcf,'WindowButtonUpFcn'));
        set(gcf,'WindowButtonUpFcn','threshold(''buttonup'')');
                
        %setappdata(handle,'threshhold_WindowButtonMotionFcn',get(gcf,'WindowButtonMotionFcn'));              
        %set(gcf,'WindowButtonMotionFcn','threshold(''move'')');
        

    case 'buttonup'        
        %set(gcf,'Pointer',getappdata(handle,'threshhold_Pointer'));
        %rmappdata(handle,'threshhold_Pointer')
        
        % Restauriere alte Event Funtion        
        set(gcf,'WindowButtonUpFcn',getappdata(handle,'threshhold_WindowButtonUpFcn'));        
        rmappdata(handle,'threshhold_WindowButtonUpFcn')
        
        %set(gcf,'WindowButtonMotionFcn',getappdata(handle,'threshhold_WindowButtonMotionFcn'));                       
        %rmappdata(handle,'threshhold_WindowButtonMotionFcn')
        
    case 'move'
        if(strcmp(get(gcf,'WindowButtonUpFcn'),'threshold(''buttonup'')'))
            data=get(handle,'CurrentPoint');
            y=data(1,2);
            zer=getappdata(handle,'threshhold_zerro');
            threshold('update',zer-y);
        else
            %hier checken wir ob eine Linie berhrt wird.
            % geg. Mauszeiger ndern
            
            point=get(handle,'CurrentPoint'); %wo ist die maus ?
            zer=getappdata(handle,'threshhold_zerro');
            val=getappdata(handle,'threshhold_value');                                  
            y=round(point(1,2));
            y1=round(zer-val);            
            y2=round(zer+val);            
            
            if  ((y == y1) | (y == y2))
               set(gcf,'Pointer','Top');            
            else      
               mpart=getappdata(handle,'threshhold_Pointer'); 
               set(gcf,'Pointer',mpart);
            end
        end
        
        % wenn es eine alte Fcn gab, diese Auswerten.
        orgfcn=getappdata(handle,'threshhold_WindowButtonMotionFcn');
        if ~isempty(orgfcn)
            eval(orgfcn);
        end
        
    case 'getValue'                        
        ret=getappdata(handle,'threshhold_value');
end




% ==============================================================================
% FUNCTION click_object
%   Executed when the object is clicked
% ==============================================================================

function click_object() 
    disp(['hallo ' num2str(threshold('getValue'))]);

    

Contact us