0001 function vb_cb_clip_trigger(state)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027 vb_define_process_trigger;
0028
0029 VERBOSE = true;
0030
0031 if ~exist('state', 'var')
0032 state = [];
0033 end
0034
0035
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
0045
0046 if isempty(state)
0047 if VERBOSE fprintf('no state\n'); end;
0048 return;
0049 end
0050
0051
0052
0053 switch state
0054
0055
0056
0057
0058
0059
0060 case 'down'
0061
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);
0069 y = cp(1,2);
0070
0071 if inner_is_select_switch_on
0072
0073 return;
0074
0075 elseif strcmp(tag, DPT_TRIGGERLINE_TAG)
0076
0077
0078 inner_delete_line(VERBOSE);
0079
0080 else
0081
0082 inner_draw_line(trigger_line_gap, trigger_line_clr, x, VERBOSE);
0083 end
0084
0085
0086
0087
0088 case 'move'
0089
0090
0091 ud = get(gcf, 'UserData');
0092 if ud.drag_switch == false
0093 return;
0094 end
0095
0096
0097 select_xrange('move', gca);
0098
0099
0100
0101
0102
0103 case 'up'
0104
0105
0106
0107 return;
0108
0109
0110
0111
0112
0113
0114
0115
0116 case 'mode'
0117 if VERBOSE, fprintf('[callback] state : %s\n', state); end;
0118 inner_switch_mode(VERBOSE);
0119
0120
0121
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
0129
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
0142
0143 case 'prev'
0144 if VERBOSE fprintf('[callback] state : %s\n', state); end;
0145 ud = get(gcf, 'UserData');
0146
0147
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
0154
0155 case 'restore'
0156 if VERBOSE fprintf('[callback] state : %s\n', state); end;
0157 ud = get(gcf, 'UserData');
0158
0159
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
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
0180 inner_save(VERBOSE);
0181
0182
0183
0184
0185 case 'zoom_slide_x'
0186 if VERBOSE fprintf('[callback] state : %s\n', state); end;
0187
0188
0189 ud = get(gcf, 'UserData');
0190
0191
0192
0193
0194
0195 value = get(gco,'Value');
0196
0197
0198
0199
0200 [base.begin, base.end] = vb_axisends_get(ud.axis_ends, 'SLIDER', 'X');
0201
0202 new_begin = base.begin;
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
0213 return;
0214
0215
0216
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
0225
0226 [base.begin, base.end] = vb_axisends_get(ud.axis_ends, 'SLIDER', 'Y');
0227
0228 new_begin = base.begin;
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
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
0254
0255 case 'aux_1'
0256 if VERBOSE fprintf('[callback] state : %s\n', state); end;
0257 inner_aux1(VERBOSE);
0258
0259
0260
0261 otherwise
0262 warning('unimplemented state : %s', state);
0263 end
0264
0265
0266
0267
0268
0269
0270
0271
0272
0273
0274
0275 function inner_zoom(x_range, y_range, VERBOSE)
0276
0277 vb_define_process_trigger;
0278
0279
0280
0281 ud = get(gcf, 'UserData');
0282
0283
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
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
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
0337
0338 set(gcf, 'UserData', ud);
0339
0340
0341
0342 inner_reset_selected_region;
0343
0344
0345
0346
0347
0348
0349 function inner_slider_zoom(range, tag, VERBOSE)
0350
0351 [new_begin, new_end] = inner_get_real_begin_end(range);
0352
0353
0354
0355 ud = get(gcf, 'UserData');
0356
0357
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
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
0374
0375 set(gcf, 'UserData', ud);
0376
0377
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
0385
0386
0387
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
0414
0415
0416
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
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
0447
0448
0449
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
0460
0461
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
0475
0476
0477
0478 function inner_aux1(VERBOSE)
0479
0480
0481 return;
0482
0483
0484
0485
0486
0487
0488 function [result] = inner_is_select_switch_on
0489 ud = get(gcf, 'UserData');
0490 result = ud.drag_switch;
0491
0492
0493
0494
0495
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
0507
0508
0509
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
0520 ud = get(gcf, 'UserData');
0521
0522 if strcmp(XY_TAG, 'Y')
0523 lim = get(gca, 'YLim');
0524 else
0525 lim = get(gca, 'XLim');
0526 end
0527
0528 [base.begin, base.end] = vb_axisends_get(ud.axis_ends, 'SLIDER', XY_TAG);
0529
0530
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
0543
0544
0545
0546
0547 function inner_reset_selected_region
0548 select_xrange('clear', gca);
0549 select_xrange('init', gca);
0550
0551
0552
0553