'Set this transform mased on the elements of *m*
The input matrix must be affine AND have no shear,
otherwise the conversion will most likely fail.'

def setFromMatrix(self, m):

    import numpy.linalg
    for i in range(4):
        self.setRow(i, m.row(i))
    m = self.matrix().reshape(4, 4)
    self._state['pos'] = m[:3, 3]
    scale = ((m[:3, :3] ** 2).sum(axis=0) ** 0.5)
    z = np.cross(m[0, :3], m[1, :3])
    if (np.dot(z, m[2, :3]) < 0):
        scale[1] *= (-1)
    self._state['scale'] = scale
    r = (m[:3, :3] / scale[np.newaxis, :])
    try:
        (evals, evecs) = numpy.linalg.eig(r)
    except:
        print ('Rotation    matrix:    %s' % str(r))
        print ('Scale:    %s' % str(scale))
        print ('Original    matrix:    %s' % str(m))
        raise
    eigIndex = np.argwhere((np.abs((evals - 1)) < 1e-06))
    if (len(eigIndex) < 1):
        print ('eigenvalues:    %s' % str(evals))
        print ('eigenvectors:    %s' % str(evecs))
        print ('index:    %s,    %s' % (str(eigIndex), str((evals - 1))))
        raise Exception('Could    not    determine    rotation    axis.')
    axis = evecs[:, eigIndex[(0, 0)]].real
    axis /= ((axis ** 2).sum() ** 0.5)
    self._state['axis'] = axis
    cos = ((r.trace() - 1) * 0.5)
    axisInd = np.argmax(np.abs(axis))
    (rInd, sign) = [((1, 2), (-1)), ((0, 2), 1), ((0, 1), (-1))][axisInd]
    sin = ((r - r.T)[rInd] / ((2.0 * sign) * axis[axisInd]))
    self._state['angle'] = ((np.arctan2(sin, cos) * 180) / np.pi)
    if (self._state['angle'] == 0):
        self._state['axis'] = (0, 0, 1)
