예제 #1
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')
예제 #2
0
def balls_mark_rest():
    cnf = Canvas3DFrame(None)
    os = np.random.rand(30).reshape((-1, 3))
    rs = np.random.rand(10) / 7 + 0.01
    cs = (np.random.rand(10) * 255).astype(np.uint8)
    cs = surfutil.linear_color('jet')[cs] / 255

    vts_b, fs_b, ns_b, cs_b = surfutil.build_balls(os, rs, cs)
    cont = ['ID:%s' % i for i in range(10)]
    vtss, fss, pps, h, color = surfutil.build_marks(cont, os, rs, 0.05,
                                                    (1, 1, 1))
    cnf.add_surf('balls', Surface(vts_b, fs_b, ns_b, cs_b))
    cnf.add_surf('line', MarkText(vtss, fss, pps, h, color))
    cnf.Show()
예제 #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')