4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "bcdisplayinfo.h"
26 #include "edlsession.h"
28 #include "motion-cv.h"
29 #include "motionwindow-cv.h"
31 #include "pluginserver.h"
33 MotionCVWindow::MotionCVWindow(MotionCVMain *plugin)
34 : PluginClientWindow(plugin, 815, 600, 815, 600, 0)
36 this->plugin = plugin;
39 MotionCVWindow::~MotionCVWindow()
43 void MotionCVWindow::create_objects()
45 int x1 = 10, x = 10, y = 10;
49 add_subwindow(global = new MotionCVGlobal(plugin, this, x1, y));
50 add_subwindow(rotate = new MotionCVRotate(plugin, this, x2, y));
53 add_subwindow(title = new BC_Title(x1, y,
54 _("Translation search radius:\n(W/H Percent of image)")));
55 add_subwindow(global_range_w = new GlobalRange(plugin,
56 x1 + title->get_w() + 10, y,
57 &plugin->config.global_range_w));
58 add_subwindow(global_range_h = new GlobalRange(plugin,
59 x1 + title->get_w() + 30 + global_range_w->get_w(), y,
60 &plugin->config.global_range_h));
62 add_subwindow(title = new BC_Title(x2, y,
63 _("Rotation search radius:\n(Degrees)")));
64 add_subwindow(rotation_range =
65 new RotationRange(plugin, x2 + title->get_w() + 10, y));
68 add_subwindow(title = new BC_Title(x1, y,
69 _("Translation block size:\n(W/H Percent of image)")));
70 add_subwindow(global_block_w = new BlockSize(plugin,
71 x1 + title->get_w() + 10, y,
72 &plugin->config.global_block_w));
73 add_subwindow(global_block_h = new BlockSize(plugin,
74 x1 + title->get_w() + 30 + global_block_w->get_w(), y,
75 &plugin->config.global_block_h));
77 add_subwindow(title = new BC_Title(x2, y,
78 _("Rotation block size:\n(W/H Percent of image)")));
79 add_subwindow(rotation_block_w = new BlockSize(plugin,
80 x2 + title->get_w() + 10, y,
81 &plugin->config.rotation_block_w));
82 add_subwindow(rotation_block_h = new BlockSize(plugin,
83 x2 + title->get_w() + 30 + rotation_block_w->get_w(), y,
84 &plugin->config.rotation_block_h));
87 add_subwindow(title = new BC_Title(x1, y, _("Translation search steps:")));
88 add_subwindow(global_search_positions = new GlobalSearchPositions(plugin,
89 x1 + title->get_w() + 10, y, 80));
90 global_search_positions->create_objects();
92 add_subwindow(title = new BC_Title(x2, y, _("Rotation search steps:")));
93 add_subwindow(rotation_search_positions = new RotationSearchPositions(plugin,
94 x2 + title->get_w() + 10, y, 80));
95 rotation_search_positions->create_objects();
98 add_subwindow(title = new BC_Title(x, y, _("Translation direction:")));
99 add_subwindow(mode3 = new Mode3(plugin,
100 this, x + title->get_w() + 10, y));
101 mode3->create_objects();
104 add_subwindow(title = new BC_Title(x2, y, _("Tracking file:")));
105 add_subwindow(tracking_file = new MotionCVTrackingFile(plugin,
106 plugin->config. tracking_file, this,
107 x2 + title->get_w() + 20, y));
108 y1 += tracking_file->get_h() + 10;
110 add_subwindow(title = new BC_Title(x, y + 10, _("Block X:")));
111 add_subwindow(block_x = new MotionCVBlockX(plugin, this,
112 x + title->get_w() + 10, y));
113 add_subwindow(block_x_text = new MotionCVBlockXText(plugin,
114 this, x + title->get_w() + 10 + block_x->get_w() + 10, y + 10));
117 add_subwindow(title = new BC_Title(x, y + 10, _("Block Y:")));
118 add_subwindow(block_y = new MotionCVBlockY(plugin, this,
119 x + title->get_w() + 10, y));
120 add_subwindow(block_y_text = new MotionCVBlockYText(plugin, this,
121 x + title->get_w() + 10 + block_y->get_w() + 10, y + 10));
123 add_subwindow(title = new BC_Title(x2, y1 + 10, _("Maximum absolute offset:")));
124 add_subwindow(magnitude = new MotionCVMagnitude(plugin,
125 x2 + title->get_w() + 10, y1));
128 add_subwindow(title = new BC_Title(x2, y1 + 10, _("Settling speed:")));
129 add_subwindow(return_speed = new MotionCVReturnSpeed(plugin,
130 x2 + title->get_w() + 10, y1));
133 add_subwindow(vectors = new MotionCVDrawVectors(plugin, this, x2, y1));
134 y = y1 + vectors->get_h() + 10;
137 add_subwindow(track_single =
138 new TrackSingleFrame(plugin, this, x1, y1));
140 add_subwindow(track_previous = new TrackPreviousFrame(plugin, this, x, y));
142 add_subwindow(previous_same = new PreviousFrameSameBlock(plugin, this, x, y));
145 add_subwindow(title = new BC_Title(x, y, _("Master layer:")));
146 add_subwindow(master_layer = new MasterLayer(plugin, this,
147 x + title->get_w() + 10, y));
148 master_layer->create_objects();
149 add_subwindow(title =
150 new BC_Title(x1=x2, y1=y, _("Frame number:")));
151 add_subwindow(track_frame_number =
152 new TrackFrameNumber(plugin, this, x1 += title->get_w(), y1));
153 add_subwindow(addtrackedframeoffset =
154 new AddTrackedFrameOffset(plugin, this, x1=x2, y1+=track_frame_number->get_h()));
155 int pef = client->server->mwindow->edl->session->video_every_frame;
156 add_subwindow(pef_title = new BC_Title(x1=x2+50, y1+=addtrackedframeoffset->get_h() + 5,
157 !pef ? _("For best results\n"
158 " Set: Play every frame\n"
159 " Preferences-> Playback-> Video Out") :
160 _("Currently using: Play every frame"), MEDIUMFONT,
161 !pef ? RED : GREEN));
164 add_subwindow(title = new BC_Title(x, y, _("Action:")));
165 add_subwindow(mode1 = new Mode1(plugin, this,
166 x + title->get_w() + 10, y));
167 mode1->create_objects();
170 add_subwindow(title = new BC_Title(x, y, _("Calculation:")));
171 add_subwindow(mode2 = new Mode2(plugin, this,
172 x + title->get_w() + 10, y));
173 mode2->create_objects();
178 void MotionCVWindow::update_mode()
180 global_range_w->update(plugin->config.global_range_w, MIN_RADIUS, MAX_RADIUS);
181 global_range_h->update(plugin->config.global_range_h, MIN_RADIUS, MAX_RADIUS);
182 rotation_range->update(plugin->config.rotation_range, MIN_ROTATION, MAX_ROTATION);
183 vectors->update(plugin->config.draw_vectors);
184 tracking_file->update(plugin->config.tracking_file);
185 global->update(plugin->config.global);
186 rotate->update(plugin->config.rotate);
187 addtrackedframeoffset->update(plugin->config.addtrackedframeoffset);
190 GlobalRange::GlobalRange(MotionCVMain *plugin, int x, int y, int *value)
191 :BC_IPot(x, y, (int64_t) * value, (int64_t) MIN_RADIUS, (int64_t) MAX_RADIUS)
193 this->plugin = plugin;
197 int GlobalRange::handle_event()
199 *value = (int)get_value();
200 plugin->send_configure_change();
204 RotationRange::RotationRange(MotionCVMain *plugin, int x, int y)
207 y, (int64_t) plugin->config.rotation_range,
208 (int64_t) MIN_ROTATION, (int64_t) MAX_ROTATION)
210 this->plugin = plugin;
213 int RotationRange::handle_event()
215 plugin->config.rotation_range = (int)get_value();
216 plugin->send_configure_change();
220 BlockSize::BlockSize(MotionCVMain *plugin, int x, int y, int *value)
221 : BC_IPot(x, y, (int64_t) * value, (int64_t) MIN_BLOCK, (int64_t) MAX_BLOCK)
223 this->plugin = plugin;
227 int BlockSize::handle_event()
229 *value = (int)get_value();
230 plugin->send_configure_change();
234 GlobalSearchPositions::GlobalSearchPositions(MotionCVMain *plugin,
236 : BC_PopupMenu(x, y, w, "", 1)
238 this->plugin = plugin;
241 void GlobalSearchPositions::create_objects()
243 add_item(new BC_MenuItem("64"));
244 add_item(new BC_MenuItem("128"));
245 add_item(new BC_MenuItem("256"));
246 add_item(new BC_MenuItem("512"));
247 add_item(new BC_MenuItem("1024"));
248 add_item(new BC_MenuItem("2048"));
249 add_item(new BC_MenuItem("4096"));
250 add_item(new BC_MenuItem("8192"));
251 add_item(new BC_MenuItem("16384"));
252 add_item(new BC_MenuItem("32768"));
253 add_item(new BC_MenuItem("65536"));
254 add_item(new BC_MenuItem("131072"));
255 char string[BCTEXTLEN];
256 sprintf(string, "%d", plugin->config.global_positions);
260 int GlobalSearchPositions::handle_event()
262 plugin->config.global_positions = atoi(get_text());
263 plugin->send_configure_change();
267 RotationSearchPositions::RotationSearchPositions(MotionCVMain *plugin,
269 : BC_PopupMenu(x, y, w, "", 1)
271 this->plugin = plugin;
274 void RotationSearchPositions::create_objects()
276 add_item(new BC_MenuItem("4"));
277 add_item(new BC_MenuItem("8"));
278 add_item(new BC_MenuItem("16"));
279 add_item(new BC_MenuItem("32"));
280 char string[BCTEXTLEN];
281 sprintf(string, "%d", plugin->config.rotate_positions);
285 int RotationSearchPositions::handle_event()
287 plugin->config.rotate_positions = atoi(get_text());
288 plugin->send_configure_change();
292 MotionCVMagnitude::MotionCVMagnitude(MotionCVMain *plugin, int x, int y)
293 : BC_IPot(x, y, (int64_t) plugin->config.magnitude, (int64_t) 0, (int64_t) 100)
295 this->plugin = plugin;
298 int MotionCVMagnitude::handle_event()
300 plugin->config.magnitude = (int)get_value();
301 plugin->send_configure_change();
305 MotionCVReturnSpeed::MotionCVReturnSpeed(MotionCVMain *plugin, int x, int y)
306 : BC_IPot(x, y, (int64_t) plugin->config.return_speed, (int64_t) 0, (int64_t) 100)
308 this->plugin = plugin;
311 int MotionCVReturnSpeed::handle_event()
313 plugin->config.return_speed = (int)get_value();
314 plugin->send_configure_change();
318 AddTrackedFrameOffset::AddTrackedFrameOffset(MotionCVMain *plugin,
319 MotionCVWindow *gui, int x, int y)
320 : BC_CheckBox(x, y, plugin->config.addtrackedframeoffset,
321 _("Add (loaded) offset from tracked frame"))
323 this->plugin = plugin;
327 int AddTrackedFrameOffset::handle_event()
329 plugin->config.addtrackedframeoffset = get_value();
330 plugin->send_configure_change();
334 MotionCVTrackingFile::MotionCVTrackingFile(MotionCVMain *plugin,
335 const char *filename, MotionCVWindow *gui, int x, int y)
336 : BC_TextBox(x, y, 250, 1, filename)
338 this->plugin = plugin;
342 int MotionCVTrackingFile::handle_event()
344 strcpy(plugin->config.tracking_file, get_text());
345 plugin->send_configure_change();
349 MotionCVGlobal::MotionCVGlobal(MotionCVMain *plugin,
350 MotionCVWindow *gui, int x, int y)
351 :BC_CheckBox(x, y, plugin->config.global, _("Track translation"))
353 this->plugin = plugin;
357 int MotionCVGlobal::handle_event()
359 plugin->config.global = get_value();
360 plugin->send_configure_change();
364 MotionCVRotate::MotionCVRotate(MotionCVMain *plugin,
365 MotionCVWindow *gui, int x, int y)
366 : BC_CheckBox(x, y, plugin->config.rotate, _("Track rotation"))
368 this->plugin = plugin;
372 int MotionCVRotate::handle_event()
374 plugin->config.rotate = get_value();
375 plugin->send_configure_change();
379 MotionCVBlockX::MotionCVBlockX(MotionCVMain *plugin,
380 MotionCVWindow *gui, int x, int y)
381 : BC_FPot(x, y, plugin->config.block_x, (float)0, (float)100)
383 this->plugin = plugin;
387 int MotionCVBlockX::handle_event()
389 plugin->config.block_x = get_value();
390 gui->block_x_text->update((float)plugin->config.block_x);
391 plugin->send_configure_change();
395 MotionCVBlockY::MotionCVBlockY(MotionCVMain *plugin,
396 MotionCVWindow *gui, int x, int y)
397 : BC_FPot(x, y, (float)plugin->config.block_y, (float)0, (float)100)
399 this->plugin = plugin;
403 int MotionCVBlockY::handle_event()
405 plugin->config.block_y = get_value();
406 gui->block_y_text->update((float)plugin->config.block_y);
407 plugin->send_configure_change();
411 MotionCVBlockXText::MotionCVBlockXText(MotionCVMain *plugin,
412 MotionCVWindow *gui, int x, int y)
413 : BC_TextBox(x, y, 75, 1, (float)plugin->config.block_x)
415 this->plugin = plugin;
420 int MotionCVBlockXText::handle_event()
422 plugin->config.block_x = atof(get_text());
423 gui->block_x->update(plugin->config.block_x);
424 plugin->send_configure_change();
428 MotionCVBlockYText::MotionCVBlockYText(MotionCVMain *plugin,
429 MotionCVWindow *gui, int x, int y)
430 : BC_TextBox(x, y, 75, 1, (float)plugin->config.block_y)
432 this->plugin = plugin;
437 int MotionCVBlockYText::handle_event()
439 plugin->config.block_y = atof(get_text());
440 gui->block_y->update(plugin->config.block_y);
441 plugin->send_configure_change();
445 MotionCVDrawVectors::MotionCVDrawVectors(MotionCVMain *plugin,
446 MotionCVWindow *gui, int x, int y)
447 : BC_CheckBox(x, y, plugin->config.draw_vectors, _("Draw vectors"))
450 this->plugin = plugin;
453 int MotionCVDrawVectors::handle_event()
455 plugin->config.draw_vectors = get_value();
456 plugin->send_configure_change();
460 TrackSingleFrame::TrackSingleFrame(MotionCVMain *plugin,
461 MotionCVWindow *gui, int x, int y)
464 y, plugin->config.mode3 == MotionCVConfig::TRACK_SINGLE,
465 _("Track single frame"))
467 this->plugin = plugin;
471 int TrackSingleFrame::handle_event()
473 plugin->config.mode3 = MotionCVConfig::TRACK_SINGLE;
474 gui->track_previous->update(0);
475 gui->previous_same->update(0);
476 gui->track_frame_number->enable();
477 plugin->send_configure_change();
481 TrackFrameNumber::TrackFrameNumber(MotionCVMain *plugin,
482 MotionCVWindow *gui, int x, int y)
483 : BC_TextBox(x, y, 100, 1, plugin->config.track_frame)
485 this->plugin = plugin;
487 if( plugin->config.mode3 != MotionCVConfig::TRACK_SINGLE )
491 int TrackFrameNumber::handle_event()
493 plugin->config.track_frame = atol(get_text());
494 plugin->send_configure_change();
498 TrackPreviousFrame::TrackPreviousFrame(MotionCVMain *plugin,
499 MotionCVWindow *gui, int x, int y)
502 y, plugin->config.mode3 == MotionCVConfig::TRACK_PREVIOUS,
503 _("Track previous frame"))
505 this->plugin = plugin;
509 int TrackPreviousFrame::handle_event()
511 plugin->config.mode3 = MotionCVConfig::TRACK_PREVIOUS;
512 gui->track_single->update(0);
513 gui->previous_same->update(0);
514 gui->track_frame_number->disable();
515 plugin->send_configure_change();
519 PreviousFrameSameBlock::PreviousFrameSameBlock(MotionCVMain *plugin,
520 MotionCVWindow *gui, int x, int y)
523 y, plugin->config.mode3 == MotionCVConfig::PREVIOUS_SAME_BLOCK,
524 _("Previous frame same block"))
526 this->plugin = plugin;
530 int PreviousFrameSameBlock::handle_event()
532 plugin->config.mode3 = MotionCVConfig::PREVIOUS_SAME_BLOCK;
533 gui->track_single->update(0);
534 gui->track_previous->update(0);
535 gui->track_frame_number->disable();
536 plugin->send_configure_change();
540 MasterLayer::MasterLayer(MotionCVMain *plugin, MotionCVWindow *gui, int x,
542 : BC_PopupMenu(x, y, calculate_w(gui),
543 to_text(plugin->config.bottom_is_master))
545 this->plugin = plugin;
549 int MasterLayer::handle_event()
551 plugin->config.bottom_is_master = from_text(get_text());
552 plugin->send_configure_change();
556 void MasterLayer::create_objects()
558 add_item(new BC_MenuItem(to_text(0)));
559 add_item(new BC_MenuItem(to_text(1)));
562 int MasterLayer::from_text(char *text)
564 if( !strcmp(text, _("Top")) ) return 0;
568 const char *MasterLayer::to_text(int mode)
570 return mode ? _("Bottom") : _("Top");
573 int MasterLayer::calculate_w(MotionCVWindow *gui)
576 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(0)));
577 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(1)));
581 Mode1::Mode1(MotionCVMain *plugin, MotionCVWindow *gui, int x, int y)
582 : BC_PopupMenu(x, y, calculate_w(gui), to_text(plugin->config.mode1))
584 this->plugin = plugin;
588 int Mode1::handle_event()
590 plugin->config.mode1 = from_text(get_text());
591 plugin->send_configure_change();
595 void Mode1::create_objects()
597 add_item(new BC_MenuItem(to_text(MotionCVConfig::TRACK)));
598 add_item(new BC_MenuItem(to_text(MotionCVConfig::TRACK_PIXEL)));
599 add_item(new BC_MenuItem(to_text(MotionCVConfig::STABILIZE)));
600 add_item(new BC_MenuItem(to_text(MotionCVConfig::STABILIZE_PIXEL)));
601 add_item(new BC_MenuItem(to_text(MotionCVConfig::NOTHING)));
604 int Mode1::from_text(char *text)
606 if( !strcmp(text, _("Track Subpixel")) ) return MotionCVConfig::TRACK;
607 if( !strcmp(text, _("Track Pixel")) ) return MotionCVConfig::TRACK_PIXEL;
608 if( !strcmp(text, _("Stabilize Subpixel")) ) return MotionCVConfig::STABILIZE;
609 if( !strcmp(text, _("Stabilize Pixel")) ) return MotionCVConfig::STABILIZE_PIXEL;
610 //if( !strcmp(text, _("Do Nothing")) ) return MotionCVConfig::NOTHING;
611 return MotionCVConfig::NOTHING;
614 const char *Mode1::to_text(int mode)
617 case MotionCVConfig::TRACK: return _("Track Subpixel");
618 case MotionCVConfig::TRACK_PIXEL: return _("Track Pixel");
619 case MotionCVConfig::STABILIZE: return _("Stabilize Subpixel");
620 case MotionCVConfig::STABILIZE_PIXEL: return _("Stabilize Pixel");
621 case MotionCVConfig::NOTHING: return _("Do Nothing");
626 int Mode1::calculate_w(MotionCVWindow *gui)
629 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionCVConfig::TRACK)));
630 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionCVConfig::TRACK_PIXEL)));
631 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionCVConfig::STABILIZE)));
632 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionCVConfig::STABILIZE_PIXEL)));
633 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionCVConfig::NOTHING)));
637 Mode2::Mode2(MotionCVMain *plugin, MotionCVWindow *gui, int x, int y)
638 : BC_PopupMenu(x, y, calculate_w(gui), to_text(plugin->config.mode2))
640 this->plugin = plugin;
644 int Mode2::handle_event()
646 plugin->config.mode2 = from_text(get_text());
647 plugin->send_configure_change();
651 void Mode2::create_objects()
653 add_item(new BC_MenuItem(to_text(MotionCVConfig::SAVE)));
654 add_item(new BC_MenuItem(to_text(MotionCVConfig::LOAD)));
655 add_item(new BC_MenuItem(to_text(MotionCVConfig::RECALCULATE)));
656 add_item(new BC_MenuItem(to_text(MotionCVConfig::NO_CALCULATE)));
659 int Mode2::from_text(char *text)
661 if( !strcmp(text, _("Recalculate")) ) return MotionCVConfig::RECALCULATE;
662 if( !strcmp(text, _("Save coords to tracking file")) ) return MotionCVConfig::SAVE;
663 if( !strcmp(text, _("Load coords from tracking file")) ) return MotionCVConfig::LOAD;
664 //if( !strcmp(text, _("Don't Calculate")) ) return MotionCVConfig::NO_CALCULATE;
665 return MotionCVConfig::NO_CALCULATE;
668 const char *Mode2::to_text(int mode)
671 case MotionCVConfig::NO_CALCULATE: return _("Don't Calculate");
672 case MotionCVConfig::RECALCULATE: return _("Recalculate");
673 case MotionCVConfig::SAVE: return _("Save coords to tracking file");
674 case MotionCVConfig::LOAD: return _("Load coords from tracking file");
679 int Mode2::calculate_w(MotionCVWindow *gui)
682 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionCVConfig::NO_CALCULATE)));
683 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionCVConfig::RECALCULATE)));
684 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionCVConfig::SAVE)));
685 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionCVConfig::LOAD)));
689 Mode3::Mode3(MotionCVMain *plugin, MotionCVWindow *gui, int x, int y)
691 BC_PopupMenu(x, y, calculate_w(gui),
692 to_text(plugin->config.horizontal_only, plugin->config.vertical_only))
694 this->plugin = plugin;
698 int Mode3::handle_event()
700 from_text(&plugin->config.horizontal_only,
701 &plugin->config.vertical_only, get_text());
702 plugin->send_configure_change();
706 void Mode3::create_objects()
708 add_item(new BC_MenuItem(to_text(1, 0)));
709 add_item(new BC_MenuItem(to_text(0, 1)));
710 add_item(new BC_MenuItem(to_text(0, 0)));
713 void Mode3::from_text(int *horizontal_only, int *vertical_only, char *text)
715 *horizontal_only = 0;
717 if( !strcmp(text, to_text(1, 0)) ) *horizontal_only = 1;
718 if( !strcmp(text, to_text(0, 1)) ) *vertical_only = 1;
721 const char *Mode3::to_text(int horizontal_only, int vertical_only)
723 if( horizontal_only ) return _("Horizontal only");
724 if( vertical_only ) return _("Vertical only");
728 int Mode3::calculate_w(MotionCVWindow *gui)
731 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(1, 0)));
732 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(0, 1)));
733 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(0, 0)));