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"
25 #include "motion-cv.h"
26 #include "motionwindow-cv.h"
36 MotionCVWindow::MotionCVWindow(MotionCVMain *plugin)
37 : PluginClientWindow(plugin, 815, 650, 815, 650, 0)
39 this->plugin = plugin;
42 MotionCVWindow::~MotionCVWindow()
46 void MotionCVWindow::create_objects()
48 int x1 = 10, x = 10, y = 10;
54 add_subwindow(global = new MotionCVGlobal(plugin,
59 add_subwindow(rotate = new MotionCVRotate(plugin,
65 add_subwindow(title = new BC_Title(x1,
67 _("Translation search radius:\n(W/H Percent of image)")));
68 add_subwindow(global_range_w = new GlobalRange(plugin,
69 x1 + title->get_w() + 10,
71 &plugin->config.global_range_w));
72 add_subwindow(global_range_h = new GlobalRange(plugin,
73 x1 + title->get_w() + 30 + global_range_w->get_w(),
75 &plugin->config.global_range_h));
77 add_subwindow(title = new BC_Title(x2,
79 _("Rotation search radius:\n(Degrees)")));
80 add_subwindow(rotation_range = new RotationRange(plugin,
81 x2 + title->get_w() + 10,
85 add_subwindow(title = new BC_Title(x1,
87 _("Translation block size:\n(W/H Percent of image)")));
88 add_subwindow(global_block_w = new BlockSize(plugin,
89 x1 + title->get_w() + 10,
91 &plugin->config.global_block_w));
92 add_subwindow(global_block_h = new BlockSize(plugin,
93 x1 + title->get_w() + 30 + global_block_w->get_w(),
95 &plugin->config.global_block_h));
97 add_subwindow(title = new BC_Title(x2,
99 _("Rotation block size:\n(W/H Percent of image)")));
100 add_subwindow(rotation_block_w = new BlockSize(plugin,
101 x2 + title->get_w() + 10,
103 &plugin->config.rotation_block_w));
104 add_subwindow(rotation_block_h = new BlockSize(plugin,
105 x2 + title->get_w() + 30 + rotation_block_w->get_w(),
107 &plugin->config.rotation_block_h));
110 add_subwindow(title = new BC_Title(x1, y, _("Translation search steps:")));
111 add_subwindow(global_search_positions = new GlobalSearchPositions(plugin,
112 x1 + title->get_w() + 10,
115 global_search_positions->create_objects();
117 add_subwindow(title = new BC_Title(x2, y, _("Rotation search steps:")));
118 add_subwindow(rotation_search_positions = new RotationSearchPositions(plugin,
119 x2 + title->get_w() + 10,
122 rotation_search_positions->create_objects();
125 add_subwindow(title = new BC_Title(x, y, _("Translation direction:")));
126 add_subwindow(mode3 = new Mode3(plugin,
128 x + title->get_w() + 10,
130 mode3->create_objects();
133 add_subwindow(title = new BC_Title(x, y + 10, _("Block X:")));
134 add_subwindow(block_x = new MotionCVBlockX(plugin,
136 x + title->get_w() + 10,
138 add_subwindow(block_x_text = new MotionCVBlockXText(plugin,
140 x + title->get_w() + 10 + block_x->get_w() + 10,
144 add_subwindow(title = new BC_Title(x, y + 10, _("Block Y:")));
145 add_subwindow(block_y = new MotionCVBlockY(plugin,
147 x + title->get_w() + 10,
149 add_subwindow(block_y_text = new MotionCVBlockYText(plugin,
151 x + title->get_w() + 10 + block_y->get_w() + 10,
155 add_subwindow(title = new BC_Title(x, y + 10, _("Maximum absolute offset:")));
156 add_subwindow(magnitude = new MotionCVMagnitude(plugin,
157 x + title->get_w() + 10,
161 add_subwindow(title = new BC_Title(x, y + 10, _("Settling speed:")));
162 add_subwindow(return_speed = new MotionCVReturnSpeed(plugin,
163 x + title->get_w() + 10,
169 add_subwindow(vectors = new MotionCVDrawVectors(plugin,
174 add_subwindow(title = new BC_Title(x2, y, _("Tracking file:")));
175 add_subwindow(tracking_file = new MotionCVTrackingFile(plugin,
176 plugin->config.tracking_file, this, x2+title->get_w() + 20, y));
179 add_subwindow(track_single = new TrackSingleFrame(plugin,
183 add_subwindow(title = new BC_Title(x + track_single->get_w() + 20,
185 _("Frame number:")));
186 add_subwindow(track_frame_number = new TrackFrameNumber(plugin,
188 x + track_single->get_w() + title->get_w() + 20,
190 add_subwindow(addtrackedframeoffset = new AddTrackedFrameOffset(plugin,
192 x + track_single->get_w() + title->get_w() + 30,
193 y + track_single->get_h()));
197 add_subwindow(track_previous = new TrackPreviousFrame(plugin,
203 add_subwindow(previous_same = new PreviousFrameSameBlock(plugin,
210 add_subwindow(title = new BC_Title(x, y, _("Master layer:")));
211 add_subwindow(master_layer = new MasterLayer(plugin,
213 x + title->get_w() + 10,
215 master_layer->create_objects();
219 add_subwindow(title = new BC_Title(x, y, _("Action:")));
220 add_subwindow(mode1 = new Mode1(plugin,
222 x + title->get_w() + 10,
224 mode1->create_objects();
230 add_subwindow(title = new BC_Title(x, y, _("Calculation:")));
231 add_subwindow(mode2 = new Mode2(plugin,
233 x + title->get_w() + 10,
235 mode2->create_objects();
242 void MotionCVWindow::update_mode()
244 global_range_w->update(plugin->config.global_range_w,
247 global_range_h->update(plugin->config.global_range_h,
250 rotation_range->update(plugin->config.rotation_range,
253 vectors->update(plugin->config.draw_vectors);
254 tracking_file->update(plugin->config.tracking_file);
255 global->update(plugin->config.global);
256 rotate->update(plugin->config.rotate);
257 addtrackedframeoffset->update(plugin->config.addtrackedframeoffset);
271 GlobalRange::GlobalRange(MotionCVMain *plugin,
281 this->plugin = plugin;
286 int GlobalRange::handle_event()
288 *value = (int)get_value();
289 plugin->send_configure_change();
296 RotationRange::RotationRange(MotionCVMain *plugin,
301 (int64_t)plugin->config.rotation_range,
302 (int64_t)MIN_ROTATION,
303 (int64_t)MAX_ROTATION)
305 this->plugin = plugin;
309 int RotationRange::handle_event()
311 plugin->config.rotation_range = (int)get_value();
312 plugin->send_configure_change();
323 BlockSize::BlockSize(MotionCVMain *plugin,
333 this->plugin = plugin;
338 int BlockSize::handle_event()
340 *value = (int)get_value();
341 plugin->send_configure_change();
357 GlobalSearchPositions::GlobalSearchPositions(MotionCVMain *plugin,
367 this->plugin = plugin;
369 void GlobalSearchPositions::create_objects()
371 add_item(new BC_MenuItem("64"));
372 add_item(new BC_MenuItem("128"));
373 add_item(new BC_MenuItem("256"));
374 add_item(new BC_MenuItem("512"));
375 add_item(new BC_MenuItem("1024"));
376 add_item(new BC_MenuItem("2048"));
377 add_item(new BC_MenuItem("4096"));
378 add_item(new BC_MenuItem("8192"));
379 add_item(new BC_MenuItem("16384"));
380 add_item(new BC_MenuItem("32768"));
381 add_item(new BC_MenuItem("65536"));
382 add_item(new BC_MenuItem("131072"));
383 char string[BCTEXTLEN];
384 sprintf(string, "%d", plugin->config.global_positions);
388 int GlobalSearchPositions::handle_event()
390 plugin->config.global_positions = atoi(get_text());
391 plugin->send_configure_change();
401 RotationSearchPositions::RotationSearchPositions(MotionCVMain *plugin,
411 this->plugin = plugin;
413 void RotationSearchPositions::create_objects()
415 add_item(new BC_MenuItem("4"));
416 add_item(new BC_MenuItem("8"));
417 add_item(new BC_MenuItem("16"));
418 add_item(new BC_MenuItem("32"));
419 char string[BCTEXTLEN];
420 sprintf(string, "%d", plugin->config.rotate_positions);
424 int RotationSearchPositions::handle_event()
426 plugin->config.rotate_positions = atoi(get_text());
427 plugin->send_configure_change();
438 MotionCVMagnitude::MotionCVMagnitude(MotionCVMain *plugin,
443 (int64_t)plugin->config.magnitude,
447 this->plugin = plugin;
450 int MotionCVMagnitude::handle_event()
452 plugin->config.magnitude = (int)get_value();
453 plugin->send_configure_change();
458 MotionCVReturnSpeed::MotionCVReturnSpeed(MotionCVMain *plugin,
463 (int64_t)plugin->config.return_speed,
467 this->plugin = plugin;
470 int MotionCVReturnSpeed::handle_event()
472 plugin->config.return_speed = (int)get_value();
473 plugin->send_configure_change();
479 AddTrackedFrameOffset::AddTrackedFrameOffset(MotionCVMain *plugin,
485 plugin->config.addtrackedframeoffset,
486 _("Add (loaded) offset from tracked frame"))
488 this->plugin = plugin;
492 int AddTrackedFrameOffset::handle_event()
494 plugin->config.addtrackedframeoffset = get_value();
495 plugin->send_configure_change();
499 MotionCVTrackingFile::MotionCVTrackingFile(MotionCVMain *plugin,
500 const char *filename, MotionCVWindow *gui, int x, int y)
501 : BC_TextBox(x, y, 250, 1, filename)
503 this->plugin = plugin;
507 int MotionCVTrackingFile::handle_event()
509 strcpy(plugin->config.tracking_file, get_text());
510 plugin->send_configure_change();
514 MotionCVGlobal::MotionCVGlobal(MotionCVMain *plugin,
520 plugin->config.global,
521 _("Track translation"))
523 this->plugin = plugin;
527 int MotionCVGlobal::handle_event()
529 plugin->config.global = get_value();
530 plugin->send_configure_change();
534 MotionCVRotate::MotionCVRotate(MotionCVMain *plugin,
540 plugin->config.rotate,
543 this->plugin = plugin;
547 int MotionCVRotate::handle_event()
549 plugin->config.rotate = get_value();
550 plugin->send_configure_change();
558 MotionCVBlockX::MotionCVBlockX(MotionCVMain *plugin,
564 plugin->config.block_x,
568 this->plugin = plugin;
572 int MotionCVBlockX::handle_event()
574 plugin->config.block_x = get_value();
575 gui->block_x_text->update((float)plugin->config.block_x);
576 plugin->send_configure_change();
583 MotionCVBlockY::MotionCVBlockY(MotionCVMain *plugin,
589 (float)plugin->config.block_y,
593 this->plugin = plugin;
597 int MotionCVBlockY::handle_event()
599 plugin->config.block_y = get_value();
600 gui->block_y_text->update((float)plugin->config.block_y);
601 plugin->send_configure_change();
605 MotionCVBlockXText::MotionCVBlockXText(MotionCVMain *plugin,
613 (float)plugin->config.block_x)
615 this->plugin = plugin;
620 int MotionCVBlockXText::handle_event()
622 plugin->config.block_x = atof(get_text());
623 gui->block_x->update(plugin->config.block_x);
624 plugin->send_configure_change();
631 MotionCVBlockYText::MotionCVBlockYText(MotionCVMain *plugin,
639 (float)plugin->config.block_y)
641 this->plugin = plugin;
646 int MotionCVBlockYText::handle_event()
648 plugin->config.block_y = atof(get_text());
649 gui->block_y->update(plugin->config.block_y);
650 plugin->send_configure_change();
669 MotionCVDrawVectors::MotionCVDrawVectors(MotionCVMain *plugin,
675 plugin->config.draw_vectors,
679 this->plugin = plugin;
682 int MotionCVDrawVectors::handle_event()
684 plugin->config.draw_vectors = get_value();
685 plugin->send_configure_change();
696 TrackSingleFrame::TrackSingleFrame(MotionCVMain *plugin,
702 plugin->config.mode3 == MotionCVConfig::TRACK_SINGLE,
703 _("Track single frame"))
705 this->plugin = plugin;
709 int TrackSingleFrame::handle_event()
711 plugin->config.mode3 = MotionCVConfig::TRACK_SINGLE;
712 gui->track_previous->update(0);
713 gui->previous_same->update(0);
714 gui->track_frame_number->enable();
715 plugin->send_configure_change();
726 TrackFrameNumber::TrackFrameNumber(MotionCVMain *plugin,
730 : BC_TextBox(x, y, 100, 1, plugin->config.track_frame)
732 this->plugin = plugin;
734 if(plugin->config.mode3 != MotionCVConfig::TRACK_SINGLE) disable();
737 int TrackFrameNumber::handle_event()
739 plugin->config.track_frame = atol(get_text());
740 plugin->send_configure_change();
750 TrackPreviousFrame::TrackPreviousFrame(MotionCVMain *plugin,
756 plugin->config.mode3 == MotionCVConfig::TRACK_PREVIOUS,
757 _("Track previous frame"))
759 this->plugin = plugin;
762 int TrackPreviousFrame::handle_event()
764 plugin->config.mode3 = MotionCVConfig::TRACK_PREVIOUS;
765 gui->track_single->update(0);
766 gui->previous_same->update(0);
767 gui->track_frame_number->disable();
768 plugin->send_configure_change();
779 PreviousFrameSameBlock::PreviousFrameSameBlock(MotionCVMain *plugin,
785 plugin->config.mode3 == MotionCVConfig::PREVIOUS_SAME_BLOCK,
786 _("Previous frame same block"))
788 this->plugin = plugin;
791 int PreviousFrameSameBlock::handle_event()
793 plugin->config.mode3 = MotionCVConfig::PREVIOUS_SAME_BLOCK;
794 gui->track_single->update(0);
795 gui->track_previous->update(0);
796 gui->track_frame_number->disable();
797 plugin->send_configure_change();
808 MasterLayer::MasterLayer(MotionCVMain *plugin, MotionCVWindow *gui, int x, int y)
809 : BC_PopupMenu(x, y, calculate_w(gui),
810 to_text(plugin->config.bottom_is_master))
812 this->plugin = plugin;
816 int MasterLayer::handle_event()
818 plugin->config.bottom_is_master = from_text(get_text());
819 plugin->send_configure_change();
823 void MasterLayer::create_objects()
825 add_item(new BC_MenuItem(to_text(0)));
826 add_item(new BC_MenuItem(to_text(1)));
829 int MasterLayer::from_text(char *text)
831 if(!strcmp(text, _("Top"))) return 0;
835 const char* MasterLayer::to_text(int mode)
837 return mode ? _("Bottom") : _("Top");
840 int MasterLayer::calculate_w(MotionCVWindow *gui)
843 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(0)));
844 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(1)));
855 Mode1::Mode1(MotionCVMain *plugin, MotionCVWindow *gui, int x, int y)
856 : BC_PopupMenu(x, y, calculate_w(gui),
857 to_text(plugin->config.mode1))
859 this->plugin = plugin;
863 int Mode1::handle_event()
865 plugin->config.mode1 = from_text(get_text());
866 plugin->send_configure_change();
870 void Mode1::create_objects()
872 add_item(new BC_MenuItem(to_text(MotionCVConfig::TRACK)));
873 add_item(new BC_MenuItem(to_text(MotionCVConfig::TRACK_PIXEL)));
874 add_item(new BC_MenuItem(to_text(MotionCVConfig::STABILIZE)));
875 add_item(new BC_MenuItem(to_text(MotionCVConfig::STABILIZE_PIXEL)));
876 add_item(new BC_MenuItem(to_text(MotionCVConfig::NOTHING)));
879 int Mode1::from_text(char *text)
881 if(!strcmp(text, _("Track Subpixel"))) return MotionCVConfig::TRACK;
882 if(!strcmp(text, _("Track Pixel"))) return MotionCVConfig::TRACK_PIXEL;
883 if(!strcmp(text, _("Stabilize Subpixel"))) return MotionCVConfig::STABILIZE;
884 if(!strcmp(text, _("Stabilize Pixel"))) return MotionCVConfig::STABILIZE_PIXEL;
885 //if(!strcmp(text, _("Do Nothing"))) return MotionCVConfig::NOTHING;
886 return MotionCVConfig::NOTHING;
889 const char* Mode1::to_text(int mode)
892 case MotionCVConfig::TRACK: return _("Track Subpixel");
893 case MotionCVConfig::TRACK_PIXEL: return _("Track Pixel");
894 case MotionCVConfig::STABILIZE: return _("Stabilize Subpixel");
895 case MotionCVConfig::STABILIZE_PIXEL: return _("Stabilize Pixel");
896 case MotionCVConfig::NOTHING: return _("Do Nothing");
901 int Mode1::calculate_w(MotionCVWindow *gui)
904 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionCVConfig::TRACK)));
905 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionCVConfig::TRACK_PIXEL)));
906 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionCVConfig::STABILIZE)));
907 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionCVConfig::STABILIZE_PIXEL)));
908 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionCVConfig::NOTHING)));
916 Mode2::Mode2(MotionCVMain *plugin, MotionCVWindow *gui, int x, int y)
917 : BC_PopupMenu(x, y, calculate_w(gui),
918 to_text(plugin->config.mode2))
920 this->plugin = plugin;
924 int Mode2::handle_event()
926 plugin->config.mode2 = from_text(get_text());
927 plugin->send_configure_change();
931 void Mode2::create_objects()
933 add_item(new BC_MenuItem(to_text(MotionCVConfig::NO_CALCULATE)));
934 add_item(new BC_MenuItem(to_text(MotionCVConfig::RECALCULATE)));
935 add_item(new BC_MenuItem(to_text(MotionCVConfig::SAVE)));
936 add_item(new BC_MenuItem(to_text(MotionCVConfig::LOAD)));
939 int Mode2::from_text(char *text)
941 if(!strcmp(text, _("Recalculate"))) return MotionCVConfig::RECALCULATE;
942 if(!strcmp(text, _("Save coords to tracking file"))) return MotionCVConfig::SAVE;
943 if(!strcmp(text, _("Load coords from tracking file"))) return MotionCVConfig::LOAD;
944 //if(!strcmp(text, _("Don't Calculate"))) return MotionCVConfig::NO_CALCULATE;
945 return MotionCVConfig::NO_CALCULATE;
948 const char* Mode2::to_text(int mode)
951 case MotionCVConfig::NO_CALCULATE: return _("Don't Calculate");
952 case MotionCVConfig::RECALCULATE: return _("Recalculate");
953 case MotionCVConfig::SAVE: return _("Save coords to tracking file");
954 case MotionCVConfig::LOAD: return _("Load coords from tracking file");
959 int Mode2::calculate_w(MotionCVWindow *gui)
962 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionCVConfig::NO_CALCULATE)));
963 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionCVConfig::RECALCULATE)));
964 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionCVConfig::SAVE)));
965 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(MotionCVConfig::LOAD)));
978 Mode3::Mode3(MotionCVMain *plugin, MotionCVWindow *gui, int x, int y)
979 : BC_PopupMenu(x, y, calculate_w(gui),
980 to_text(plugin->config.horizontal_only, plugin->config.vertical_only))
982 this->plugin = plugin;
986 int Mode3::handle_event()
988 from_text(&plugin->config.horizontal_only, &plugin->config.vertical_only, get_text());
989 plugin->send_configure_change();
993 void Mode3::create_objects()
995 add_item(new BC_MenuItem(to_text(1, 0)));
996 add_item(new BC_MenuItem(to_text(0, 1)));
997 add_item(new BC_MenuItem(to_text(0, 0)));
1000 void Mode3::from_text(int *horizontal_only, int *vertical_only, char *text)
1002 *horizontal_only = 0;
1004 if(!strcmp(text, to_text(1, 0))) *horizontal_only = 1;
1005 if(!strcmp(text, to_text(0, 1))) *vertical_only = 1;
1008 const char* Mode3::to_text(int horizontal_only, int vertical_only)
1010 if(horizontal_only) return _("Horizontal only");
1011 if(vertical_only) return _("Vertical only");
1015 int Mode3::calculate_w(MotionCVWindow *gui)
1018 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(1, 0)));
1019 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(0, 1)));
1020 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(0, 0)));