AllenInstitute/render-python

discussion: transform.tform(points, sharedTransforms=[]) ?

Opened this issue · 0 comments

To clean up some fusion something, I created the tform() method for InterpolatedTransform, you can see it below.In this particular case, the InterpolatedTransforms had lists with ReferenceTransforms in them, and rather than de-reference them, I added this kwarg into the call. This breaks the symmetry with all other tform methods, which kind of sucks, but... I was thinking that if all transform.tform() methods had sharedTransforms=[] then we could update ReferenceTransform and TransformList to actually have a tform method. The leaf transforms would need to be able to accept the keyword so the user would not have to worry about what kind of transform he/she is calling.

    def tform(self, points, sharedTransforms=[]):
        """transform a set of points through this transformation
        Parameters
        ----------
        points : numpy.array
            a Nx2 array of x,y points
        Returns
        -------
        numpy.array
            a Nx2 array of x,y points after transformation
        """
        dst = []

        refids = np.array([r.transformId for r in sharedTransforms])

        for ab in [self.a, self.b]:
            dst.append(np.copy(points))
            for tf in ab.tforms:
                if isinstance(tf, ReferenceTransform):
                    rind = np.argwhere(refids == tf.refId).flatten()
                    if rind.size != 1:
                        raise RenderError("Could not find unique "
                                          "sharedTransform for refId %s" %
                                          tf.refId)
                    tf = sharedTransforms[rind[0]]
                dst[-1] = tf.tform(dst[-1])

        return (1.0 - self.lambda_) * dst[0] + self.lambda_ * dst[1]