remove whitespace at eol
[goodguy/history.git] / cinelerra-5.1 / plugins / findobject / findobjectwindow.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 "findobject.h"
26 #include "findobjectwindow.h"
27 #include "theme.h"
28
29
30 FindObjectWindow::FindObjectWindow(FindObjectMain *plugin)
31  : PluginClientWindow(plugin,
32         300,
33         550,
34         300,
35         550,
36         0)
37 {
38         this->plugin = plugin;
39 }
40
41 FindObjectWindow::~FindObjectWindow()
42 {
43 }
44
45 void FindObjectWindow::create_objects()
46 {
47         int x1 = 10, x = 10, y = 10;
48         int x2 = 310;
49         BC_Title *title;
50
51
52         add_subwindow(title = new BC_Title(x1,
53                 y,
54                 _("Algorithm:")));
55         add_subwindow(algorithm = new FindObjectAlgorithm(plugin,
56                 this,
57                 x1 + title->get_w() + 10,
58                 y));
59         algorithm->create_objects();
60         y += algorithm->get_h() + plugin->get_theme()->widget_border;
61
62
63         add_subwindow(title = new BC_Title(x1,
64                 y,
65                 _("Search radius:\n(W/H Percent of image)")));
66         add_subwindow(global_range_w = new FindObjectGlobalRange(plugin,
67                 x1 + title->get_w() + 10,
68                 y,
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(),
72                 y,
73                 &plugin->config.global_range_h));
74
75         y += 50;
76         add_subwindow(title = new BC_Title(x1,
77                 y,
78                 _("Object size:\n(W/H Percent of image)")));
79         add_subwindow(global_block_w = new FindObjectBlockSize(plugin,
80                 x1 + title->get_w() + 10,
81                 y,
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(),
85                 y,
86                 &plugin->config.global_block_h));
87
88         y += 40;
89         add_subwindow(title = new BC_Title(x, y + 10, _("Block X:")));
90         add_subwindow(block_x = new FindObjectBlockCenter(plugin,
91                 this,
92                 x + title->get_w() + 10,
93                 y,
94                 &plugin->config.block_x));
95         add_subwindow(block_x_text = new FindObjectBlockCenterText(plugin,
96                 this,
97                 x + title->get_w() + 10 + block_x->get_w() + 10,
98                 y + 10,
99                 &plugin->config.block_x));
100         block_x->center_text = block_x_text;
101         block_x_text->center = block_x;
102
103         y += 40;
104         add_subwindow(title = new BC_Title(x, y + 10, _("Block Y:")));
105         add_subwindow(block_y = new FindObjectBlockCenter(plugin,
106                 this,
107                 x + title->get_w() + 10,
108                 y,
109                 &plugin->config.block_y));
110         add_subwindow(block_y_text = new FindObjectBlockCenterText(plugin,
111                 this,
112                 x + title->get_w() + 10 + block_y->get_w() + 10,
113                 y + 10,
114                 &plugin->config.block_y));
115         block_y->center_text = block_y_text;
116         block_y_text->center = block_y;
117
118
119         y += 40;
120         add_subwindow(draw_keypoints = new FindObjectDrawKeypoints(plugin,
121                 this,
122                 x,
123                 y));
124
125         y += draw_keypoints->get_h() + plugin->get_theme()->widget_border;
126         add_subwindow(draw_border = new FindObjectDrawBorder(plugin,
127                 this,
128                 x,
129                 y));
130
131         y += draw_keypoints->get_h() + plugin->get_theme()->widget_border;
132         add_subwindow(replace_object = new FindObjectReplace(plugin,
133                 this,
134                 x,
135                 y));
136
137         y += draw_keypoints->get_h() + plugin->get_theme()->widget_border;
138         add_subwindow(draw_object_border = new FindObjectDrawObjectBorder(plugin,
139                 this,
140                 x,
141                 y));
142
143
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,
147                 this,
148                 x + title->get_w() + 10,
149                 y,
150                 &plugin->config.object_layer);
151         object_layer->create_objects();
152         y += object_layer->get_h() + plugin->get_theme()->widget_border;
153
154         add_subwindow(title = new BC_Title(x, y, _("Replacement object layer:")));
155         replace_layer = new FindObjectLayer(plugin,
156                 this,
157                 x + title->get_w() + 10,
158                 y,
159                 &plugin->config.replace_layer);
160         replace_layer->create_objects();
161         y += replace_layer->get_h() + plugin->get_theme()->widget_border;
162
163         add_subwindow(title = new BC_Title(x, y, _("Output/scene layer:")));
164         scene_layer = new FindObjectLayer(plugin,
165                 this,
166                 x + title->get_w() + 10,
167                 y,
168                 &plugin->config.scene_layer);
169         scene_layer->create_objects();
170         y += scene_layer->get_h() + plugin->get_theme()->widget_border;
171
172
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,
176                 y,
177                 &plugin->config.blend));
178         y += blend->get_h();
179
180
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,
184                 y,
185                 &plugin->config.vmin));
186         y += vmin->get_h() * 2 / 3;
187
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,
191                 y,
192                 &plugin->config.vmax));
193         y += vmin->get_h() * 2 / 3;
194
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,
198                 y,
199                 &plugin->config.smin));
200         y += vmin->get_h();
201
202
203
204         show_window(1);
205 }
206
207
208
209
210
211
212
213 FindObjectGlobalRange::FindObjectGlobalRange(FindObjectMain *plugin,
214         int x,
215         int y,
216         int *value)
217  : BC_IPot(x,
218                 y,
219                 (int64_t)*value,
220                 (int64_t)MIN_RADIUS,
221                 (int64_t)MAX_RADIUS)
222 {
223         this->plugin = plugin;
224         this->value = value;
225 }
226
227
228 int FindObjectGlobalRange::handle_event()
229 {
230         *value = (int)get_value();
231         plugin->send_configure_change();
232         return 1;
233 }
234
235
236
237
238
239 FindObjectBlockSize::FindObjectBlockSize(FindObjectMain *plugin,
240         int x,
241         int y,
242         float *value)
243  : BC_FPot(x,
244                 y,
245                 (float)*value,
246                 (float)MIN_BLOCK,
247                 (float)MAX_BLOCK)
248 {
249         this->plugin = plugin;
250         this->value = value;
251         set_precision(0.1);
252 }
253
254
255
256 int FindObjectBlockSize::handle_event()
257 {
258         *value = get_value();
259         plugin->send_configure_change();
260         return 1;
261 }
262
263
264
265
266
267
268
269 FindObjectBlockCenter::FindObjectBlockCenter(FindObjectMain *plugin,
270         FindObjectWindow *gui,
271         int x,
272         int y,
273         float *value)
274  : BC_FPot(x,
275         y,
276         *value,
277         (float)0,
278         (float)100)
279 {
280         this->plugin = plugin;
281         this->gui = gui;
282         this->value = value;
283         set_precision(0.1);
284 }
285
286 int FindObjectBlockCenter::handle_event()
287 {
288         *value = get_value();
289         center_text->update(*value);
290         plugin->send_configure_change();
291         return 1;
292 }
293
294
295
296
297
298
299 FindObjectBlockCenterText::FindObjectBlockCenterText(FindObjectMain *plugin,
300         FindObjectWindow *gui,
301         int x,
302         int y,
303         float *value)
304  : BC_TextBox(x,
305         y,
306         75,
307         1,
308         *value)
309 {
310         this->plugin = plugin;
311         this->gui = gui;
312         this->value = value;
313         set_precision(1);
314 }
315
316 int FindObjectBlockCenterText::handle_event()
317 {
318         *value = atof(get_text());
319         center->update(*value);
320         plugin->send_configure_change();
321         return 1;
322 }
323
324
325
326
327
328
329
330 FindObjectDrawBorder::FindObjectDrawBorder(FindObjectMain *plugin,
331         FindObjectWindow *gui,
332         int x,
333         int y)
334  : BC_CheckBox(x,
335         y,
336         plugin->config.draw_border,
337         _("Draw border"))
338 {
339         this->gui = gui;
340         this->plugin = plugin;
341 }
342
343 int FindObjectDrawBorder::handle_event()
344 {
345         plugin->config.draw_border = get_value();
346         plugin->send_configure_change();
347         return 1;
348 }
349
350
351
352
353
354
355 FindObjectDrawKeypoints::FindObjectDrawKeypoints(FindObjectMain *plugin,
356         FindObjectWindow *gui,
357         int x,
358         int y)
359  : BC_CheckBox(x,
360         y,
361         plugin->config.draw_keypoints,
362         _("Draw keypoints"))
363 {
364         this->gui = gui;
365         this->plugin = plugin;
366 }
367
368 int FindObjectDrawKeypoints::handle_event()
369 {
370         plugin->config.draw_keypoints = get_value();
371         plugin->send_configure_change();
372         return 1;
373 }
374
375
376
377
378 FindObjectReplace::FindObjectReplace(FindObjectMain *plugin,
379         FindObjectWindow *gui,
380         int x,
381         int y)
382  : BC_CheckBox(x,
383         y,
384         plugin->config.replace_object,
385         _("Replace object"))
386 {
387         this->gui = gui;
388         this->plugin = plugin;
389 }
390
391 int FindObjectReplace::handle_event()
392 {
393         plugin->config.replace_object = get_value();
394         plugin->send_configure_change();
395         return 1;
396 }
397
398
399
400
401
402
403 FindObjectDrawObjectBorder::FindObjectDrawObjectBorder(FindObjectMain *plugin,
404         FindObjectWindow *gui,
405         int x,
406         int y)
407  : BC_CheckBox(x,
408         y,
409         plugin->config.draw_object_border,
410         _("Draw object border"))
411 {
412         this->gui = gui;
413         this->plugin = plugin;
414 }
415
416 int FindObjectDrawObjectBorder::handle_event()
417 {
418         plugin->config.draw_object_border = get_value();
419         plugin->send_configure_change();
420         return 1;
421 }
422
423
424
425
426
427
428 FindObjectLayer::FindObjectLayer(FindObjectMain *plugin,
429         FindObjectWindow *gui,
430         int x,
431         int y,
432         int *value)
433  : BC_TumbleTextBox(gui,
434         *value,
435         MIN_LAYER,
436         MAX_LAYER,
437         x,
438         y,
439         calculate_w(gui))
440 {
441         this->plugin = plugin;
442         this->gui = gui;
443         this->value = value;
444 }
445
446 int FindObjectLayer::handle_event()
447 {
448         *value = atoi(get_text());
449         plugin->send_configure_change();
450         return 1;
451 }
452
453 int FindObjectLayer::calculate_w(FindObjectWindow *gui)
454 {
455         int result = 0;
456         result = gui->get_text_width(MEDIUMFONT, "000");
457         return result + 50;
458 }
459
460
461
462
463
464
465
466
467 FindObjectAlgorithm::FindObjectAlgorithm(FindObjectMain *plugin, FindObjectWindow *gui, int x, int y)
468  : BC_PopupMenu(x,
469         y,
470         calculate_w(gui),
471         to_text(plugin->config.algorithm))
472 {
473         this->plugin = plugin;
474         this->gui = gui;
475 }
476
477 int FindObjectAlgorithm::handle_event()
478 {
479         plugin->config.algorithm = from_text(get_text());
480         plugin->send_configure_change();
481         return 1;
482 }
483
484 void FindObjectAlgorithm::create_objects()
485 {
486         add_item(new BC_MenuItem(to_text(NO_ALGORITHM)));
487 #if HAVE_OPENCV_SURF
488         add_item(new BC_MenuItem(to_text(ALGORITHM_SURF)));
489 #endif
490         add_item(new BC_MenuItem(to_text(ALGORITHM_CAMSHIFT)));
491         add_item(new BC_MenuItem(to_text(ALGORITHM_BLOB)));
492 }
493
494 int FindObjectAlgorithm::from_text(char *text)
495 {
496         if(!strcmp(text, _("Don't Calculate"))) return NO_ALGORITHM;
497 #if HAVE_OPENCV_SURF
498         if(!strcmp(text, _("SURF"))) return ALGORITHM_SURF;
499 #endif
500         if(!strcmp(text, _("CAMSHIFT"))) return ALGORITHM_CAMSHIFT;
501         if(!strcmp(text, _("Blob"))) return ALGORITHM_BLOB;
502         return ALGORITHM_CAMSHIFT;
503 }
504
505 char* FindObjectAlgorithm::to_text(int mode)
506 {
507         switch(mode)
508         {
509                 case NO_ALGORITHM:
510                         return _("Don't Calculate");
511 #if HAVE_OPENCV_SURF
512                 case ALGORITHM_SURF:
513                         return _("SURF");
514 #endif
515                 case ALGORITHM_BLOB:
516                         return _("Blob");
517                 case ALGORITHM_CAMSHIFT:
518                         break;
519         }
520         return _("CAMSHIFT");
521 }
522
523 int FindObjectAlgorithm::calculate_w(FindObjectWindow *gui)
524 {
525         int result = 0;
526         result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(NO_ALGORITHM)));
527 #if HAVE_OPENCV_SURF
528         result = MAX(result, gui->get_text_width(MEDIUMFONT, to_text(ALGORITHM_SURF)));
529 #endif
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)));
532         return result + 50;
533 }
534
535
536
537
538
539
540
541
542 FindObjectCamParam::FindObjectCamParam(FindObjectMain *plugin,
543         int x,
544         int y,
545         int *value)
546  : BC_IPot(x,
547                 y,
548                 (int64_t)*value,
549                 (int64_t)MIN_CAMSHIFT,
550                 (int64_t)MAX_CAMSHIFT)
551 {
552         this->plugin = plugin;
553         this->value = value;
554 }
555
556
557 int FindObjectCamParam::handle_event()
558 {
559         *value = (int)get_value();
560         plugin->send_configure_change();
561         return 1;
562 }
563
564
565
566
567
568
569
570
571 FindObjectBlend::FindObjectBlend(FindObjectMain *plugin,
572         int x,
573         int y,
574         int *value)
575  : BC_IPot(x,
576                 y,
577                 (int64_t)*value,
578                 (int64_t)MIN_BLEND,
579                 (int64_t)MAX_BLEND)
580 {
581         this->plugin = plugin;
582         this->value = value;
583 }
584
585
586 int FindObjectBlend::handle_event()
587 {
588         *value = (int)get_value();
589         plugin->send_configure_change();
590         return 1;
591 }
592
593
594
595
596
597
598
599
600
601
602
603
604