96fe6e68ebb9ba5c3509d7269a9c76394ad065c9
[goodguy/history.git] / cinelerra-5.1 / plugins / findobj / findobjwindow.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 1997-2012 Adam Williams <broadcast at earthling dot net>
5  *
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.
10  *
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.
15  *
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
19  *
20  */
21
22 #include "bcdisplayinfo.h"
23 #include "clip.h"
24 #include "language.h"
25 #include "findobj.h"
26 #include "findobjwindow.h"
27 #include "theme.h"
28
29
30 FindObjWindow::FindObjWindow(FindObjMain *plugin)
31  : PluginClientWindow(plugin, 340, 660, 340, 660, 0)
32 {
33         this->plugin = plugin;
34 }
35
36 FindObjWindow::~FindObjWindow()
37 {
38 }
39
40 void FindObjWindow::create_objects()
41 {
42         int x = 10, y = 10, x1 = x, x2 = get_w()/2;
43         plugin->load_configuration();
44
45         BC_Title *title;
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;
51
52         add_subwindow(use_flann = new FindObjUseFlann(plugin, this, x, y));
53         y += use_flann->get_h() + plugin->get_theme()->widget_border + 20;
54
55         int x0 = x + 200;
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;
61
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;
67
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;
73
74         add_subwindow(title = new BC_Title(x+15, y, _("Units: 0 to 100 percent")));
75         y += title->get_h();
76
77         int y1 = y;
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;
86
87         y += 40;
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;
96
97         y += 40;
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;
106
107         y += 40;
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;
117
118         y = y1;
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;
127
128         y += 40;
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;
137
138         y += 40;
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;
147
148         y += 40;
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;
158
159         y += 40 + 15;
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;
168
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));
173         y += blend->get_h();
174
175         show_window(1);
176 }
177
178
179 FindObjScanFloat::FindObjScanFloat(FindObjMain *plugin, FindObjWindow *gui,
180         int x, int y, float *value)
181  : BC_FPot(x, y, *value, (float)0, (float)100)
182 {
183         this->plugin = plugin;
184         this->gui = gui;
185         this->value = value;
186         this->center_text = 0;
187         set_precision(0.1);
188 }
189
190 int FindObjScanFloat::handle_event()
191 {
192         *value = get_value();
193         center_text->update(*value);
194         plugin->send_configure_change();
195         return 1;
196 }
197
198
199 FindObjScanFloatText::FindObjScanFloatText(FindObjMain *plugin, FindObjWindow *gui,
200         int x, int y, float *value)
201  : BC_TextBox(x, y, 75, 1, *value)
202 {
203         this->plugin = plugin;
204         this->gui = gui;
205         this->value = value;
206         this->center = 0;
207         set_precision(1);
208 }
209
210 int FindObjScanFloatText::handle_event()
211 {
212         *value = atof(get_text());
213         center->update(*value);
214         plugin->send_configure_change();
215         return 1;
216 }
217
218
219 FindObjDrawBorder::FindObjDrawBorder(FindObjMain *plugin, FindObjWindow *gui,
220         int x, int y)
221  : BC_CheckBox(x, y, plugin->config.draw_border, _("Draw border"))
222 {
223         this->gui = gui;
224         this->plugin = plugin;
225 }
226
227 int FindObjDrawBorder::handle_event()
228 {
229         plugin->config.draw_border = get_value();
230         plugin->send_configure_change();
231         return 1;
232 }
233
234
235 FindObjDrawKeypoints::FindObjDrawKeypoints(FindObjMain *plugin, FindObjWindow *gui,
236         int x, int y)
237  : BC_CheckBox(x, y, plugin->config.draw_keypoints, _("Draw keypoints"))
238 {
239         this->gui = gui;
240         this->plugin = plugin;
241 }
242
243 int FindObjDrawKeypoints::handle_event()
244 {
245         plugin->config.draw_keypoints = get_value();
246         plugin->send_configure_change();
247         return 1;
248 }
249
250
251 FindObjReplace::FindObjReplace(FindObjMain *plugin, FindObjWindow *gui,
252         int x, int y)
253  : BC_CheckBox(x, y, plugin->config.replace_object, _("Replace object"))
254 {
255         this->gui = gui;
256         this->plugin = plugin;
257 }
258
259 int FindObjReplace::handle_event()
260 {
261         plugin->config.replace_object = get_value();
262         plugin->send_configure_change();
263         return 1;
264 }
265
266
267 FindObjDrawObjectBorder::FindObjDrawObjectBorder(FindObjMain *plugin, FindObjWindow *gui,
268         int x, int y)
269  : BC_CheckBox(x, y, plugin->config.draw_object_border, _("Draw object border"))
270 {
271         this->gui = gui;
272         this->plugin = plugin;
273 }
274
275 int FindObjDrawObjectBorder::handle_event()
276 {
277         plugin->config.draw_object_border = get_value();
278         plugin->send_configure_change();
279         return 1;
280 }
281
282
283 FindObjAlgorithm::FindObjAlgorithm(FindObjMain *plugin, FindObjWindow *gui, int x, int y)
284  : BC_PopupMenu(x, y, calculate_w(gui), to_text(plugin->config.algorithm))
285 {
286         this->plugin = plugin;
287         this->gui = gui;
288 }
289
290 int FindObjAlgorithm::handle_event()
291 {
292         plugin->config.algorithm = from_text(get_text());
293         plugin->send_configure_change();
294         return 1;
295 }
296
297 void FindObjAlgorithm::create_objects()
298 {
299         add_item(new BC_MenuItem(to_text(NO_ALGORITHM)));
300 #ifdef _SIFT
301         add_item(new BC_MenuItem(to_text(ALGORITHM_SIFT)));
302 #endif
303 #ifdef _SURF
304         add_item(new BC_MenuItem(to_text(ALGORITHM_SURF)));
305 #endif
306 #ifdef _ORB
307         add_item(new BC_MenuItem(to_text(ALGORITHM_ORB)));
308 #endif
309 #ifdef _AKAZE
310         add_item(new BC_MenuItem(to_text(ALGORITHM_AKAZE)));
311 #endif
312 #ifdef _BRISK
313         add_item(new BC_MenuItem(to_text(ALGORITHM_BRISK)));
314 #endif
315 }
316
317 int FindObjAlgorithm::from_text(char *text)
318 {
319 #ifdef _SIFT
320         if(!strcmp(text, _("SIFT"))) return ALGORITHM_SIFT;
321 #endif
322 #ifdef _SURF
323         if(!strcmp(text, _("SURF"))) return ALGORITHM_SURF;
324 #endif
325 #ifdef _ORB
326         if(!strcmp(text, _("ORB"))) return ALGORITHM_ORB;
327 #endif
328 #ifdef _AKAZE
329         if(!strcmp(text, _("AKAZE"))) return ALGORITHM_AKAZE;
330 #endif
331 #ifdef _BRISK
332         if(!strcmp(text, _("BRISK"))) return ALGORITHM_BRISK;
333 #endif
334         return NO_ALGORITHM;
335 }
336
337 char* FindObjAlgorithm::to_text(int mode)
338 {
339         switch( mode ) {
340 #ifdef _SIFT
341         case ALGORITHM_SIFT:    return _("SIFT");
342 #endif
343 #ifdef _SURF
344         case ALGORITHM_SURF:    return _("SURF");
345 #endif
346 #ifdef _ORB
347         case ALGORITHM_ORB:     return _("ORB");
348 #endif
349 #ifdef _AKAZE
350         case ALGORITHM_AKAZE:   return _("AKAZE");
351 #endif
352 #ifdef _BRISK
353         case ALGORITHM_BRISK:   return _("BRISK");
354 #endif
355         }
356         return _("Don't Calculate");
357 }
358
359 int FindObjAlgorithm::calculate_w(FindObjWindow *gui)
360 {
361         int result = 0;
362         result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(NO_ALGORITHM)));
363 #ifdef _SIFT
364         result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(ALGORITHM_SIFT)));
365 #endif
366 #ifdef _SURF
367         result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(ALGORITHM_SURF)));
368 #endif
369 #ifdef _ORB
370         result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(ALGORITHM_ORB)));
371 #endif
372 #ifdef _AKAZE
373         result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(ALGORITHM_AKAZE)));
374 #endif
375 #ifdef _BRISK
376         result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(ALGORITHM_BRISK)));
377 #endif
378         return result + 50;
379 }
380
381
382 FindObjUseFlann::FindObjUseFlann(FindObjMain *plugin, FindObjWindow *gui,
383         int x, int y)
384  : BC_CheckBox(x, y, plugin->config.use_flann, _("Use FLANN"))
385 {
386         this->gui = gui;
387         this->plugin = plugin;
388 }
389
390 int FindObjUseFlann::handle_event()
391 {
392         plugin->config.use_flann = get_value();
393         plugin->send_configure_change();
394         return 1;
395 }
396
397
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))
401 {
402         this->plugin = plugin;
403         this->gui = gui;
404         this->value = value;
405 }
406
407 int FindObjLayer::handle_event()
408 {
409         *value = atoi(get_text());
410         plugin->send_configure_change();
411         return 1;
412 }
413
414 int FindObjLayer::calculate_w(FindObjWindow *gui)
415 {
416         int result = 0;
417         result = gui->get_text_width(MEDIUMFONT, "000");
418         return result + 50;
419 }
420
421
422 FindObjBlend::FindObjBlend(FindObjMain *plugin,
423         int x,
424         int y,
425         int *value)
426  : BC_IPot(x,
427                 y,
428                 (int64_t)*value,
429                 (int64_t)MIN_BLEND,
430                 (int64_t)MAX_BLEND)
431 {
432         this->plugin = plugin;
433         this->value = value;
434 }
435
436 int FindObjBlend::handle_event()
437 {
438         *value = (int)get_value();
439         plugin->send_configure_change();
440         return 1;
441 }
442