Home > bioelectromagnetism > eeg_crosshair.m

eeg_crosshair

PURPOSE ^

eeg_crosshair - A gui interface for reading (x,y) values from a plot.

SYNOPSIS ^

function [Xpoint,Ypoint] = eeg_crosshair(action,p,parent);

DESCRIPTION ^

 eeg_crosshair - A gui interface for reading (x,y) values from a plot.

  A set of mouse driven eeg_crosshairs is placed on the current axes,
  and displays the current (x,y) values of the line plot.  There is an
  option to provide data specific values or interpolated values.  The
  resolution of the data specific values depends on both the data
  resolution and the GUI interface (mainly mouse movement resolution).
  The interpolated values appear to provide a more continuous function,
  however they too depend on the GUI interface resolution.  There are 
  no options for extrapolation.
  
  For multiple traces, plots with the same length(xdata) are
  tracked. Each mouse click returns Xpoint,Ypoint values and selecting 
  'done' will remove the GUI and restore the mouse buttons to previous 
  values.  Selecting 'exit' will remove the GUI and close the figure.

  Some further help is given in the tool tips of the GUI.

  Usage: x = [1:10]; y(1,:) = sin(x); y(2,:) = cos(x); x2 = x.^2;
          figure; plot(x2,y); eeg_crosshair

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [Xpoint,Ypoint] = eeg_crosshair(action,p,parent);
0002 
0003 % eeg_crosshair - A gui interface for reading (x,y) values from a plot.
0004 %
0005 %  A set of mouse driven eeg_crosshairs is placed on the current axes,
0006 %  and displays the current (x,y) values of the line plot.  There is an
0007 %  option to provide data specific values or interpolated values.  The
0008 %  resolution of the data specific values depends on both the data
0009 %  resolution and the GUI interface (mainly mouse movement resolution).
0010 %  The interpolated values appear to provide a more continuous function,
0011 %  however they too depend on the GUI interface resolution.  There are
0012 %  no options for extrapolation.
0013 %
0014 %  For multiple traces, plots with the same length(xdata) are
0015 %  tracked. Each mouse click returns Xpoint,Ypoint values and selecting
0016 %  'done' will remove the GUI and restore the mouse buttons to previous
0017 %  values.  Selecting 'exit' will remove the GUI and close the figure.
0018 %
0019 %  Some further help is given in the tool tips of the GUI.
0020 %
0021 %  Usage: x = [1:10]; y(1,:) = sin(x); y(2,:) = cos(x); x2 = x.^2;
0022 %          figure; plot(x2,y); eeg_crosshair
0023 %
0024 
0025 
0026 % $Revision: 1.1 $ $Date: 2004/11/12 01:32:33 $
0027 
0028 %
0029 %  Licence:        GNU GPL, no express or implied warranties
0030 %  History: 03/96, Richard G. Cobb <cobbr@plk.af.mil>
0031 %           08/01, Darren.Weber_at_radiology.ucsf.edu
0032 %                  replaced obsolete 'table1' with 'interp1'; fixed bug
0033 %                  with number of 'traces'; rationalized calculations into
0034 %                  a common subfunction for x,y point calc in 'down','up',
0035 %                  & 'move' button functions; added option to turn on/off
0036 %                  interpolation and the exit button; simplified updates
0037 %                  to graphics using global GUI handle structure.
0038 %           11/01, Darren.Weber_at_radiology.ucsf.edu
0039 %                  added tooltips for several GUI handles
0040 %                  added multiple interpolation methods
0041 %                  added GUI for data matrix indices (given no interpolation)
0042 %                  added option to select trace nearest to mouse click point
0043 %                  reversed order of lines in data matrix to be consistent
0044 %                    with the value returned from the nearest trace subfunction
0045 %                  create eeg_crosshair lines after finding all plot lines to
0046 %                    avoid confusing them with the plot lines
0047 %           01/02, Darren.Weber_at_radiology.ucsf.edu
0048 %                  should now work across multiple plot figures, given
0049 %                    that all gui handles and data are now stored in the
0050 %                    plot figure 'userdata' handle.
0051 %                  added functionality to move smoothly from interpolation
0052 %                    back to the delimited data via the "next/previous"
0053 %                    buttons.
0054 %           02/02, Darren.Weber_at_radiology.ucsf.edu
0055 %                  added functionality to accept general eeg parameter
0056 %                    structure and call eeg_contours for topo mapping.
0057 %                  added functions for eeg peak detection and visualization.
0058 %           04/02, Darren.Weber_at_radiology.ucsf.edu
0059 %                  only update crosshair if cursor is inside axis limits
0060 %                  optimised peak updating logic and next/prev peak method
0061 %                  added option to 'add channels' when using 'view channels'
0062 %                  added LT/GT for yindex movement
0063 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0064 
0065 if ~exist('action','var') 
0066     action = 'init';
0067 elseif isempty(action)
0068     action = 'init';
0069 end
0070 
0071 XHR = get(gcbf,'userdata');
0072 
0073 action = lower(action);
0074 
0075 % Check for specific keys and assign reasonable actions
0076 if strcmp(action, 'keypress'),
0077     
0078     CC = get(XHR.gui,'CurrentCharacter');
0079     cc = double(CC);
0080     if cc,
0081         switch cc,
0082         case 27, action = 'done';  % ESC
0083         case 28, action = 'prevx'; % left
0084         case 29, action = 'nextx'; % right
0085         case 30, action = 'ygt';   % up
0086         case 31, action = 'ylt';   % down
0087         case 13, action = 'store'; % return/enter
0088         otherwise, action = 'up';  % all other keys
0089         end
0090     end
0091 end
0092 
0093 
0094 switch action,
0095 case 'init',
0096     
0097     if ~isempty(XHR),
0098         if isfield(XHR,'data'),
0099             fprintf('\nWarning...Crosshair already initialised in current figure.\n');
0100             return;
0101         end
0102     end
0103     
0104     % Paint GUI
0105     XHR = INIT;
0106     
0107     % Pass input parameters to the figure handles
0108     if exist('p','var'),
0109         XHR.p = p;
0110         %XHR.p = eeg_peaks(XHR.p); % slows init too much
0111     end
0112     if exist('parent','var'), XHR.parent.gui = parent; end
0113     
0114     % Update and return values
0115     XHR = updateDATA(XHR);
0116     
0117 case 'down',    % Mouse Click Down
0118     
0119     set(XHR.gui,'WindowButtonMotionFcn','[Xpoint,Ypoint] = eeg_crosshair(''move'');');
0120     set(XHR.gui,'WindowButtonUpFcn','[Xpoint,Ypoint] = eeg_crosshair(''up'');');
0121     
0122     XHR = updateDATA(XHR);
0123     
0124 case 'move',    % Mouse Drag Motion
0125     
0126     XHR = updateDATA(XHR);
0127     
0128 case 'up',      % Mouse Click Up
0129     
0130     set(XHR.gui,'WindowButtonMotionFcn',' ');
0131     set(XHR.gui,'WindowButtonUpFcn',' ');
0132     
0133     XHR = updateDATA(XHR);
0134     
0135 case {'nextx','prevx','changex','nexty','prevy','changey','ylt','ygt'}, % Change X/Y
0136     
0137     XHR = moveXY(XHR,action);
0138     
0139 case {'nextpeak','prevpeak','nearpeak'}, % Next or Previous Peak
0140     
0141     XHR = movepeak(XHR,action);
0142 
0143 case {'viewpeaks'}, % View Peaks
0144     
0145     XHR = viewpeaks(XHR);
0146 
0147 % Store XY values into a history array
0148 case 'store',
0149     
0150     Xpoint = get(XHR.handles.xvalue,'Value');
0151     Ypoint = get(XHR.handles.yvalue,'Value');
0152     updateXYhistory(XHR.handles);
0153     
0154 case {'done','exit'},   % Exit eeg_crosshairs GUI
0155     
0156     handles = fieldnames(XHR.handles);
0157     for i=1:length(handles),
0158         switch handles{i},
0159         case {'axis','datalines','gui'},
0160         otherwise,
0161             h = getfield(XHR.handles,handles{i});
0162             if ishandle(h), delete(h); end
0163         end
0164     end
0165     
0166     if strcmp(action,'exit');
0167         
0168         close(XHR.gui);
0169     else
0170         
0171         set(XHR.gui,'WindowButtonUpFcn','');
0172         set(XHR.gui,'WindowButtonMotionFcn','');
0173         set(XHR.gui,'WindowButtonDownFcn',XHR.handles.button);
0174         set(XHR.gui,'HandleVisibility','on');
0175         set(XHR.gui,'MenuBar','figure');
0176         set(XHR.gui,'userdata',[]);
0177         refresh(XHR.gui);
0178     end
0179     
0180     if isfield(XHR,'parent'),
0181         if isfield(XHR.parent,'gui'),
0182             if ishandle(XHR.parent.gui),
0183                 % Get the userdata from the parent
0184                 parent = get(XHR.parent.gui,'userdata');
0185                 if isfield(parent,'p') & isfield(XHR,'p'),
0186                     % Update the parent p structure
0187                     XHR.p.volt.peaks = [];
0188                     parent.p = XHR.p;
0189                     set(XHR.parent.gui,'userdata',parent);
0190                     if isfield(parent,'handles'),
0191                         if isfield(parent.handles,'EvoltFile'),
0192                             set(parent.handles.EvoltFile,'String',parent.p.volt.file);
0193                         end
0194                         if isfield(parent.handles,'EvoltPath'),
0195                             set(parent.handles.EvoltPath,'String',parent.p.volt.path);
0196                         end
0197                     end
0198                 end
0199             end
0200         end
0201     end
0202     
0203     Xpoint = XHR.data.xpoint;
0204     Ypoint = XHR.data.ypoint;
0205     clear XHR;
0206     return;
0207     
0208 otherwise,
0209     
0210 end
0211 
0212 set(XHR.gui,'userdata',XHR);
0213 Xpoint = XHR.data.xpoint;
0214 Ypoint = XHR.data.ypoint;
0215 if ishandle(XHR.gui),
0216     figure(XHR.gui);
0217 end
0218 
0219 return;
0220 
0221 
0222 
0223 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0224 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0225 function updateXYhistory(H),
0226     
0227     Ch = get(H.yindex,'Value');
0228     X  = get(H.xvalue,'Value');
0229     Y  = get(H.yvalue,'Value');
0230     
0231     XY.labels = {'Channel','X','Y'};
0232     XY.data   = [Ch,X,Y];
0233     
0234     if evalin('base','exist(''XYhist'',''var'');'),
0235         XYhist = evalin('base','XYhist');
0236         if size(XYhist,2) == 3,
0237             XYhist.data(end+1,:) = XY.data;
0238             assignin('base','XYhist',XYhist);
0239         else
0240             fprintf('\nWarning: creating new XYhist in base workspace.\n\n');
0241             assignin('base','XYhist',XY);
0242         end
0243     else
0244         assignin('base','XYhist',XY);
0245     end
0246     
0247 return
0248 
0249 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0250 function [ H ] = updateGUI( H )
0251 
0252     InterpMethod = get(H.handles.interp,'Value');
0253     if (InterpMethod > 1)
0254         % There is no specific matrix x-index for
0255         % an interpolated point, but the nearest xindex 'value'
0256         % is always returned from the interp function
0257         % so that next/prev move function works correctly
0258         set(H.handles.xindex,'String','interp');
0259     else
0260         set(H.handles.xindex,'String',num2str(H.data.xindex));
0261     end
0262     set(H.handles.xindex,'Value',H.data.xindex);
0263     
0264     % Switch on/off views of traces
0265     if (get(H.handles.traceView,'Value')),
0266         prevY = get(H.handles.yindex,'Value');
0267         currY = uint16(H.data.yindex);
0268         if ~isequal(prevY,currY),
0269             addchan = get(H.handles.traceAdd,'Value');
0270             if ~addchan,
0271                 set(H.handles.datalines(prevY),'Visible','off');
0272             end
0273             set(H.handles.datalines(currY),'Visible','on');
0274         else
0275             set(H.handles.datalines(currY),'Visible','on');
0276         end
0277     else
0278         set(H.handles.datalines,'Visible','on');
0279     end
0280     
0281     tracestr = sprintf('%d',H.data.yindex);
0282     set(H.handles.yindex,'String',tracestr,'Value',uint16(H.data.yindex));
0283     %set(H.handles.trace,'Value',uint16(H.data.yindex));
0284     
0285     % Create the crosshair lines on the figure, crossing at the x,y point
0286     x_rng  = get(H.handles.axis,'Xlim');
0287     y_rng  = get(H.handles.axis,'Ylim');
0288     set(H.handles.xline,'Xdata',[H.data.xpoint H.data.xpoint],'Ydata',y_rng);
0289     set(H.handles.yline,'Ydata',[H.data.ypoint H.data.ypoint],'Xdata',x_rng);
0290     
0291     % Update the x,y values displayed for the x,y point
0292     xstring = sprintf('%14.4f',H.data.xpoint);
0293     ystring = sprintf('%14.4f',H.data.ypoint);
0294     set(H.handles.xvalue,'String',xstring,'Value',H.data.xpoint);
0295     set(H.handles.yvalue,'String',ystring,'Value',H.data.ypoint);
0296     
0297     % Update the view of the peak scatterplot
0298     H = viewpeaks(H);
0299     
0300     set(H.gui,'userdata',H);
0301 
0302 return
0303 
0304 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0305 function [H] = viewpeaks(H)
0306     
0307     view = get(H.handles.peaksView,'Value');
0308     if ~view,
0309         % switch off any current peak handles from plot
0310         if isfield(H.handles,'peakhandles'),
0311             h = H.handles.peakhandles;
0312             if ishandle(h(1)), delete(h); end
0313         end
0314         return;
0315     end
0316     
0317     % Make sure data required for peaks is available
0318     H = checkpeaks(H);
0319     
0320     % delete any current peak handles from plot
0321     if isfield(H.handles,'peakhandles'),
0322         h = H.handles.peakhandles;
0323         if ishandle(h(1)), delete(h); end
0324     end
0325     
0326     elec = H.data.yindex;
0327     peaksindex = find(H.p.volt.peaks.data(:,elec) ~= 0);
0328     
0329     time = H.p.volt.timeArray(peaksindex,elec);
0330     volt = H.p.volt.data(peaksindex,elec);
0331     
0332     figure(H.gui);
0333     hold on;
0334     H.handles.peakhandles = scatter(time,volt);
0335     hold off;
0336     
0337     %if view,
0338     %    set(H.handles.peakhandles,'Visible','on');
0339     %else
0340     %    set(H.handles.peakhandles,'Visible','off');
0341     %end
0342     
0343 return
0344 
0345 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0346 function [H] = movepeak(H,move)
0347     
0348     % Make sure data required for peaks is available
0349     H = checkpeaks(H);
0350     
0351     elec = H.data.yindex;
0352     peaksindex = find(H.p.volt.peaks.data(:,elec) ~= 0);
0353     
0354     time = H.p.volt.timeArray(peaksindex,elec);
0355     volt = H.p.volt.data(peaksindex,elec);
0356     
0357     % Find nearest peakindex to currentpoint
0358     x = H.data.xpoint;
0359     peaks = [time volt];
0360     nindex = 1; pindex = 1;
0361     for i=1:length(peaks),
0362         peak = peaks(i,:);
0363         if (x > peak(1)),
0364             pindex = i;
0365             if (i+1 <= length(peaks)), nindex = i+1; 
0366             else                       nindex = i;
0367             end
0368         elseif (x == peak(1)),
0369             pindex = i-1;
0370             if (i-1 > 0), pindex = i-1;
0371             else          pindex = 1;
0372             end
0373             if (i+1 <= length(peaks)), nindex = i+1;
0374             else                       nindex = i;
0375             end
0376         end
0377     end
0378     % Identify prev/next peak
0379     if strcmp(move,'nextpeak'), index = nindex;
0380     else                        index = pindex;
0381     end
0382     
0383     H.data.xpoint = time(index);
0384     H.data.ypoint = volt(index);
0385     
0386     xdata = H.data.xdata(:,H.data.yindex);
0387     H.data.xindex = NearestXYArrayPoint( xdata, H.data.xpoint, 'exact' );
0388     
0389     set(H.handles.interp,'Value',1);
0390     H = updateGUI(H);
0391     
0392 return
0393 
0394 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0395 function [H] = checkpeaks(H)
0396     % Make sure peaks data required is available
0397     if isfield(H,'p'),
0398         if isfield(H.p.volt,'peaks'),
0399             if isempty(H.p.volt.peaks),
0400                 H.p.volt.timeArray = H.data.xdata;
0401                 H.p.volt.data = H.data.ydata;
0402                 H.p = eeg_peaks(H.p);
0403             end
0404         else
0405             H.p.volt.timeArray = H.data.xdata;
0406             H.p.volt.data = H.data.ydata;
0407             H.p = eeg_peaks(H.p);
0408         end
0409     else
0410         H.p.volt.timeArray = H.data.xdata;
0411         H.p.volt.data = H.data.ydata;
0412         H.p = eeg_peaks(H.p);
0413     end
0414     
0415     % Check the volt.timeArray
0416     if isempty(H.p.volt.timeArray),
0417         H.p.volt.timeArray = H.data.xdata;
0418     end
0419     if ~isequal(size(H.p.volt.timeArray),size(H.p.volt.data)),
0420         H.p.volt.timeArray = repmat(H.p.volt.timeArray,1,size(H.p.volt.data,2));
0421     end
0422     
0423 return
0424 
0425 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0426 function [H] = moveXY(H,move)
0427     
0428     interp  = get(H.handles.interp,'Value');
0429     xinterp = get(H.handles.xinterp,'Value');
0430     
0431     
0432     if (xinterp > 0) & (interp > 1),
0433         
0434         % Use incremental interpolation of x values
0435         switch move,
0436         case 'nexty', H.data.yindex = H.data.yindex + 1;
0437         case 'prevy', H.data.yindex = H.data.yindex - 1;
0438         case 'ygt',
0439             ydata = interpYall(H);
0440             [ysort,yi] = sort(ydata);
0441             currYI = find(ysort > H.data.ypoint);
0442             if min(currYI),
0443                 H.data.yindex = yi(min(currYI));
0444             end
0445         case 'ylt',
0446             ydata = interpYall(H);
0447             [ysort,yi] = sort(ydata);
0448             currYI = find(ysort < H.data.ypoint);
0449             if max(currYI),
0450                 H.data.yindex = yi(max(currYI));
0451             end
0452         case 'nextx',
0453             H.data.xpoint = H.data.xpoint + xinterp;
0454         case 'prevx',
0455             H.data.xpoint = H.data.xpoint - xinterp;
0456         end
0457         H = checkdatarange(H);
0458         H = interpY(H);
0459         updateGUI(H);
0460         return
0461     end
0462     
0463     
0464     % No interpolation of x values...
0465     
0466     if (interp > 1)
0467         xdata = H.data.xdata(:,H.data.yindex);
0468         [H.data.xindex] = NearestXYArrayPoint( xdata, H.data.xpoint, move );
0469     end
0470     
0471     switch move,
0472     case 'nextx',
0473         % Increase current xindex by one
0474         if(interp == 1), H.data.xindex = H.data.xindex + 1; end
0475     case 'prevx',
0476         % Decrease current xindex by one
0477         if(interp == 1), H.data.xindex = H.data.xindex - 1; end
0478     case 'nexty', H.data.yindex = H.data.yindex + 1;
0479     case 'prevy', H.data.yindex = H.data.yindex - 1;
0480     case 'ygt',
0481         ydata = H.data.ydata(H.data.xindex,:);
0482         [ysort,yi] = sort(ydata);
0483         currYI = find(ysort == H.data.ypoint);
0484         if currYI < length(yi),
0485             H.data.yindex = yi(currYI+1);
0486         end
0487     case 'ylt',
0488         ydata = H.data.ydata(H.data.xindex,:);
0489         [ysort,yi] = sort(ydata);
0490         currYI = find(ysort == H.data.ypoint);
0491         if currYI > 1,
0492             H.data.yindex = yi(currYI-1);
0493         end
0494     otherwise
0495     end
0496     
0497     % Ensure that x/y index is within data range
0498     H = checkdatarange(H);
0499     
0500     % Get x/y value at new x/y index
0501     H.data.xpoint = H.data.xdata(H.data.xindex,H.data.yindex);
0502     H.data.ypoint = H.data.ydata(H.data.xindex,H.data.yindex);
0503     
0504     set(H.handles.interp,'Value',1);
0505     H = updateGUI(H);
0506     
0507 return
0508 
0509 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0510 function [ H ] = checkdatarange(H),
0511 
0512     % Ensure that x/y index is within data range
0513     s = size(H.data.xdata,1);
0514     if( H.data.xindex < 1 ),
0515         H.data.xindex = 1;
0516     elseif( H.data.xindex >= s ),
0517         H.data.xindex = s;
0518     end
0519     s = size(H.data.ydata,2);
0520     if( H.data.yindex < 1 ),
0521         H.data.yindex = 1;
0522     elseif( H.data.yindex >= s ),
0523         H.data.yindex = s;
0524     end
0525 
0526 return
0527 
0528 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0529 function [ H ] = updateDATA( H )
0530 
0531     % Only update if mouse pointer is in the
0532     % axis limits
0533     set(H.gui,'units','normalized');
0534     axpos = get(H.handles.axis,'position');
0535     figcp = get(H.gui,'Currentpoint');
0536     axlim = axpos(1) + axpos(3);
0537     aylim = axpos(2) + axpos(4);
0538     if or(figcp(1) > (axlim+.01),figcp(1) < (axpos(1)-.01)),
0539         return;
0540     elseif or(figcp(2) > (aylim+.01),figcp(2) < (axpos(2)-.01)),
0541         return;
0542     end
0543     
0544     % OK, update...
0545     CurrentPoint  = get(H.handles.axis,'Currentpoint');
0546     H.data.xpoint = CurrentPoint(1,1);
0547     H.data.ypoint = CurrentPoint(1,2);
0548     
0549     doNearTrace   = get(H.handles.traceNearest,'Value');
0550     
0551     if (doNearTrace > 0)
0552         
0553         % Get new yindex for nearest trace
0554         [ H.data.xpoint, ...
0555           H.data.xindex, ...
0556           H.data.ypoint, ...
0557           H.data.yindex ] = NearestXYMatrixPoint( H.data.xdata,...
0558                                                   H.data.ydata,...
0559                                                   H.data.xpoint,...
0560                                                   H.data.ypoint);
0561 %     else
0562 %         H.data.yindex = get(H.handles.trace,'Value');
0563     end
0564     
0565     CurrentPoint  = get(H.handles.axis,'Currentpoint');
0566     H.data.xpoint = CurrentPoint(1,1);
0567     H.data.ypoint = CurrentPoint(1,2);
0568     
0569     H = interpY(H);
0570     H = updateGUI(H);
0571 
0572 return
0573 
0574 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0575 function [ H ] = interpY( H )
0576     
0577     % In this function, xdata & ydata are arrays, not matrices
0578     xdata = H.data.xdata(:,H.data.yindex);
0579     ydata = H.data.ydata(:,H.data.yindex);
0580     
0581     if      H.data.xpoint >= max(xdata)                
0582             H.data.xpoint  = max(xdata);
0583             H.data.xindex  = find(xdata == max(xdata));
0584             H.data.ypoint  = ydata(H.data.xindex);
0585             return;
0586     elseif  H.data.xpoint <= min(xdata)
0587             H.data.xpoint  = min(xdata);
0588             H.data.xindex  = find(xdata == min(xdata));
0589             H.data.ypoint  = ydata(H.data.xindex);
0590             return;
0591     end
0592     
0593     % 'none|nearest|linear|spline|cubic'
0594     interp = get(H.handles.interp,'Value');
0595     
0596     switch interp
0597     case 1
0598         % Given that xdata & ydata are the same length arrays,
0599         % we can find the ypoint given the nearest xpoint.
0600         [H.data.xindex, H.data.xpoint] = NearestXYArrayPoint( xdata, H.data.xpoint );
0601         H.data.ypoint = ydata(H.data.xindex);
0602     case 2
0603         H.data.ypoint = interp1( xdata, ydata, H.data.xpoint, 'nearest' );
0604     case 3
0605         H.data.ypoint = interp1( xdata, ydata, H.data.xpoint, 'linear' );
0606     case 4
0607         H.data.ypoint = interp1( xdata, ydata, H.data.xpoint, 'spline' );
0608     case 5
0609         H.data.ypoint = interp1( xdata, ydata, H.data.xpoint, 'cubic' );
0610     otherwise
0611         %use default (linear in matlabR12)
0612         H.data.ypoint = interp1( xdata, ydata, H.data.xpoint );
0613     end
0614 
0615 return
0616 
0617 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0618 function [ Yall ] = interpYall( H )
0619     
0620     xdata = H.data.xdata(:,H.data.yindex);
0621     Yall  = H.data.ydata;
0622     
0623     if      H.data.xpoint >= max(xdata),
0624             H.data.xpoint  = max(xdata);
0625             H.data.xindex  = find(xdata == max(xdata));
0626             Yall = ydata(:,H.data.xindex);
0627             return;
0628     elseif  H.data.xpoint <= min(xdata),
0629             H.data.xpoint  = min(xdata);
0630             H.data.xindex  = find(xdata == min(xdata));
0631             Yall = ydata(:,H.data.xindex);
0632             return;
0633     end
0634     
0635     % 'none|nearest|linear|spline|cubic'
0636     interp = get(H.handles.interp,'Value');
0637     
0638     switch interp,
0639     case 1
0640         % do nothing in this case
0641     case 2
0642         Yall = interp1( xdata, Yall, H.data.xpoint, 'nearest' );
0643     case 3
0644         Yall = interp1( xdata, Yall, H.data.xpoint, 'linear' );
0645     case 4
0646         Yall = interp1( xdata, Yall, H.data.xpoint, 'spline' );
0647     case 5
0648         Yall = interp1( xdata, Yall, H.data.xpoint, 'cubic' );
0649     otherwise
0650         %use default (linear in matlabR12)
0651         Yall = interp1( xdata, Yall, H.data.xpoint );
0652     end
0653 
0654 return
0655 
0656 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0657 function [ index, point ] = NearestXYArrayPoint( data_array, point, type )
0658     
0659     if ~exist('type','var') type = ''; end
0660 
0661     % In this function, input data_array is an array, not a matrix.
0662     % This function returns the data point in the array
0663     % that has the closest value to the value given (point).  In
0664     % the context of 'eeg_crosshair' the point is a mouse position.
0665     
0666     if      point >= max(data_array)
0667             point  = max(data_array);
0668             index  = find(data_array == point);
0669             return;
0670     elseif  point <= min(data_array)
0671             point  = min(data_array);
0672             index  = find(data_array == point);
0673             return;
0674     end
0675     
0676     data_sorted = sort(data_array);
0677     
0678     greater = find(data_sorted > point);
0679     greater_index = greater(1);
0680     
0681     lesser = find(data_sorted < point);
0682     lesser_index = lesser(end);
0683     
0684     greater_dif = data_sorted(greater_index) - point;
0685     lesser_dif  = point - data_sorted(lesser_index);
0686     
0687     if     strcmp(type,'exact'),  index = find(data_array == point);
0688     elseif strcmp(type,'nextx'),  index = greater_index;
0689     elseif strcmp(type,'prevx'),  index = lesser_index;
0690     else
0691         if (greater_dif < lesser_dif)
0692             index = find(data_array == data_sorted(greater_index));
0693         else
0694             index = find(data_array == data_sorted(lesser_index));
0695         end
0696     end
0697     point = data_array(index);
0698     
0699 return
0700 
0701 
0702 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0703 function [ xpoint, xindex, ypoint, yindex ] = NearestXYMatrixPoint( Xdata, Ydata, xpoint, ypoint )
0704 
0705     % In this function, Xdata & Ydata are matrices of the same dimensions.
0706     % This function attempts to find the nearest values in Xdata & Ydata
0707     % to the mouse position (xpoint, ypoint).
0708     
0709     % It is assumed that Xdata has identical columns, so we only really
0710     % need the first column to find the nearest value to xpoint.
0711     
0712     [ xindex, xpoint ] = NearestXYArrayPoint( Xdata(:,1), xpoint );
0713     
0714     % Now, given the xpoint, we can select just that row of the
0715     % Ydata matrix corresponding to the xpoint.
0716     ydata = Ydata(xindex,:);
0717     
0718     % The ydata array is searched in same manner as the xdata
0719     % array for the nearest value.
0720     [ yindex, ypoint ] = NearestXYArrayPoint( ydata, ypoint );
0721     
0722 return
0723 
0724 
0725 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0726 function [H] = INIT
0727     
0728     H.gui = gcf;          % Get current figure handle
0729     
0730     % Match background figure colour
0731     bgcolor = get(H.gui,'Color');
0732     % Try to adapt the foreground colour a little
0733     black = find(bgcolor <= .6);
0734     fgcolor = [0 0 0]; %black text
0735     if length(black)>2, fgcolor = [1 1 1]; end
0736     
0737     
0738     H.handles.axis = gca; % Get current axis handles
0739     axis tight;
0740     set(H.handles.axis,'YDir','reverse');
0741     H.handles.ylim = get(H.handles.axis,'ylim');
0742     
0743     % enable right click access to eeg_crosshair
0744     if isempty(get(H.handles.axis,'uicontextmenu')),
0745         amenu=uicontextmenu;
0746         a=uimenu(amenu,'Label','Crosshair','Callback','eeg_crosshair; ');
0747         set(H.handles.axis,'uicontextmenu',amenu);
0748     end
0749     
0750     % store current button fcn
0751     H.handles.button = get(H.gui,'WindowButtonDownFcn');
0752     % set XHR button down fcn
0753     set(H.gui,'WindowButtonDownFcn','[Xpoint,Ypoint] = eeg_crosshair(''down'');');
0754     set(H.gui,'KeyPressFcn','[Xpoint,Ypoint] = eeg_crosshair(''keypress'');');
0755     
0756     Font.FontName   = 'Helvetica';
0757     Font.FontUnits  = 'Pixels';
0758     Font.FontSize   = 10;
0759     Font.FontWeight = 'normal';
0760     Font.FontAngle  = 'normal';
0761     
0762     
0763     H.handles.yflip       =   uicontrol(H.gui,'Style','pushbutton','Units','Normalized',Font,...
0764                               'Position',[.00 .70 .08 .05],...
0765                               'Tag','YFLIP',...
0766                               'TooltipString','Flip Y Axis', ...
0767                               'String','Flip',...
0768                               'Callback',strcat('XHR = get(gcbf,''userdata'');',...
0769                                                 'ydir = get(XHR.handles.axis,''YDir'');',...
0770                                                 'if isequal(ydir,''normal''),',...
0771                                                 '   set(XHR.handles.axis,''YDir'',''reverse'');',...
0772                                                 'else,',...
0773                                                 '   set(XHR.handles.axis,''YDir'',''normal'');',...
0774                                                 'end;',...
0775                                                 'set(gcbf,''userdata'',XHR); figure(XHR.gui); clear XHR;'));
0776     
0777     H.handles.yreset      =   uicontrol(H.gui,'Style','pushbutton','Units','Normalized',Font,...
0778                               'Position',[.00 .65 .08 .05],...
0779                               'Tag','YRESET',...
0780                               'TooltipString','Reset Axis Limits', ...
0781                               'String','Reset',...
0782                               'Callback',strcat('XHR = get(gcbf,''userdata'');',...
0783                                                 'axis tight;',...
0784                                                 'XHR.handles.ylim = get(XHR.handles.axis,''ylim'');',...
0785                                                 'set(XHR.handles.ymin,''string'',sprintf(''%7.1f'',XHR.handles.ylim(1)));',...
0786                                                 'set(XHR.handles.ymax,''string'',sprintf(''%7.1f'',XHR.handles.ylim(2)));',...
0787                                                 'set(gcbf,''userdata'',XHR); figure(XHR.gui); clear XHR;'));
0788     
0789     H.handles.ymin        =   uicontrol(H.gui,'Style','edit','Units','Normalized',Font,...
0790                               'Position',[.00 .60 .08 .05],...
0791                               'HorizontalAlign','left',...
0792                               'Tag','YMIN',...
0793                               'TooltipString','Set Y min', ...
0794                               'String',sprintf('%7.1f',H.handles.ylim(1)),...
0795                               'Callback',strcat('XHR = get(gcbf,''userdata'');',...
0796                                                 'ymin = str2num(get(XHR.handles.ymin,''string''));',...
0797                                                 'XHR.handles.ylim(1) = ymin;',...
0798                                                 'set(XHR.handles.axis,''ylim'',XHR.handles.ylim);',...
0799                                                 'set(XHR.handles.ymin,''string'',sprintf(''%7.1f'',XHR.handles.ylim(1)));',...
0800                                                 'set(gcbf,''userdata'',XHR); figure(XHR.gui); clear XHR ymin;'));
0801     
0802     H.handles.ymax        =   uicontrol(H.gui,'Style','edit','Units','Normalized',Font,...
0803                               'Position',[.00 .55 .08 .05],...
0804                               'HorizontalAlign','left',...
0805                               'Tag','YMAX',...
0806                               'TooltipString','Set Y max', ...
0807                               'String',sprintf('%7.1f',H.handles.ylim(2)),...
0808                               'Callback',strcat('XHR = get(gcbf,''userdata'');',...
0809                                                 'ymax = str2num(get(XHR.handles.ymax,''string''));',...
0810                                                 'XHR.handles.ylim(2) = ymax;',...
0811                                                 'set(XHR.handles.axis,''ylim'',XHR.handles.ylim);',...
0812                                                 'set(XHR.handles.ymax,''string'',sprintf(''%7.1f'',XHR.handles.ylim(2)));',...
0813                                                 'set(gcbf,''userdata'',XHR); figure(XHR.gui); clear XHR ymax;'));
0814     
0815     H.handles.grid        =   uicontrol(H.gui,'Style','checkbox','Units','Normalized',Font,...
0816                               'Position',[.00 .50 .08 .05],...
0817                               'BackgroundColor',bgcolor,'ForegroundColor',fgcolor,...
0818                               'Tag','GRID',...
0819                               'TooltipString','Toggle plot grid on/off.', ...
0820                               'String','grid',...
0821                               'Callback',strcat('XHR = get(gcbf,''userdata'');',...
0822                                                 'grid(XHR.handles.axis);',...
0823                                                 'set(gcbf,''userdata'',XHR); figure(XHR.gui); clear XHR;'));
0824     
0825     H.handles.xvalue      = uicontrol(H.gui,'Style','edit','Units','Normalized',Font,...
0826                               'Position',[.13 .95 .15 .05],...
0827                               'Tag','XVALUE',...
0828                               'TooltipString','X value (Read Only)',...
0829                               'BackGroundColor',[ 0 .7 .7],'String',' ');
0830     H.handles.yvalue      = uicontrol(H.gui,'Style','edit','Units','Normalized',Font,...
0831                               'Position',[.28 .95 .15 .05],...
0832                               'Tag','YVALUE',...
0833                               'TooltipString','Y value (Read Only)',...
0834                               'BackGroundColor',[ 0 .7 .7],'String',' ');
0835     
0836     H.handles.yindex      = uicontrol(H.gui,'Style','edit','Units','Normalized',Font,...
0837                               'Position',[.92 .87 .08 .05],...
0838                               'BackGroundColor',[ 0 .7 .7],...
0839                               'Tag','YINDEX',...
0840                               'TooltipString','Enter Y index into plot data matrix.  Same as trace number.',...
0841                               'String','1',...
0842                               'Value',1,...
0843                               'Callback',strcat('XHR = get(gcbf,''userdata'');',...
0844                                                 'yi = str2num(get(XHR.handles.yindex,''String''));',...
0845                                                 'XHR.data.yindex = yi;',...
0846                                                 'set(XHR.gui,''userdata'',XHR); figure(XHR.gui); clear XHR yi; ',...
0847                                                 '[Xpoint,Ypoint] = eeg_crosshair(''changey'');'));
0848     H.handles.yprev       = uicontrol(H.gui,'Style','Push','Units','Normalized',Font,...
0849                               'Position',[.92 .82 .04 .05],...
0850                               'String','<',...
0851                               'Tag','YPREV',...
0852                               'TooltipString','Goto Previous Y Index (channel).',...
0853                               'CallBack','[Xpoint,Ypoint] = eeg_crosshair(''prevy'');');
0854     H.handles.ynext       = uicontrol(H.gui,'Style','Push','Units','Normalized',Font,...
0855                               'Position',[.96 .82 .04 .05],...
0856                               'String','>',...
0857                               'Tag','YNEXT',...
0858                               'TooltipString','Goto Next Y Index (channel).',...
0859                               'CallBack','[Xpoint,Ypoint] = eeg_crosshair(''nexty'');');
0860     H.handles.yLT         = uicontrol(H.gui,'Style','Push','Units','Normalized',Font,...
0861                               'Position',[.92 .77 .04 .05],...
0862                               'String','LT',...
0863                               'Tag','YLT',...
0864                               'TooltipString','Goto next Y Less Than current Y.',...
0865                               'CallBack','[Xpoint,Ypoint] = eeg_crosshair(''yLT'');');
0866     H.handles.yGT         = uicontrol(H.gui,'Style','Push','Units','Normalized',Font,...
0867                               'Position',[.96 .77 .04 .05],...
0868                               'String','GT',...
0869                               'Tag','YGT',...
0870                               'TooltipString','Goto next Y Greater Than current Y.',...
0871                               'CallBack','[Xpoint,Ypoint] = eeg_crosshair(''yGT'');');
0872     
0873     H.handles.xindex      = uicontrol(H.gui,'Style','edit','Units','Normalized',Font,...
0874                               'Position',[.92 .70 .08 .05],...
0875                               'BackGroundColor',[ 0 .7 .7],...
0876                               'Tag','XINDEX',...
0877                               'TooltipString','Enter X index into plot data matrix.  Only available for interpolation = ''none''.',...
0878                               'String','1',...
0879                               'Value',1,...
0880                               'Callback',strcat('XHR = get(gcbf,''userdata'');',...
0881                                                 'xi = str2num(get(XHR.handles.xindex,''String''));',...
0882                                                 'XHR.data.xindex = xi;',...
0883                                                 'set(XHR.handles.xinterp,''value'',0); ',...
0884                                                 'set(XHR.handles.xinterp,''string'',''0''); ',...
0885                                                 'set(XHR.handles.interp, ''value'',1); ',...
0886                                                 'set(XHR.gui,''userdata'',XHR); figure(XHR.gui); clear XHR; ',...
0887                                                 '[Xpoint,Ypoint] = eeg_crosshair(''changex'');'));
0888     H.handles.xprev       = uicontrol(H.gui,'Style','Push','Units','Normalized',Font,...
0889                               'Position',[.92 .65 .04 .05],...
0890                               'String','<',...
0891                               'Tag','XPREV',...
0892                               'TooltipString','Goto Previous X Index (no interpolation).',...
0893                               'CallBack','[Xpoint,Ypoint] = eeg_crosshair(''prevx'');');
0894     H.handles.xnext       = uicontrol(H.gui,'Style','Push','Units','Normalized',Font,...
0895                               'Position',[.96 .65 .04 .05],...
0896                               'String','>',...
0897                               'Tag','XNEXT',...
0898                               'TooltipString','Goto Next X Index (no interpolation).',...
0899                               'CallBack','[Xpoint,Ypoint] = eeg_crosshair(''nextx'');');
0900     H.handles.xinterp     = uicontrol('Style','Edit','Units','Normalized',...
0901                               'Position',[.92 .60 .08 .05],...
0902                               'String','0',...
0903                               'Value',0,....
0904                               'Tag','XINTERP',...
0905                               'TooltipString','Interpolation X increment (zero = nearest X).',...
0906                               'Callback',strcat('XHR = get(gcbf,''userdata''); ',...
0907                                                 'xint = str2num(get(XHR.handles.xinterp,''string'')); ',...
0908                                                 'set(XHR.handles.xinterp,''value'',xint); figure(XHR.gui); clear XHR;'));
0909     
0910     interpstr     =   'none|nearest|linear|spline|cubic';
0911     H.handles.interp      =   uicontrol(H.gui,'Style','popup','Units','Normalized',Font,...
0912                               'Position',[.92 .55 .08 .05],...
0913                               'Tag','INTERP',...
0914                               'TooltipString','INTERP1 methods (none = raw values).', ...
0915                               'String',interpstr,...
0916                               'Callback',strcat('XHR = get(gcbf,''userdata'');',...
0917                                                 'xint = get(XHR.handles.xinterp,''Value''); ',...
0918                                                 'if xint == 0, ',...
0919                                                 '   xint = 0.5; ',...
0920                                                 '   set(XHR.handles.xinterp,''value'',xint); ',...
0921                                                 '   set(XHR.handles.xinterp,''string'',num2str(xint)); ',...
0922                                                 '   set(XHR.handles.xindex, ''string'',''interp''); ',...
0923                                                 'end; ',...
0924                                                 'set(XHR.gui,''userdata'',XHR); figure(XHR.gui); clear XHR; '));
0925     
0926     Font.FontWeight = 'bold';
0927     H.handles.store       = uicontrol('Style','Push','Units','Normalized',Font,...
0928                               'Position',[.92 .45 .08 .05],...
0929                               'BackgroundColor',[0 0.7 0],'ForegroundColor', [1 1 1],...
0930                               'String','Store',...
0931                               'Tag','STORE',...
0932                               'TooltipString','Store current values into base XYhist array.', ...
0933                               'CallBack','eeg_crosshair(''store'');');
0934     Font.FontWeight = 'normal';
0935     
0936     H.handles.topo        = uicontrol(H.gui,'Style','Push','Units','Normalized',Font,...
0937                               'Position',[.92 .35 .08 .05],...
0938                               'String','Topo',...
0939                               'Tag','TOPO',...
0940                               'TooltipString','Show Topographic Map (or GUI)', ...
0941                               'CallBack',strcat('XHR = get(gcbf,''userdata'');',...
0942                                                 'if isfield(XHR,''p''), ',...
0943                                                     'XHR.p.clickTimePoint = 0;',...
0944                                                     'XHR.p.volt.samplePoint = XHR.data.xindex;',...
0945                                                     'XHR.p.volt.sampleTime = XHR.data.xpoint;',...
0946                                                     'if get(XHR.handles.topo_opt,''Value''),',...
0947                                                         '[G,XHR.p] = gui_eeg_contours(XHR.p,XHR.gui);',...
0948                                                         'clear G; ',...
0949                                                     'else, ',...
0950                                                         'XHR.p = eeg_contours_engine(XHR.p);',...
0951                                                     'end;',...
0952                                                 'else ',...
0953                                                     '[G,XHR.p] = gui_eeg_contours('''',XHR.gui);',...
0954                                                     'clear G; ',...
0955                                                 'end;[p] = XHR.p;',...
0956                                                 'set(XHR.gui,''userdata'',XHR); clear XHR;'));                                            
0957     H.handles.topo_opt    = uicontrol(H.gui,'Style','checkbox', 'Units','Normalized',Font,...
0958                               'Position',[.92 .30 .08 .05],...
0959                               'BackgroundColor',bgcolor,'ForegroundColor',fgcolor,...
0960                               'Tag','TOPO_OPT',...
0961                               'String','GUI','Value',0,...
0962                               'TooltipString','View/Modify Topography Parameters');
0963                           
0964     H.handles.peaks       = uicontrol(H.gui,'Style','Push','Units','Normalized',Font,...
0965                               'Position',[.92 .25 .08 .05],...
0966                               'String','Peaks',...
0967                               'Tag','PEAKS',...
0968                               'TooltipString','Calculate Peaks for All Channels (RunOnce)', ...
0969                               'CallBack',strcat('XHR = get(gcbf,''userdata'');',...
0970                                                 'if isfield(XHR,''p''), ',...
0971                                                     'XHR.p = eeg_peaks(XHR.p);',...
0972                                                     'set(XHR.handles.peaksView,''Value'',1); ',...
0973                                                 'else, ',...
0974                                                     'XHR.p.volt.data = XHR.data.ydata;',...
0975                                                     'XHR.p.volt.timeArray = XHR.data.xdata;',...
0976                                                     'XHR.p = eeg_peaks(XHR.p);',...
0977                                                     'set(XHR.handles.peaksView,''Value'',1); ',...
0978                                                 'end; ',...
0979                                                 'set(XHR.gui,''userdata'',XHR); clear XHR;',...
0980                                                 '[Xpoint,Ypoint] = eeg_crosshair(''viewpeaks''); '));
0981     H.handles.pprev       = uicontrol(H.gui,'Style','Push','Units','Normalized',Font,...
0982                               'Position',[.92 .20 .04 .05],...
0983                               'String','<',...
0984                               'Tag','PPREV',...
0985                               'TooltipString','Goto Previous Peak of Current Channel',...
0986                               'CallBack','[Xpoint,Ypoint] = eeg_crosshair(''prevpeak'');');                          
0987     H.handles.pnext       = uicontrol(H.gui,'Style','Push','Units','Normalized',Font,...
0988                               'Position',[.96 .20 .04 .05],...
0989                               'String','>',...
0990                               'Tag','PNEXT',...
0991                               'TooltipString','Goto Next Peak of Current Channel',...
0992                               'CallBack','[Xpoint,Ypoint] = eeg_crosshair(''nextpeak'');');
0993     H.handles.peaksView   = uicontrol(H.gui,'Style','checkbox','Units','Normalized',Font,...
0994                                'Position',[.92 .15 .08 .05],...
0995                                'BackgroundColor',bgcolor,'ForegroundColor',fgcolor,...
0996                                'String','View','Value',0,...
0997                                'Tag','VIEWPEAK',...
0998                                'TooltipString','View peaks for current channel.',...
0999                                'CallBack','[Xpoint,Ypoint] = eeg_crosshair(''viewpeaks'');');
1000     H.handles.peaksMove   = uicontrol(H.gui,'Style','checkbox','Units','Normalized',Font,...
1001                                'Position',[.92 .10 .08 .05],...
1002                                'BackgroundColor',bgcolor,'ForegroundColor',fgcolor,...
1003                                'String','Move','Value',0,...
1004                                'Tag','MOVEPEAK','Visible','off',...
1005                                'TooltipString','Auto move to nearest peak for current channel.',...
1006                                'CallBack',strcat('[Xpoint,Ypoint] = eeg_crosshair(''nearpeak'');'));
1007     
1008     %%%%%%%%%%%%%%%%%%%%%%%%%
1009     % Get Line Data from Plot
1010     
1011     % Lines are referenced as axis children, among other
1012     % axis children; so first get all axis children
1013     sibs = get(H.handles.axis,'Children');
1014     
1015     % Now search axis children for any line types.
1016     % Because the columns of the y data matrix in a plot
1017     % command seem to be reversed in the axis children,
1018     % count down from max sibs to the first sib.
1019     lines = 0;
1020     H.data.xdata = [];
1021     H.data.ydata = [];
1022     H.data.xpoint = [];
1023     H.data.ypoint = [];
1024     H.data.xindex = 1;
1025     H.data.yindex = 1;
1026     i = max(size(sibs));
1027     while i >= 1
1028         if strcmp(get(sibs(i),'Type'),'line')
1029             % Found a line child, but check its size
1030             getline = 1;
1031             if ~isempty(H.data.xdata),
1032                 if isequal(size(get(sibs(i),'XData').',1),size(H.data.xdata,1)),
1033                     getline = 1;
1034                 else
1035                     getline = 0;
1036                 end
1037             end
1038             if getline,
1039                 % OK, found a line among the axis children.
1040                 lines = lines + 1;
1041                 H.handles.datalines(lines) = sibs(i);
1042                 
1043                 % put line data into a column of data.xdata|data.ydata
1044                 H.data.xdata(:,lines) = get(sibs(i),'XData').';
1045                 H.data.ydata(:,lines) = get(sibs(i),'YData').';
1046             end
1047         end
1048         i = i - 1;
1049     end
1050     
1051     % Switch off||on Trace GUI controls
1052     Vis = 'Off';
1053     if lines > 1,
1054         Vis = 'On';
1055     elseif lines == 0,
1056         error('No lines found in the current plot window\n');
1057     end
1058     
1059     % REMOVING THE FOLLOWING, AS NOW EFFECTIVELY AVAILABLE FROM YINDEX edit box
1060     
1061 %     % 'traces' string variable must be in ascending order
1062 %     traces  = '';
1063 %     i = 1;
1064 %     while i <= lines;
1065 %         if i < lines
1066 %             tracelabel = sprintf('Channel %4d|',i);
1067 %         else
1068 %             tracelabel = sprintf('Channel %4d',i);
1069 %         end
1070 %         traces = strcat(traces,tracelabel);
1071 %         i = i + 1;
1072 %     end
1073 %
1074 %     % If more than one line, provide GUI for line selection
1075 %
1076 %
1077 %     % Create Trace Index GUI
1078 %     H.handles.traceLabel   = uicontrol(H.gui,'Style','Edit', 'Units','Normalized',Font,...
1079 %                                'Position',[.00 .00 .09 .05],...
1080 %                                'Tag','TRACELABEL',...
1081 %                                'Visible',Vis,'String','Select :',...
1082 %                                'TooltipString','Select channel to follow with crosshairs.');
1083 %     H.handles.trace        = uicontrol(H.gui,'Style','Popup','Units','Normalized',Font,...
1084 %                                'Position',[.10 .00 .19 .05],...
1085 %                                'Tag','TRACESWITCH',...
1086 %                                'BackGroundColor','w','String',traces,...
1087 %                                'Visible',Vis,...
1088 %                                'CallBack',strcat('XHR = get(gcbf,''userdata'');',...
1089 %                                                  'XHR.data.yindex = get(XHR.handles.trace,''Value'');',...
1090 %                                                  'set(XHR.gui,''userdata'',XHR); clear XHR; ',...
1091 %                                                  '[Xpoint,Ypoint] = eeg_crosshair(''changey'');'));
1092     
1093     
1094     H.handles.traceNearest = uicontrol(H.gui,'Style','checkbox', 'Units','Normalized',Font,...
1095                                'Position',[.30 .00 .14 .05],...
1096                                'BackgroundColor',bgcolor,'ForegroundColor',fgcolor,...
1097                                'Tag','TRACENEAREST',...
1098                                'Visible',Vis,'String','Nearest','Value',1,...
1099                                'TooltipString','Channel nearest to mouse click selection. Switch off for fixed channel.');
1100     H.handles.traceView    = uicontrol(H.gui,'Style','checkbox','Units','Normalized',Font,...
1101                                'Position',[.45 .00 .19 .05],...
1102                                'BackgroundColor',bgcolor,'ForegroundColor',fgcolor,...
1103                                'String','View Channel','Value',0,...
1104                                'Tag','VIEW','Visible',Vis,...
1105                                'TooltipString','View only selected channel (on) or all channels (off).', ...
1106                                'CallBack',strcat('XHR = get(gcbf,''userdata'');',...
1107                                                  'if (get(XHR.handles.traceView,''Value'')),',...
1108                                                      'set(XHR.handles.datalines,''Visible'',''off''); ',...
1109                                                      'set(XHR.handles.datalines(XHR.data.yindex),''Visible'',''on''); ',...
1110                                                  'else, ',...
1111                                                      'set(XHR.handles.datalines,''Visible'',''on''); ',...
1112                                                  'end; ',...
1113                                                  'figure(XHR.gui); clear XHR;'));
1114     H.handles.traceAdd    = uicontrol(H.gui,'Style','checkbox', 'Units','Normalized',Font,...
1115                                'Position',[.65 .00 .19 .05],...
1116                                'BackgroundColor',bgcolor,'ForegroundColor',fgcolor,...
1117                                'Tag','TRACEADD',...
1118                                'Visible',Vis,'String','Add Channel','Value',0,...
1119                                'TooltipString','Add channels when using ''view channel'' rather than replace them.');
1120     
1121     Font.FontWeight = 'bold';
1122     
1123     % ASCII Parameters
1124     H.handles.Bparam      = uicontrol(H.gui,'Style','pushbutton','Units','Normalized',Font,...
1125                               'Position',[.69 .95 .1 .05],'BusyAction','queue',...
1126                               'String','PARAM',...
1127                               'TooltipString','Define ERP sample rate, epoch, etc.',...
1128                               'BackgroundColor',[0.0 0.0 0.75],...
1129                               'ForegroundColor',[1 1 1], 'HorizontalAlignment', 'center',...
1130                               'Callback',strcat('XHR = get(gcbf,''userdata'');',...
1131                                                 'tempgui = gui_eeg_ascii_parameters(XHR.gui); clear tempgui; ',...
1132                                                 'XHR = get(gcbf,''userdata'');',...
1133                                                 'figure(XHR.gui); [Xpoint,Ypoint] = eeg_crosshair(''done''); clf;',...
1134                                                 'plot(XHR.p.volt.timeArray,XHR.p.volt.data);',...
1135                                                 '[Xpoint,Ypoint] = eeg_crosshair(''init'',XHR.p,XHR.parent.gui); clear XHR; '));
1136     % Interface to electrodes
1137     H.handles.Belec       = uicontrol(H.gui,'Style','pushbutton','Units','Normalized',Font,...
1138                               'Position',[.79 .95 .1 .05],...
1139                               'String','ELEC','HorizontalAlignment','center',...
1140                               'TooltipString','Load associated electrode coordinates.',...
1141                               'BackgroundColor',[0.0 0.0 0.75],'ForegroundColor', [1 1 1],...
1142                               'Callback',strcat('XHR = get(gcbf,''userdata'');',...
1143                                                 'p = gui_elec_open(XHR.p,''init'',XHR.gui);',...
1144                                                 'clear XHR;'));
1145     % Interface to meshes
1146     H.handles.Bmesh       = uicontrol(H.gui,'Style','pushbutton','Units','Normalized',Font,...
1147                               'Position',[.89 .95 .1 .05],...
1148                               'String','MESH','HorizontalAlignment','center',...
1149                               'visible','on',...
1150                               'TooltipString','Load associated MRI tesselations.',...
1151                               'BackgroundColor',[0.0 0.0 0.75],'ForegroundColor', [1 1 1],...
1152                               'Callback',strcat('XHR = get(gcbf,''userdata'');',...
1153                                                 'XHR.p = gui_mesh_open(XHR.p,''init'',XHR.gui);',...
1154                                                 'clear XHR;'));
1155     
1156     
1157     H.handles.done        = uicontrol(H.gui,'Style','Push','Units','Normalized',Font,...
1158                               'Position',[.84 .00 .08 .05],...
1159                               'BackgroundColor',[0.7 0 0],'ForegroundColor', [1 1 1],...
1160                               'String','Done',...
1161                               'Tag','DONE',...
1162                               'TooltipString','Close eeg_crosshair', ...
1163                               'CallBack','[Xpoint,Ypoint] = eeg_crosshair(''done'');');
1164     H.handles.exit        = uicontrol(H.gui,'Style','Push','Units','Normalized',Font,...
1165                               'Position',[.92 .00 .08 .05],...
1166                               'BackgroundColor',[0.8 0 0],'ForegroundColor', [1 1 1],...
1167                               'String','Exit',...
1168                               'Tag','EXIT',...
1169                               'TooltipString','Close eeg_crosshair and Figure', ...
1170                               'CallBack','[Xpoint,Ypoint] = eeg_crosshair(''exit'');');
1171                           
1172 
1173     % Set X,Y cross hair lines
1174     % Do this after finding all the line axis children
1175     % to avoid confusing these lines with those of the
1176     % plot itself (counted above).
1177     x_rng = get(H.handles.axis,'Xlim');
1178     y_rng = get(H.handles.axis,'Ylim');
1179     axes(H.handles.axis);
1180     H.handles.xline = line(x_rng,[y_rng(1) y_rng(1)]);
1181     H.handles.yline = line(x_rng,[y_rng(1) y_rng(1)]);
1182     set(H.handles.xline,'Color','r','EraseMode','xor','Tag','XLINE');
1183     set(H.handles.yline,'Color','r','EraseMode','xor','Tag','YLINE');
1184     
1185     %set(H.gui,'HandleVisibility','callback'); % hide fig from other commands
1186     
1187 return

Generated on Mon 15-Aug-2005 15:36:19 by m2html © 2003