Ejemplo n.º 1
0
    def run(self, para=None):
        cnf = Canvas3DFrame(None)

        n = para['n'] + 1
        xs = [np.linspace(0, 1, n)] * n**2
        ys = list(np.arange(n**3).reshape((-1, n)) // n % n / (n - 1))
        zs = list(np.arange(n**3).reshape((-1, n)) // n**2 / (n - 1))
        cs = [np.array((x, y, z)).T for x, y, z in zip(xs, ys, zs)]
        # cs[:] = myvi.util.auto_lookup(vts[:,2], myvi.util.linear_color('jet'))/255
        vts, fs, ns, cs = surfutil.build_lines(xs, ys, zs, cs)
        X = Surface(vts, fs, ns, cs)
        X.mode, X.width = 'grid', 2
        cnf.add_surf('X', X)

        cs = [np.array((x, y, z)).T for x, y, z in zip(ys, xs, zs)]
        vts, fs, ns, cs = surfutil.build_lines(ys, xs, zs, cs)
        Y = Surface(vts, fs, ns, cs)
        Y.mode, Y.width = 'grid', 2
        cnf.add_surf('Y', Y)

        cs = [np.array((x, y, z)).T for x, y, z in zip(zs, ys, xs)]
        vts, fs, ns, cs = surfutil.build_lines(zs, ys, xs, cs)
        Z = Surface(vts, fs, ns, cs)
        Z.mode, Z.width = 'grid', 2
        cnf.add_surf('Z', Z)
        cnf.Show()
Ejemplo n.º 2
0
    def run(self, ips, imgs, para=None):
        balls, ids, rs, graph = [], [], [], ips.data
        for idx in graph.nodes():
            ids.append(idx)
            balls.append(graph.nodes[idx]['o'])
        xs, ys, zs = [], [], []
        lxs, lys, lzs = [], [], []
        for (s, e) in graph.edges():
            eds = graph[s][e]
            st, ed = graph.nodes[s]['o'], graph.nodes[e]['o']
            lxs.append([st[0], ed[0]])
            lys.append([st[1], ed[1]])
            lzs.append([st[2], ed[2]])
            for i in eds:
                pts = eds[i]['pts']
                xs.append(pts[:, 0])
                ys.append(pts[:, 1])
                zs.append(pts[:, 2])

        rs = [para['r']] * len(balls)
        cs = tuple(np.array(para['ncolor']) / 255.0)
        vts, fs, ns, cs = surfutil.build_balls(balls, rs, cs)
        self.app.show_mesh(Surface(vts, fs, ns, cs), 'balls')

        vts, fs, pos, h, color = surfutil.build_marks(
            ['ID:%s' % i for i in ids], balls, para['r'], para['r'], (1, 1, 1))
        self.app.show_mesh(MarkText(vts, fs, pos, h, color), 'txt')

        cs = tuple(np.array(para['lcolor']) / 255.0)
        vts, fs, ns, cs = surfutil.build_lines(xs, ys, zs, cs)
        self.app.show_mesh(Surface(vts, fs, ns, cs, mode='grid'), 'path')

        cs = tuple(np.array(para['pcolor']) / 255.0)
        vts, fs, ns, cs = surfutil.build_lines(lxs, lys, lzs, cs)
        self.app.show_mesh(Surface(vts, fs, ns, cs, mode='grid'), 'lines')
Ejemplo n.º 3
0
    def run(self, ips, imgs, para=None):
        dis = self.app.get_img(para['dis']).imgs
        balls, ids, rs, graph = [], [], [], ips.data
        for idx in graph.nodes():
            ids.append(idx)
            balls.append(graph.nodes[idx]['o'])

        xs, ys, zs = [], [], []
        v1s, v2s = [], []
        for (s, e) in graph.edges():
            eds = graph[s][e]
            st, ed = graph.nodes[s]['o'], graph.nodes[e]['o']
            v1s.append(st)
            v2s.append(ed)
            for i in eds:
                pts = eds[i]['pts']
                xs.append(pts[:, 0])
                ys.append(pts[:, 1])
                zs.append(pts[:, 2])

        rs1 = dis[list(np.array(v1s).astype(np.int16).T)]
        rs2 = dis[list(np.array(v2s).astype(np.int16).T)]
        rs1 = list(np.clip(rs1, 2, 1e4) * 0.5)
        rs2 = list(np.clip(rs2, 2, 1e4) * 0.5)
        rs = dis[list(np.array(balls).astype(np.int16).T)]
        rs = list(np.clip(rs, 2, 1e4))

        print(balls, rs1, rs2, rs)

        cs = tuple(np.array(para['ncolor']) / 255.0)
        vts, fs, ns, cs = surfutil.build_balls(balls, rs, cs)
        self.app.show_mesh(Surface(vts, fs, ns, cs), 'balls')

        meansize = sum(rs) / len(rs)
        vts, fs, pos, h, color = surfutil.build_marks(
            ['ID:%s' % i for i in ids], balls, rs, meansize, (1, 1, 1))
        self.app.show_mesh(MarkText(vts, fs, pos, h, color), 'txt')

        cs = tuple(np.array(para['lcolor']) / 255.0)
        vts, fs, ns, cs = surfutil.build_lines(xs, ys, zs, cs)
        self.app.show_mesh(Surface(vts, fs, ns, cs, mode='grid'), 'path')

        cs = tuple(np.array(para['pcolor']) / 255.0)
        vts, fs, ns, cs = surfutil.build_arrows(v1s, v2s, rs1, rs2, 0, 0, cs)
        self.app.show_mesh(Surface(vts, fs, ns, cs), 'lines')
Ejemplo n.º 4
0
    def run(self, para=None):
        n, angs = para['rings'], para['angs'] + 1
        a = np.linspace(0, np.pi * 2, angs)
        xs, ys, zs, cs = [], [], [], []
        for r in np.arange(1, n + 1) / n:
            xs.append(np.cos(a) * r)
            ys.append(np.sin(a) * r)
            zs.append([1] * angs)
            hsv = np.array([a / np.pi / 2, [r] * angs, [1] * angs]).T
            rgb = hsv2rgb(hsv.reshape((-1, 1, 3)))
            cs.append(list(rgb.reshape((-1, 3))))

        rr = np.hstack((np.arange(0, n + 1) / n, [0]))
        xs.extend(list(np.cos(a).reshape((-1, 1)) * rr))
        ys.extend(list(np.sin(a).reshape((-1, 1)) * rr))
        zs.extend([[1] * n + [1, -1]] * angs)
        hsvs = [
            np.array(([h / np.pi / 2] * (n + 2), rr, [1] * n + [1, 0])).T
            for h in a
        ]
        rgbs = [hsv2rgb(i.reshape((-1, 1, 3))).reshape(-1, 3) for i in hsvs]
        cs.extend([list(i) for i in rgbs])
        # cs[:] = myvi.util.auto_lookup(vts[:,2], myvi.util.linear_color('jet'))/255
        xs.append([0, 0])
        ys.append([0, 0])
        zs.append([1, -1])
        cs.append([(1, 1, 1), (0, 0, 0)])

        cnf = Canvas3DFrame(None)
        vts, fs, ns, cs = surfutil.build_lines(xs, ys, zs, cs)
        X = Surface(vts, fs, ns, cs)
        cnf.add_surf('X', X)

        X.mode, X.width = 'grid', 2

        cnf.Show()