-
Notifications
You must be signed in to change notification settings - Fork 24
/
fullEllipse.py
97 lines (61 loc) · 3.49 KB
/
fullEllipse.py
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
#This Source Code Form is subject to the terms of the Mozilla Public
#License, v. 2.0. If a copy of the MPL was not distributed with this
#file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#Created by Fabrice Fernandez on 22/07/2019.
import string
import NatronEngine
from NatronGui import *
# CREATE A FULL FRAME ELLIPSE #
def fullEllipse():
# get current Natron instance running in memory
app = natron.getGuiInstance(0)
# create a 'Roto' node
myRoto = app.createNode("fr.inria.built-in.Roto")
# get input image size
imageWidth = myRoto.getOutputFormat().width()
imageHeight = myRoto.getOutputFormat().height()
# set 'Roto' label
myRoto.setLabel('full_Ellipse1')
# get roto context
rotoContext = myRoto.getRotoContext()
# get 'Base Layer'
Layer1_layer = rotoContext.getBaseLayer()
# create ellipse
fullEllipse = rotoContext.createEllipse(imageWidth/2, imageHeight/2, imageWidth, True, 1)
fullEllipse.setLabel('full_Ellipse1')
# set center position
myRoto.getParam('center').setValue(imageWidth/2,0)
myRoto.getParam('center').setValue(imageHeight/2,1)
# get bottom point position
bottomPointPosition = fullEllipse.getControlPointPosition(0,1)
# set bottom point position
fullEllipse.setPointAtIndex(0, 1, bottomPointPosition[0], 0, bottomPointPosition[2], 0, bottomPointPosition[4], 0)
fullEllipse.setFeatherPointAtIndex(0, 1, bottomPointPosition[0], 0, bottomPointPosition[2], 0, bottomPointPosition[4], 0)
# get top point position
topPointPosition = fullEllipse.getControlPointPosition(2,1)
# set top point position
fullEllipse.setPointAtIndex(2, 1, topPointPosition[0], imageHeight, topPointPosition[2], imageHeight, topPointPosition[4], imageHeight)
fullEllipse.setFeatherPointAtIndex(2, 1, topPointPosition[0], imageHeight, topPointPosition[2], imageHeight, topPointPosition[4], imageHeight)
bbox = myRoto.getRegionOfDefinition(1,0)
myWidth = bbox.width() -3
myHeight = bbox.height() -3
imageRatio = myHeight/myWidth
# get right point position
rightPointPosition = fullEllipse.getControlPointPosition(1,1)
rightPointLeftTangentPosition = rightPointPosition[1] - rightPointPosition[3]
rightPointLeftTangentPosition *= imageRatio
rightPointRightTangentPosition = rightPointPosition[1] - rightPointPosition[5]
rightPointRightTangentPosition *= imageRatio
rightPointRightTangentPosition += myHeight
fullEllipse.setPointAtIndex(1, 1, rightPointPosition[0], rightPointPosition[1], rightPointPosition[2], rightPointLeftTangentPosition, rightPointPosition[4], rightPointRightTangentPosition)
fullEllipse.setFeatherPointAtIndex(1, 1, rightPointPosition[0], rightPointPosition[1], rightPointPosition[2], rightPointLeftTangentPosition, rightPointPosition[4], rightPointRightTangentPosition)
# get left point position
leftPointPosition = fullEllipse.getControlPointPosition(3,1)
leftPointRightTangentPosition = leftPointPosition[1] - leftPointPosition[3]
leftPointRightTangentPosition *= imageRatio
leftPointRightTangentPosition += (myHeight/2)
leftPointLeftTangentPosition = leftPointPosition[1] - leftPointPosition[5]
leftPointLeftTangentPosition *= imageRatio
leftPointLeftTangentPosition += (myHeight/2)
fullEllipse.setPointAtIndex(3, 1, leftPointPosition[0], leftPointPosition[1], leftPointPosition[2], leftPointLeftTangentPosition, leftPointPosition[4], leftPointRightTangentPosition)
fullEllipse.setFeatherPointAtIndex(3, 1, leftPointPosition[0], leftPointPosition[1], leftPointPosition[2], leftPointLeftTangentPosition, leftPointPosition[4], leftPointRightTangentPosition)