Home > vbmeg > functions > device > eeg > biosemi > vb_cb_clip_trigger.m

vb_cb_clip_trigger

PURPOSE ^

clip trigger as a callback function of vb_do_mark_trigger

SYNOPSIS ^

function vb_cb_clip_trigger(state)

DESCRIPTION ^

 clip trigger as a callback function of vb_do_mark_trigger
 [usage]
   vb_cb_clip_trigger(state)
 [input]
   state : program handle label
         :  'down' or 'move' or 'up'
         :  'mode' or 'prev' or 'restore' or 'save'
 [output]
   none
 [note]
   [CALLBACK]
   This function is only expected to be called as callback.
   @see vb_do_mark_trigger
   @see vb_util_line_trigger
   @see vb_define_process_trigger;
   <<struct>> x_range
       begin : beginning value
         end : ending value
 [history]
   2007-01-25 (Sako) prototype #2 - added zoom function

 Copyright (C) 2011, ATR All Rights Reserved.
 License : New BSD License(see VBMEG_LICENSE.txt)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function vb_cb_clip_trigger(state)
0002 % clip trigger as a callback function of vb_do_mark_trigger
0003 % [usage]
0004 %   vb_cb_clip_trigger(state)
0005 % [input]
0006 %   state : program handle label
0007 %         :  'down' or 'move' or 'up'
0008 %         :  'mode' or 'prev' or 'restore' or 'save'
0009 % [output]
0010 %   none
0011 % [note]
0012 %   [CALLBACK]
0013 %   This function is only expected to be called as callback.
0014 %   @see vb_do_mark_trigger
0015 %   @see vb_util_line_trigger
0016 %   @see vb_define_process_trigger;
0017 %   <<struct>> x_range
0018 %       begin : beginning value
0019 %         end : ending value
0020 % [history]
0021 %   2007-01-25 (Sako) prototype #2 - added zoom function
0022 %
0023 % Copyright (C) 2011, ATR All Rights Reserved.
0024 % License : New BSD License(see VBMEG_LICENSE.txt)
0025 
0026 % common definition
0027 vb_define_process_trigger;
0028 
0029 VERBOSE = true;
0030 
0031 if ~exist('state', 'var')
0032   state = [];
0033 end
0034 
0035 % --- initialize --- %
0036 trigger_line_gap = 10;
0037 trigger_line_clr = 'g';
0038 
0039 htype = get(gco,'Type');
0040 tag = get(gco,'Tag');
0041 marker = getappdata(gcf,'Marker');
0042 color  = getappdata(gcf,'Color');
0043 
0044 % --- MAIN PROCEDURE --------------------------------------------------------- %
0045 %
0046 if isempty(state)
0047   if VERBOSE fprintf('no state\n'); end;
0048   return;
0049 end
0050 
0051 % fprintf('  --- state [ %s ]\n', state);
0052 
0053 switch  state
0054 
0055 
0056   % --- MOUSE EVENT ---------------------------------------------------------- %
0057   %
0058   % --- down
0059   %
0060   case  'down'
0061   % Execute the WindowButtonDownFcn
0062 
0063     if VERBOSE fprintf( ...
0064       '[callback] state:%s, htype:%s, tag:%s\n', state, htype, tag); end;
0065 
0066     ud = get(gcf, 'UserData');
0067     cp = get(gca, 'CurrentPoint');
0068     x = cp(1,1);       %first xy values
0069     y = cp(1,2);       %first xy values
0070 
0071     if inner_is_select_switch_on
0072       % do nothing
0073       return;
0074       
0075     elseif strcmp(tag, DPT_TRIGGERLINE_TAG)
0076 
0077       % --- DELETE LINE --- %
0078       inner_delete_line(VERBOSE);
0079 
0080     else
0081       % --- DRAW LINE --- %
0082       inner_draw_line(trigger_line_gap, trigger_line_clr, x, VERBOSE);
0083     end
0084 
0085 
0086   % --- move
0087   %
0088   case  'move'
0089 
0090     % Execute the WindowButtonMotionFcn
0091     ud = get(gcf, 'UserData');
0092     if ud.drag_switch == false
0093       return;
0094     end
0095 
0096     % test
0097     select_xrange('move', gca);
0098   %   if VERBOSE fprintf('[callback] state : move - do nothing\n'); end;
0099 
0100   
0101   % --- up
0102   %
0103   case  'up'
0104   % if VERBOSE fprintf('[callback] state : %s\n', state); end;
0105 
0106     % do nothing
0107     return;
0108   %
0109   % --- END OF MOUSE EVENT --------------------------------------------------- %
0110 
0111 
0112   % --- CONTROL BUTTON EVENT ------------------------------------------------- %
0113   %
0114   % --- mode
0115   %
0116   case  'mode'
0117     if VERBOSE, fprintf('[callback] state : %s\n', state); end;
0118     inner_switch_mode(VERBOSE);
0119   
0120 
0121   % --- zoonin
0122   %
0123   case  'zoomin'
0124     if VERBOSE fprintf('[callback] state : %s\n', state); end;
0125     if inner_is_select_switch_on
0126       ud = get(gcf, 'UserData');
0127       xlim = get(gca, 'XLim');
0128 %       ud.previous_x_begin = xlim(1);
0129 %       ud.previous_x_end = xlim(2);
0130       ud.axis_ends = ...
0131         vb_axisends_set(ud.axis_ends, 'PREVIOUS', 'X', xlim(1), xlim(2));
0132       set(gcf, 'UserData', ud);
0133 
0134       x_data = select_xrange('get', gca);
0135       x_range.begin = x_data(1);
0136       x_range.end   = x_data(2);
0137       inner_zoom(x_range, [], true);
0138     end
0139 
0140 
0141   % --- previous
0142   %
0143   case  'prev'
0144     if VERBOSE fprintf('[callback] state : %s\n', state); end;
0145     ud = get(gcf, 'UserData');
0146 %     x_range.begin = ud.previous_x_begin;
0147 %     x_range.end = ud.previous_x_end;
0148     [x_range.begin, x_range.end] = vb_axisends_get(ud.axis_ends, 'PREVIOUS', 'X');
0149     [y_range.begin, y_range.end] = vb_axisends_get(ud.axis_ends, 'PREVIOUS', 'Y');
0150     inner_zoom(x_range, y_range, VERBOSE);
0151 
0152     
0153   % --- restore (initial size)
0154   %
0155   case  'restore'
0156     if VERBOSE fprintf('[callback] state : %s\n', state); end;
0157     ud = get(gcf, 'UserData');
0158 %     x_range.begin = ud.org_begin_x;
0159 %     x_range.end = ud.org_end_x;
0160     [x_range.begin, x_range.end] = vb_axisends_get(ud.axis_ends, 'ORIGINAL', 'X');
0161     [y_range.begin, y_range.end] = vb_axisends_get(ud.axis_ends, 'ORIGINAL', 'Y');
0162     inner_zoom(x_range, y_range, VERBOSE);
0163 
0164   
0165   % --- save
0166   %
0167   case  'save'
0168     if VERBOSE fprintf('[callback] state : %s\n', state); end;
0169     [FileName,PathName,FilterIndex] = uiputfile( ...
0170       '*.mat', DPT_TITLE_FILE_SELECTOR);
0171 
0172     if FileName == 0 return; end
0173     if PathName == 0 return; end
0174     
0175     ud = get(gcf, 'UserData');
0176     ud.output_file = [PathName FileName];
0177     set(gcf, 'UserData', ud);
0178 
0179     % --- SAVE --- %
0180     inner_save(VERBOSE);
0181 
0182   
0183   % --- zoom_slide_x
0184   %
0185   case  'zoom_slide_x'
0186     if VERBOSE fprintf('[callback] state : %s\n', state); end;
0187 
0188 %     if inner_is_select_switch_on
0189     ud = get(gcf, 'UserData');
0190 %     xlim = get(gca, 'XLim');
0191 %     ud.previous_x_begin = xlim(1);
0192 %     ud.previous_x_end   = xlim(2);
0193 %     set(gcf, 'UserData', ud);
0194 
0195     value = get(gco,'Value');
0196 %     fprintf('slider value = %d\n', value);
0197 
0198 %     base_begin = ud.slider_base_begin_x;
0199 %     base_end   = ud.slider_base_end_x;
0200     [base.begin, base.end] = vb_axisends_get(ud.axis_ends, 'SLIDER', 'X');
0201 
0202     new_begin = base.begin;    % no change
0203     
0204     current_dist = base.end - base.begin;
0205     retreat_dist = current_dist * value / (MAX_ZOOM_RANGE+1);
0206     new_end = base.end - retreat_dist;
0207 
0208     x_range.begin = new_begin;
0209     x_range.end   = new_end;
0210     fprintf('xrange.[begin,end] = [%f,%f]\n', x_range.begin, x_range.end);
0211     inner_slider_zoom(x_range, 'X', true);
0212 %     end
0213   return;
0214 
0215   
0216   % --- zoom_slide_y
0217   %
0218   case  'zoom_slide_y'
0219     if VERBOSE fprintf('[callback] state : %s\n', state); end;
0220 
0221     value = get(gco,'Value');
0222 
0223     ud = get(gcf, 'UserData');
0224 %     base_begin = ud.slider_base_begin_y;
0225 %     base_end   = ud.slider_base_end_y;
0226     [base.begin, base.end] = vb_axisends_get(ud.axis_ends, 'SLIDER', 'Y');
0227 
0228     new_begin = base.begin;    % no change
0229     
0230     current_dist = base.end - base.begin;
0231     retreat_dist = current_dist * value / (MAX_ZOOM_RANGE+1);
0232     new_end = base.end - retreat_dist;
0233 
0234     y_range.begin = new_begin;
0235     y_range.end   = new_end;
0236     fprintf('y_range.[begin,end] = [%f,%f]\n', y_range.begin, y_range.end);
0237     inner_slider_zoom(y_range, 'Y', true);
0238     return;
0239     
0240 
0241   % --- move_slide_y
0242   %
0243   case  'move_slide_y'
0244     if VERBOSE fprintf('[callback] state : %s\n', state); end;
0245     [new_begin, new_end] = inner_calc_movement('Y');
0246 
0247     y_range.begin = new_begin;
0248     y_range.end   = new_end;
0249     fprintf('y_range.[begin,end] = [%f,%f]\n', y_range.begin, y_range.end);
0250     inner_slider_zoom(y_range, 'Y', true);
0251     return;
0252     
0253   % --- aux_1
0254   %
0255   case 'aux_1'
0256     if VERBOSE fprintf('[callback] state : %s\n', state); end;
0257     inner_aux1(VERBOSE);
0258   %
0259   % --- END OF CONTROL BUTTON EVENT ------------------------------------------- %
0260 
0261   otherwise
0262     warning('unimplemented state : %s', state);
0263 end
0264 %
0265 % --- END OF MAIN PROCEDURE -------------------------------------------------- %
0266 
0267 
0268 % --- INNER FUNCTIONS -------------------------------------------------------- %
0269 %
0270 % --- inner_zoom()
0271 %
0272 % prior conditions
0273 %   : all arguments must be required.
0274 %   : x_range and y_range are allowable to be empty
0275 function inner_zoom(x_range, y_range, VERBOSE)
0276 
0277   vb_define_process_trigger;
0278 
0279   % --- get user data
0280   %
0281   ud = get(gcf, 'UserData');
0282 
0283   % --- set both ends of X-axis and Y-axis
0284   %
0285   x_slider_reset = true;
0286   y_slider_reset = true;
0287 
0288   xlim = get(gca, 'XLim');
0289   ylim = get(gca, 'YLim');
0290 
0291   if isempty(x_range)
0292     x_slider_reset = false;
0293     x_range.begin = xlim(1);
0294     x_range.end   = xlim(2);
0295   end
0296 
0297   if isempty(y_range)
0298     y_slider_reset = false;
0299     y_range.begin = ylim(1);
0300     y_range.end   = ylim(2);
0301   end
0302 
0303   % update previous data
0304   ud.axis_ends = vb_axisends_set(ud.axis_ends, 'PREVIOUS', 'X', xlim(1), xlim(2));
0305   ud.axis_ends = vb_axisends_set(ud.axis_ends, 'PREVIOUS', 'Y', ylim(1), ylim(2));
0306 
0307   [begin_x, end_x] = inner_get_real_begin_end(x_range);
0308   set(gca, 'XLim', [begin_x, end_x]);
0309 
0310   [begin_y, end_y] = inner_get_real_begin_end(y_range);
0311   set(gca, 'YLim', [begin_y, end_y]);
0312 
0313 
0314   % --- reset zoom slider
0315   %
0316   if x_slider_reset
0317 
0318     sld_zoom_x = findobj(gcf, 'Tag', DPT_CTRL_TAG_ZOOM_X);
0319     set(sld_zoom_x, 'Value', 1);
0320 
0321     ud.axis_ends = vb_axisends_set(ud.axis_ends, 'SLIDER', 'X', begin_x, end_x);
0322     fprintf('X_zoom[begin,end] = [%f,%f]\n', begin_x, end_x);
0323   end
0324 
0325   if y_slider_reset
0326     sld_zoom_y = findobj(gcf, 'Tag', DPT_CTRL_TAG_ZOOM_Y);
0327     set(sld_zoom_y, 'Value', 1);
0328 
0329     sld_move_y = findobj(gcf, 'Tag', DPT_CTRL_TAG_MOVE_Y);
0330     set(sld_move_y, 'Value', 0);
0331 
0332     ud.axis_ends = vb_axisends_set(ud.axis_ends, 'SLIDER', 'Y', begin_y, end_y);
0333     fprintf('Y_zoom[begin,end] = [%f,%f]\n', begin_y, end_y);
0334   end
0335 
0336   % --- update UserData
0337   %
0338   set(gcf, 'UserData', ud);
0339   
0340   % --- clear selected region
0341   %
0342   inner_reset_selected_region;
0343 %
0344 % --- end of inner_zoom()
0345 
0346 
0347 % --- inner_slider_zoom()
0348 %
0349 function inner_slider_zoom(range, tag, VERBOSE)
0350 
0351   [new_begin, new_end] = inner_get_real_begin_end(range);
0352 
0353   % --- get user data
0354   %
0355   ud = get(gcf, 'UserData');
0356 
0357   % --- update previous data
0358   %
0359   xlim = get(gca, 'XLim');
0360   ylim = get(gca, 'YLim');
0361 
0362   ud.axis_ends = vb_axisends_set(ud.axis_ends, 'PREVIOUS', 'X', xlim(1), xlim(2));
0363   ud.axis_ends = vb_axisends_set(ud.axis_ends, 'PREVIOUS', 'Y', ylim(1), ylim(2));
0364 
0365   % actually move here
0366   axis_tag = upper(tag);
0367   if strcmp(axis_tag, 'Y')
0368     set(gca, 'YLim', [new_begin, new_end]);
0369   else
0370     set(gca, 'XLim', [new_begin, new_end]);
0371   end
0372 
0373   % --- update UserData
0374   %
0375   set(gcf, 'UserData', ud);
0376 
0377   % --- clear selected region
0378   %
0379   inner_reset_selected_region;
0380 
0381   if VERBOSE, ...
0382       fprintf('slider: [begin,end] = [%f,%f]\n', new_begin, new_end); end;
0383 %
0384 % --- end of inner_slider_zoom()
0385 
0386 
0387 % --- inner_switch_mode()
0388 %
0389 function inner_switch_mode(VERBOSE)
0390 
0391   vb_define_process_trigger;
0392   
0393   ud = get(gcf, 'UserData');
0394   if isfield(ud, 'drag_switch')
0395     if ud.drag_switch
0396       ud.drag_switch = false;
0397     else
0398       ud.drag_switch = true;
0399     end;
0400   else
0401     ud.drag_switch = true;
0402   end
0403 
0404   if ud.drag_switch == true
0405     mode_str = DPT_LBL_MODE_RANGE;
0406   else
0407     mode_str = DPT_LBL_MODE_LINE;
0408   end
0409 
0410   set(gco, 'String', mode_str);
0411   set(gcf, 'UserData', ud);
0412 %
0413 % --- end of inner_switch_mode()
0414 
0415 
0416 % --- inner_save()
0417 %
0418 function inner_save(VERBOSE)
0419 
0420   vb_define_process_trigger;
0421 
0422   if VERBOSE fprintf('  === gather trigger points ===\n'); end;
0423 
0424   trigger_sample_list = [];
0425     
0426   actors_h = get(gca, 'Children');
0427   for n = 1:size(actors_h,1)
0428     actor_tag = get(actors_h(n), 'Tag');
0429     if strcmp(DPT_TRIGGERTEXT_TAG, actor_tag)
0430       sample_value = get(actors_h(n), 'String');
0431       if VERBOSE fprintf('>>> label tag! : (%d,%s)\n', n, sample_value); end;
0432       trigger_sample_list = [trigger_sample_list str2num(sample_value)];
0433     end
0434   end
0435   trigger_sample_list = sort(trigger_sample_list)';
0436     
0437   % save data
0438   ud = get(gcf, 'UserData');
0439 
0440   trigger_list_file = ud.output_file;
0441   vb_save(trigger_list_file, 'trigger_sample_list');
0442 
0443   if VERBOSE fprintf( ...
0444     '  === save trigger information : %s\n', trigger_list_file); end;
0445 %
0446 % --- end of inner_save()
0447 
0448 
0449 % --- inner_delete_line()
0450 %
0451 function inner_delete_line(VERBOSE)
0452   if VERBOSE fprintf('  === delete trigger line\n'); end;
0453   ud = get(gco, 'UserData');
0454   line_h = ud(1);
0455   label_h = ud(2);
0456   delete(label_h);
0457   delete(line_h);
0458 %
0459 % --- end of inner_delete_line()
0460 
0461 % --- inner_draw_line()
0462 %
0463 function inner_draw_line( ...
0464   trigger_line_gap, trigger_line_clr, round_x, VERBOSE)
0465 
0466   y_limit = get(gca, 'YLim');
0467   y_min = y_limit(1);
0468   y_max = y_limit(2);
0469 
0470   y_data = [y_min:trigger_line_gap:y_max];
0471 
0472   vb_util_line_trigger(round_x, y_data, trigger_line_clr);
0473 %
0474 % --- end of inner_draw_line()
0475 
0476 % --- inner_aux1()
0477 %
0478 function inner_aux1(VERBOSE)
0479 % for test
0480   % do nothing
0481   return;
0482 %
0483 % --- end of inner_aux1()
0484 
0485 
0486 % --- inner_select_switch_on()
0487 %
0488 function [result] = inner_is_select_switch_on
0489   ud = get(gcf, 'UserData');
0490   result = ud.drag_switch;
0491 %
0492 % --- end of inner_select_switch_on()
0493 
0494 
0495 % --- inner_get_real_begin_end()
0496 %
0497 function  [my_begin, my_end] = inner_get_real_begin_end(both_ends)
0498   if both_ends.begin > both_ends.end
0499     my_begin = both_ends.end;
0500     my_end = both_ends.begin;
0501   else
0502     my_begin = both_ends.begin;
0503     my_end = both_ends.end;
0504   end
0505 %
0506 % --- end of inner_get_real_begin_end()
0507 
0508 
0509 % --- inner_calc_movement()
0510 %
0511 function [new_begin, new_end] = inner_calc_movement(xy_tag);
0512 
0513   vb_define_process_trigger;
0514 
0515   XY_TAG = upper(xy_tag);
0516 
0517   value = get(gco,'Value');
0518 
0519   % buffer size
0520   ud = get(gcf, 'UserData');
0521 
0522   if strcmp(XY_TAG, 'Y')
0523     lim = get(gca, 'YLim');
0524   else % X
0525     lim = get(gca, 'XLim');
0526   end
0527 
0528   [base.begin, base.end] = vb_axisends_get(ud.axis_ends, 'SLIDER', XY_TAG);
0529 
0530   % view size of Y
0531   view.begin = lim(1);
0532   view.end   = lim(2);
0533 
0534   view_dist = abs(view.end - view.begin);
0535   fprintf('before_move: [begin,end] = [%f,%f]\n', view.begin, view.end);
0536 
0537   move_dist = abs(base.end - base.begin) * value / MAX_ZOOM_RANGE;
0538   new_begin = base.begin + move_dist;
0539   new_end   = new_begin + view_dist;
0540   return;
0541 %
0542 % --- end of inner_calc_movement()
0543 
0544 
0545 % --- inner_reset_selected_region()
0546 %
0547 function inner_reset_selected_region
0548   select_xrange('clear', gca);
0549   select_xrange('init', gca);
0550 %
0551 % --- end of inner_reset_selected_region()
0552 
0553 %%% END OF FILE %%%

Generated on Mon 22-May-2023 06:53:56 by m2html © 2005