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

vb_do_mark_trigger

PURPOSE ^

mark trigger point by hand

SYNOPSIS ^

function vb_do_mark_trigger(plot_spec, draw_spec)

DESCRIPTION ^

 mark trigger point by hand
 [usage]
   vb_do_mark_trigger(plot_spec, draw_spec)
 [input]
   plot_spec : <required> <<struct>> mark_trigger_spec type
    :                data : <required> (Nchannel x Nsample) 
    :            plot_idx : <required> list of index of 'data' to be plotted
    : trigger_channel_idx : <optional> [[]]
    :                     : trigger channel index [Nch x 1] or [1 x Nch]
    :                     : re-arrange to [Nch x 1] in this function
    :  trigger_sample_idx : <optional> [[]]
    :                     : list of trigger points as sample index
    :         output_file : <optional> output file which has trigger_sample_list
    :                     :   ['.\trigger_(date).mat']
   draw_spec : <optional> <<struct>> specification for drawing
    :          data_color : color of normal sensor data
    :  trigger_data_color : color of trigger data
    :  trigger_line_color : color of trigger line
 [output]
   none
 [note]
   Nchannel must be equal to sum of sizes of plot_idx and trigger_idx.
   @prior_condition : 'trigger_sample_idx' is a list of sample number
   @see : vb_cb_clip_trigger
   @see : vb_define_process_trigger
 [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_do_mark_trigger(plot_spec, draw_spec)
0002 % mark trigger point by hand
0003 % [usage]
0004 %   vb_do_mark_trigger(plot_spec, draw_spec)
0005 % [input]
0006 %   plot_spec : <required> <<struct>> mark_trigger_spec type
0007 %    :                data : <required> (Nchannel x Nsample)
0008 %    :            plot_idx : <required> list of index of 'data' to be plotted
0009 %    : trigger_channel_idx : <optional> [[]]
0010 %    :                     : trigger channel index [Nch x 1] or [1 x Nch]
0011 %    :                     : re-arrange to [Nch x 1] in this function
0012 %    :  trigger_sample_idx : <optional> [[]]
0013 %    :                     : list of trigger points as sample index
0014 %    :         output_file : <optional> output file which has trigger_sample_list
0015 %    :                     :   ['.\trigger_(date).mat']
0016 %   draw_spec : <optional> <<struct>> specification for drawing
0017 %    :          data_color : color of normal sensor data
0018 %    :  trigger_data_color : color of trigger data
0019 %    :  trigger_line_color : color of trigger line
0020 % [output]
0021 %   none
0022 % [note]
0023 %   Nchannel must be equal to sum of sizes of plot_idx and trigger_idx.
0024 %   @prior_condition : 'trigger_sample_idx' is a list of sample number
0025 %   @see : vb_cb_clip_trigger
0026 %   @see : vb_define_process_trigger
0027 % [history]
0028 %   2007-01-25 (Sako) prototype #2 added zoom function
0029 %
0030 % Copyright (C) 2011, ATR All Rights Reserved.
0031 % License : New BSD License(see VBMEG_LICENSE.txt)
0032 
0033 % --- CHECK ARGUMENTS --- %
0034 if ~exist('plot_spec', 'var'), plot_spec = []; end;
0035 if ~exist('draw_spec', 'var'), draw_spec = []; end;
0036 [plot_spec, draw_spec] = inner_check_arguments(plot_spec, draw_spec);
0037 
0038 
0039 % --- MAIN PROCEDURE --------------------------------------------------------- %
0040 %
0041 % common definition
0042 vb_define_process_trigger;
0043 
0044 my_data = plot_spec.data;
0045 
0046 plot_idx = plot_spec.plot_idx;
0047 trigger_idx = plot_spec.trigger_channel_idx; % unused for now
0048 % plot_idx and trigger_idx are (N x 1)
0049 
0050 data_color = draw_spec.data_color;
0051 trigger_color = draw_spec.trigger_data_color;
0052 
0053 % figure('Position', DPT_WINDOW_POSITION);
0054 
0055 if isempty(plot_spec.trigger_sample_idx)
0056   figure('Position', DPT_WINDOW_POSITION);
0057   % --- line trigger <<by MANUAL>>
0058   %
0059   for ch = plot_idx'
0060     dh = plot(my_data(ch,:), 'Color', data_color); hold on;
0061     set(dh, 'Tag', DPT_DATALINE_TAG);
0062   end
0063 
0064   inner_set_controls(plot_spec.output_file);
0065   %
0066   % --- end of <<by MANUAL>>
0067   
0068 else
0069   % --- line trigger <<by FULL or SEMI-AUTO>>
0070   %
0071   trigger_list = plot_spec.trigger_sample_idx;
0072 % trigger_list is (N x 1)
0073 % trigger_list is a array of <struct>
0074 %   - all_idx : all
0075 %   - beg_idx : beginning indices
0076 %   - end_idx : ending indices
0077 
0078   trigger_num = size(trigger_list,1);
0079 
0080   for ntr = 1:trigger_num
0081     figure;
0082 
0083     for ch = plot_idx'
0084       dh = plot(my_data(ch,:), 'Color', data_color); hold on;
0085       set(dh, 'Tag', DPT_DATALINE_TAG);
0086     end
0087 
0088     % line spec
0089     trigger_line_gap = 10;
0090     trigger_line_clr = draw_spec.trigger_line_color;
0091 
0092     y_limit = get(gca, 'YLim');
0093     y_min = y_limit(1);
0094     y_max = y_limit(2);
0095 
0096     % draw trigger line
0097     y_data = [y_min:trigger_line_gap:y_max];
0098 
0099 %   plot_index = trigger_list(ntr).all_idx;
0100     plot_index = trigger_list(ntr).beg_idx;
0101 %   plot_index = trigger_list(ntr).all_idx;
0102 
0103     for this_x = plot_index
0104       % trigger point label
0105       vb_util_line_trigger(this_x, y_data, trigger_line_clr);
0106     end
0107 
0108     % output file name
0109     if trigger_num > 1
0110       output_file = sprintf('%s_%d', plot_spec.output_file, ntr);
0111     else
0112       output_file = plot_spec.output_file;
0113     end
0114 
0115     inner_set_controls(output_file);
0116   end   % for ntr
0117   %
0118   % --- end of <<by FULL or SEMI-AUTO>>
0119 end
0120 %
0121 % --- END OF MAIN PROCEDURE ------------------------------------------------- %
0122 
0123 
0124 % --- INNER FUNCTIONS -------------------------------------------------------- %
0125 %
0126 % --- inner_check_argument()
0127 % check argument
0128 % @prior conditions : plot_spec and draw_spec exist
0129 %   plot_spec : <<struct>> mark_trigger_spec type
0130 %     :         data : <required> (Nchannel x Nsample)
0131 %     :     plot_idx : <required> list of index of 'data' to be plotted
0132 %     :  trigger_idx : <optional> trigger index of 'data'
0133 %     : trigger_list : <optional> list of trigger points as sample number
0134 %     :  output_file : <optional> output file which has trigger_sample_list
0135 %     :              :  ['.\trigger_(date).mat']
0136 %   draw_spec : <optional> <<struct>> specification for drawing
0137 %     :         data_color : color of normal sensor data
0138 %     : trigger_data_color : color of trigger data
0139 %     : trigger_line_color : color of trigger line
0140 function [plot_spec, draw_spec] = inner_check_arguments(plot_spec, draw_spec)
0141 
0142 vb_define_process_trigger;
0143 
0144 if isempty(plot_spec)
0145   error('plot_spec is a required parameter');
0146 end
0147 
0148 if ~isfield(plot_spec, 'data')
0149   error('data is a required field of plot_spec');
0150 end
0151 
0152 if ~isfield(plot_spec, 'plot_idx')
0153   error('plot_idx is a required field of plot_spec');
0154 elseif ~isempty( find(plot_spec.plot_idx > size(plot_spec.data,1) ...
0155     | plot_spec.plot_idx < 1))
0156   error('invalid index : plot_spec.plot_idx');
0157 else
0158   plot_spec.plot_idx = vb_util_arrange_list(plot_spec.plot_idx);
0159 end
0160 
0161 %
0162 % trigger channel index
0163 %
0164 if ~isfield(plot_spec, 'trigger_channel_idx') ...
0165     || isempty(plot_spec.trigger_channel_idx)
0166   
0167   plot_spec.trigger_channel_idx = [];
0168   
0169 elseif ~isempty(find(plot_spec.trigger_channel_idx > size(plot_spec.data,1) ...
0170     | plot_spec.trigger_channel_idx < 1))
0171   
0172   error('invalid index : plot_spec.trigger_channel_idx');
0173   
0174 else
0175   plot_spec.trigger_channel_idx = ...
0176     vb_util_arrange_list(plot_spec.trigger_channel_idx);
0177 end
0178 
0179 %
0180 % trigger sample index
0181 %
0182 if ~isfield(plot_spec, 'trigger_sample_idx')
0183   plot_spec.trigger_sample_idx = [];
0184 end
0185 
0186 %
0187 % output file
0188 %
0189 if ~isfield(plot_spec, 'output_file') || isempty(plot_spec.output_file)
0190   plot_spec.output_file = sprintf('.%strigger_%s.mat', filesep, date);
0191 end
0192 
0193 %
0194 % draw_spec
0195 %
0196 if isempty(draw_spec)
0197   draw_spec.data_color = DPT_DEFAULT_ND_COLOR;
0198   draw_spec.trigger_data_color = DPT_DEFAULT_TD_COLOR;
0199   draw_spec.trigger_line_color = DPT_DEFAULT_TL_COLOR;
0200 else
0201   if ~isfield(draw_spec, 'data_color') ...
0202       || isempty(draw_spec.data_color)
0203     draw_spec.data_color = DPT_DEFAULT_ND_COLOR;
0204   end
0205   if ~isfield(draw_spec, 'trigger_data_color') ...
0206       || isempty(draw_spec.trigger_data_color)
0207     draw_spec.trigger_data_color = DPT_DEFAULT_TD_COLOR;
0208   end
0209   if ~isfield(draw_spec, 'trigger_line_color') ...
0210       || isempty(draw_spec.trigger_line_color)
0211     draw_spec.trigger_line_color = DPT_DEFAULT_TL_COLOR;
0212   end
0213 end
0214 %
0215 % --- end of inner_check_argument()
0216 
0217 
0218 % --- inner_set_controls()
0219 %
0220 function inner_set_controls(output_file)
0221 vb_define_process_trigger;
0222 
0223 % check defined parameters
0224 if ~exist('MAX_ZOOM_RANGE', 'var'), MAX_ZOOM_RANGE = 100; end;
0225 
0226 % --- set figure
0227 set(gcf,'WindowButtonDownFcn','vb_cb_clip_trigger down')
0228 set(gcf,'WindowButtonMotionFcn','vb_cb_clip_trigger move')
0229 set(gcf,'WindowButtonUpFcn','vb_cb_clip_trigger up')
0230 
0231 % WINDOW_POSITION = [100 100 640 480];
0232 % set(gcf, 'Position', DPT_WINDOW_POSITION);
0233 
0234 
0235 %
0236 % --- set initial figure's properties
0237 %
0238 
0239 % default output file
0240 ud.output_file = output_file;
0241 
0242 % LINE/RANGE switch
0243 % ud.drag_switch = false;
0244 ud.drag_switch = true;
0245 
0246 % original x-range / y-range
0247 xlim = get(gca, 'XLim');
0248 ylim = get(gca, 'YLim');
0249 
0250 axis_ends = [];
0251 axis_ends = vb_axisends_set(axis_ends, 'ORIGINAL', 'X', xlim(1), xlim(2));
0252 axis_ends = vb_axisends_set(axis_ends, 'PREVIOUS', 'X', xlim(1), xlim(2));
0253 axis_ends = vb_axisends_set(axis_ends, 'SLIDER',   'X', xlim(1), xlim(2));
0254 
0255 axis_ends = vb_axisends_set(axis_ends, 'ORIGINAL', 'Y', ylim(1), ylim(2));
0256 axis_ends = vb_axisends_set(axis_ends, 'PREVIOUS', 'Y', ylim(1), ylim(2));
0257 axis_ends = vb_axisends_set(axis_ends, 'SLIDER',   'Y', ylim(1), ylim(2));
0258 
0259 ud.axis_ends = axis_ends;
0260 
0261 set(gcf, 'UserData', ud);
0262 set(gcf, 'Tag', DPT_FIGURE_TAG);
0263   
0264 %
0265 % --- set initial controllers' properties
0266 %
0267 if ud.drag_switch == true
0268   mode_str = DPT_LBL_MODE_RANGE;
0269 else
0270   mode_str = DPT_LBL_MODE_LINE;
0271 end
0272 
0273 % --- ZOOM SLIDER
0274 %
0275 SLD_L = 50;
0276 SLD_B = 10;
0277 SLD_W = 100;
0278 SLD_H = 15;
0279 
0280 % --- zoom X
0281 LBL_W = 50;
0282 LBL_H = SLD_H;
0283 LEFT = SLD_L;
0284 uicontrol('Tag', 'zoom_x_label', ...
0285   'Style','Text', ...
0286   'String',DPT_LBL_X_ZOOM, ...
0287   'Position',[LEFT SLD_B LBL_W LBL_H]);
0288 
0289 LEFT = LEFT + LBL_W;
0290 
0291 sld_x = uicontrol('Tag', DPT_CTRL_TAG_ZOOM_X, ...
0292   'Style','Slider', ...
0293   'Min',1, 'Max',MAX_ZOOM_RANGE, ...
0294   'SliderStep', [1/MAX_ZOOM_RANGE 10/MAX_ZOOM_RANGE], ...
0295   'Value', 1, ...
0296     'Callback',['vb_cb_clip_trigger(''zoom_slide_x'')'], ...
0297   'Position',[LEFT SLD_B SLD_W SLD_H]);
0298 
0299 % --- zoom Y
0300 SLD_Y_L = 30;
0301 SLD_Y_B = 50;
0302 SLD_Y_W = SLD_H;
0303 SLD_Y_H = SLD_W;
0304 sld_y = uicontrol('Tag', DPT_CTRL_TAG_ZOOM_Y, ...
0305   'Style','Slider', ...
0306   'Min',1, 'Max',MAX_ZOOM_RANGE, ...
0307   'SliderStep', [1/MAX_ZOOM_RANGE 10/MAX_ZOOM_RANGE], ...
0308   'Value', 1, ...
0309     'Callback',['vb_cb_clip_trigger(''zoom_slide_y'')'], ...
0310   'Position',[SLD_Y_L SLD_Y_B SLD_Y_W SLD_Y_H]);
0311 
0312 LBL_Y_L = 5;
0313 LBL_Y_B = SLD_Y_B + SLD_Y_H;
0314 uicontrol('Tag', DPT_LBL_Y_ZOOM, ...
0315   'Style', 'Text', ...
0316   'String', DPT_LBL_Y_ZOOM, ...
0317   'Position',[LBL_Y_L LBL_Y_B LBL_W LBL_H]);
0318 
0319 % --- move Y
0320 SLD_Y_L = SLD_Y_L;
0321 SLD_Y_B = LBL_Y_B + LBL_H + 10;
0322 SLD_Y_W = SLD_H;
0323 SLD_Y_H = SLD_W;
0324 sld_y = uicontrol('Tag', DPT_CTRL_TAG_ZOOM_Y, ...
0325   'Style','Slider', ...
0326   'Min',-100, 'Max',MAX_ZOOM_RANGE, ...
0327   'SliderStep', [1/MAX_ZOOM_RANGE 10/MAX_ZOOM_RANGE], ...
0328   'Value', 0, ...
0329     'Callback',['vb_cb_clip_trigger(''move_slide_y'')'], ...
0330   'Position',[SLD_Y_L SLD_Y_B SLD_Y_W SLD_Y_H]);
0331 
0332 % LBL_Y_L = 5;
0333 LBL_Y_B = SLD_Y_B + SLD_Y_H;
0334 uicontrol('Tag', DPT_LBL_Y_MOVE, ...
0335   'Style', 'Text', ...
0336   'String', DPT_LBL_Y_MOVE, ...
0337   'Position',[LBL_Y_L LBL_Y_B LBL_W LBL_H]);
0338 
0339 %
0340 % --- base coordinats of control buttons
0341 %
0342 BTN_L = LEFT + SLD_W + 20;  % left
0343 BTN_B = SLD_B;              % buttom
0344 BTN_W = 80;                 % width
0345 BTN_H = 20;                 % height
0346 BTN_I = BTN_W + 5;          % interval between left positions of buttons
0347 
0348 % --- MODE SWITCH LABEL
0349 %
0350 LEFT = BTN_L;
0351 
0352 % --- MODE SWITCH
0353 %
0354 % LEFT = LEFT + BTN_I;
0355 control_btn_1 = uicontrol(gcf, ...
0356   'Tag',   DPT_CTRL_TAG_MODE_SWITCH, ...
0357   'Style', 'Pushbutton', ...
0358   'Position', [LEFT BTN_B BTN_W BTN_H], ...
0359   'String', mode_str, ...
0360   'Callback', ['vb_cb_clip_trigger(''mode'')'] ...
0361   );
0362 
0363 % --- ZOOMIN
0364 %
0365 LEFT = LEFT + BTN_I;
0366 control_btn_2 = uicontrol(gcf, ...
0367   'Style', 'Pushbutton', ...
0368   'Position', [LEFT BTN_B BTN_W BTN_H], ...
0369   'String', DPT_LBL_ZOOMIN, ...
0370   'Callback', ['vb_cb_clip_trigger(''zoomin'')'] ...
0371   );
0372 
0373 % --- PREVIOUS
0374 %
0375 LEFT = LEFT + BTN_I;
0376 control_btn_3 = uicontrol(gcf, ...
0377   'Style', 'Pushbutton', ...
0378   'Position', [LEFT BTN_B BTN_W BTN_H], ...
0379   'String', DPT_LBL_PREVIOUS, ...
0380   'Callback', ['vb_cb_clip_trigger(''prev'')'] ...
0381   );
0382 
0383 % --- RESTORE
0384 %
0385 % RESTORE_LABEL = 'Restore';
0386 LEFT = LEFT + BTN_I;
0387 control_btn_4 = uicontrol(gcf, ...
0388   'Style', 'Pushbutton', ...
0389   'Position', [LEFT BTN_B BTN_W BTN_H], ...
0390   'String', DPT_LBL_INITIALIZE, ...
0391   'Callback', ['vb_cb_clip_trigger(''restore'')'] ...
0392   );
0393 
0394 % --- SAVE
0395 %
0396 LEFT = LEFT + BTN_I;
0397 control_btn_5 = uicontrol(gcf, ...
0398   'Style', 'Pushbutton', ...
0399   'Position', [LEFT BTN_B BTN_W BTN_H], ...
0400   'String', DPT_LBL_SAVE, ...
0401   'Callback', ['vb_cb_clip_trigger(''save'')'] ...
0402   );
0403 
0404 % --- AUX
0405 %
0406 % LEFT = LEFT + BTN_I;
0407 % control_btn_6 = uicontrol(gcf, ...
0408 %   'Style', 'Pushbutton', ...
0409 %   'Position', [LEFT BTN_B BTN_W BTN_H], ...
0410 %   'String', 'aux_1', ...
0411 %   'Callback', ['vb_cb_clip_trigger(''aux_1'')'] ...
0412 %   );
0413 
0414 select_xrange('init', gca);
0415 %
0416 % --- end of inner_set_controls()
0417 
0418 %%% END OF FILE %%%

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