4 * Copyright (C) 1997-2012 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 "findobject.h"
26 #include "findobjectwindow.h"
30 FindObjectWindow::FindObjectWindow(FindObjectMain *plugin)
31 : PluginClientWindow(plugin,
38 this->plugin = plugin;
41 FindObjectWindow::~FindObjectWindow()
45 void FindObjectWindow::create_objects()
47 int x1 = 10, x = 10, y = 10;
52 add_subwindow(title = new BC_Title(x1,
55 add_subwindow(algorithm = new FindObjectAlgorithm(plugin,
57 x1 + title->get_w() + 10,
59 algorithm->create_objects();
60 y += algorithm->get_h() + plugin->get_theme()->widget_border;
63 add_subwindow(title = new BC_Title(x1,
65 _("Search radius:\n(W/H Percent of image)")));
66 add_subwindow(global_range_w = new FindObjectGlobalRange(plugin,
67 x1 + title->get_w() + 10,
69 &plugin->config.global_range_w));
70 add_subwindow(global_range_h = new FindObjectGlobalRange(plugin,
71 x1 + title->get_w() + 10 + global_range_w->get_w(),
73 &plugin->config.global_range_h));
76 add_subwindow(title = new BC_Title(x1,
78 _("Object size:\n(W/H Percent of image)")));
79 add_subwindow(global_block_w = new FindObjectBlockSize(plugin,
80 x1 + title->get_w() + 10,
82 &plugin->config.global_block_w));
83 add_subwindow(global_block_h = new FindObjectBlockSize(plugin,
84 x1 + title->get_w() + 10 + global_block_w->get_w(),
86 &plugin->config.global_block_h));
89 add_subwindow(title = new BC_Title(x, y + 10, _("Block X:")));
90 add_subwindow(block_x = new FindObjectBlockCenter(plugin,
92 x + title->get_w() + 10,
94 &plugin->config.block_x));
95 add_subwindow(block_x_text = new FindObjectBlockCenterText(plugin,
97 x + title->get_w() + 10 + block_x->get_w() + 10,
99 &plugin->config.block_x));
100 block_x->center_text = block_x_text;
101 block_x_text->center = block_x;
104 add_subwindow(title = new BC_Title(x, y + 10, _("Block Y:")));
105 add_subwindow(block_y = new FindObjectBlockCenter(plugin,
107 x + title->get_w() + 10,
109 &plugin->config.block_y));
110 add_subwindow(block_y_text = new FindObjectBlockCenterText(plugin,
112 x + title->get_w() + 10 + block_y->get_w() + 10,
114 &plugin->config.block_y));
115 block_y->center_text = block_y_text;
116 block_y_text->center = block_y;
120 add_subwindow(draw_keypoints = new FindObjectDrawKeypoints(plugin,
125 y += draw_keypoints->get_h() + plugin->get_theme()->widget_border;
126 add_subwindow(draw_border = new FindObjectDrawBorder(plugin,
131 y += draw_keypoints->get_h() + plugin->get_theme()->widget_border;
132 add_subwindow(replace_object = new FindObjectReplace(plugin,
137 y += draw_keypoints->get_h() + plugin->get_theme()->widget_border;
138 add_subwindow(draw_object_border = new FindObjectDrawObjectBorder(plugin,
144 y += draw_keypoints->get_h() + plugin->get_theme()->widget_border;
145 add_subwindow(title = new BC_Title(x, y, _("Object layer:")));
146 object_layer = new FindObjectLayer(plugin,
148 x + title->get_w() + 10,
150 &plugin->config.object_layer);
151 object_layer->create_objects();
152 y += object_layer->get_h() + plugin->get_theme()->widget_border;
154 add_subwindow(title = new BC_Title(x, y, _("Replacement object layer:")));
155 replace_layer = new FindObjectLayer(plugin,
157 x + title->get_w() + 10,
159 &plugin->config.replace_layer);
160 replace_layer->create_objects();
161 y += replace_layer->get_h() + plugin->get_theme()->widget_border;
163 add_subwindow(title = new BC_Title(x, y, _("Output/scene layer:")));
164 scene_layer = new FindObjectLayer(plugin,
166 x + title->get_w() + 10,
168 &plugin->config.scene_layer);
169 scene_layer->create_objects();
170 y += scene_layer->get_h() + plugin->get_theme()->widget_border;
173 add_subwindow(title = new BC_Title(x, y + 10, _("Object blend amount:")));
174 add_subwindow(blend = new FindObjectBlend(plugin,
175 x + title->get_w() + plugin->get_theme()->widget_border,
177 &plugin->config.blend));
181 add_subwindow(title = new BC_Title(x, y + 10, _("Camshift VMIN:")));
182 add_subwindow(vmin = new FindObjectCamParam(plugin,
183 x + title->get_w() + plugin->get_theme()->widget_border,
185 &plugin->config.vmin));
186 y += vmin->get_h() * 2 / 3;
188 add_subwindow(title = new BC_Title(x, y + 10, _("Camshift VMAX:")));
189 add_subwindow(vmax = new FindObjectCamParam(plugin,
190 x + title->get_w() + vmin->get_w() + plugin->get_theme()->widget_border,
192 &plugin->config.vmax));
193 y += vmin->get_h() * 2 / 3;
195 add_subwindow(title = new BC_Title(x, y + 10, _("Camshift SMIN:")));
196 add_subwindow(smin = new FindObjectCamParam(plugin,
197 x + title->get_w() + plugin->get_theme()->widget_border,
199 &plugin->config.smin));
213 FindObjectGlobalRange::FindObjectGlobalRange(FindObjectMain *plugin,
223 this->plugin = plugin;
228 int FindObjectGlobalRange::handle_event()
230 *value = (int)get_value();
231 plugin->send_configure_change();
239 FindObjectBlockSize::FindObjectBlockSize(FindObjectMain *plugin,
249 this->plugin = plugin;
256 int FindObjectBlockSize::handle_event()
258 *value = get_value();
259 plugin->send_configure_change();
269 FindObjectBlockCenter::FindObjectBlockCenter(FindObjectMain *plugin,
270 FindObjectWindow *gui,
280 this->plugin = plugin;
286 int FindObjectBlockCenter::handle_event()
288 *value = get_value();
289 center_text->update(*value);
290 plugin->send_configure_change();
299 FindObjectBlockCenterText::FindObjectBlockCenterText(FindObjectMain *plugin,
300 FindObjectWindow *gui,
310 this->plugin = plugin;
316 int FindObjectBlockCenterText::handle_event()
318 *value = atof(get_text());
319 center->update(*value);
320 plugin->send_configure_change();
330 FindObjectDrawBorder::FindObjectDrawBorder(FindObjectMain *plugin,
331 FindObjectWindow *gui,
336 plugin->config.draw_border,
340 this->plugin = plugin;
343 int FindObjectDrawBorder::handle_event()
345 plugin->config.draw_border = get_value();
346 plugin->send_configure_change();
355 FindObjectDrawKeypoints::FindObjectDrawKeypoints(FindObjectMain *plugin,
356 FindObjectWindow *gui,
361 plugin->config.draw_keypoints,
365 this->plugin = plugin;
368 int FindObjectDrawKeypoints::handle_event()
370 plugin->config.draw_keypoints = get_value();
371 plugin->send_configure_change();
378 FindObjectReplace::FindObjectReplace(FindObjectMain *plugin,
379 FindObjectWindow *gui,
384 plugin->config.replace_object,
388 this->plugin = plugin;
391 int FindObjectReplace::handle_event()
393 plugin->config.replace_object = get_value();
394 plugin->send_configure_change();
403 FindObjectDrawObjectBorder::FindObjectDrawObjectBorder(FindObjectMain *plugin,
404 FindObjectWindow *gui,
409 plugin->config.draw_object_border,
410 _("Draw object border"))
413 this->plugin = plugin;
416 int FindObjectDrawObjectBorder::handle_event()
418 plugin->config.draw_object_border = get_value();
419 plugin->send_configure_change();
428 FindObjectLayer::FindObjectLayer(FindObjectMain *plugin,
429 FindObjectWindow *gui,
433 : BC_TumbleTextBox(gui,
441 this->plugin = plugin;
446 int FindObjectLayer::handle_event()
448 *value = atoi(get_text());
449 plugin->send_configure_change();
453 int FindObjectLayer::calculate_w(FindObjectWindow *gui)
456 result = gui->get_text_width(MEDIUMFONT, "000");
467 FindObjectAlgorithm::FindObjectAlgorithm(FindObjectMain *plugin, FindObjectWindow *gui, int x, int y)
471 to_text(plugin->config.algorithm))
473 this->plugin = plugin;
477 int FindObjectAlgorithm::handle_event()
479 plugin->config.algorithm = from_text(get_text());
480 plugin->send_configure_change();
484 void FindObjectAlgorithm::create_objects()
486 add_item(new BC_MenuItem(to_text(NO_ALGORITHM)));
488 add_item(new BC_MenuItem(to_text(ALGORITHM_SURF)));
490 add_item(new BC_MenuItem(to_text(ALGORITHM_CAMSHIFT)));
491 add_item(new BC_MenuItem(to_text(ALGORITHM_BLOB)));
494 int FindObjectAlgorithm::from_text(char *text)
496 if(!strcmp(text, _("Don't Calculate"))) return NO_ALGORITHM;
498 if(!strcmp(text, _("SURF"))) return ALGORITHM_SURF;
500 if(!strcmp(text, _("CAMSHIFT"))) return ALGORITHM_CAMSHIFT;
501 if(!strcmp(text, _("Blob"))) return ALGORITHM_BLOB;
502 return ALGORITHM_CAMSHIFT;
505 char* FindObjectAlgorithm::to_text(int mode)
510 return _("Don't Calculate");
517 case ALGORITHM_CAMSHIFT:
520 return _("CAMSHIFT");
523 int FindObjectAlgorithm::calculate_w(FindObjectWindow *gui)
526 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(NO_ALGORITHM)));
528 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(ALGORITHM_SURF)));
530 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(ALGORITHM_CAMSHIFT)));
531 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(ALGORITHM_BLOB)));
542 FindObjectCamParam::FindObjectCamParam(FindObjectMain *plugin,
549 (int64_t)MIN_CAMSHIFT,
550 (int64_t)MAX_CAMSHIFT)
552 this->plugin = plugin;
557 int FindObjectCamParam::handle_event()
559 *value = (int)get_value();
560 plugin->send_configure_change();
571 FindObjectBlend::FindObjectBlend(FindObjectMain *plugin,
581 this->plugin = plugin;
586 int FindObjectBlend::handle_event()
588 *value = (int)get_value();
589 plugin->send_configure_change();