forked from NatronGitHub/Natron
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RotoContextPrivate.h
2246 lines (1957 loc) · 101 KB
/
RotoContextPrivate.h
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 ***** */
#ifndef ROTOCONTEXTPRIVATE_H
#define ROTOCONTEXTPRIVATE_H
// ***** 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 "Global/Macros.h"
#include <list>
#include <map>
#include <string>
#include <vector>
#include <limits>
#include <sstream> // stringstream
#include <stdexcept>
#if !defined(Q_MOC_RUN) && !defined(SBK_RUN)
#include <boost/shared_ptr.hpp>
#include <boost/weak_ptr.hpp>
#endif
CLANG_DIAG_OFF(deprecated)
CLANG_DIAG_OFF(uninitialized)
#include <QtCore/QMutex>
#include <QtCore/QReadWriteLock>
#include <QtCore/QCoreApplication>
#include <QtCore/QThread>
#include <QtCore/QReadWriteLock>
#include <QtCore/QWaitCondition>
CLANG_DIAG_ON(deprecated)
CLANG_DIAG_ON(uninitialized)
#include <cairo/cairo.h>
#include "Global/GlobalDefines.h"
#include "Engine/AppManager.h"
#include "Engine/BezierCP.h"
#include "Engine/Curve.h"
#include "Engine/EffectInstance.h"
#include "Engine/Image.h"
#include "Engine/KnobTypes.h"
#include "Engine/MergingEnum.h"
#include "Engine/Node.h"
#include "Engine/RotoContext.h"
#include "Engine/RotoPaint.h"
#include "Engine/Transform.h"
#include "Engine/ViewIdx.h"
#include "Engine/EngineFwd.h"
#define ROTO_DEFAULT_OPACITY 1.
#define ROTO_DEFAULT_FEATHER 1.5
#define ROTO_DEFAULT_FEATHERFALLOFF 1.
#define ROTO_DEFAULT_COLOR_R 1.
#define ROTO_DEFAULT_COLOR_G 1.
#define ROTO_DEFAULT_COLOR_B 1.
#define kRotoScriptNameHint "Script-name of the item for Python scripts. It cannot be edited."
#define kRotoLabelHint "Label of the layer or curve"
#define kRotoNameHint "Name of the layer or curve."
#define kRotoOpacityParam "opacity"
#define kRotoOpacityParamLabel "Opacity"
#define kRotoOpacityHint \
"Controls the opacity of the selected shape(s)."
#define kRotoFeatherParam "feather"
#define kRotoFeatherParamLabel "Feather"
#define kRotoFeatherHint \
"Controls the distance of feather (in pixels) to add around the selected shape(s)"
#define kRotoFeatherFallOffParam "featherFallOff"
#define kRotoFeatherFallOffParamLabel "Feather fall-off"
#define kRotoFeatherFallOffHint \
"Controls the rate at which the feather is applied on the selected shape(s)."
#define kRotoActivatedParam "activated"
#define kRotoActivatedParamLabel "Activated"
#define kRotoActivatedHint \
"Controls whether the selected shape(s) should be rendered or not." \
"Note that you can animate this parameter so you can activate/deactivate the shape " \
"throughout the time."
#define kRotoLockedHint \
"Control whether the layer/curve is editable or locked."
#define kRotoInvertedParam "inverted"
#define kRotoInvertedParamLabel "Inverted"
#define kRotoInvertedHint \
"Controls whether the selected shape(s) should be inverted. When inverted everything " \
"outside the shape will be set to 1 and everything inside the shape will be set to 0."
#define kRotoOverlayHint "Color of the display overlay for this curve. Doesn't affect output."
#define kRotoColorParam "color"
#define kRotoColorParamLabel "Color"
#define kRotoColorHint \
"The color of the shape. This parameter is used when the output components are set to RGBA."
#define kRotoCompOperatorParam "operator"
#define kRotoCompOperatorParamLabel "Operator"
#define kRotoCompOperatorHint \
"The compositing operator controls how this shape is merged with the shapes that have already been rendered.\n" \
"The roto mask is initialised as black and transparent, then each shape is drawn in the selected order, with the selected color and operator.\n" \
"Finally, the mask is composed with the source image, if connected, using the 'over' operator.\n" \
"See http://cairographics.org/operators/ for a full description of available operators."
#define kRotoBrushSourceColor "sourceType"
#define kRotoBrushSourceColorLabel "Source"
#define kRotoBrushSourceColorHint "Source color used for painting the stroke when the Reveal/Clone tools are used."
#define kRotoBrushSourceColorOptionForegroundHint "The painted result at this point in the hierarchy."
#define kRotoBrushSourceColorOptionBackgroundHint "The original image unpainted connected to bg."
#define kRotoBrushSourceColorOptionBackgroundNHint "The original image unpainted connected to bg%1."
#define kRotoBrushSizeParam "brushSize"
#define kRotoBrushSizeParamLabel "Brush Size"
#define kRotoBrushSizeParamHint "This is the diameter of the brush in pixels. Shift + drag on the viewer to modify this value"
#define kRotoBrushSpacingParam "brushSpacing"
#define kRotoBrushSpacingParamLabel "Brush Spacing"
#define kRotoBrushSpacingParamHint "Spacing between stamps of the paint brush"
#define kRotoBrushHardnessParam "brushHardness"
#define kRotoBrushHardnessParamLabel "Brush Hardness"
#define kRotoBrushHardnessParamHint "Fall off of the brush effect from the center to the edge"
#define kRotoBrushEffectParam "brushEffect"
#define kRotoBrushEffectParamLabel "Brush effect"
#define kRotoBrushEffectParamHint "The strength of the effect"
#define kRotoBrushVisiblePortionParam "strokeVisiblePortion"
#define kRotoBrushVisiblePortionParamLabel "Visible portion"
#define kRotoBrushVisiblePortionParamHint "Defines the range of the stroke that should be visible: 0 is the start of the stroke and 1 the end."
#define kRotoBrushPressureLabelParam "pressureAlters"
#define kRotoBrushPressureLabelParamLabel "Pressure alters"
#define kRotoBrushPressureLabelParamHint ""
#define kRotoBrushPressureOpacityParam "pressureOpacity"
#define kRotoBrushPressureOpacityParamLabel "Opacity"
#define kRotoBrushPressureOpacityParamHint "Alters the opacity of the paint brush proportionate to changes in pen pressure"
#define kRotoBrushPressureSizeParam "pressureSize"
#define kRotoBrushPressureSizeParamLabel "Size"
#define kRotoBrushPressureSizeParamHint "Alters the size of the paint brush proportionate to changes in pen pressure"
#define kRotoBrushPressureHardnessParam "pressureHardness"
#define kRotoBrushPressureHardnessParamLabel "Hardness"
#define kRotoBrushPressureHardnessParamHint "Alters the hardness of the paint brush proportionate to changes in pen pressure"
#define kRotoBrushBuildupParam "buildUp"
#define kRotoBrushBuildupParamLabel "Build-up"
#define kRotoBrushBuildupParamHint "When checked, the paint stroke builds up when painted over itself"
#define kRotoBrushTimeOffsetParam "timeOffset"
#define kRotoBrushTimeOffsetParamLabel "Clone time offset"
#define kRotoBrushTimeOffsetParamHint "When the Clone tool is used, this determines depending on the time offset mode the source frame to " \
"clone. When in absolute mode, this is the frame number of the source, when in relative mode, this is an offset relative to the current frame."
#define kRotoBrushTimeOffsetModeParam "timeOffsetMode"
#define kRotoBrushTimeOffsetModeParamLabel "Mode"
#define kRotoBrushTimeOffsetModeParamHint "Time offset mode: when in absolute mode, this is the frame number of the source, when in relative mode, this is an offset relative to the current frame."
#define kRotoBrushTranslateParam "cloneTranslate"
#define kRotoBrushTranslateParamLabel "Translate"
#define kRotoBrushTranslateParamHint ""
#define kRotoBrushRotateParam "cloneRotate"
#define kRotoBrushRotateParamLabel "Rotate"
#define kRotoBrushRotateParamHint ""
#define kRotoBrushScaleParam "cloneScale"
#define kRotoBrushScaleParamLabel "Scale"
#define kRotoBrushScaleParamHint ""
#define kRotoBrushScaleUniformParam "cloneUniform"
#define kRotoBrushScaleUniformParamLabel "Uniform"
#define kRotoBrushScaleUniformParamHint ""
#define kRotoBrushSkewXParam "cloneSkewx"
#define kRotoBrushSkewXParamLabel "Skew X"
#define kRotoBrushSkewXParamHint ""
#define kRotoBrushSkewYParam "cloneSkewy"
#define kRotoBrushSkewYParamLabel "Skew Y"
#define kRotoBrushSkewYParamHint ""
#define kRotoBrushSkewOrderParam "cloneSkewOrder"
#define kRotoBrushSkewOrderParamLabel "Skew Order"
#define kRotoBrushSkewOrderParamHint ""
#define kRotoBrushCenterParam "cloneCenter"
#define kRotoBrushCenterParamLabel "Center"
#define kRotoBrushCenterParamHint ""
#define kRotoBrushFilterParam "cloneFilter"
#define kRotoBrushFilterParamLabel "Filter"
#define kRotoBrushFilterParamHint "Filtering algorithm - some filters may produce values outside of the initial range (*) or modify the values even if there is no movement (+)."
#define kRotoBrushBlackOutsideParam "blackOutside"
#define kRotoBrushBlackOutsideParamLabel "Black Outside"
#define kRotoBrushBlackOutsideParamHint "Fill the area outside the source image with black"
#define kFilterImpulse "Impulse"
#define kFilterImpulseHint "(nearest neighbor / box) Use original values."
#define kFilterBox "Box"
#define kFilterBoxHint "Integrate the source image over the bounding box of the back-transformed pixel."
#define kFilterBilinear "Bilinear"
#define kFilterBilinearHint "(tent / triangle) Bilinear interpolation between original values."
#define kFilterCubic "Cubic"
#define kFilterCubicHint "(cubic spline) Some smoothing."
#define kFilterKeys "Keys"
#define kFilterKeysHint "(Catmull-Rom / Hermite spline) Some smoothing, plus minor sharpening (*)."
#define kFilterSimon "Simon"
#define kFilterSimonHint "Some smoothing, plus medium sharpening (*)."
#define kFilterRifman "Rifman"
#define kFilterRifmanHint "Some smoothing, plus significant sharpening (*)."
#define kFilterMitchell "Mitchell"
#define kFilterMitchellHint "Some smoothing, plus blurring to hide pixelation (*)(+)."
#define kFilterParzen "Parzen"
#define kFilterParzenHint "(cubic B-spline) Greatest smoothing of all filters (+)."
#define kFilterNotch "Notch"
#define kFilterNotchHint "Flat smoothing (which tends to hide moire' patterns) (+)."
#define kRotoDrawableItemTranslateParam "translate"
#define kRotoDrawableItemTranslateParamLabel "Translate"
#define kRotoDrawableItemTranslateParamHint ""
#define kRotoDrawableItemRotateParam "rotate"
#define kRotoDrawableItemRotateParamLabel "Rotate"
#define kRotoDrawableItemRotateParamHint ""
#define kRotoDrawableItemScaleParam "scale"
#define kRotoDrawableItemScaleParamLabel "Scale"
#define kRotoDrawableItemScaleParamHint ""
#define kRotoDrawableItemScaleUniformParam "uniform"
#define kRotoDrawableItemScaleUniformParamLabel "Uniform"
#define kRotoDrawableItemScaleUniformParamHint ""
#define kRotoDrawableItemSkewXParam "skewx"
#define kRotoDrawableItemSkewXParamLabel "Skew X"
#define kRotoDrawableItemSkewXParamHint ""
#define kRotoDrawableItemSkewYParam "skewy"
#define kRotoDrawableItemSkewYParamLabel "Skew Y"
#define kRotoDrawableItemSkewYParamHint ""
#define kRotoDrawableItemSkewOrderParam "skewOrder"
#define kRotoDrawableItemSkewOrderParamLabel "Skew Order"
#define kRotoDrawableItemSkewOrderParamHint ""
#define kRotoDrawableItemCenterParam "center"
#define kRotoDrawableItemCenterParamLabel "Center"
#define kRotoDrawableItemCenterParamHint ""
#define kRotoDrawableItemExtraMatrixParam "extraMatrix"
#define kRotoDrawableItemExtraMatrixParamLabel "Extra Matrix"
#define kRotoDrawableItemExtraMatrixParamHint "This matrix gets concatenated to the transform resulting from the parameter above."
#define kRotoDrawableItemLifeTimeParam "lifeTime"
#define kRotoDrawableItemLifeTimeParamLabel "Life Time"
#define kRotoDrawableItemLifeTimeParamHint "Controls the life-time of the shape/stroke"
#define kRotoDrawableItemLifeTimeAll "All"
#define kRotoDrawableItemLifeTimeAllHelp "All frames"
#define kRotoDrawableItemLifeTimeSingle "Single"
#define kRotoDrawableItemLifeTimeSingleHelp "Only for the specified frame"
#define kRotoDrawableItemLifeTimeFromStart "From start"
#define kRotoDrawableItemLifeTimeFromStartHelp "From the start of the sequence up to the specified frame"
#define kRotoDrawableItemLifeTimeToEnd "To end"
#define kRotoDrawableItemLifeTimeToEndHelp "From the specified frame to the end of the sequence"
#define kRotoDrawableItemLifeTimeCustom "Custom"
#define kRotoDrawableItemLifeTimeCustomHelp "Use the Activated parameter animation to control the life-time of the shape/stroke using keyframes"
enum RotoPaintItemLifeTimeTypeEnum
{
eRotoPaintItemLifeTimeTypeAll = 0,
eRotoPaintItemLifeTimeTypeSingle,
eRotoPaintItemLifeTimeTypeFromStart,
eRotoPaintItemLifeTimeTypeToEnd,
eRotoPaintItemLifeTimeTypeCustom
};
#define kRotoDrawableItemLifeTimeFrameParam "lifeTimeFrame"
#define kRotoDrawableItemLifeTimeFrameParamLabel "Frame"
#define kRotoDrawableItemLifeTimeFrameParamHint "Use this to specify the frame when in mode Single/From start/To end"
#define kRotoResetCloneTransformParam "resetCloneTransform"
#define kRotoResetCloneTransformParamLabel "Reset Transform"
#define kRotoResetCloneTransformParamHint "Reset the clone transform to an identity"
#define kRotoResetTransformParam "resetTransform"
#define kRotoResetTransformParamLabel "Reset Transform"
#define kRotoResetTransformParamHint "Reset the transform to an identity"
#define kRotoResetCloneCenterParam "resetCloneCenter"
#define kRotoResetCloneCenterParamLabel "Reset Center"
#define kRotoResetCloneCenterParamHint "Reset the clone transform center"
#define kRotoResetCenterParam "resetTransformCenter"
#define kRotoResetCenterParamLabel "Reset Center"
#define kRotoResetCenterParamHint "Reset the transform center"
#define kRotoTransformInteractive "RotoTransformInteractive"
#define kRotoTransformInteractiveLabel "Interactive"
#define kRotoTransformInteractiveHint "When check, modifying the transform will directly render the shape in the viewer. When unchecked, modifications are applied when releasing the mouse button."
#define kRotoMotionBlurModeParam "motionBlurMode"
#define kRotoMotionBlurModeParamLabel "Mode"
#define kRotoMotionBlurModeParamHint "Per-shape motion blurs applies motion blur independently to each shape and then blends them together." \
" This may produce artifacts when shapes blur over the same portion of the image, but might be more efficient than global motion-blur." \
" Global motion-blur takes into account the interaction between shapes and will not create artifacts at the expense of being slightly " \
"more expensive than the per-shape motion blur. Note that when using the global motion-blur, all shapes will have the same motion-blur " \
"settings applied to them."
#define kRotoPerShapeMotionBlurParam "motionBlur"
#define kRotoGlobalMotionBlurParam "globalMotionBlur"
#define kRotoMotionBlurParamLabel "Motion Blur"
#define kRotoMotionBlurParamHint "The number of Motion-Blur samples used for blurring. Increase for better quality but slower rendering."
#define kRotoPerShapeShutterParam "motionBlurShutter"
#define kRotoGlobalShutterParam "globalMotionBlurShutter"
#define kRotoShutterParamLabel "Shutter"
#define kRotoShutterParamHint "The number of frames during which the shutter should be opened when motion blurring."
#define kRotoPerShapeShutterOffsetTypeParam "motionBlurShutterOffset"
#define kRotoGlobalShutterOffsetTypeParam "gobalMotionBlurShutterOffset"
#define kRotoShutterOffsetTypeParamLabel "Shutter Offset"
#define kRotoShutterOffsetTypeParamHint "This controls how the shutter operates in respect to the current frame value."
#define kRotoShutterOffsetCenteredHint "Centers the shutter around the current frame, that is the shutter will be opened from f - shutter/2 to " \
"f + shutter/2"
#define kRotoShutterOffsetStartHint "The shutter will open at the current frame and stay open until f + shutter"
#define kRotoShutterOffsetEndHint "The shutter will open at f - shutter until the current frame"
#define kRotoShutterOffsetCustomHint "The shutter will open at the time indicated by the shutter offset parameter"
#define kRotoPerShapeShutterCustomOffsetParam "motionBlurCustomShutterOffset"
#define kRotoGlobalShutterCustomOffsetParam "globalMotionBlurCustomShutterOffset"
#define kRotoShutterCustomOffsetParamLabel "Custom Offset"
#define kRotoShutterCustomOffsetParamHint "If the Shutter Offset parameter is set to Custom then this parameter controls the frame at " \
"which the shutter opens. The value is an offset in frames to the current frame, e.g: -1 would open the shutter 1 frame before the current frame."
NATRON_NAMESPACE_ENTER
struct RotoFeatherVertex
{
double x,y;
bool isInner;
};
struct RotoTriangleStrips
{
std::list<Point> vertices;
};
struct RotoTriangleFans
{
std::list<Point> vertices;
};
struct RotoTriangles
{
std::list<Point> vertices;
};
struct BezierPrivate
{
BezierCPs points; //< the control points of the curve
BezierCPs featherPoints; //< the feather points, the number of feather points must equal the number of cp.
//updated whenever the Bezier is edited, this is used to determine if a point lies inside the bezier or not
//it has a value for each keyframe
mutable std::map<double, bool> isClockwiseOriented;
mutable bool isClockwiseOrientedStatic; //< used when the bezier has no keyframes
mutable std::map<double, bool> guiIsClockwiseOriented;
mutable bool guiIsClockwiseOrientedStatic; //< used when the bezier has no keyframes
bool autoRecomputeOrientation; // when true, orientation will be computed automatically on editing
bool finished; //< when finished is true, the last point of the list is connected to the first point of the list.
bool isOpenBezier;
mutable QMutex guiCopyMutex;
bool mustCopyGui;
BezierPrivate(bool isOpenBezier)
: points()
, featherPoints()
, isClockwiseOriented()
, isClockwiseOrientedStatic(false)
, guiIsClockwiseOriented()
, guiIsClockwiseOrientedStatic(false)
, autoRecomputeOrientation(true)
, finished(false)
, isOpenBezier(isOpenBezier)
, guiCopyMutex()
, mustCopyGui(false)
{
}
void setMustCopyGuiBezier(bool copy)
{
QMutexLocker k(&guiCopyMutex);
mustCopyGui = copy;
}
bool hasKeyframeAtTime(bool useGuiCurves,
double time) const
{
// PRIVATE - should not lock
if ( points.empty() ) {
return false;
} else {
KeyFrame k;
return points.front()->hasKeyFrameAtTime(useGuiCurves, time);
}
}
void getKeyframeTimes(bool useGuiCurves,
std::set<double>* times) const
{
// PRIVATE - should not lock
if ( points.empty() ) {
return;
}
points.front()->getKeyframeTimes(useGuiCurves, times);
}
BezierCPs::const_iterator atIndex(int index) const
{
// PRIVATE - should not lock
if ( ( index >= (int)points.size() ) || (index < 0) ) {
throw std::out_of_range("RotoSpline::atIndex: non-existent control point");
}
BezierCPs::const_iterator it = points.begin();
std::advance(it, index);
return it;
}
BezierCPs::iterator atIndex(int index)
{
// PRIVATE - should not lock
if ( ( index >= (int)points.size() ) || (index < 0) ) {
throw std::out_of_range("RotoSpline::atIndex: non-existent control point");
}
BezierCPs::iterator it = points.begin();
std::advance(it, index);
return it;
}
BezierCPs::const_iterator findControlPointNearby(double x,
double y,
double acceptance,
double time,
ViewIdx view,
const Transform::Matrix3x3& transform,
int* index) const
{
// PRIVATE - should not lock
int i = 0;
for (BezierCPs::const_iterator it = points.begin(); it != points.end(); ++it, ++i) {
Transform::Point3D p;
p.z = 1;
(*it)->getPositionAtTime(true, time, view, &p.x, &p.y);
p = Transform::matApply(transform, p);
if ( ( p.x >= (x - acceptance) ) && ( p.x <= (x + acceptance) ) && ( p.y >= (y - acceptance) ) && ( p.y <= (y + acceptance) ) ) {
*index = i;
return it;
}
}
return points.end();
}
BezierCPs::const_iterator findFeatherPointNearby(double x,
double y,
double acceptance,
double time,
ViewIdx view,
const Transform::Matrix3x3& transform,
int* index) const
{
// PRIVATE - should not lock
int i = 0;
for (BezierCPs::const_iterator it = featherPoints.begin(); it != featherPoints.end(); ++it, ++i) {
Transform::Point3D p;
p.z = 1;
(*it)->getPositionAtTime(true, time, view, &p.x, &p.y);
p = Transform::matApply(transform, p);
if ( ( p.x >= (x - acceptance) ) && ( p.x <= (x + acceptance) ) && ( p.y >= (y - acceptance) ) && ( p.y <= (y + acceptance) ) ) {
*index = i;
return it;
}
}
return featherPoints.end();
}
};
class RotoLayer;
struct RotoItemPrivate
{
RotoContextWPtr context;
std::string scriptName, label;
RotoLayerWPtr parentLayer;
////This controls whether the item (and all its children if it is a layer)
////should be visible/rendered or not at any time.
////This is different from the "activated" knob for RotoDrawableItem's which in that
////case allows to define a life-time
bool globallyActivated;
////A locked item should not be modifiable by the GUI
bool locked;
RotoItemPrivate(const RotoContextPtr context,
const std::string & n,
const RotoLayerPtr& parent)
: context(context)
, scriptName(n)
, label(n)
, parentLayer(parent)
, globallyActivated(true)
, locked(false)
{
}
};
typedef std::list<RotoItemPtr> RotoItems;
struct RotoLayerPrivate
{
RotoItems items;
RotoLayerPrivate()
: items()
{
}
};
///Keep this in synch with the cairo_operator_t enum !
///We are not going to create a similar enum just to represent the same thing
inline void
getCairoCompositingOperators(std::vector<std::string>* operators,
std::vector<std::string>* toolTips)
{
assert(operators->size() == CAIRO_OPERATOR_CLEAR);
operators->push_back("clear");
toolTips->push_back("clear destination layer");
assert(operators->size() == CAIRO_OPERATOR_SOURCE);
operators->push_back("source");
toolTips->push_back("replace destination layer");
assert(operators->size() == CAIRO_OPERATOR_OVER);
operators->push_back("over");
toolTips->push_back("draw source layer on top of destination layer ");
assert(operators->size() == CAIRO_OPERATOR_IN);
operators->push_back("in");
toolTips->push_back("draw source where there was destination content");
assert(operators->size() == CAIRO_OPERATOR_OUT);
operators->push_back("out");
toolTips->push_back("draw source where there was no destination content");
assert(operators->size() == CAIRO_OPERATOR_ATOP);
operators->push_back("atop");
toolTips->push_back("draw source on top of destination content and only there");
assert(operators->size() == CAIRO_OPERATOR_DEST);
operators->push_back("dest");
toolTips->push_back("ignore the source");
assert(operators->size() == CAIRO_OPERATOR_DEST_OVER);
operators->push_back("dest-over");
toolTips->push_back("draw destination on top of source");
assert(operators->size() == CAIRO_OPERATOR_DEST_IN);
operators->push_back("dest-in");
toolTips->push_back("leave destination only where there was source content");
assert(operators->size() == CAIRO_OPERATOR_DEST_OUT);
operators->push_back("dest-out");
toolTips->push_back("leave destination only where there was no source content");
assert(operators->size() == CAIRO_OPERATOR_DEST_ATOP);
operators->push_back("dest-atop");
toolTips->push_back("leave destination on top of source content and only there ");
assert(operators->size() == CAIRO_OPERATOR_XOR);
operators->push_back("xor");
toolTips->push_back("source and destination are shown where there is only one of them");
assert(operators->size() == CAIRO_OPERATOR_ADD);
operators->push_back("add");
toolTips->push_back("source and destination layers are accumulated");
assert(operators->size() == CAIRO_OPERATOR_SATURATE);
operators->push_back("saturate");
toolTips->push_back("like over, but assuming source and dest are disjoint geometries ");
assert(operators->size() == CAIRO_OPERATOR_MULTIPLY);
operators->push_back("multiply");
toolTips->push_back("source and destination layers are multiplied. This causes the result to be at least as dark as the darker inputs.");
assert(operators->size() == CAIRO_OPERATOR_SCREEN);
operators->push_back("screen");
toolTips->push_back("source and destination are complemented and multiplied. This causes the result to be at least as "
"light as the lighter inputs.");
assert(operators->size() == CAIRO_OPERATOR_OVERLAY);
operators->push_back("overlay");
toolTips->push_back("multiplies or screens, depending on the lightness of the destination color. ");
assert(operators->size() == CAIRO_OPERATOR_DARKEN);
operators->push_back("darken");
toolTips->push_back("replaces the destination with the source if it is darker, otherwise keeps the source");
assert(operators->size() == CAIRO_OPERATOR_LIGHTEN);
operators->push_back("lighten");
toolTips->push_back("replaces the destination with the source if it is lighter, otherwise keeps the source.");
assert(operators->size() == CAIRO_OPERATOR_COLOR_DODGE);
operators->push_back("color-dodge");
toolTips->push_back("brightens the destination color to reflect the source color. ");
assert(operators->size() == CAIRO_OPERATOR_COLOR_BURN);
operators->push_back("color-burn");
toolTips->push_back("darkens the destination color to reflect the source color.");
assert(operators->size() == CAIRO_OPERATOR_HARD_LIGHT);
operators->push_back("hard-light");
toolTips->push_back("Multiplies or screens, dependent on source color.");
assert(operators->size() == CAIRO_OPERATOR_SOFT_LIGHT);
operators->push_back("soft-light");
toolTips->push_back("Darkens or lightens, dependent on source color.");
assert(operators->size() == CAIRO_OPERATOR_DIFFERENCE);
operators->push_back("difference");
toolTips->push_back("Takes the difference of the source and destination color. ");
assert(operators->size() == CAIRO_OPERATOR_EXCLUSION);
operators->push_back("exclusion");
toolTips->push_back("Produces an effect similar to difference, but with lower contrast. ");
assert(operators->size() == CAIRO_OPERATOR_HSL_HUE);
operators->push_back("HSL-hue");
toolTips->push_back("Creates a color with the hue of the source and the saturation and luminosity of the target.");
assert(operators->size() == CAIRO_OPERATOR_HSL_SATURATION);
operators->push_back("HSL-saturation");
toolTips->push_back("Creates a color with the saturation of the source and the hue and luminosity of the target."
" Painting with this mode onto a gray area produces no change.");
assert(operators->size() == CAIRO_OPERATOR_HSL_COLOR);
operators->push_back("HSL-color");
toolTips->push_back("Creates a color with the hue and saturation of the source and the luminosity of the target."
" This preserves the gray levels of the target and is useful for coloring monochrome"
" images or tinting color images");
assert(operators->size() == CAIRO_OPERATOR_HSL_LUMINOSITY);
operators->push_back("HSL-luminosity");
toolTips->push_back("Creates a color with the luminosity of the source and the hue and saturation of the target."
" This produces an inverse effect to HSL-color.");
} // getCompositingOperators
struct RotoDrawableItemPrivate
{
Q_DECLARE_TR_FUNCTIONS(RotoDrawableItem)
public:
/*
* The effect node corresponds to the following given the selected tool:
* Stroke= RotoOFX
* Blur = BlurCImg
* Clone = TransformOFX
* Sharpen = SharpenCImg
* Smear = hand made tool
* Reveal = Merge(over) with A being color type and B the tree upstream
* Dodge/Burn = Merge(color-dodge/color-burn) with A being the tree upstream and B the color type
*
* Each effect is followed by a merge (except for the ones that use a merge) with the user given operator
* onto the previous tree upstream of the effectNode.
*/
NodePtr effectNode;
NodePtr mergeNode;
NodePtr timeOffsetNode, frameHoldNode;
double overlayColor[4]; //< the color the shape overlay should be drawn with, defaults to smooth red
KnobDoublePtr opacity; //< opacity of the rendered shape between 0 and 1
KnobDoublePtr feather; //< number of pixels to add to the feather distance (from the feather point), between -100 and 100
KnobDoublePtr featherFallOff; //< the rate of fall-off for the feather, between 0 and 1, 0.5 meaning the
//alpha value is half the original value when at half distance from the feather distance
KnobChoicePtr lifeTime;
KnobBoolPtr activated; //< should the curve be visible/rendered ? (animable)
KnobIntPtr lifeTimeFrame;
#ifdef NATRON_ROTO_INVERTIBLE
KnobBoolPtr inverted; //< invert the rendering
#endif
KnobColorPtr color;
KnobChoicePtr compOperator;
KnobDoublePtr translate;
KnobDoublePtr rotate;
KnobDoublePtr scale;
KnobBoolPtr scaleUniform;
KnobDoublePtr skewX;
KnobDoublePtr skewY;
KnobChoicePtr skewOrder;
KnobDoublePtr center;
KnobDoublePtr extraMatrix;
KnobDoublePtr brushSize;
KnobDoublePtr brushSpacing;
KnobDoublePtr brushHardness;
KnobDoublePtr effectStrength;
KnobBoolPtr pressureOpacity, pressureSize, pressureHardness, buildUp;
KnobDoublePtr visiblePortion; // [0,1] by default
KnobDoublePtr cloneTranslate;
KnobDoublePtr cloneRotate;
KnobDoublePtr cloneScale;
KnobBoolPtr cloneScaleUniform;
KnobDoublePtr cloneSkewX;
KnobDoublePtr cloneSkewY;
KnobChoicePtr cloneSkewOrder;
KnobDoublePtr cloneCenter;
KnobChoicePtr cloneFilter;
KnobBoolPtr cloneBlackOutside;
KnobChoicePtr sourceColor;
KnobIntPtr timeOffset;
KnobChoicePtr timeOffsetMode;
#ifdef NATRON_ROTO_ENABLE_MOTION_BLUR
KnobDoublePtr motionBlur;
KnobDoublePtr shutter;
KnobChoicePtr shutterType;
KnobDoublePtr customOffset;
#endif
std::list<KnobIPtr> knobs; //< list for easy access to all knobs
//Used to prevent 2 threads from writing the same image in the rotocontext
mutable QReadWriteLock cacheAccessMutex;
RotoDrawableItemPrivate(bool isPaintingNode)
: effectNode()
, mergeNode()
, timeOffsetNode()
, frameHoldNode()
, opacity()
, feather()
, featherFallOff()
, lifeTime()
, activated()
, lifeTimeFrame()
#ifdef NATRON_ROTO_INVERTIBLE
, inverted()
#endif
, color()
, compOperator()
, translate()
, rotate()
, scale()
, scaleUniform()
, skewX()
, skewY()
, skewOrder()
, center()
, brushSize()
, brushSpacing()
, brushHardness()
, effectStrength()
, pressureOpacity()
, pressureSize()
, pressureHardness()
, buildUp()
, visiblePortion()
, cloneTranslate()
, cloneRotate()
, cloneScale()
, cloneScaleUniform()
, cloneSkewX()
, cloneSkewY()
, cloneSkewOrder()
, cloneCenter()
, cloneFilter()
, cloneBlackOutside()
, sourceColor()
, timeOffset()
, timeOffsetMode()
, knobs()
, cacheAccessMutex()
{
opacity = boost::make_shared<KnobDouble>((KnobHolder*)NULL, tr(kRotoOpacityParamLabel), 1, true);
opacity->setHintToolTip( tr(kRotoOpacityHint) );
opacity->setName(kRotoOpacityParam);
opacity->populate();
opacity->setMinimum(0.);
opacity->setMaximum(1.);
opacity->setDisplayMinimum(0.);
opacity->setDisplayMaximum(1.);
opacity->setDefaultValue(ROTO_DEFAULT_OPACITY);
knobs.push_back(opacity);
feather = boost::make_shared<KnobDouble>((KnobHolder*)NULL, tr(kRotoFeatherParamLabel), 1, true);
feather->setHintToolTip( tr(kRotoFeatherHint) );
feather->setName(kRotoFeatherParam);
feather->populate();
feather->setMinimum(0);
feather->setDisplayMinimum(0);
feather->setDisplayMaximum(500);
feather->setDefaultValue(ROTO_DEFAULT_FEATHER);
knobs.push_back(feather);
featherFallOff = boost::make_shared<KnobDouble>((KnobHolder*)NULL, tr(kRotoFeatherFallOffParamLabel), 1, true);
featherFallOff->setHintToolTip( tr(kRotoFeatherFallOffHint) );
featherFallOff->setName(kRotoFeatherFallOffParam);
featherFallOff->populate();
featherFallOff->setMinimum(0.001);
featherFallOff->setMaximum(5.);
featherFallOff->setDisplayMinimum(0.2);
featherFallOff->setDisplayMaximum(5.);
featherFallOff->setDefaultValue(ROTO_DEFAULT_FEATHERFALLOFF);
knobs.push_back(featherFallOff);
lifeTime = boost::make_shared<KnobChoice>((KnobHolder*)NULL, tr(kRotoDrawableItemLifeTimeParamLabel), 1, true);
lifeTime->setHintToolTip( tr(kRotoDrawableItemLifeTimeParamHint) );
lifeTime->populate();
lifeTime->setName(kRotoDrawableItemLifeTimeParam);
{
std::vector<ChoiceOption> choices;
assert(choices.size() == eRotoPaintItemLifeTimeTypeAll);
choices.push_back(ChoiceOption(kRotoDrawableItemLifeTimeAll));
assert(choices.size() == eRotoPaintItemLifeTimeTypeSingle);
choices.push_back(ChoiceOption(kRotoDrawableItemLifeTimeSingle));
assert(choices.size() == eRotoPaintItemLifeTimeTypeFromStart);
choices.push_back(ChoiceOption(kRotoDrawableItemLifeTimeFromStart));
assert(choices.size() == eRotoPaintItemLifeTimeTypeToEnd);
choices.push_back(ChoiceOption(kRotoDrawableItemLifeTimeToEnd));
assert(choices.size() == eRotoPaintItemLifeTimeTypeCustom);
choices.push_back(ChoiceOption(kRotoDrawableItemLifeTimeCustom));
lifeTime->populateChoices(choices);
}
RotoPaintItemLifeTimeTypeEnum defaultLifeTime = isPaintingNode ? eRotoPaintItemLifeTimeTypeSingle : eRotoPaintItemLifeTimeTypeAll;
lifeTime->setDefaultValue((int)defaultLifeTime);
knobs.push_back(lifeTime);
lifeTimeFrame = boost::make_shared<KnobInt>((KnobHolder*)NULL, tr(kRotoDrawableItemLifeTimeFrameParamLabel), 1, true);
lifeTimeFrame->setHintToolTip( tr(kRotoDrawableItemLifeTimeFrameParamHint) );
lifeTimeFrame->setName(kRotoDrawableItemLifeTimeFrameParam);
lifeTimeFrame->populate();
knobs.push_back(lifeTimeFrame);
activated = boost::make_shared<KnobBool>((KnobHolder*)NULL, tr(kRotoActivatedParamLabel), 1, true);
activated->setHintToolTip( tr(kRotoActivatedHint) );
activated->setName(kRotoActivatedParam);
activated->populate();
activated->setDefaultValue(true);
knobs.push_back(activated);
#ifdef NATRON_ROTO_INVERTIBLE
inverted = boost::make_shared<KnobBool>((KnobHolder*)NULL, tr(kRotoInvertedParamLabel), 1, true) );
inverted->setHintToolTip( tr(kRotoInvertedHint) );
inverted->setName(kRotoInvertedParam);
inverted->populate();
inverted->setDefaultValue(false);
knobs.push_back(inverted);
#endif
color = boost::make_shared<KnobColor>((KnobHolder*)NULL, tr(kRotoColorParamLabel), 3, true);
color->setHintToolTip( tr(kRotoColorHint) );
color->setName(kRotoColorParam);
color->populate();
color->setDefaultValue(ROTO_DEFAULT_COLOR_R, 0);
color->setDefaultValue(ROTO_DEFAULT_COLOR_G, 1);
color->setDefaultValue(ROTO_DEFAULT_COLOR_B, 2);
knobs.push_back(color);
compOperator = boost::make_shared<KnobChoice>((KnobHolder*)NULL, tr(kRotoCompOperatorParamLabel), 1, true);
compOperator->setHintToolTip( tr(kRotoCompOperatorHint) );
compOperator->setName(kRotoCompOperatorParam);
compOperator->populate();
knobs.push_back(compOperator);
translate = boost::make_shared<KnobDouble>((KnobHolder*)NULL, tr(kRotoDrawableItemTranslateParamLabel), 2, true);
translate->setName(kRotoDrawableItemTranslateParam);
translate->setHintToolTip( tr(kRotoDrawableItemTranslateParamHint) );
translate->populate();
knobs.push_back(translate);
rotate = boost::make_shared<KnobDouble>((KnobHolder*)NULL, tr(kRotoDrawableItemRotateParamLabel), 1, true);
rotate->setName(kRotoDrawableItemRotateParam);
rotate->setHintToolTip( tr(kRotoDrawableItemRotateParamHint) );
rotate->populate();
knobs.push_back(rotate);
scale = boost::make_shared<KnobDouble>((KnobHolder*)NULL, tr(kRotoDrawableItemScaleParamLabel), 2, true);
scale->setName(kRotoDrawableItemScaleParam);
scale->setHintToolTip( tr(kRotoDrawableItemScaleParamHint) );
scale->populate();
scale->setDefaultValue(1, 0);
scale->setDefaultValue(1, 1);
knobs.push_back(scale);
scaleUniform = boost::make_shared<KnobBool>((KnobHolder*)NULL, tr(kRotoDrawableItemScaleUniformParamLabel), 1, true);
scaleUniform->setName(kRotoDrawableItemScaleUniformParam);
scaleUniform->setHintToolTip( tr(kRotoDrawableItemScaleUniformParamHint) );
scaleUniform->populate();
scaleUniform->setDefaultValue(true);
knobs.push_back(scaleUniform);
skewX = boost::make_shared<KnobDouble>((KnobHolder*)NULL, tr(kRotoDrawableItemSkewXParamLabel), 1, true);
skewX->setName(kRotoDrawableItemSkewXParam);
skewX->setHintToolTip( tr(kRotoDrawableItemSkewXParamHint) );
skewX->populate();
knobs.push_back(skewX);
skewY = boost::make_shared<KnobDouble>((KnobHolder*)NULL, tr(kRotoDrawableItemSkewYParamLabel), 1, true);
skewY->setName(kRotoDrawableItemSkewYParam);
skewY->setHintToolTip( tr(kRotoDrawableItemSkewYParamHint) );
skewY->populate();
knobs.push_back(skewY);
skewOrder = boost::make_shared<KnobChoice>((KnobHolder*)NULL, tr(kRotoDrawableItemSkewOrderParamLabel), 1, true);
skewOrder->setName(kRotoDrawableItemSkewOrderParam);
skewOrder->setHintToolTip( tr(kRotoDrawableItemSkewOrderParamHint) );
skewOrder->populate();
knobs.push_back(skewOrder);
{
std::vector<ChoiceOption> choices;
choices.push_back(ChoiceOption("XY"));
choices.push_back(ChoiceOption("YX"));
skewOrder->populateChoices(choices);
}
center = boost::make_shared<KnobDouble>((KnobHolder*)NULL, tr(kRotoDrawableItemCenterParamLabel), 2, true);
center->setName(kRotoDrawableItemCenterParam);
center->setHintToolTip( tr(kRotoDrawableItemCenterParamHint) );
center->populate();
knobs.push_back(center);
extraMatrix = boost::make_shared<KnobDouble>((KnobHolder*)NULL, tr(kRotoDrawableItemExtraMatrixParamLabel), 9, true);
extraMatrix->setName(kRotoDrawableItemExtraMatrixParam);
extraMatrix->setHintToolTip( tr(kRotoDrawableItemExtraMatrixParamHint) );
extraMatrix->populate();
extraMatrix->setDefaultValue(1, 0);
extraMatrix->setDefaultValue(1, 4);
extraMatrix->setDefaultValue(1, 8);
knobs.push_back(extraMatrix);
brushSize = boost::make_shared<KnobDouble>((KnobHolder*)NULL, tr(kRotoBrushSizeParamLabel), 1, true);
brushSize->setName(kRotoBrushSizeParam);
brushSize->setHintToolTip( tr(kRotoBrushSizeParamHint) );
brushSize->populate();