Пример #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()
Пример #2
0
def arrow_test():
    cnf = Canvas3DFrame(None)
    v1, v2 = np.array([[[0, 0, 0], [5, 5, 5]], [[0, 15, 5], [2, 8, 3]]],
                      dtype=np.float32)
    vts, fs, ns, cs = geoutil.build_arrows(v1, v2, 1, 1, 1, 1, (1, 0, 0))
    cnf.add_surf('arrow', vts, fs, ns, cs)
    cnf.Show()
Пример #3
0
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 = geoutil.build_surf2d(z, ds=1, k=20, sigma=2)
    cs[:] = geoutil.auto_lookup(vts[:, 2], geoutil.linear_color('jet')) / 255
    cnf.add_surf('dem', vts, fs, ns, cs)
    cnf.Show()
Пример #4
0
def random_ball_test():
    cnf = Canvas3DFrame(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 = geoutil.linear_color('jet')[cs] / 255
    vts, fs, ns, cs = geoutil.build_balls(os, rs, cs)
    cnf.add_surf('ball', vts, fs, ns, cs)
    cnf.Show()
Пример #5
0
def volume_test():
    cnf = Canvas3DFrame(None)
    cube = np.zeros((100, 100, 100), dtype=np.float32)
    x, y, z = np.random.randint(10, 90, 900).reshape(3, -1)
    cube[x, y, z] = 1000
    cube = ndimg.gaussian_filter(cube, 3)
    vts, fs, ns, vs = geoutil.build_surf3d(cube, 1, 2)
    cnf.add_surf('volume', vts, fs, ns, (1, 0, 0))
    cnf.Show()
Пример #6
0
def cube_surf_test():
    cnf = Canvas3DFrame(None)
    lut = np.zeros((256, 3), dtype=np.uint8)
    lut[:, 0] = np.arange(256)
    imgs = np.array([camera()[:300, ::]] * 256)
    vts, fs, ns, cs = geoutil.build_img_cube(imgs)
    obj = cnf.add_surf('cube', vts, fs, ns, cs)
    vts, fs, ns, cs = geoutil.build_img_box(imgs)
    cnf.add_surf('box', vts, fs, ns, cs, mode='grid')
    cnf.Show()
Пример #7
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 = geoutil.linear_color('jet')[cs]/255

    vts_b, fs_b, ns_b, cs_b = geoutil.build_balls(os, rs, cs)
    cont = ['ID:%s'%i for i in range(10)]
    vtss, fss, pps, h, color = geoutil.build_marks(cont, os, rs, 0.05, (1,1,1))
    cnf.add_surf('balls', vts_b, fs_b, ns_b, cs_b)
    cnf.add_mark('line', vtss, fss, pps, h, color)
    cnf.Show()
Пример #8
0
def mesh_test():
    cnf = Canvas3DFrame(None)
    dphi, dtheta = np.pi/16.0, np.pi/16.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 = geoutil.build_mesh(x, y, z)
    cs[:] = geoutil.auto_lookup(vts[:,2], geoutil.linear_color('jet'))/255
    cnf.add_surf('ball', vts, fs, ns, cs)
    cnf.Show()
Пример #9
0
    def _show_mesh(self, mesh=None, title=None):
        if mesh is None:
            cframe = Canvas3DFrame(self)
            canvas = cframe.canvas
            canvas.mesh.name = 'Surface'

        elif hasattr(mesh, 'vts'):
            canvas = self.get_mesh_win()
            if canvas is None:
                cframe = Canvas3DFrame(self)
                canvas = cframe.canvas
                canvas.mesh.name = 'Surface'
            canvas.add_surf(title, mesh)
        else:
            cframe = Canvas3DFrame(self)
            canvas = cframe.canvas
            canvas.set_mesh(mesh)
        canvas.GetParent().Show()
        canvas.GetParent().Bind(wx.EVT_ACTIVATE, self.on_new_mesh)
        canvas.GetParent().Bind(wx.EVT_CLOSE, self.on_close_mesh)
        self.add_mesh(canvas.mesh)
        self.add_mesh_win(canvas)
Пример #10
0
def ball_ring_test():
    cnf = Canvas3DFrame(None)
    os = np.random.rand(30).reshape((-1,3))
    rs = np.random.rand(10)/7
    cs = (np.random.rand(10)*255).astype(np.uint8)
    cs = geoutil.linear_color('jet')[cs]/255

    vts_b, fs_b, ns_b, cs_b = geoutil.build_balls(list(os), list(rs), list(cs))
    vts_l, fs_l, ns_l, cs_l = geoutil.build_line(os[:,0], os[:,1], os[:,2], list(cs))
    vts_c, fs_c, ns_c, cs_c = geoutil.build_cube((0,0,0), (1,1,1))
    cnf.add_surf('balls', vts_b, fs_b, ns_b, cs_b)
    cnf.add_surf('line', vts_l, fs_l, ns_l, cs_l, mode='grid')
    cnf.add_surf('box', vts_c, fs_c, ns_c, cs_c, mode='grid')
    cnf.Show()
Пример #11
0
def mesh_obj_test():
    cnf = Canvas3DFrame(None)
    meshes = MeshSet()
    vts, fs, ns, cs = geoutil.build_ball((100, 100, 100), 50, (1, 0, 0))
    redball = meshes.add_surf('redball', vts, fs, ns, cs)
    vts, fs, ns, cs = geoutil.build_ball((300, 100, 100), 50, (1, 1, 0))
    yellowball = meshes.add_surf('yellowball', vts, fs, ns, cs)
    yellowball.mode = 'grid'
    vts, fs, ns, cs = geoutil.build_ball((300, -300, 100), 50, (0, 1, 0))
    hideball = meshes.add_surf('hideball', vts, fs, ns, cs)
    hideball.visible = False
    meshes.background = (0, 0, 0.3)
    cnf.set_mesh(meshes)
    cnf.Show()
Пример #12
0
def line_test():
    cnf = Canvas3DFrame(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 = geoutil.build_line(x, y, z, (1, 0, 0))
    cs[:] = geoutil.auto_lookup(vts[:,2], geoutil.linear_color('jet'))/255
    cnf.add_surf('ball', vts, fs, ns, cs, mode='grid')
    cnf.Show()
Пример #13
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()
Пример #14
0
def canvas3d_frame_test():
    cnf = Canvas3DFrame(None)
    cnf.add_surf('ball', vts, fs, ns, cs)
    cnf.Show()
Пример #15
0
def add_with_para():
    cnf = Canvas3DFrame(None)
    surf = Surface(vts, fs, ns, cs, mode='grid')
    cnf.add_surf('gridball', surf)
    cnf.Show()
Пример #16
0
def cube_test():
    cnf = Canvas3DFrame(None)
    vts, fs, ns, cs = geoutil.build_cube((0, 0, 0), (1, 1, 1))
    cnf.add_surf('box', vts, fs, ns, cs, mode='grid')
    cnf.Show()
Пример #17
0
def ball_test():
    cnf = Canvas3DFrame(None)
    vts, fs, ns, cs = geoutil.build_ball((100, 100, 100), 50, (1, 0, 0))
    cnf.add_surf('ball', vts, fs, ns, cs)
    cnf.Show()
Пример #18
0
def dem_test():
    cnf = Canvas3DFrame(None)
    vts, fs, ns, cs = geoutil.build_surf2d(moon(), ds=1, k=0.3, sigma=2)
    cnf.add_surf('dem', vts, fs, ns, cs)
    cnf.Show()