import numpy as np

from menpo.shape import PointCloud
from menpo.transform import Homogeneous

"""
Explanation: Homogeneous Transforms
End of explanation
"""


# mirror along y=x
xy_yx = Homogeneous(np.array([[0, 1, 0], 
                              [1, 0, 0], 
                              [0, 0, 1]]))

s = np.linspace(0, 1)
len(s)
p = np.ones([len(s), 2])
p[:, 1] = s
pc = PointCloud(p)
print(pc)

%matplotlib inline
pc.view(axes_y_limits=(0.5, 1.5));

"""
Explanation: If you know the form of a basic homogeneous transform (like here a mirror along y=x) it's trivial to build a Homogeneous to use this operation in Menpo
End of explanation
"""


print(xy_yx)

"""
Explanation: Let's take a look at what our homogeneous transform is exactly
End of explanation
"""


pc_flipped = xy_yx.apply(pc)

pc_flipped.view(axes_x_limits=(0.5, 1.5));

"""
Explanation: Applying this Transform to a PointCloud has the desired effect
End of explanation
"""


no_op = xy_yx.compose_before(xy_yx)
print(no_op)

no_op = xy_yx.compose_after(xy_yx)
print(no_op)

xy_yx.compose_before_inplace(xy_yx)
print(xy_yx)

"""
Explanation: Homogeneous transforms support native composition
End of explanation
"""


