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"
24 #include "dragcheckbox.h"
27 #include "findobjwindow.h"
29 #include "pluginserver.h"
34 FindObjWindow::FindObjWindow(FindObjMain *plugin)
35 : PluginClientWindow(plugin, 340, 660, 340, 660, 0)
37 this->plugin = plugin;
40 FindObjWindow::~FindObjWindow()
44 void FindObjWindow::create_objects()
46 int x = 10, y = 10, x1 = x, x2 = get_w()/2;
47 plugin->load_configuration();
50 add_subwindow(title = new BC_Title(x1, y, _("Algorithm:")));
51 add_subwindow(algorithm = new FindObjAlgorithm(plugin, this,
52 x1 + title->get_w() + 10, y));
53 algorithm->create_objects();
54 y += algorithm->get_h() + plugin->get_theme()->widget_border;
56 add_subwindow(use_flann = new FindObjUseFlann(plugin, this, x, y));
57 y += use_flann->get_h() + plugin->get_theme()->widget_border + 20;
60 add_subwindow(title = new BC_Title(x, y, _("Output/scene layer:")));
61 scene_layer = new FindObjLayer(plugin, this, x0, y,
62 &plugin->config.scene_layer);
63 scene_layer->create_objects();
64 y += scene_layer->get_h() + plugin->get_theme()->widget_border;
66 add_subwindow(title = new BC_Title(x, y, _("Object layer:")));
67 object_layer = new FindObjLayer(plugin, this, x0, y,
68 &plugin->config.object_layer);
69 object_layer->create_objects();
70 y += object_layer->get_h() + plugin->get_theme()->widget_border;
72 add_subwindow(title = new BC_Title(x, y, _("Replacement object layer:")));
73 replace_layer = new FindObjLayer(plugin, this, x0, y,
74 &plugin->config.replace_layer);
75 replace_layer->create_objects();
76 y += replace_layer->get_h() + plugin->get_theme()->widget_border + 10;
78 add_subwindow(title = new BC_Title(x+15, y, _("Units: 0 to 100 percent")));
82 add_subwindow(title = new BC_Title(x1, y + 10, _("Scene X:")));
83 Track *track = plugin->server->plugin->track;
84 int trk_w = track->track_w, trk_h = track->track_h;
85 float drag_w = trk_w * plugin->config.scene_w / 100.;
86 float drag_h = trk_h * plugin->config.scene_h / 100.;
87 float ctr_x = trk_w * plugin->config.scene_x / 100.;
88 float ctr_y = trk_h * plugin->config.scene_y / 100.;
89 float drag_x = ctr_x - drag_w/2, drag_y = ctr_y - drag_h/2;
90 drag_scene = new FindObjDragScene(plugin, this, x1+title->get_w()+10, y+5,
91 drag_x, drag_y, drag_w, drag_h);
92 add_subwindow(drag_scene);
93 drag_scene->create_objects();
94 y += title->get_h() + 15;
96 add_subwindow(scene_x = new FindObjScanFloat(plugin, this,
97 x1, y, &plugin->config.scene_x));
98 add_subwindow(scene_x_text = new FindObjScanFloatText(plugin, this,
99 x1 + scene_x->get_w() + 10, y + 10, &plugin->config.scene_x));
100 scene_x->center_text = scene_x_text;
101 scene_x_text->center = scene_x;
104 add_subwindow(title = new BC_Title(x1, y + 10, _("Scene Y:")));
105 y += title->get_h() + 15;
106 add_subwindow(scene_y = new FindObjScanFloat(plugin, this,
107 x1, y, &plugin->config.scene_y));
108 add_subwindow(scene_y_text = new FindObjScanFloatText(plugin, this,
109 x1 + scene_y->get_w() + 10, y + 10, &plugin->config.scene_y));
110 scene_y->center_text = scene_y_text;
111 scene_y_text->center = scene_y;
114 add_subwindow(new BC_Title(x1, y + 10, _("Scene W:")));
115 y += title->get_h() + 15;
116 add_subwindow(scene_w = new FindObjScanFloat(plugin, this,
117 x1, y, &plugin->config.scene_w));
118 add_subwindow(scene_w_text = new FindObjScanFloatText(plugin, this,
119 x1 + scene_w->get_w() + 10, y + 10, &plugin->config.scene_w));
120 scene_w->center_text = scene_w_text;
121 scene_w_text->center = scene_w;
124 add_subwindow(title = new BC_Title(x1, y + 10, _("Scene H:")));
125 y += title->get_h() + 15;
126 add_subwindow(scene_h = new FindObjScanFloat(plugin, this,
127 x1, y, &plugin->config.scene_h));
128 add_subwindow(scene_h_text = new FindObjScanFloatText(plugin, this,
129 x1 + scene_h->get_w() + 10, y + 10,
130 &plugin->config.scene_h));
131 scene_h->center_text = scene_h_text;
132 scene_h_text->center = scene_h;
135 add_subwindow(title = new BC_Title(x2, y + 10, _("Object X:")));
136 drag_w = trk_w * plugin->config.object_w / 100.;
137 drag_h = trk_h * plugin->config.object_h / 100.;
138 ctr_x = trk_w * plugin->config.object_x / 100.,
139 ctr_y = trk_h * plugin->config.object_y / 100.;
140 drag_x = ctr_x - drag_w/2; drag_y = ctr_y - drag_h/2;
141 drag_object = new FindObjDragObject(plugin, this, x2+title->get_w()+10, y+5,
142 drag_x, drag_y, drag_w, drag_h);
143 add_subwindow(drag_object);
144 drag_object->create_objects();
145 y += title->get_h() + 15;
147 add_subwindow(object_x = new FindObjScanFloat(plugin, this,
148 x2, y, &plugin->config.object_x));
149 add_subwindow(object_x_text = new FindObjScanFloatText(plugin, this,
150 x2 + object_x->get_w() + 10, y + 10, &plugin->config.object_x));
151 object_x->center_text = object_x_text;
152 object_x_text->center = object_x;
155 add_subwindow(title = new BC_Title(x2, y + 10, _("Object Y:")));
156 y += title->get_h() + 15;
157 add_subwindow(object_y = new FindObjScanFloat(plugin, this,
158 x2, y, &plugin->config.object_y));
159 add_subwindow(object_y_text = new FindObjScanFloatText(plugin, this,
160 x2 + object_y->get_w() + 10, y + 10, &plugin->config.object_y));
161 object_y->center_text = object_y_text;
162 object_y_text->center = object_y;
165 add_subwindow(new BC_Title(x2, y + 10, _("Object W:")));
166 y += title->get_h() + 15;
167 add_subwindow(object_w = new FindObjScanFloat(plugin, this,
168 x2, y, &plugin->config.object_w));
169 add_subwindow(object_w_text = new FindObjScanFloatText(plugin, this,
170 x2 + object_w->get_w() + 10, y + 10, &plugin->config.object_w));
171 object_w->center_text = object_w_text;
172 object_w_text->center = object_w;
175 add_subwindow(title = new BC_Title(x2, y + 10, _("Object H:")));
176 y += title->get_h() + 15;
177 add_subwindow(object_h = new FindObjScanFloat(plugin, this,
178 x2, y, &plugin->config.object_h));
179 add_subwindow(object_h_text = new FindObjScanFloatText(plugin, this,
180 x2 + object_h->get_w() + 10, y + 10,
181 &plugin->config.object_h));
182 object_h->center_text = object_h_text;
183 object_h_text->center = object_h;
186 add_subwindow(draw_keypoints = new FindObjDrawKeypoints(plugin, this, x, y));
187 y += draw_keypoints->get_h() + plugin->get_theme()->widget_border;
188 add_subwindow(replace_object = new FindObjReplace(plugin, this, x, y));
189 y += replace_object->get_h() + plugin->get_theme()->widget_border;
190 add_subwindow(draw_scene_border = new FindObjDrawSceneBorder(plugin, this, x, y));
191 y += draw_scene_border->get_h() + plugin->get_theme()->widget_border;
192 add_subwindow(draw_object_border = new FindObjDrawObjectBorder(plugin, this, x, y));
193 y += draw_object_border->get_h() + plugin->get_theme()->widget_border;
195 add_subwindow(title = new BC_Title(x, y + 10, _("Object blend amount:")));
196 add_subwindow(blend = new FindObjBlend(plugin,
197 x + title->get_w() + plugin->get_theme()->widget_border, y,
198 &plugin->config.blend));
204 void FindObjWindow::update_drag()
206 Track *track = drag_scene->get_drag_track();
207 int trk_w = track->track_w, trk_h = track->track_h;
208 drag_scene->drag_w = trk_w * plugin->config.scene_w/100.;
209 drag_scene->drag_h = trk_h * plugin->config.scene_h/100.;
210 drag_scene->drag_x = trk_w * plugin->config.scene_x/100. - drag_scene->drag_w/2;
211 drag_scene->drag_y = trk_h * plugin->config.scene_y/100. - drag_scene->drag_h/2;
212 track = drag_object->get_drag_track();
213 trk_w = track->track_w, trk_h = track->track_h;
214 drag_object->drag_w = trk_w * plugin->config.object_w/100.;
215 drag_object->drag_h = trk_h * plugin->config.object_h/100.;
216 drag_object->drag_x = trk_w * plugin->config.object_x/100. - drag_object->drag_w/2;
217 drag_object->drag_y = trk_h * plugin->config.object_y/100. - drag_object->drag_h/2;
218 plugin->send_configure_change();
221 FindObjScanFloat::FindObjScanFloat(FindObjMain *plugin, FindObjWindow *gui,
222 int x, int y, float *value)
223 : BC_FPot(x, y, *value, (float)0, (float)100)
225 this->plugin = plugin;
228 this->center_text = 0;
232 int FindObjScanFloat::handle_event()
234 *value = get_value();
235 center_text->update(*value);
240 void FindObjScanFloat::update(float v)
242 BC_FPot::update(*value = v);
243 center_text->update(v);
244 plugin->send_configure_change();
248 FindObjScanFloatText::FindObjScanFloatText(FindObjMain *plugin, FindObjWindow *gui,
249 int x, int y, float *value)
250 : BC_TextBox(x, y, 75, 1, *value)
252 this->plugin = plugin;
259 int FindObjScanFloatText::handle_event()
261 *value = atof(get_text());
262 center->update(*value);
268 FindObjDrawSceneBorder::FindObjDrawSceneBorder(FindObjMain *plugin, FindObjWindow *gui,
270 : BC_CheckBox(x, y, plugin->config.draw_scene_border, _("Draw scene border"))
273 this->plugin = plugin;
276 int FindObjDrawSceneBorder::handle_event()
278 plugin->config.draw_scene_border = get_value();
279 plugin->send_configure_change();
283 FindObjDrawObjectBorder::FindObjDrawObjectBorder(FindObjMain *plugin, FindObjWindow *gui,
285 : BC_CheckBox(x, y, plugin->config.draw_object_border, _("Draw object border"))
288 this->plugin = plugin;
292 FindObjDrawKeypoints::FindObjDrawKeypoints(FindObjMain *plugin, FindObjWindow *gui,
294 : BC_CheckBox(x, y, plugin->config.draw_keypoints, _("Draw keypoints"))
297 this->plugin = plugin;
300 int FindObjDrawKeypoints::handle_event()
302 plugin->config.draw_keypoints = get_value();
303 plugin->send_configure_change();
308 FindObjReplace::FindObjReplace(FindObjMain *plugin, FindObjWindow *gui,
310 : BC_CheckBox(x, y, plugin->config.replace_object, _("Replace object"))
313 this->plugin = plugin;
316 int FindObjReplace::handle_event()
318 plugin->config.replace_object = get_value();
319 plugin->send_configure_change();
324 int FindObjDrawObjectBorder::handle_event()
326 plugin->config.draw_object_border = get_value();
327 plugin->send_configure_change();
332 FindObjDragScene::FindObjDragScene(FindObjMain *plugin, FindObjWindow *gui, int x, int y,
333 float drag_x, float drag_y, float drag_w, float drag_h)
334 : DragCheckBox(plugin->server->mwindow, x, y, _("Drag"), &plugin->config.drag_scene,
335 drag_x, drag_y, drag_w, drag_h)
337 this->plugin = plugin;
341 FindObjDragScene::~FindObjDragScene()
345 int FindObjDragScene::handle_event()
347 int ret = DragCheckBox::handle_event();
348 plugin->send_configure_change();
351 Track *FindObjDragScene::get_drag_track()
353 return plugin->server->plugin->track;
355 int64_t FindObjDragScene::get_drag_position()
357 return plugin->get_source_position();
359 void FindObjDragScene::update_gui()
361 Track *track = get_drag_track();
362 int trk_w = track->track_w, trk_h = track->track_h;
363 float ctr_x = drag_x + drag_w/2, ctr_y = drag_y + drag_h/2;
364 printf("scene=%f,%f wxh=%fx%f ctr=%f,%f\n",drag_x,drag_y,drag_w,drag_h, ctr_x,ctr_y);
365 gui->scene_x->update( plugin->config.scene_x = 100. * ctr_x / trk_w );
366 gui->scene_y->update( plugin->config.scene_y = 100. * ctr_y / trk_h );
367 gui->scene_w->update( plugin->config.scene_w = 100. * drag_w / trk_w );
368 gui->scene_h->update( plugin->config.scene_h = 100. * drag_h / trk_h );
369 plugin->send_configure_change();
372 FindObjDragObject::FindObjDragObject(FindObjMain *plugin, FindObjWindow *gui, int x, int y,
373 float drag_x, float drag_y, float drag_w, float drag_h)
374 : DragCheckBox(plugin->server->mwindow, x, y, _("Drag"), &plugin->config.drag_object,
375 drag_x, drag_y, drag_w, drag_h)
377 this->plugin = plugin;
381 FindObjDragObject::~FindObjDragObject()
385 int FindObjDragObject::handle_event()
387 int ret = DragCheckBox::handle_event();
388 plugin->send_configure_change();
391 Track *FindObjDragObject::get_drag_track()
393 return plugin->server->plugin->track;
395 int64_t FindObjDragObject::get_drag_position()
397 return plugin->get_source_position();
399 void FindObjDragObject::update_gui()
401 Track *track = get_drag_track();
402 int trk_w = track->track_w, trk_h = track->track_h;
403 float ctr_x = drag_x + drag_w/2, ctr_y = drag_y + drag_h/2;
404 printf("object %f,%f %fx%f ctr %f,%f\n", drag_x,drag_y,drag_w,drag_h,ctr_x,ctr_y);
405 gui->object_x->update( plugin->config.object_x = 100. * ctr_x / trk_w );
406 gui->object_y->update( plugin->config.object_y = 100. * ctr_y / trk_h );
407 gui->object_w->update( plugin->config.object_w = 100. * drag_w / trk_w );
408 gui->object_h->update( plugin->config.object_h = 100. * drag_h / trk_h );
409 plugin->send_configure_change();
414 FindObjAlgorithm::FindObjAlgorithm(FindObjMain *plugin, FindObjWindow *gui, int x, int y)
415 : BC_PopupMenu(x, y, calculate_w(gui), to_text(plugin->config.algorithm))
417 this->plugin = plugin;
421 int FindObjAlgorithm::handle_event()
423 plugin->config.algorithm = from_text(get_text());
424 plugin->send_configure_change();
428 void FindObjAlgorithm::create_objects()
430 add_item(new BC_MenuItem(to_text(NO_ALGORITHM)));
432 add_item(new BC_MenuItem(to_text(ALGORITHM_SIFT)));
435 add_item(new BC_MenuItem(to_text(ALGORITHM_SURF)));
438 add_item(new BC_MenuItem(to_text(ALGORITHM_ORB)));
441 add_item(new BC_MenuItem(to_text(ALGORITHM_AKAZE)));
444 add_item(new BC_MenuItem(to_text(ALGORITHM_BRISK)));
448 int FindObjAlgorithm::from_text(char *text)
451 if(!strcmp(text, _("SIFT"))) return ALGORITHM_SIFT;
454 if(!strcmp(text, _("SURF"))) return ALGORITHM_SURF;
457 if(!strcmp(text, _("ORB"))) return ALGORITHM_ORB;
460 if(!strcmp(text, _("AKAZE"))) return ALGORITHM_AKAZE;
463 if(!strcmp(text, _("BRISK"))) return ALGORITHM_BRISK;
468 char* FindObjAlgorithm::to_text(int mode)
472 case ALGORITHM_SIFT: return _("SIFT");
475 case ALGORITHM_SURF: return _("SURF");
478 case ALGORITHM_ORB: return _("ORB");
481 case ALGORITHM_AKAZE: return _("AKAZE");
484 case ALGORITHM_BRISK: return _("BRISK");
487 return _("Don't Calculate");
490 int FindObjAlgorithm::calculate_w(FindObjWindow *gui)
493 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(NO_ALGORITHM)));
495 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(ALGORITHM_SIFT)));
498 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(ALGORITHM_SURF)));
501 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(ALGORITHM_ORB)));
504 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(ALGORITHM_AKAZE)));
507 result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(ALGORITHM_BRISK)));
513 FindObjUseFlann::FindObjUseFlann(FindObjMain *plugin, FindObjWindow *gui,
515 : BC_CheckBox(x, y, plugin->config.use_flann, _("Use FLANN"))
518 this->plugin = plugin;
521 int FindObjUseFlann::handle_event()
523 plugin->config.use_flann = get_value();
524 plugin->send_configure_change();
529 FindObjLayer::FindObjLayer(FindObjMain *plugin, FindObjWindow *gui,
530 int x, int y, int *value)
531 : BC_TumbleTextBox(gui, *value, MIN_LAYER, MAX_LAYER, x, y, calculate_w(gui))
533 this->plugin = plugin;
538 int FindObjLayer::handle_event()
540 *value = atoi(get_text());
541 plugin->send_configure_change();
545 int FindObjLayer::calculate_w(FindObjWindow *gui)
548 result = gui->get_text_width(MEDIUMFONT, "000");
553 FindObjBlend::FindObjBlend(FindObjMain *plugin,
563 this->plugin = plugin;
567 int FindObjBlend::handle_event()
569 *value = (int)get_value();
570 plugin->send_configure_change();