forked from NatronGitHub/Natron
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTrackerNode.cpp
2469 lines (2195 loc) · 124 KB
/
TrackerNode.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* ***** BEGIN LICENSE BLOCK *****
* This file is part of Natron <https://natrongithub.github.io/>,
* (C) 2018-2021 The Natron developers
* (C) 2013-2018 INRIA and Alexandre Gauthier-Foichat
*
* Natron is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Natron is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Natron. If not, see <http://www.gnu.org/licenses/gpl-2.0.html>
* ***** END LICENSE BLOCK ***** */
// ***** BEGIN PYTHON BLOCK *****
// from <https://docs.python.org/3/c-api/intro.html#include-files>:
// "Since Python may define some pre-processor definitions which affect the standard headers on some systems, you must include Python.h before any standard headers are included."
#include <Python.h>
// ***** END PYTHON BLOCK *****
#include <boost/algorithm/clamp.hpp>
#include "TrackerNode.h"
#include "Engine/AppInstance.h"
#include "Engine/Curve.h"
#include "Engine/KnobTypes.h"
#include "Engine/Node.h"
#include "Engine/Lut.h"
#include "Engine/TimeLine.h"
#include "Engine/TrackerContext.h"
#include "Engine/TrackMarker.h"
#include "Engine/TrackerNodeInteract.h"
#include "Engine/TrackerUndoCommand.h"
#include "Engine/ViewerInstance.h"
#define NATRON_TRACKER_UI_BUTTONS_CATEGORIES_SPACING 10
NATRON_NAMESPACE_ENTER
TrackerNode::TrackerNode(Natron::NodePtr node)
: NodeGroup(node)
, _imp( new TrackerNodePrivate(this) )
{
}
TrackerNode::~TrackerNode()
{
}
std::string
TrackerNode::getPluginID() const
{
return PLUGINID_NATRON_TRACKER;
}
std::string
TrackerNode::getPluginLabel() const
{
return "Tracker";
}
std::string
TrackerNode::getPluginDescription() const
{
return "Track one or more 2D point(s) using LibMV from the Blender open-source software.\n\n"
"Goal\n"
"----\n\n"
"Track one or more 2D point and use them to either make another object/image match-move their motion or to stabilize the input image.\n\n"
"Tracking\n"
"--------\n\n"
"* Connect a Tracker node to the image containing the item you need to track\n"
"* Place tracking markers with CTRL+ALT+Click on the Viewer or by clicking the **+** button below the track table in the settings panel\n"
"* Setup the motion model to match the motion type of the item you need to track. By default the tracker will only assume the item is underoing a translation. Other motion models can be used for complex tracks but may be slower.\n"
"* Select in the settings panel or on the Viewer the markers you want to track and then start tracking with the player buttons on the top of the Viewer.\n"
"* If a track is getting lost or fails at some point, you may refine it by moving the marker at its correct position, this will force a new keyframe on the pattern which will be visible in the Viewer and on the timeline.\n\n"
"Using the tracks data\n"
"---------------------\n\n"
"You can either use the Tracker node itself to use the track data or you may export it to another node.\n\n"
"Using the Transform within the Tracker node\n"
"-------------------------------------------\n\n"
"Go to the Transform tab in the settings panel, and set the Transform Type to the operation you want to achieve. During tracking, the Transform Type should always been set to None if you want to correctly see the tracks on the Viewer.\n\n"
"You will notice that the transform parameters will be set automatically when the tracking is finished. Depending on the Transform Type, the values will be computed either to match-move the motion of the tracked points or to stabilize the image.\n\n"
"Exporting the tracking data\n"
"---------------------------\n\n"
"You may export the tracking data either to a CornerPin node or to a Transform node. The CornerPin node performs a warp that may be more stable than a Transform node when using 4 or more tracks: it retains more information than the Transform node.";
}
void
TrackerNode::getPluginShortcuts(std::list<PluginActionShortcut>* shortcuts)
{
// Viewer buttons
shortcuts->push_back( PluginActionShortcut(kTrackerUIParamTrackBW, kTrackerUIParamTrackBWLabel, Key_Z) );
shortcuts->push_back( PluginActionShortcut(kTrackerUIParamTrackPrevious, kTrackerUIParamTrackPreviousLabel, Key_X) );
shortcuts->push_back( PluginActionShortcut(kTrackerUIParamTrackNext, kTrackerUIParamTrackNextLabel, Key_C) );
shortcuts->push_back( PluginActionShortcut(kTrackerUIParamStopTracking, kTrackerUIParamStopTrackingLabel, Key_Escape) );
shortcuts->push_back( PluginActionShortcut(kTrackerUIParamTrackFW, kTrackerUIParamTrackFWLabel, Key_V) );
shortcuts->push_back( PluginActionShortcut(kTrackerUIParamTrackRange, kTrackerUIParamTrackRangeLabel) );
shortcuts->push_back( PluginActionShortcut(kTrackerUIParamTrackAllKeyframes, kTrackerUIParamTrackAllKeyframesLabel, Key_V, eKeyboardModifierControl) );
shortcuts->push_back( PluginActionShortcut(kTrackerUIParamTrackCurrentKeyframe, kTrackerUIParamTrackCurrentKeyframeLabel, Key_C, eKeyboardModifierControl) );
shortcuts->push_back( PluginActionShortcut(kTrackerUIParamClearAllAnimation, kTrackerUIParamClearAllAnimationLabel) );
shortcuts->push_back( PluginActionShortcut(kTrackerUIParamClearAnimationBw, kTrackerUIParamClearAnimationBwLabel) );
shortcuts->push_back( PluginActionShortcut(kTrackerUIParamClearAnimationFw, kTrackerUIParamClearAnimationFwLabel) );
shortcuts->push_back( PluginActionShortcut(kTrackerUIParamRefreshViewer, kTrackerUIParamRefreshViewerLabel) );
shortcuts->push_back( PluginActionShortcut(kTrackerUIParamCenterViewer, kTrackerUIParamCenterViewerLabel) );
shortcuts->push_back( PluginActionShortcut(kTrackerUIParamCreateKeyOnMove, kTrackerUIParamCreateKeyOnMoveLabel) );
shortcuts->push_back( PluginActionShortcut(kTrackerUIParamShowError, kTrackerUIParamShowErrorLabel) );
shortcuts->push_back( PluginActionShortcut(kTrackerUIParamSetPatternKeyFrame, kTrackerUIParamSetPatternKeyFrameLabel) );
shortcuts->push_back( PluginActionShortcut(kTrackerUIParamRemovePatternKeyFrame, kTrackerUIParamRemovePatternKeyFrameLabel) );
shortcuts->push_back( PluginActionShortcut(kTrackerUIParamResetOffset, kTrackerUIParamResetOffsetLabel) );
shortcuts->push_back( PluginActionShortcut(kTrackerUIParamResetTrack, kTrackerUIParamResetTrackLabel) );
shortcuts->push_back( PluginActionShortcut(kTrackerUIParamRightClickMenuActionSelectAllTracks, kTrackerUIParamRightClickMenuActionSelectAllTracksLabel, Key_A, eKeyboardModifierControl) );
shortcuts->push_back( PluginActionShortcut(kTrackerUIParamRightClickMenuActionRemoveTracks, kTrackerUIParamRightClickMenuActionRemoveTracksLabel, Key_BackSpace) );
shortcuts->push_back( PluginActionShortcut(kTrackerUIParamRightClickMenuActionNudgeBottom, kTrackerUIParamRightClickMenuActionNudgeBottomLabel, Key_Down) );
shortcuts->push_back( PluginActionShortcut(kTrackerUIParamRightClickMenuActionNudgeTop, kTrackerUIParamRightClickMenuActionNudgeTopLabel, Key_Up) );
shortcuts->push_back( PluginActionShortcut(kTrackerUIParamRightClickMenuActionNudgeRight, kTrackerUIParamRightClickMenuActionNudgeRightLabel, Key_Right) );
shortcuts->push_back( PluginActionShortcut(kTrackerUIParamRightClickMenuActionNudgeLeft, kTrackerUIParamRightClickMenuActionNudgeLeftLabel, Key_Left) );
// Right click menu
}
void
TrackerNode::initializeKnobs()
{
TrackerContextPtr context = getNode()->getTrackerContext();
KnobPagePtr trackingPage = context->getTrackingPageKnob();
KnobButtonPtr addMarker = AppManager::createKnob<KnobButton>( this, tr(kTrackerUIParamAddTrackLabel) );
addMarker->setName(kTrackerUIParamAddTrack);
addMarker->setHintToolTip( tr(kTrackerUIParamAddTrackHint) );
addMarker->setEvaluateOnChange(false);
addMarker->setCheckable(true);
addMarker->setDefaultValue(false);
addMarker->setSecretByDefault(true);
addMarker->setIconLabel(NATRON_IMAGES_PATH "addTrack.png");
addOverlaySlaveParam(addMarker);
trackingPage->addKnob(addMarker);
_imp->ui->addTrackButton = addMarker;
KnobButtonPtr trackBw = AppManager::createKnob<KnobButton>( this, tr(kTrackerUIParamTrackBWLabel) );
trackBw->setName(kTrackerUIParamTrackBW);
trackBw->setHintToolTip( tr(kTrackerUIParamTrackBWHint) );
trackBw->setEvaluateOnChange(false);
trackBw->setCheckable(true);
trackBw->setDefaultValue(false);
trackBw->setSecretByDefault(true);
trackBw->setInViewerContextCanHaveShortcut(true);
trackBw->setIconLabel(NATRON_IMAGES_PATH "trackBackwardOn.png", true);
trackBw->setIconLabel(NATRON_IMAGES_PATH "trackBackwardOff.png", false);
trackingPage->addKnob(trackBw);
_imp->ui->trackBwButton = trackBw;
KnobButtonPtr trackPrev = AppManager::createKnob<KnobButton>( this, tr(kTrackerUIParamTrackPreviousLabel) );
trackPrev->setName(kTrackerUIParamTrackPrevious);
trackPrev->setHintToolTip( tr(kTrackerUIParamTrackPreviousHint) );
trackPrev->setEvaluateOnChange(false);
trackPrev->setSecretByDefault(true);
trackPrev->setInViewerContextCanHaveShortcut(true);
trackPrev->setIconLabel(NATRON_IMAGES_PATH "trackPrev.png");
trackingPage->addKnob(trackPrev);
_imp->ui->trackPrevButton = trackPrev;
KnobButtonPtr stopTracking = AppManager::createKnob<KnobButton>( this, tr(kTrackerUIParamStopTrackingLabel) );
stopTracking->setName(kTrackerUIParamStopTracking);
stopTracking->setHintToolTip( tr(kTrackerUIParamStopTrackingHint) );
stopTracking->setEvaluateOnChange(false);
stopTracking->setSecretByDefault(true);
stopTracking->setInViewerContextCanHaveShortcut(true);
stopTracking->setIconLabel(NATRON_IMAGES_PATH "pauseDisabled.png");
trackingPage->addKnob(stopTracking);
_imp->ui->stopTrackingButton = stopTracking;
KnobButtonPtr trackNext = AppManager::createKnob<KnobButton>( this, tr(kTrackerUIParamTrackNextLabel) );
trackNext->setName(kTrackerUIParamTrackNext);
trackNext->setHintToolTip( tr(kTrackerUIParamTrackNextHint) );
trackNext->setEvaluateOnChange(false);
trackNext->setSecretByDefault(true);
trackNext->setInViewerContextCanHaveShortcut(true);
trackNext->setIconLabel(NATRON_IMAGES_PATH "trackNext.png");
trackingPage->addKnob(trackNext);
_imp->ui->trackNextButton = trackNext;
KnobButtonPtr trackFw = AppManager::createKnob<KnobButton>( this, tr(kTrackerUIParamTrackFWLabel) );
trackFw->setName(kTrackerUIParamTrackFW);
trackFw->setHintToolTip( tr(kTrackerUIParamTrackFWHint) );
trackFw->setEvaluateOnChange(false);
trackFw->setCheckable(true);
trackFw->setDefaultValue(false);
trackFw->setSecretByDefault(true);
trackFw->setInViewerContextCanHaveShortcut(true);
trackFw->setIconLabel(NATRON_IMAGES_PATH "trackForwardOn.png", true);
trackFw->setIconLabel(NATRON_IMAGES_PATH "trackForwardOff.png", false);
trackingPage->addKnob(trackFw);
_imp->ui->trackFwButton = trackFw;
KnobButtonPtr trackRange = AppManager::createKnob<KnobButton>( this, tr(kTrackerUIParamTrackRangeLabel) );
trackRange->setName(kTrackerUIParamTrackRange);
trackRange->setHintToolTip( tr(kTrackerUIParamTrackRangeHint) );
trackRange->setEvaluateOnChange(false);
trackRange->setSecretByDefault(true);
trackRange->setInViewerContextCanHaveShortcut(true);
trackRange->setIconLabel(NATRON_IMAGES_PATH "trackRange.png");
trackingPage->addKnob(trackRange);
_imp->ui->trackRangeButton = trackRange;
KnobButtonPtr trackAllKeys = AppManager::createKnob<KnobButton>( this, tr(kTrackerUIParamTrackAllKeyframesLabel) );
trackAllKeys->setName(kTrackerUIParamTrackAllKeyframes);
trackAllKeys->setHintToolTip( tr(kTrackerUIParamTrackAllKeyframesHint) );
trackAllKeys->setEvaluateOnChange(false);
trackAllKeys->setSecretByDefault(true);
trackAllKeys->setInViewerContextCanHaveShortcut(true);
trackAllKeys->setIconLabel(NATRON_IMAGES_PATH "trackAllKeyframes.png");
trackingPage->addKnob(trackAllKeys);
_imp->ui->trackAllKeyframesButton = trackAllKeys;
KnobButtonPtr trackCurKey = AppManager::createKnob<KnobButton>( this, tr(kTrackerUIParamTrackCurrentKeyframeLabel) );
trackCurKey->setName(kTrackerUIParamTrackCurrentKeyframe);
trackCurKey->setHintToolTip( tr(kTrackerUIParamTrackCurrentKeyframeHint) );
trackCurKey->setEvaluateOnChange(false);
trackCurKey->setSecretByDefault(true);
trackCurKey->setInViewerContextCanHaveShortcut(true);
trackCurKey->setIconLabel(NATRON_IMAGES_PATH "trackCurrentKeyframe.png");
trackingPage->addKnob(trackCurKey);
_imp->ui->trackCurrentKeyframeButton = trackCurKey;
KnobButtonPtr addKeyframe = AppManager::createKnob<KnobButton>( this, tr(kTrackerUIParamSetPatternKeyFrameLabel) );
addKeyframe->setName(kTrackerUIParamSetPatternKeyFrame);
addKeyframe->setHintToolTip( tr(kTrackerUIParamSetPatternKeyFrameHint) );
addKeyframe->setEvaluateOnChange(false);
addKeyframe->setSecretByDefault(true);
addKeyframe->setInViewerContextCanHaveShortcut(true);
addKeyframe->setIconLabel(NATRON_IMAGES_PATH "addUserKey.png");
trackingPage->addKnob(addKeyframe);
_imp->ui->setKeyFrameButton = addKeyframe;
KnobButtonPtr removeKeyframe = AppManager::createKnob<KnobButton>( this, tr(kTrackerUIParamRemovePatternKeyFrameLabel) );
removeKeyframe->setName(kTrackerUIParamRemovePatternKeyFrame);
removeKeyframe->setHintToolTip( tr(kTrackerUIParamRemovePatternKeyFrameHint) );
removeKeyframe->setEvaluateOnChange(false);
removeKeyframe->setSecretByDefault(true);
removeKeyframe->setInViewerContextCanHaveShortcut(true);
removeKeyframe->setIconLabel(NATRON_IMAGES_PATH "removeUserKey.png");
trackingPage->addKnob(removeKeyframe);
_imp->ui->removeKeyFrameButton = removeKeyframe;
KnobButtonPtr clearAllAnimation = AppManager::createKnob<KnobButton>( this, tr(kTrackerUIParamClearAllAnimationLabel) );
clearAllAnimation->setName(kTrackerUIParamClearAllAnimation);
clearAllAnimation->setHintToolTip( tr(kTrackerUIParamClearAllAnimationHint) );
clearAllAnimation->setEvaluateOnChange(false);
clearAllAnimation->setSecretByDefault(true);
clearAllAnimation->setInViewerContextCanHaveShortcut(true);
clearAllAnimation->setIconLabel(NATRON_IMAGES_PATH "clearAnimation.png");
trackingPage->addKnob(clearAllAnimation);
_imp->ui->clearAllAnimationButton = clearAllAnimation;
KnobButtonPtr clearBackwardAnim = AppManager::createKnob<KnobButton>( this, tr(kTrackerUIParamClearAnimationBwLabel) );
clearBackwardAnim->setName(kTrackerUIParamClearAnimationBw);
clearBackwardAnim->setHintToolTip( tr(kTrackerUIParamClearAnimationBwHint) );
clearBackwardAnim->setEvaluateOnChange(false);
clearBackwardAnim->setSecretByDefault(true);
clearBackwardAnim->setInViewerContextCanHaveShortcut(true);
clearBackwardAnim->setIconLabel(NATRON_IMAGES_PATH "clearAnimationBw.png");
trackingPage->addKnob(clearBackwardAnim);
_imp->ui->clearBwAnimationButton = clearBackwardAnim;
KnobButtonPtr clearForwardAnim = AppManager::createKnob<KnobButton>( this, tr(kTrackerUIParamClearAnimationFwLabel) );
clearForwardAnim->setName(kTrackerUIParamClearAnimationFw);
clearForwardAnim->setHintToolTip( tr(kTrackerUIParamClearAnimationFwHint) );
clearForwardAnim->setEvaluateOnChange(false);
clearForwardAnim->setSecretByDefault(true);
clearForwardAnim->setInViewerContextCanHaveShortcut(true);
clearForwardAnim->setIconLabel(NATRON_IMAGES_PATH "clearAnimationFw.png");
trackingPage->addKnob(clearForwardAnim);
_imp->ui->clearFwAnimationButton = clearForwardAnim;
KnobButtonPtr updateViewer = AppManager::createKnob<KnobButton>( this, tr(kTrackerUIParamRefreshViewerLabel) );
updateViewer->setName(kTrackerUIParamRefreshViewer);
updateViewer->setHintToolTip( tr(kTrackerUIParamRefreshViewerHint) );
updateViewer->setEvaluateOnChange(false);
updateViewer->setCheckable(true);
updateViewer->setDefaultValue(true);
updateViewer->setSecretByDefault(true);
updateViewer->setInViewerContextCanHaveShortcut(true);
updateViewer->setIconLabel(NATRON_IMAGES_PATH "refreshActive.png", true);
updateViewer->setIconLabel(NATRON_IMAGES_PATH "refresh.png", false);
trackingPage->addKnob(updateViewer);
_imp->ui->updateViewerButton = updateViewer;
KnobButtonPtr centerViewer = AppManager::createKnob<KnobButton>( this, tr(kTrackerUIParamCenterViewerLabel) );
centerViewer->setName(kTrackerUIParamCenterViewer);
centerViewer->setHintToolTip( tr(kTrackerUIParamCenterViewerHint) );
centerViewer->setEvaluateOnChange(false);
centerViewer->setCheckable(true);
centerViewer->setDefaultValue(false);
centerViewer->setSecretByDefault(true);
centerViewer->setInViewerContextCanHaveShortcut(true);
centerViewer->setIconLabel(NATRON_IMAGES_PATH "centerOnTrack.png");
trackingPage->addKnob(centerViewer);
_imp->ui->centerViewerButton = centerViewer;
KnobButtonPtr createKeyOnMove = AppManager::createKnob<KnobButton>( this, tr(kTrackerUIParamCreateKeyOnMoveLabel) );
createKeyOnMove->setName(kTrackerUIParamCreateKeyOnMove);
createKeyOnMove->setHintToolTip( tr(kTrackerUIParamCreateKeyOnMoveHint) );
createKeyOnMove->setEvaluateOnChange(false);
createKeyOnMove->setCheckable(true);
createKeyOnMove->setDefaultValue(true);
createKeyOnMove->setSecretByDefault(true);
createKeyOnMove->setInViewerContextCanHaveShortcut(true);
createKeyOnMove->setIconLabel(NATRON_IMAGES_PATH "createKeyOnMoveOn.png", true);
createKeyOnMove->setIconLabel(NATRON_IMAGES_PATH "createKeyOnMoveOff.png", false);
trackingPage->addKnob(createKeyOnMove);
_imp->ui->createKeyOnMoveButton = createKeyOnMove;
KnobButtonPtr showError = AppManager::createKnob<KnobButton>( this, tr(kTrackerUIParamShowErrorLabel) );
showError->setName(kTrackerUIParamShowError);
showError->setHintToolTip( tr(kTrackerUIParamShowErrorHint) );
showError->setEvaluateOnChange(false);
showError->setCheckable(true);
showError->setDefaultValue(false);
showError->setSecretByDefault(true);
showError->setInViewerContextCanHaveShortcut(true);
addOverlaySlaveParam(showError);
showError->setIconLabel(NATRON_IMAGES_PATH "showTrackError.png", true);
showError->setIconLabel(NATRON_IMAGES_PATH "hideTrackError.png", false);
trackingPage->addKnob(showError);
_imp->ui->showCorrelationButton = showError;
KnobButtonPtr resetOffset = AppManager::createKnob<KnobButton>( this, tr(kTrackerUIParamResetOffsetLabel) );
resetOffset->setName(kTrackerUIParamResetOffset);
resetOffset->setHintToolTip( tr(kTrackerUIParamResetOffsetHint) );
resetOffset->setEvaluateOnChange(false);
resetOffset->setSecretByDefault(true);
resetOffset->setInViewerContextCanHaveShortcut(true);
addOverlaySlaveParam(resetOffset);
resetOffset->setIconLabel(NATRON_IMAGES_PATH "resetTrackOffset.png");
trackingPage->addKnob(resetOffset);
_imp->ui->resetOffsetButton = resetOffset;
KnobButtonPtr resetTrack = AppManager::createKnob<KnobButton>( this, tr(kTrackerUIParamResetTrackLabel) );
resetTrack->setName(kTrackerUIParamResetTrack);
resetTrack->setHintToolTip( tr(kTrackerUIParamResetTrackHint) );
resetTrack->setEvaluateOnChange(false);
resetTrack->setSecretByDefault(true);
resetTrack->setInViewerContextCanHaveShortcut(true);
addOverlaySlaveParam(resetTrack);
resetTrack->setIconLabel(NATRON_IMAGES_PATH "restoreDefaultEnabled.png");
trackingPage->addKnob(resetTrack);
_imp->ui->resetTrackButton = resetTrack;
KnobIntPtr magWindow = AppManager::createKnob<KnobInt>( this, tr(kTrackerUIParamMagWindowSizeLabel) );
magWindow->setInViewerContextLabel(tr(kTrackerUIParamMagWindowSizeLabel));
magWindow->setName(kTrackerUIParamMagWindowSize);
magWindow->setHintToolTip( tr(kTrackerUIParamMagWindowSizeHint) );
magWindow->setEvaluateOnChange(false);
magWindow->setDefaultValue(200);
magWindow->setMinimum(10);
magWindow->setMaximum(10000);
magWindow->disableSlider();
addOverlaySlaveParam(magWindow);
trackingPage->addKnob(magWindow);
_imp->ui->magWindowPxSizeKnob = magWindow;
addKnobToViewerUI(addMarker);
addMarker->setInViewerContextItemSpacing(NATRON_TRACKER_UI_BUTTONS_CATEGORIES_SPACING);
addKnobToViewerUI(trackBw);
trackBw->setInViewerContextItemSpacing(0);
addKnobToViewerUI(trackPrev);
trackPrev->setInViewerContextItemSpacing(0);
addKnobToViewerUI(trackNext);
trackNext->setInViewerContextItemSpacing(0);
addKnobToViewerUI(trackFw);
trackFw->setInViewerContextItemSpacing(NATRON_TRACKER_UI_BUTTONS_CATEGORIES_SPACING);
addKnobToViewerUI(trackRange);
trackRange->setInViewerContextItemSpacing(NATRON_TRACKER_UI_BUTTONS_CATEGORIES_SPACING);
addKnobToViewerUI(trackAllKeys);
trackAllKeys->setInViewerContextItemSpacing(0);
addKnobToViewerUI(trackCurKey);
trackCurKey->setInViewerContextItemSpacing(NATRON_TRACKER_UI_BUTTONS_CATEGORIES_SPACING);
addKnobToViewerUI(addKeyframe);
addKeyframe->setInViewerContextItemSpacing(0);
addKnobToViewerUI(removeKeyframe);
removeKeyframe->setInViewerContextItemSpacing(NATRON_TRACKER_UI_BUTTONS_CATEGORIES_SPACING);
addKnobToViewerUI(clearAllAnimation);
clearAllAnimation->setInViewerContextItemSpacing(0);
addKnobToViewerUI(clearBackwardAnim);
clearBackwardAnim->setInViewerContextItemSpacing(0);
addKnobToViewerUI(clearForwardAnim);
clearForwardAnim->setInViewerContextItemSpacing(NATRON_TRACKER_UI_BUTTONS_CATEGORIES_SPACING);
addKnobToViewerUI(updateViewer);
updateViewer->setInViewerContextItemSpacing(0);
addKnobToViewerUI(centerViewer);
centerViewer->setInViewerContextItemSpacing(NATRON_TRACKER_UI_BUTTONS_CATEGORIES_SPACING);
addKnobToViewerUI(createKeyOnMove);
addKnobToViewerUI(showError);
showError->setInViewerContextItemSpacing(NATRON_TRACKER_UI_BUTTONS_CATEGORIES_SPACING);
addKnobToViewerUI(resetOffset);
resetOffset->setInViewerContextItemSpacing(0);
addKnobToViewerUI(resetTrack);
resetTrack->setInViewerContextItemSpacing(NATRON_TRACKER_UI_BUTTONS_CATEGORIES_SPACING);
addKnobToViewerUI(context->getDefaultMarkerPatternWinSizeKnob());
addKnobToViewerUI(context->getDefaultMarkerSearchWinSizeKnob());
addKnobToViewerUI(context->getDefaultMotionModelKnob());
context->setUpdateViewer( updateViewer->getValue() );
context->setCenterOnTrack( centerViewer->getValue() );
QObject::connect( getNode().get(), SIGNAL(s_refreshPreviewsAfterProjectLoadRequested()), _imp->ui.get(), SLOT(rebuildMarkerTextures()) );
QObject::connect( context.get(), SIGNAL(selectionChanged(int)), _imp->ui.get(), SLOT(onContextSelectionChanged(int)) );
QObject::connect( context.get(), SIGNAL(keyframeSetOnTrack(TrackMarkerPtr,int)), _imp->ui.get(), SLOT(onKeyframeSetOnTrack(TrackMarkerPtr,int)) );
QObject::connect( context.get(), SIGNAL(keyframeRemovedOnTrack(TrackMarkerPtr,int)), _imp->ui.get(), SLOT(onKeyframeRemovedOnTrack(TrackMarkerPtr,int)) );
QObject::connect( context.get(), SIGNAL(allKeyframesRemovedOnTrack(TrackMarkerPtr)), _imp->ui.get(), SLOT(onAllKeyframesRemovedOnTrack(TrackMarkerPtr)) );
QObject::connect( context.get(), SIGNAL(trackingFinished()), _imp->ui.get(), SLOT(onTrackingEnded()) );
QObject::connect( context.get(), SIGNAL(trackingStarted(int)), _imp->ui.get(), SLOT(onTrackingStarted(int)) );
// Right click menu
KnobChoicePtr rightClickMenu = AppManager::createKnob<KnobChoice>( this, std::string(kTrackerUIParamRightClickMenu) );
rightClickMenu->setSecretByDefault(true);
rightClickMenu->setEvaluateOnChange(false);
trackingPage->addKnob(rightClickMenu);
_imp->ui->rightClickMenuKnob = rightClickMenu;
{
KnobButtonPtr action = AppManager::createKnob<KnobButton>( this, tr(kTrackerUIParamRightClickMenuActionSelectAllTracksLabel) );
action->setName(kTrackerUIParamRightClickMenuActionSelectAllTracks);
action->setSecretByDefault(true);
action->setEvaluateOnChange(false);
action->setInViewerContextCanHaveShortcut(true);
addOverlaySlaveParam(action);
trackingPage->addKnob(action);
_imp->ui->selectAllTracksMenuAction = action;
}
{
KnobButtonPtr action = AppManager::createKnob<KnobButton>( this, tr(kTrackerUIParamRightClickMenuActionRemoveTracksLabel) );
action->setName(kTrackerUIParamRightClickMenuActionRemoveTracks);
action->setSecretByDefault(true);
action->setEvaluateOnChange(false);
action->setInViewerContextCanHaveShortcut(true);
addOverlaySlaveParam(action);
trackingPage->addKnob(action);
_imp->ui->removeTracksMenuAction = action;
}
{
KnobButtonPtr action = AppManager::createKnob<KnobButton>( this, tr(kTrackerUIParamRightClickMenuActionNudgeBottomLabel) );
action->setName(kTrackerUIParamRightClickMenuActionNudgeBottom);
action->setSecretByDefault(true);
action->setEvaluateOnChange(false);
action->setInViewerContextCanHaveShortcut(true);
addOverlaySlaveParam(action);
trackingPage->addKnob(action);
_imp->ui->nudgeTracksOnBottomMenuAction = action;
}
{
KnobButtonPtr action = AppManager::createKnob<KnobButton>( this, tr(kTrackerUIParamRightClickMenuActionNudgeLeftLabel) );
action->setName(kTrackerUIParamRightClickMenuActionNudgeLeft);
action->setSecretByDefault(true);
action->setEvaluateOnChange(false);
action->setInViewerContextCanHaveShortcut(true);
addOverlaySlaveParam(action);
trackingPage->addKnob(action);
_imp->ui->nudgeTracksOnLeftMenuAction = action;
}
{
KnobButtonPtr action = AppManager::createKnob<KnobButton>( this, tr(kTrackerUIParamRightClickMenuActionNudgeRightLabel) );
action->setName(kTrackerUIParamRightClickMenuActionNudgeRight);
action->setSecretByDefault(true);
action->setEvaluateOnChange(false);
action->setInViewerContextCanHaveShortcut(true);
addOverlaySlaveParam(action);
trackingPage->addKnob(action);
_imp->ui->nudgeTracksOnRightMenuAction = action;
}
{
KnobButtonPtr action = AppManager::createKnob<KnobButton>( this, tr(kTrackerUIParamRightClickMenuActionNudgeTopLabel) );
action->setName(kTrackerUIParamRightClickMenuActionNudgeTop);
action->setSecretByDefault(true);
action->setEvaluateOnChange(false);
action->setInViewerContextCanHaveShortcut(true);
addOverlaySlaveParam(action);
trackingPage->addKnob(action);
_imp->ui->nudgeTracksOnTopMenuAction = action;
}
// Track range dialog
KnobGroupPtr trackRangeDialog = AppManager::createKnob<KnobGroup>( this, tr(kTrackerUIParamTrackRangeDialogLabel) );
trackRangeDialog->setName(kTrackerUIParamTrackRangeDialog);
trackRangeDialog->setSecretByDefault(true);
trackRangeDialog->setEvaluateOnChange(false);
trackRangeDialog->setDefaultValue(false);
trackRangeDialog->setIsPersistent(false);
trackRangeDialog->setAsDialog(true);
trackingPage->addKnob(trackRangeDialog);
_imp->ui->trackRangeDialogGroup = trackRangeDialog;
KnobIntPtr trackRangeDialogFirstFrame = AppManager::createKnob<KnobInt>( this, tr(kTrackerUIParamTrackRangeDialogFirstFrameLabel) );
trackRangeDialogFirstFrame->setName(kTrackerUIParamTrackRangeDialogFirstFrame);
trackRangeDialogFirstFrame->setHintToolTip( tr(kTrackerUIParamTrackRangeDialogFirstFrameHint) );
trackRangeDialogFirstFrame->setSecretByDefault(true);
trackRangeDialogFirstFrame->setEvaluateOnChange(false);
trackRangeDialogFirstFrame->setAnimationEnabled(false);
trackRangeDialogFirstFrame->setIsPersistent(false);
trackRangeDialogFirstFrame->setDefaultValue(INT_MIN);
trackRangeDialog->addKnob(trackRangeDialogFirstFrame);
_imp->ui->trackRangeDialogFirstFrame = trackRangeDialogFirstFrame;
KnobIntPtr trackRangeDialogLastFrame = AppManager::createKnob<KnobInt>( this, tr(kTrackerUIParamTrackRangeDialogLastFrameLabel) );
trackRangeDialogLastFrame->setName(kTrackerUIParamTrackRangeDialogLastFrame);
trackRangeDialogLastFrame->setHintToolTip( tr(kTrackerUIParamTrackRangeDialogLastFrameHint) );
trackRangeDialogLastFrame->setSecretByDefault(true);
trackRangeDialogLastFrame->setEvaluateOnChange(false);
trackRangeDialogLastFrame->setAnimationEnabled(false);
trackRangeDialogLastFrame->setIsPersistent(false);
trackRangeDialogLastFrame->setDefaultValue(INT_MIN);
trackRangeDialog->addKnob(trackRangeDialogLastFrame);
_imp->ui->trackRangeDialogLastFrame = trackRangeDialogLastFrame;
KnobIntPtr trackRangeDialogFrameStep = AppManager::createKnob<KnobInt>( this, tr(kTrackerUIParamTrackRangeDialogStepLabel) );
trackRangeDialogFrameStep->setName(kTrackerUIParamTrackRangeDialogStep);
trackRangeDialogFrameStep->setHintToolTip( tr(kTrackerUIParamTrackRangeDialogStepHint) );
trackRangeDialogFrameStep->setSecretByDefault(true);
trackRangeDialogFrameStep->setEvaluateOnChange(false);
trackRangeDialogFrameStep->setAnimationEnabled(false);
trackRangeDialogFrameStep->setIsPersistent(false);
trackRangeDialogFrameStep->setDefaultValue(INT_MIN);
trackRangeDialog->addKnob(trackRangeDialogFrameStep);
_imp->ui->trackRangeDialogStep = trackRangeDialogFrameStep;
KnobButtonPtr trackRangeDialogOkButton = AppManager::createKnob<KnobButton>( this, tr(kTrackerUIParamTrackRangeDialogOkButtonLabel) );
trackRangeDialogOkButton->setName(kTrackerUIParamTrackRangeDialogOkButton);
trackRangeDialogOkButton->setHintToolTip( tr(kTrackerUIParamTrackRangeDialogOkButtonHint) );
trackRangeDialogOkButton->setSecretByDefault(true);
trackRangeDialogOkButton->setAddNewLine(false);
trackRangeDialogOkButton->setEvaluateOnChange(false);
trackRangeDialogOkButton->setSpacingBetweenItems(3);
trackRangeDialogOkButton->setIsPersistent(false);
trackRangeDialog->addKnob(trackRangeDialogOkButton);
_imp->ui->trackRangeDialogOkButton = trackRangeDialogOkButton;
KnobButtonPtr trackRangeDialogCancelButton = AppManager::createKnob<KnobButton>( this, tr(kTrackerUIParamTrackRangeDialogCancelButtonLabel) );
trackRangeDialogCancelButton->setName(kTrackerUIParamTrackRangeDialogCancelButton);
trackRangeDialogCancelButton->setHintToolTip( tr(kTrackerUIParamTrackRangeDialogCancelButtonHint) );
trackRangeDialogCancelButton->setSecretByDefault(true);
trackRangeDialogCancelButton->setEvaluateOnChange(false);
trackRangeDialog->addKnob(trackRangeDialogCancelButton);
_imp->ui->trackRangeDialogCancelButton = trackRangeDialogCancelButton;
} // TrackerNode::initializeKnobs
bool
TrackerNode::knobChanged(KnobI* k,
ValueChangedReasonEnum reason,
ViewSpec view,
double time,
bool originatedFromMainThread)
{
TrackerContextPtr ctx = getNode()->getTrackerContext();
if (!ctx) {
return false;
}
ctx->onKnobsLoaded();
bool ret = true;
if ( k == _imp->ui->trackRangeDialogOkButton.lock().get() ) {
int first = _imp->ui->trackRangeDialogFirstFrame.lock()->getValue();
int last = _imp->ui->trackRangeDialogLastFrame.lock()->getValue();
int step = _imp->ui->trackRangeDialogStep.lock()->getValue();
TrackerContextPtr ctx = getNode()->getTrackerContext();
if ( ctx->isCurrentlyTracking() ) {
ctx->abortTracking();
}
if (step == 0) {
message( eMessageTypeError, tr("The Step cannot be 0").toStdString() );
return false;
}
int startFrame = step > 0 ? first : last;
int lastFrame = step > 0 ? last + 1 : first - 1;
if ( ( (step > 0) && (startFrame >= lastFrame) ) || ( (step < 0) && (startFrame <= lastFrame) ) ) {
return false;
}
OverlaySupport* overlay = getCurrentViewportForOverlays();
ctx->trackSelectedMarkers( startFrame, lastFrame, step, overlay);
_imp->ui->trackRangeDialogGroup.lock()->setValue(false);
} else if ( k == _imp->ui->trackRangeDialogCancelButton.lock().get() ) {
_imp->ui->trackRangeDialogGroup.lock()->setValue(false);
} else if ( k == _imp->ui->selectAllTracksMenuAction.lock().get() ) {
getNode()->getTrackerContext()->selectAll(TrackerContext::eTrackSelectionInternal);
} else if ( k == _imp->ui->removeTracksMenuAction.lock().get() ) {
std::list<TrackMarkerPtr> markers;
TrackerContextPtr context = getNode()->getTrackerContext();
context->getSelectedMarkers(&markers);
if ( !markers.empty() ) {
pushUndoCommand( new RemoveTracksCommand( markers, context ) );
}
} else if ( ( k == _imp->ui->nudgeTracksOnTopMenuAction.lock().get() ) && (reason == eValueChangedReasonUserEdited) ) {
if ( !_imp->ui->nudgeSelectedTracks(0, 1) ) {
return false;
}
} else if ( ( k == _imp->ui->nudgeTracksOnRightMenuAction.lock().get() ) && (reason == eValueChangedReasonUserEdited) ) {
if ( !_imp->ui->nudgeSelectedTracks(1, 0) ) {
return false;
}
} else if ( ( k == _imp->ui->nudgeTracksOnLeftMenuAction.lock().get() ) && (reason == eValueChangedReasonUserEdited) ) {
if ( !_imp->ui->nudgeSelectedTracks(-1, 0) ) {
return false;
}
} else if ( ( k == _imp->ui->nudgeTracksOnBottomMenuAction.lock().get() ) && (reason == eValueChangedReasonUserEdited) ) {
if ( !_imp->ui->nudgeSelectedTracks(0, -1) ) {
return false;
}
} else if ( ( k == _imp->ui->stopTrackingButton.lock().get() ) && (reason == eValueChangedReasonUserEdited) ) {
_imp->ui->onStopButtonClicked();
} else if ( ( k == _imp->ui->trackBwButton.lock().get() ) && (reason == eValueChangedReasonUserEdited) ) {
_imp->ui->onTrackBwClicked();
} else if ( ( k == _imp->ui->trackPrevButton.lock().get() ) && (reason == eValueChangedReasonUserEdited) ) {
_imp->ui->onTrackPrevClicked();
} else if ( ( k == _imp->ui->trackFwButton.lock().get() ) && (reason == eValueChangedReasonUserEdited) ) {
_imp->ui->onTrackFwClicked();
} else if ( ( k == _imp->ui->trackNextButton.lock().get() ) && (reason == eValueChangedReasonUserEdited) ) {
_imp->ui->onTrackNextClicked();
} else if ( ( k == _imp->ui->trackRangeButton.lock().get() ) && (reason == eValueChangedReasonUserEdited) ) {
_imp->ui->onTrackRangeClicked();
} else if ( ( k == _imp->ui->trackAllKeyframesButton.lock().get() ) && (reason == eValueChangedReasonUserEdited) ) {
_imp->ui->onTrackAllKeyframesClicked();
} else if ( ( k == _imp->ui->trackCurrentKeyframeButton.lock().get() ) && (reason == eValueChangedReasonUserEdited) ) {
_imp->ui->onTrackCurrentKeyframeClicked();
} else if ( ( k == _imp->ui->clearAllAnimationButton.lock().get() ) && (reason == eValueChangedReasonUserEdited) ) {
_imp->ui->onClearAllAnimationClicked();
} else if ( ( k == _imp->ui->clearBwAnimationButton.lock().get() ) && (reason == eValueChangedReasonUserEdited) ) {
_imp->ui->onClearBwAnimationClicked();
} else if ( ( k == _imp->ui->clearFwAnimationButton.lock().get() ) && (reason == eValueChangedReasonUserEdited) ) {
_imp->ui->onClearFwAnimationClicked();
} else if ( ( k == _imp->ui->updateViewerButton.lock().get() ) && (reason == eValueChangedReasonUserEdited) ) {
_imp->ui->onUpdateViewerClicked( _imp->ui->updateViewerButton.lock()->getValue() );
} else if ( ( k == _imp->ui->centerViewerButton.lock().get() ) && (reason == eValueChangedReasonUserEdited) ) {
_imp->ui->onCenterViewerButtonClicked( _imp->ui->centerViewerButton.lock()->getValue() );
} else if ( ( k == _imp->ui->setKeyFrameButton.lock().get() ) && (reason == eValueChangedReasonUserEdited) ) {
_imp->ui->onSetKeyframeButtonClicked();
} else if ( ( k == _imp->ui->removeKeyFrameButton.lock().get() ) && (reason == eValueChangedReasonUserEdited) ) {
_imp->ui->onRemoveKeyframeButtonClicked();
} else if ( ( k == _imp->ui->resetOffsetButton.lock().get() ) && (reason == eValueChangedReasonUserEdited) ) {
_imp->ui->onResetOffsetButtonClicked();
} else if ( ( k == _imp->ui->resetTrackButton.lock().get() ) && (reason == eValueChangedReasonUserEdited) ) {
_imp->ui->onResetTrackButtonClicked();
} else if ( k == _imp->ui->addTrackButton.lock().get() ) {
_imp->ui->clickToAddTrackEnabled = _imp->ui->addTrackButton.lock()->getValue();
} else {
ret = false;
}
if (!ret) {
ret |= ctx->knobChanged(k, reason, view, time, originatedFromMainThread);
}
return ret;
} // TrackerNode::knobChanged
void
TrackerNode::onKnobsLoaded()
{
TrackerContextPtr ctx = getNode()->getTrackerContext();
if (!ctx) {
return;
}
ctx->onKnobsLoaded();
ctx->setUpdateViewer( _imp->ui->updateViewerButton.lock()->getValue() );
ctx->setCenterOnTrack( _imp->ui->centerViewerButton.lock()->getValue() );
}
void
TrackerNode::evaluate(bool isSignificant, bool refreshMetadata)
{
NodeGroup::evaluate(isSignificant, refreshMetadata);
_imp->ui->refreshSelectedMarkerTexture();
}
void
TrackerNode::onInputChanged(int inputNb)
{
TrackerContextPtr ctx = getNode()->getTrackerContext();
ctx->inputChanged(inputNb);
_imp->ui->refreshSelectedMarkerTexture();
}
struct CenterPointDisplayInfo
{
double x;
double y;
double err;
bool isValid;
CenterPointDisplayInfo()
: x(0)
, y(0)
, err(0)
, isValid(false)
{
}
};
typedef std::map<double, CenterPointDisplayInfo> CenterPointsMap;
void
TrackerNode::drawOverlay(double time,
const RenderScale & /*renderScale*/,
ViewIdx /*view*/)
{
double pixelScaleX, pixelScaleY;
OverlaySupport* overlay = getCurrentViewportForOverlays();
assert(overlay);
overlay->getPixelScale(pixelScaleX, pixelScaleY);
double viewportSize[2];
overlay->getViewportSize(viewportSize[0], viewportSize[1]);
double screenPixelRatio = overlay->getScreenPixelRatio();
{
GLProtectAttrib a(GL_CURRENT_BIT | GL_COLOR_BUFFER_BIT | GL_LINE_BIT | GL_POINT_BIT | GL_ENABLE_BIT | GL_HINT_BIT | GL_TRANSFORM_BIT);
double markerColor[3];
if ( !getNode()->getOverlayColor(&markerColor[0], &markerColor[1], &markerColor[2]) ) {
markerColor[0] = markerColor[1] = markerColor[2] = 0.8;
}
std::vector<TrackMarkerPtr> allMarkers;
std::list<TrackMarkerPtr> selectedMarkers;
TrackerContextPtr context = getNode()->getTrackerContext();
context->getSelectedMarkers(&selectedMarkers);
context->getAllMarkers(&allMarkers);
bool trackingPageSecret = context->getTrackingPageKnob()->getIsSecret();
bool showErrorColor = _imp->ui->showCorrelationButton.lock()->getValue();
TrackMarkerPtr selectedMarker = _imp->ui->selectedMarker.lock();
bool selectedFound = false;
Point selectedCenter;
Point selectedPtnTopLeft;
Point selectedPtnTopRight;
Point selectedPtnBtmRight;
Point selectedPtnBtmLeft;
Point selectedOffset;
Point selectedSearchBtmLeft;
Point selectedSearchTopRight;
for (std::vector<TrackMarkerPtr>::iterator it = allMarkers.begin(); it != allMarkers.end(); ++it) {
bool isEnabled = (*it)->isEnabled(time);
double thisMarkerColor[3];
if (!isEnabled) {
for (int i = 0; i < 3; ++i) {
thisMarkerColor[i] = markerColor[i] / 2.;
}
} else {
for (int i = 0; i < 3; ++i) {
thisMarkerColor[i] = markerColor[i];
}
}
bool isHoverMarker = *it == _imp->ui->hoverMarker;
bool isDraggedMarker = *it == _imp->ui->interactMarker;
bool isHoverOrDraggedMarker = isHoverMarker || isDraggedMarker;
std::list<TrackMarkerPtr>::iterator foundSelected = std::find(selectedMarkers.begin(), selectedMarkers.end(), *it);
bool isSelected = foundSelected != selectedMarkers.end();
KnobDoublePtr centerKnob = (*it)->getCenterKnob();
KnobDoublePtr offsetKnob = (*it)->getOffsetKnob();
KnobDoublePtr errorKnob = (*it)->getErrorKnob();
KnobDoublePtr ptnTopLeft = (*it)->getPatternTopLeftKnob();
KnobDoublePtr ptnTopRight = (*it)->getPatternTopRightKnob();
KnobDoublePtr ptnBtmRight = (*it)->getPatternBtmRightKnob();
KnobDoublePtr ptnBtmLeft = (*it)->getPatternBtmLeftKnob();
KnobDoublePtr searchWndBtmLeft = (*it)->getSearchWindowBottomLeftKnob();
KnobDoublePtr searchWndTopRight = (*it)->getSearchWindowTopRightKnob();
// When the tracking page is secret, still show markers, but as if deselected
if (!isSelected || trackingPageSecret) {
///Draw a custom interact, indicating the track isn't selected
glEnable(GL_LINE_SMOOTH);
glHint(GL_LINE_SMOOTH_HINT, GL_DONT_CARE);
for (int l = 0; l < 2; ++l) {
// shadow (uses GL_PROJECTION)
glMatrixMode(GL_PROJECTION);
int direction = (l == 0) ? 1 : -1;
// translate (1,-1) pixels
glTranslated(direction * pixelScaleX / 256, -direction * pixelScaleY / 256, 0);
glMatrixMode(GL_MODELVIEW);
if (l == 0) {
glColor4d(0., 0., 0., 1.);
} else {
glColor4f(thisMarkerColor[0], thisMarkerColor[1], thisMarkerColor[2], 1.);
}
double x = centerKnob->getValueAtTime(time, 0);
double y = centerKnob->getValueAtTime(time, 1);
glPointSize(POINT_SIZE * screenPixelRatio);
glBegin(GL_POINTS);
glVertex2d(x, y);
glEnd();
glLineWidth(1.5f * screenPixelRatio);
glBegin(GL_LINES);
glVertex2d(x - CROSS_SIZE * pixelScaleX, y);
glVertex2d(x + CROSS_SIZE * pixelScaleX, y);
glVertex2d(x, y - CROSS_SIZE * pixelScaleY);
glVertex2d(x, y + CROSS_SIZE * pixelScaleY);
glEnd();
}
glPointSize(1. * screenPixelRatio);
} else { // if (isSelected) {
glEnable(GL_LINE_SMOOTH);
glHint(GL_LINE_SMOOTH_HINT, GL_DONT_CARE);
GLdouble projection[16];
glGetDoublev( GL_PROJECTION_MATRIX, projection);
OfxPointD shadow; // how much to translate GL_PROJECTION to get exactly one pixel on screen
shadow.x = 2. / (projection[0] * viewportSize[0]);
shadow.y = 2. / (projection[5] * viewportSize[1]);
const QPointF center( centerKnob->getValueAtTime(time, 0),
centerKnob->getValueAtTime(time, 1) );
const QPointF offset( offsetKnob->getValueAtTime(time, 0),
offsetKnob->getValueAtTime(time, 1) );
const QPointF topLeft( ptnTopLeft->getValueAtTime(time, 0) + offset.x() + center.x(),
ptnTopLeft->getValueAtTime(time, 1) + offset.y() + center.y() );
const QPointF topRight( ptnTopRight->getValueAtTime(time, 0) + offset.x() + center.x(),
ptnTopRight->getValueAtTime(time, 1) + offset.y() + center.y() );
const QPointF btmRight( ptnBtmRight->getValueAtTime(time, 0) + offset.x() + center.x(),
ptnBtmRight->getValueAtTime(time, 1) + offset.y() + center.y() );
const QPointF btmLeft( ptnBtmLeft->getValueAtTime(time, 0) + offset.x() + center.x(),
ptnBtmLeft->getValueAtTime(time, 1) + offset.y() + center.y() );
const double searchLeft = searchWndBtmLeft->getValueAtTime(time, 0) + offset.x() + center.x();
const double searchBottom = searchWndBtmLeft->getValueAtTime(time, 1) + offset.y() + center.y();
const double searchRight = searchWndTopRight->getValueAtTime(time, 0) + offset.x() + center.x();
const double searchTop = searchWndTopRight->getValueAtTime(time, 1) + offset.y() + center.y();
const double searchMidX = (searchLeft + searchRight) / 2;
const double searchMidY = (searchTop + searchBottom) / 2;
if (selectedMarker == *it) {
selectedCenter.x = center.x();
selectedCenter.y = center.y();
selectedOffset.x = offset.x();
selectedOffset.y = offset.y();
selectedPtnBtmLeft.x = btmLeft.x();
selectedPtnBtmLeft.y = btmLeft.y();
selectedPtnBtmRight.x = btmRight.x();
selectedPtnBtmRight.y = btmRight.y();
selectedPtnTopRight.x = topRight.x();
selectedPtnTopRight.y = topRight.y();
selectedPtnTopLeft.x = topLeft.x();
selectedPtnTopLeft.y = topLeft.y();
selectedSearchBtmLeft.x = searchLeft;
selectedSearchBtmLeft.y = searchBottom;
selectedSearchTopRight.x = searchRight;
selectedSearchTopRight.y = searchTop;
selectedFound = true;
}
const QPointF innerMidLeft( (btmLeft + topLeft) / 2 );
const QPointF innerMidTop( (topLeft + topRight) / 2 );
const QPointF innerMidRight( (btmRight + topRight) / 2 );
const QPointF innerMidBtm( (btmLeft + btmRight) / 2 );
const QPointF outterMidLeft(searchLeft, searchMidY);
const QPointF outterMidTop(searchMidX, searchTop);
const QPointF outterMidRight(searchRight, searchMidY);
const QPointF outterMidBtm(searchMidX, searchBottom);
const QPointF handleSize( HANDLE_SIZE * pixelScaleX, HANDLE_SIZE * pixelScaleY );
const QPointF innerMidLeftExt = TrackerNodeInteract::computeMidPointExtent(topLeft, btmLeft, innerMidLeft, handleSize);
const QPointF innerMidRightExt = TrackerNodeInteract::computeMidPointExtent(btmRight, topRight, innerMidRight, handleSize);
const QPointF innerMidTopExt = TrackerNodeInteract::computeMidPointExtent(topRight, topLeft, innerMidTop, handleSize);
const QPointF innerMidBtmExt = TrackerNodeInteract::computeMidPointExtent(btmLeft, btmRight, innerMidBtm, handleSize);
const QPointF searchTopLeft(searchLeft, searchTop);
const QPointF searchTopRight(searchRight, searchTop);
const QPointF searchBtmRight(searchRight, searchBottom);
const QPointF searchBtmLeft(searchLeft, searchBottom);
const QPointF searchTopMid(searchMidX, searchTop);
const QPointF searchRightMid(searchRight, searchMidY);
const QPointF searchLeftMid(searchLeft, searchMidY);
const QPointF searchBtmMid(searchMidX, searchBottom);
const QPointF outterMidLeftExt = TrackerNodeInteract::computeMidPointExtent(searchTopLeft, searchBtmLeft, outterMidLeft, handleSize);
const QPointF outterMidRightExt = TrackerNodeInteract::computeMidPointExtent(searchBtmRight, searchTopRight, outterMidRight, handleSize);
const QPointF outterMidTopExt = TrackerNodeInteract::computeMidPointExtent(searchTopRight, searchTopLeft, outterMidTop, handleSize);
const QPointF outterMidBtmExt = TrackerNodeInteract::computeMidPointExtent(searchBtmLeft, searchBtmRight, outterMidBtm, handleSize);
std::string name = (*it)->getLabel();
if (!isEnabled) {
name += ' ';
name += tr("(disabled)").toStdString();
}
CenterPointsMap centerPoints;
CurvePtr xCurve = centerKnob->getCurve(ViewSpec::current(), 0);
CurvePtr yCurve = centerKnob->getCurve(ViewSpec::current(), 1);
CurvePtr errorCurve = errorKnob->getCurve(ViewSpec::current(), 0);
{
KeyFrameSet xKeyframes = xCurve->getKeyFrames_mt_safe();
KeyFrameSet yKeyframes = yCurve->getKeyFrames_mt_safe();
KeyFrameSet errKeyframes;
if (showErrorColor) {
errKeyframes = errorCurve->getKeyFrames_mt_safe();
}
// Try first to do an optimized case in O(N) where we assume that all 3 curves have the same keyframes
// at the same time
KeyFrameSet remainingXKeys,remainingYKeys, remainingErrKeys;
if (xKeyframes.size() == yKeyframes.size() && (!showErrorColor || xKeyframes.size() == errKeyframes.size())) {
KeyFrameSet::iterator errIt = errKeyframes.begin();
KeyFrameSet::iterator xIt = xKeyframes.begin();
KeyFrameSet::iterator yIt = yKeyframes.begin();
bool setsHaveDifferentKeyTimes = false;
while (xIt!=xKeyframes.end()) {
if (xIt->getTime() != yIt->getTime() || (showErrorColor && xIt->getTime() != errIt->getTime())) {
setsHaveDifferentKeyTimes = true;
break;
}
CenterPointDisplayInfo& p = centerPoints[xIt->getTime()];
p.x = xIt->getValue();
p.y = yIt->getValue();
if ( showErrorColor ) {
p.err = errIt->getValue();
}
p.isValid = true;
++xIt;
++yIt;
if (showErrorColor) {
++errIt;
}
}
if (setsHaveDifferentKeyTimes) {
remainingXKeys.insert(xIt, xKeyframes.end());
remainingYKeys.insert(yIt, yKeyframes.end());
if (showErrorColor) {
remainingErrKeys.insert(errIt, errKeyframes.end());
}
}
} else {
remainingXKeys = xKeyframes;
remainingYKeys = yKeyframes;
if (showErrorColor) {
remainingErrKeys = errKeyframes;
}
}
for (KeyFrameSet::iterator xIt = remainingXKeys.begin(); xIt != remainingXKeys.end(); ++xIt) {
CenterPointDisplayInfo& p = centerPoints[xIt->getTime()];
p.x = xIt->getValue();
p.isValid = false;
}
for (KeyFrameSet::iterator yIt = remainingYKeys.begin(); yIt != remainingYKeys.end(); ++yIt) {
CenterPointsMap::iterator foundPoint = centerPoints.find(yIt->getTime());
if (foundPoint == centerPoints.end()) {
continue;
}
foundPoint->second.y = yIt->getValue();
if (!showErrorColor) {
foundPoint->second.isValid = true;
}
}
for (KeyFrameSet::iterator errIt = remainingErrKeys.begin(); errIt != remainingErrKeys.end(); ++errIt) {
CenterPointsMap::iterator foundPoint = centerPoints.find(errIt->getTime());
if (foundPoint == centerPoints.end()) {
continue;
}
foundPoint->second.err = errIt->getValue();
foundPoint->second.isValid = true;
}
}
for (int l = 0; l < 2; ++l) {
// shadow (uses GL_PROJECTION)
glMatrixMode(GL_PROJECTION);
int direction = (l == 0) ? 1 : -1;
// translate (1,-1) pixels
glTranslated(direction * shadow.x, -direction * shadow.y, 0);
glMatrixMode(GL_MODELVIEW);