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"
26 #include "findobjwindow.h"
30 FindObjWindow::FindObjWindow(FindObjMain *plugin)
31 : PluginClientWindow(plugin, 340, 660, 340, 660, 0)
33 this->plugin = plugin;
36 FindObjWindow::~FindObjWindow()
40 void FindObjWindow::create_objects()
42 int x = 10, y = 10, x1 = x, x2 = get_w()/2;
43 plugin->load_configuration();
46 add_subwindow(title = new BC_Title(x1, y, _("Algorithm:")));
47 add_subwindow(algorithm = new FindObjAlgorithm(plugin, this,
48 x1 + title->get_w() + 10, y));
49 algorithm->create_objects();
50 y += algorithm->get_h() + plugin->get_theme()->widget_border;
52 add_subwindow(use_flann = new FindObjUseFlann(plugin, this, x, y));
53 y += use_flann->get_h() + plugin->get_theme()->widget_border + 20;
56 add_subwindow(title = new BC_Title(x, y, _("Output/scene layer:")));
57 scene_layer = new FindObjLayer(plugin, this, x0, y,
58 &plugin->config.scene_layer);
59 scene_layer->create_objects();
60 y += scene_layer->get_h() + plugin->get_theme()->widget_border;
62 add_subwindow(title = new BC_Title(x, y, _("Object layer:")));
63 object_layer = new FindObjLayer(plugin, this, x0, y,
64 &plugin->config.object_layer);
65 object_layer->create_objects();
66 y += object_layer->get_h() + plugin->get_theme()->widget_border;
68 add_subwindow(title = new BC_Title(x, y, _("Replacement object layer:")));
69 replace_layer = new FindObjLayer(plugin, this, x0, y,
70 &plugin->config.replace_layer);
71 replace_layer->create_objects();
72 y += replace_layer->get_h() + plugin->get_theme()->widget_border + 10;
74 add_subwindow(title = new BC_Title(x+15, y, _("Units: 0 to 100 percent")));
78 add_subwindow(new BC_Title(x1, y + 10, _("Scene X:")));
79 y += title->get_h() + 15;
80 add_subwindow(scene_x = new FindObjScanFloat(plugin, this,
81 x1, y, &plugin->config.scene_x));
82 add_subwindow(scene_x_text = new FindObjScanFloatText(plugin, this,
83 x1 + scene_x->get_w() + 10, y + 10, &plugin->config.scene_x));
84 scene_x->center_text = scene_x_text;
85 scene_x_text->center = scene_x;
88 add_subwindow(title = new BC_Title(x1, y + 10, _("Scene Y:")));
89 y += title->get_h() + 15;
90 add_subwindow(scene_y = new FindObjScanFloat(plugin, this,
91 x1, y, &plugin->config.scene_y));
92 add_subwindow(scene_y_text = new FindObjScanFloatText(plugin, this,
93 x1 + scene_y->get_w() + 10, y + 10, &plugin->config.scene_y));
94 scene_y->center_text = scene_y_text;
95 scene_y_text->center = scene_y;
98 add_subwindow(new BC_Title(x1, y + 10, _("Scene W:")));
99 y += title->get_h() + 15;
100 add_subwindow(scene_w = new FindObjScanFloat(plugin, this,
101 x1, y, &plugin->config.scene_w));
102 add_subwindow(scene_w_text = new FindObjScanFloatText(plugin, this,
103 x1 + scene_w->get_w() + 10, y + 10, &plugin->config.scene_w));
104 scene_w->center_text = scene_w_text;
105 scene_w_text->center = scene_w;
108 add_subwindow(title = new BC_Title(x1, y + 10, _("Scene H:")));
109 y += title->get_h() + 15;
110 add_subwindow(scene_h = new FindObjScanFloat(plugin, this,
111 x1, y, &plugin->config.scene_h));
112 add_subwindow(scene_h_text = new FindObjScanFloatText(plugin, this,
113 x1 + scene_h->get_w() + 10, y + 10,
114 &plugin->config.scene_h));
115 scene_h->center_text = scene_h_text;
116 scene_h_text->center = scene_h;
119 add_subwindow(new BC_Title(x2, y + 10, _("Object X:")));
120 y += title->get_h() + 15;
121 add_subwindow(object_x = new FindObjScanFloat(plugin, this,
122 x2, y, &plugin->config.object_x));
123 add_subwindow(object_x_text = new FindObjScanFloatText(plugin, this,
124 x2 + object_x->get_w() + 10, y + 10, &plugin->config.object_x));
125 object_x->center_text = object_x_text;
126 object_x_text->center = object_x;
129 add_subwindow(title = new BC_Title(x2, y + 10, _("Object Y:")));
130 y += title->get_h() + 15;
131 add_subwindow(object_y = new FindObjScanFloat(plugin, this,
132 x2, y, &plugin->config.object_y));
133 add_subwindow(object_y_text = new FindObjScanFloatText(plugin, this,
134 x2 + object_y->get_w() + 10, y + 10, &plugin->config.object_y));
135 object_y->center_text = object_y_text;
136 object_y_text->center = object_y;
139 add_subwindow(new BC_Title(x2, y + 10, _("Object W:")));
140 y += title->get_h() + 15;
141 add_subwindow(object_w = new FindObjScanFloat(plugin, this,
142 x2, y, &plugin->config.object_w));
143 add_subwindow(object_w_text = new FindObjScanFloatText(plugin, this,
144 x2 + object_w->get_w() + 10, y + 10, &plugin->config.object_w));
145 object_w->center_text = object_w_text;
146 object_w_text->center = object_w;
149 add_subwindow(title = new BC_Title(x2, y + 10, _("Object H:")));
150 y += title->get_h() + 15;
151 add_subwindow(object_h = new FindObjScanFloat(plugin, this,
152 x2, y, &plugin->config.object_h));
153 add_subwindow(object_h_text = new FindObjScanFloatText(plugin, this,
154 x2 + object_h->get_w() + 10, y + 10,
155 &plugin->config.object_h));
156 object_h->center_text = object_h_text;
157 object_h_text->center = object_h;
160 add_subwindow(draw_keypoints = new FindObjDrawKeypoints(plugin, this, x, y));
161 y += draw_keypoints->get_h() + plugin->get_theme()->widget_border;
162 add_subwindow(draw_border = new FindObjDrawBorder(plugin, this, x, y));
163 y += draw_border->get_h() + plugin->get_theme()->widget_border;
164 add_subwindow(replace_object = new FindObjReplace(plugin, this, x, y));
165 y += replace_object->get_h() + plugin->get_theme()->widget_border;
166 add_subwindow(draw_object_border = new FindObjDrawObjectBorder(plugin, this, x, y));
167 y += draw_object_border->get_h() + plugin->get_theme()->widget_border;
169 add_subwindow(title = new BC_Title(x, y + 10, _("Object blend amount:")));
170 add_subwindow(blend = new FindObjBlend(plugin,
171 x + title->get_w() + plugin->get_theme()->widget_border, y,
172 &plugin->config.blend));
179 FindObjScanFloat::FindObjScanFloat(FindObjMain *plugin, FindObjWindow *gui,
180 int x, int y, float *value)
181 : BC_FPot(x, y, *value, (float)0, (float)100)
183 this->plugin = plugin;
186 this->center_text = 0;
190 int FindObjScanFloat::handle_event()
192 *value = get_value();
193 center_text->update(*value);
194 plugin->send_configure_change();
199 FindObjScanFloatText::FindObjScanFloatText(FindObjMain *plugin, FindObjWindow *gui,
200 int x, int y, float *value)
201 : BC_TextBox(x, y, 75, 1, *value)
203 this->plugin = plugin;
210 int FindObjScanFloatText::handle_event()
212 *value = atof(get_text());
213 center->update(*value);
214 plugin->send_configure_change();
219 FindObjDrawBorder::FindObjDrawBorder(FindObjMain *plugin, FindObjWindow *gui,
221 : BC_CheckBox(x, y, plugin->config.draw_border, _("Draw border"))
224 this->plugin = plugin;
227 int FindObjDrawBorder::handle_event()
229 plugin->config.draw_border = get_value();
230 plugin->send_configure_change();
235 FindObjDrawKeypoints::FindObjDrawKeypoints(FindObjMain *plugin, FindObjWindow *gui,
237 : BC_CheckBox(x, y, plugin->config.draw_keypoints, _("Draw keypoints"))
240 this->plugin = plugin;
243 int FindObjDrawKeypoints::handle_event()
245 plugin->config.draw_keypoints = get_value();
246 plugin->send_configure_change();
251 FindObjReplace::FindObjReplace(FindObjMain *plugin, FindObjWindow *gui,
253 : BC_CheckBox(x, y, plugin->config.replace_object, _("Replace object"))
256 this->plugin = plugin;
259 int FindObjReplace::handle_event()
261 plugin->config.replace_object = get_value();
262 plugin->send_configure_change();
267 FindObjDrawObjectBorder::FindObjDrawObjectBorder(FindObjMain *plugin, FindObjWindow *gui,
269 : BC_CheckBox(x, y, plugin->config.draw_object_border, _("Draw object border"))
272 this->plugin = plugin;
275 int FindObjDrawObjectBorder::handle_event()
277 plugin->config.draw_object_border = get_value();
278 plugin->send_configure_change();
283 FindObjAlgorithm::FindObjAlgorithm(FindObjMain *plugin, FindObjWindow *gui, int x, int y)
284 : BC_PopupMenu(x, y, calculate_w(gui), to_text(plugin->config.algorithm))
286 this->plugin = plugin;
290 int FindObjAlgorithm::handle_event()
292 plugin->config.algorithm = from_text(get_text());
293 plugin->send_configure_change();
297 void FindObjAlgorithm::create_objects()
299 add_item(new BC_MenuItem(to_text(NO_ALGORITHM)));
301 add_item(new BC_MenuItem(to_text(ALGORITHM_SIFT)));
304 add_item(new BC_MenuItem(to_text(ALGORITHM_SURF)));
307 add_item(new BC_MenuItem(to_text(ALGORITHM_ORB)));
310 add_item(new BC_MenuItem(to_text(ALGORITHM_AKAZE)));
313 add_item(new BC_MenuItem(to_text(ALGORITHM_BRISK)));
317 int FindObjAlgorithm::from_text(char *text)
320 if(!strcmp(text, _("SIFT"))) return ALGORITHM_SIFT;
323 if(!strcmp(text, _("SURF"))) return ALGORITHM_SURF;
326 if(!strcmp(text, _("ORB"))) return ALGORITHM_ORB;
329 if(!strcmp(text, _("AKAZE"))) return ALGORITHM_AKAZE;
332 if(!strcmp(text, _("BRISK"))) return ALGORITHM_BRISK;
337 char* FindObjAlgorithm::to_text(int mode)
341 case ALGORITHM_SIFT: return _("SIFT");
344 case ALGORITHM_SURF: return _("SURF");
347 case ALGORITHM_ORB: return _("ORB");
350 case ALGORITHM_AKAZE: return _("AKAZE");
353 case ALGORITHM_BRISK: return _("BRISK");
356 return _("Don't Calculate");
359 int FindObjAlgorithm::calculate_w(FindObjWindow *gui)
362 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(NO_ALGORITHM)));
364 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(ALGORITHM_SIFT)));
367 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(ALGORITHM_SURF)));
370 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(ALGORITHM_ORB)));
373 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(ALGORITHM_AKAZE)));
376 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(ALGORITHM_BRISK)));
382 FindObjUseFlann::FindObjUseFlann(FindObjMain *plugin, FindObjWindow *gui,
384 : BC_CheckBox(x, y, plugin->config.use_flann, _("Use FLANN"))
387 this->plugin = plugin;
390 int FindObjUseFlann::handle_event()
392 plugin->config.use_flann = get_value();
393 plugin->send_configure_change();
398 FindObjLayer::FindObjLayer(FindObjMain *plugin, FindObjWindow *gui,
399 int x, int y, int *value)
400 : BC_TumbleTextBox(gui, *value, MIN_LAYER, MAX_LAYER, x, y, calculate_w(gui))
402 this->plugin = plugin;
407 int FindObjLayer::handle_event()
409 *value = atoi(get_text());
410 plugin->send_configure_change();
414 int FindObjLayer::calculate_w(FindObjWindow *gui)
417 result = gui->get_text_width(MEDIUMFONT, "000");
422 FindObjBlend::FindObjBlend(FindObjMain *plugin,
432 this->plugin = plugin;
436 int FindObjBlend::handle_event()
438 *value = (int)get_value();
439 plugin->send_configure_change();