Ejemplo n.º 1
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('input', type=str)
    parser.add_argument('-c', dest='camera_actions', type=str, default=[],
                        action='append', help='camera actions')

    args = parser.parse_args()
    z = np.load(args.input)

    vis = VisualiseMesh()

    # V0 (purple)
    V0 = z['V0']
    vis.add_mesh(V0, z['T'], actor_name='V0')
    lut = vis.actors['V0'].GetMapper().GetLookupTable()
    lut.SetTableValue(0, *int2dbl(255, 0, 255))

    # V0 w/ X (green)
    T_ = faces_to_cell_array(z['T'])
    adj, W = weights.weights(V0, T_, weights_type='cotan')
    solveV0_X = ARAPVertexSolver(adj, W, V0)

    rotM = lambda x: quat.rotationMatrix(quat.quat(x))
    V0_X = solveV0_X(map(rotM, z['X']))
    V0_X += register.displacement(V0_X, z['V'])

    vis.add_mesh(V0_X, z['T'], actor_name='V0_X')
    lut = vis.actors['V0_X'].GetMapper().GetLookupTable()
    lut.SetTableValue(0, *int2dbl(0, 255, 0))

    # V0 w/ Xg (yellow)
    if 'Xg' in z.keys():
        Xg = z['Xg'][0]
        qg = quat.quat(Xg)
        Q = [quat.quatMultiply(quat.quat(x), qg) for x in z['X']]
        V0_Xg = solveV0_X([quat.rotationMatrix(q) for q in Q])
        V0_Xg += register.displacement(V0_Xg, z['V'])
        vis.add_mesh(V0_Xg, z['T'], actor_name='V0_Xg')
        lut = vis.actors['V0_Xg'].GetMapper().GetLookupTable()
        lut.SetTableValue(0, *int2dbl(255, 255, 0))

    # V (blue)
    vis.add_mesh(z['V'], z['T'], actor_name='V')

    # input frame
    vis.add_image(z['input_frame'])

    # projection constraints
    vis.add_projection(z['C'], z['P'])

    # apply camera actions sequentially
    for action in args.camera_actions:
        method, tup, save_after = parse_camera_action(action)
        print '%s(*%s), save_after=%s' % (method, tup, save_after)
        vis.camera_actions((method, tup))

    vis.execute()
Ejemplo n.º 2
0
    def _add_sectioned_arap(self):
        if self.core_V is None:
            return

        # calculate `Xi`
        ki = self['ki']
        Xb = self['Xb']
        y = self['y']
        X = self['X']

        N = self.core_V.shape[0]
        Xi = np.zeros((N, 3), dtype=np.float64)

        iter_ki = iter(ki)

        for i in xrange(N):
            n = next(iter_ki)
            if n == 0:
                pass
            elif n < 0:
                Xi[i, :] = X[next(iter_ki)]
            else:
                yi, Xbi = [], []
                for j in xrange(n):
                    Xbi.append(Xb[next(iter_ki)])
                    yi.append(y[next(iter_ki)])

                # FIXME Potential wrong order and will need to check when
                # multiple local basis rotations
                Xi[i, :] = reduce(add, map(mul, yi, Xbi))
                    
        # setup `solve_V`
        T = self['T'] 
        core_V = self.core_V.copy()
        adj, W = weights(core_V, faces_to_cell_array(T), weights_type='uniform')

        solve_V = ARAPVertexSolver(adj, W, core_V)

        # solve for `V1`
        rotM = lambda x: rotationMatrix(quat(x))
        V1 = solve_V(map(lambda x: rotM(x), Xi))

        # apply global rotation and scale
        A = self['s'] * rotM(np.ravel(self['Xg']))

        V1 = np.dot(V1, np.transpose(A))

        # register by translation to the instance vertices
        V1 += register.displacement(V1, self[self.vertices_key])

        # add as orange actor
        self.vis.add_mesh(V1, T, actor_name='arap', 
                          is_base=False, 
                          compute_normals=self.compute_normals, 
                          color=(255, 170, 0))
Ejemplo n.º 3
0
    def _add_deprecated_sectioned_arap(self):
        if self.core_V is None:
            return

        # calculate `Xi`
        K = self['K']
        Xb = self['Xb']
        X = self['X']
        y = self['y']

        N = self.core_V.shape[0]
        Xi = np.zeros((N, 3), dtype=np.float64)
        for i in xrange(N):
            if K[i, 0] == 0:
                pass
            elif K[i, 0] < 0:
                Xi[i,:] = X[K[i, 1]]
            else:
                Xi[i,:] = axScale(y[K[i, 0] - 1], Xb[K[i, 1]])

        # setup `solve_V`
        T = self['T'] 
        core_V = self.core_V.copy()
        adj, W = weights(core_V, faces_to_cell_array(T), weights_type='uniform')

        solve_V = ARAPVertexSolver(adj, W, core_V)

        # solve for `V1`
        rotM = lambda x: rotationMatrix(quat(x))
        V1 = solve_V(map(lambda x: rotM(x), Xi))

        # apply global rotation and scale
        A = self['s'] * rotM(np.ravel(self['Xg']))

        V1 = np.dot(V1, np.transpose(A))

        # register by translation to the instance vertices
        V1 += register.displacement(V1, self[self.vertices_key])

        # add as orange actor
        self.vis.add_mesh(V1, T, actor_name='arap', 
                          is_base=False, 
                          color=(255, 170, 0))
Ejemplo n.º 4
0
    def _add_regular_arap(self):
        if self['y'] is not None or self.core_V is None:
            return

        T = self['T'] 
        core_V = self.core_V.copy()
        adj, W = weights(core_V, faces_to_cell_array(T), weights_type='uniform')

        solve_V = ARAPVertexSolver(adj, W, core_V)

        rotM = lambda x: rotationMatrix(quat(x))
        V1 = solve_V(map(lambda x: rotM(x), self['X']))

        xg = np.ravel(self['Xg'])
        A = self['s'] * rotM(xg)

        V1 = np.dot(V1, np.transpose(A))
        V1 += register.displacement(V1, self[self.vertices_key])

        self.vis.add_mesh(V1, T, actor_name='arap', is_base=False)

        lut = self.vis.actors['arap'].GetMapper().GetLookupTable()
        lut.SetTableValue(0, 1., 0.667, 0.)
Ejemplo n.º 5
0
    def _add_basis_arap(self):
        if self.core_V is None:
            return

        X = self['X']
        y = self['y']
        if not isinstance(y, np.ndarray) or len(X) != y.shape[0]:
            return

        T = self['T'] 
        core_V = self.core_V.copy()
        adj, W = weights(core_V, faces_to_cell_array(T), weights_type='uniform')

        solve_V = ARAPVertexSolver(adj, W, core_V)

        scaled_X = []
        for y_, X_ in izip(y, X):
            scaled_X.append(map(lambda x: axScale(y_, x), X_))

        N = core_V.shape[0]
        X = []
        for i in xrange(N):
            X.append(reduce(axAdd, [X_[i] for X_ in scaled_X]))

        rotM = lambda x: rotationMatrix(quat(x))
        V1 = solve_V(map(lambda x: rotM(x), X))

        xg = np.ravel(self['Xg'])
        A = self['s'] * rotM(xg)

        V1 = np.dot(V1, np.transpose(A))

        V1 += register.displacement(V1, self[self.vertices_key])

        self.vis.add_mesh(V1, T, actor_name='arap', is_base=False)
        lut = self.vis.actors['arap'].GetMapper().GetLookupTable()
        lut.SetTableValue(0, 1., 0., 1.)