|
1 | 1 | from .transform import Transform, logger |
2 | 2 | from .affine_models import AffineModel |
3 | 3 | import numpy as np |
| 4 | +from .common import calc_first_order_properties |
4 | 5 | from renderapi.errors import ConversionError, EstimationError, RenderError |
5 | 6 |
|
6 | 7 | try: |
@@ -29,7 +30,8 @@ class Polynomial2DTransform(Transform): |
29 | 30 |
|
30 | 31 | def __init__(self, dataString=None, src=None, dst=None, order=2, |
31 | 32 | force_polynomial=True, params=None, identity=False, |
32 | | - labels=None, transformId=None, json=None, **kwargs): |
| 33 | + labels=None, transformId=None, json=None, |
| 34 | + force_shear='x', **kwargs): |
33 | 35 | """Initialize Polynomial2DTransform |
34 | 36 | This provides 5 different ways to initialize the transform which are |
35 | 37 | mutually exclusive and applied in the order specified here. |
@@ -58,6 +60,7 @@ def __init__(self, dataString=None, src=None, dst=None, order=2, |
58 | 60 |
|
59 | 61 |
|
60 | 62 | """ |
| 63 | + self.force_shear = force_shear |
61 | 64 | if json is not None: |
62 | 65 | self.from_dict(json) |
63 | 66 | else: |
@@ -89,15 +92,38 @@ def order(self): |
89 | 92 | no_coeffs = len(self.params.ravel()) |
90 | 93 | return int((abs(np.sqrt(4 * no_coeffs + 1)) - 3) / 2) |
91 | 94 |
|
| 95 | + def calc_properties(self): |
| 96 | + if self.order == 0: |
| 97 | + return 1.0, 1.0, 0.0, 0.0, 0.0 |
| 98 | + return calc_first_order_properties( |
| 99 | + self.params[:, 1:3], |
| 100 | + force_shear=self.force_shear) |
| 101 | + |
92 | 102 | @property |
93 | 103 | def scale(self): |
94 | 104 | """tuple of scale for x, y""" |
95 | | - if self.order > 0: |
96 | | - scale = (self.params[0, 1], self.params[1, 2]) |
| 105 | + sx, sy, cx, cy, theta = self.calc_properties() |
| 106 | + return (sx, sy) |
| 107 | + |
| 108 | + @property |
| 109 | + def shear(self): |
| 110 | + """shear""" |
| 111 | + sx, sy, cx, cy, theta = self.calc_properties() |
| 112 | + if self.force_shear == 'x': |
| 113 | + return cx |
97 | 114 | else: |
98 | | - # translation only has no scale impact |
99 | | - scale = (1.0, 1.0) |
100 | | - return scale |
| 115 | + return cy |
| 116 | + |
| 117 | + @property |
| 118 | + def translation(self): |
| 119 | + """tuple of translation in x, y""" |
| 120 | + return tuple(self.params[:, 0]) |
| 121 | + |
| 122 | + @property |
| 123 | + def rotation(self): |
| 124 | + """counter-clockwise rotation""" |
| 125 | + sx, sy, cx, cy, theta = self.calc_properties() |
| 126 | + return theta |
101 | 127 |
|
102 | 128 | @property |
103 | 129 | def dataString(self): |
|
0 commit comments