# Path: MEHI/utils/tool.py
# def exeTime(func):
#     '''
#     Usage:
#      - just put '@exeTime'(with out quotation) before your function
#      - will show the running time
#     '''
#     import time
#     def wraper(*args, **args2):
#         s = time.time()
#         ret = func(*args, **args2)
#         e = time.time()
#         msg = "%3.3fs taken for {%s}" % (e-s, func.__name__)
#         log('time')(msg)
#         return ret
#     return wraper


import numpy as np
import math
    import scipy.optimize as sciop
    import scipy.optimize as sciop
from MEHI.utils.tool import exeTime
    from MEHI.udf._trans import trans
    from MEHI.udf._update import update
    from skimage.feature import register_translation
    from scipy.ndimage import fourier_shift

    tx, ty, sita, sx, sy, hx, hy= tuple(vec)
    A = np.array([[1, 0, tx], [0, 1, ty], [0, 0, 1]])
    B = np.array([[math.cos(sita),  -math.sin(sita),  0], [math.sin(sita),  math.cos(sita),  0], [0, 0, 1]])
    C = np.array([[sx,  0,  0], [0, sy, 0], [0, 0, 1]])
    D = np.array([[1, hx, 0], [0, 1, 0], [0, 0, 1]])
    E = np.array([[1, 0, 0], [hy, 1 , 0], [0, 0, 1]])
    F = np.dot(np.dot(A,B),C)
    return np.dot(np.dot(F,D),E)

def _update(vec, imgA, imgB):
    H = _generate_H(imgA, imgB)
    _H = H.copy()
    _X, _Y = imgA.shape
    U = _get_trans(vec)
    for i in range(_X):
        for j in range(_Y):
            p = np.array([i,j,1])
            q = np.dot(U, p)
            p = (p[0],p[1])
            q = (q[0],q[1])
            _PV_interpolation(_H, p, q, imgA, imgB)
    return _mutual_info(_H)

def _trans(frame, vec):
    frame = frame.copy(order='C')
    ret = np.zeros_like(frame)
    U = _get_trans(vec)
    trans(frame, U, ret)
    return ret  


# Path: MEHI/utils/tool.py
# def exeTime(func):
#     '''
#     Usage:
#      - just put '@exeTime'(with out quotation) before your function
#      - will show the running time
#     '''
#     import time
#     def wraper(*args, **args2):
#         s = time.time()
#         ret = func(*args, **args2)
#         e = time.time()
#         msg = "%3.3fs taken for {%s}" % (e-s, func.__name__)
#         log('time')(msg)
#         return ret
#     return wraper


# Path: MEHI/paralleled/registration.py
import numpy as np
import math
    import scipy.optimize as sciop
    import scipy.optimize as sciop
from MEHI.utils.tool import exeTime
    from MEHI.udf._trans import trans
    from MEHI.udf._update import update
    from skimage.feature import register_translation
    from scipy.ndimage import fourier_shift

    tx, ty, sita, sx, sy, hx, hy= tuple(vec)
    A = np.array([[1, 0, tx], [0, 1, ty], [0, 0, 1]])
    B = np.array([[math.cos(sita),  -math.sin(sita),  0], [math.sin(sita),  math.cos(sita),  0], [0, 0, 1]])
    C = np.array([[sx,  0,  0], [0, sy, 0], [0, 0, 1]])
    D = np.array([[1, hx, 0], [0, 1, 0], [0, 0, 1]])
    E = np.array([[1, 0, 0], [hy, 1 , 0], [0, 0, 1]])
    F = np.dot(np.dot(A,B),C)
    return np.dot(np.dot(F,D),E)

def _update(vec, imgA, imgB):
    H = _generate_H(imgA, imgB)
    _H = H.copy()
    _X, _Y = imgA.shape
    U = _get_trans(vec)
    for i in range(_X):
        for j in range(_Y):
            p = np.array([i,j,1])
            q = np.dot(U, p)
            p = (p[0],p[1])
            q = (q[0],q[1])
            _PV_interpolation(_H, p, q, imgA, imgB)
    return _mutual_info(_H)

def _trans(frame, vec):
    frame = frame.copy(order='C')
    ret = np.zeros_like(frame)
    U = _get_trans(vec)
    trans(frame, U, ret)
    return ret  


@exeTime
