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')
def run(self, ips, imgs, para = None): if para['surface']: vts, fs, ns, cs = surfutil.build_img_cube(imgs, para['ds']) self.app.show_mesh(Surface(vts, fs, ns, cs), para['name']+'-surface') if para['box']: vts, fs, ns, cs = surfutil.build_img_box(imgs, para['color']) self.app.show_mesh(Surface(vts, fs, ns, cs, mode='grid'), para['name']+'-box')
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()
def canvas3d_note_frame(): cnf = Canvas3DNoteFrame(None) canvas1 = cnf.add_canvas() ball = Surface(vts, fs, ns, cs) canvas1.add_surf('ball', ball) canvas2 = cnf.add_canvas() ball = Surface(vts, fs, ns, cs) meshset = MeshSet('ABC', {'ball': ball}) ball.mode = 'grid' canvas2.set_mesh(meshset) cnf.Show()
def run(self, ips, imgs, para = None): num,r = para['num'], para['r'] if ips.roi != None: pts = ips.img[ips.get_msk()] else: pts = ips.img.reshape((-1,3)) pts = pts[::len(pts)//num] vts, fs, ns, cs = surfutil.build_balls(pts, np.ones(len(pts))*r, pts/255) self.app.show_mesh(Surface(vts, fs, ns, cs), para['name']) (r1,g1,b1),(r2,g2,b2) = (0,0,0),(1,1,1) rs = (r1,r2,r2,r1,r1,r1,r1,r1,r1,r2,r2,r1,r2,r2,r2,r2) gs = (g1,g1,g1,g1,g1,g2,g2,g1,g2,g2,g2,g2,g2,g1,g1,g2) bs = (b1,b1,b2,b2,b1,b1,b2,b2,b2,b2,b1,b1,b1,b1,b2,b2) vts, fs, ns, cs = surfutil.build_cube((0,0,0),(255,255,255)) cs = list(zip(rs,gs,bs)) self.app.show_mesh(Surface(vts, fs, ns, cs, mode='grid'), 'cube')
def mesh_obj_test(): cnf = Canvas3DFrame(None) meshes = MeshSet() vts, fs, ns, cs = surfutil.build_ball((100, 100, 100), 50, (1, 0, 0)) redball = Surface(vts, fs, ns, cs) meshes.add_surf('redball', redball) vts, fs, ns, cs = surfutil.build_ball((300, 100, 100), 50, (1, 1, 0)) yellowball = Surface(vts, fs, ns, cs, mode='grid') meshes.add_surf('yellowball', yellowball) hideball = Surface(vts, fs, ns, cs) vts, fs, ns, cs = surfutil.build_ball((300, -300, 100), 50, (0, 1, 0)) hideball = Surface(vts, fs, ns, cs, visible=False) hideball = meshes.add_surf('hideball', hideball) meshes.background = (0, 0, 0.3) cnf.set_mesh(meshes) cnf.Show()
def run(self, ips, imgs, para=None): ds, sigma = para['scale'], para['sigma'] vts, fs, ns, cs = surfutil.build_surf2d(ips.img, ds=ds, sigma=para['sigma'], k=para['h']) self.app.show_mesh(Surface(vts, fs, ns, cs), para['name'])
def run(self, para=None): os = np.random.rand(30).reshape((-1, 3)) rs = np.random.rand(10) / 5 cs = (np.random.rand(10) * 255).astype(np.uint8) cs = surfutil.linear_color('jet')[cs] / 255 vts, fs, ns, cs = surfutil.build_balls(os, rs, cs) self.app.show_mesh(Surface(vts, fs, ns, cs), 'balls')
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')
def surface2d_test(): cnf = Canvas3DFrame(None) x, y = np.ogrid[-2:2:20j, -2:2:20j] z = x * np.exp(-x**2 - y**2) vts, fs, ns, cs = surfutil.build_surf2d(z, ds=1, k=20, sigma=2) cs[:] = surfutil.auto_lookup(vts[:, 2], surfutil.linear_color('jet')) / 255 dem = Surface(vts, fs, ns, cs) cnf.add_surf('dem', dem) cnf.Show()
def add_surf(self, name, obj): if isinstance(obj, tuple): if isinstance(obj[3], (int, float)): obj = MarkText(*obj) else: obj = Surface(*obj) if not self.ctx is None: if isinstance(obj, MarkText): self.ctx_txt(self.ctx, self.prog_txt, obj, name) elif isinstance(obj, Surface): self.ctx_obj(self.ctx, self.prog_suf, obj, name) self.objs[name] = obj self.count_box()
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()
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()
def run(self, para=None): vts = np.array([(0, 0, 0), (1, 1, 0), (2, 1, 0), (1, 0, 0)], dtype=np.float32) fs = np.array([(0, 1, 2), (1, 2, 3)], dtype=np.uint32) ns = np.ones((4, 3), dtype=np.float32) n_mer, n_long = 6, 11 pi = np.pi dphi = pi / 1000.0 phi = np.arange(0.0, 2 * pi + 0.5 * dphi, dphi) mu = phi * n_mer x = np.cos(mu) * (1 + np.cos(n_long * mu / n_mer) * 0.5) y = np.sin(mu) * (1 + np.cos(n_long * mu / n_mer) * 0.5) z = np.sin(n_long * mu / n_mer) * 0.5 vts, fs, ns, cs = surfutil.build_line(x, y, z, (1, 0, 0)) cs[:] = surfutil.auto_lookup(vts[:, 2], surfutil.linear_color('jet')) / 255 self.app.show_mesh(Surface(vts, fs, ns, cs, mode='grid'), 'line')
def run(self, para=None): dphi, dtheta = np.pi / 20.0, np.pi / 20.0 [phi, theta] = np.mgrid[0:np.pi + dphi * 1.5:dphi, 0:2 * np.pi + dtheta * 1.5:dtheta] m0 = 4 m1 = 3 m2 = 2 m3 = 3 m4 = 6 m5 = 2 m6 = 6 m7 = 4 r = np.sin(m0 * phi)**m1 + np.cos(m2 * phi)**m3 + np.sin( m4 * theta)**m5 + np.cos(m6 * theta)**m7 x = r * np.sin(phi) * np.cos(theta) y = r * np.cos(phi) z = r * np.sin(phi) * np.sin(theta) vts, fs, ns, cs = surfutil.build_mesh(x, y, z) cs[:] = surfutil.auto_lookup(vts[:, 2], surfutil.linear_color('jet')) / 255 self.app.show_mesh(Surface(vts, fs, ns, cs), 'decoration')
def run(self, ips, imgs, para = None): ips.lut = self.buflut cs = tuple([int(i/255.0) for i in para['color']]) vts, fs, ns, cs = surfutil.build_surf3d(ips.imgs, para['ds'], para['thr'], para['step'], cs) self.app.show_mesh(Surface(vts, fs, ns, cs), para['name'])
def add_with_para(): cnf = Canvas3DFrame(None) surf = Surface(vts, fs, ns, cs, mode='grid') cnf.add_surf('gridball', surf) cnf.Show()
def dem_test(): cnf = Canvas3DFrame(None) vts, fs, ns, cs = surfutil.build_surf2d(moon(), ds=1, k=0.3, sigma=2) cnf.add_surf('dem', Surface(vts, fs, ns, cs)) cnf.Show()