Skip to content

Commit e584e02

Browse files
committed
vispy
1 parent 95cd763 commit e584e02

28 files changed

+1182
-763
lines changed

imagepy/app/imagepy.py

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from sciwx.plot import PlotFrame
1111
from skimage.data import camera
1212
from sciapp import App, Source
13-
from sciapp.object import Image, Table
13+
from sciapp.object import Image, Table, Scene, Mesh
1414
from imagepy import root_dir
1515
from .startup import load_plugins, load_tools, load_widgets, load_document, load_dictionary
1616
from .manager import ConfigManager, DictManager, ShortcutManager, DocumentManager
@@ -191,7 +191,7 @@ def init_canvas(self):
191191
self.canvasnbwrap.Layout()
192192
self.auimgr.AddPane( self.canvasnbwrap, aui.AuiPaneInfo() .Center() .CaptionVisible( False ).PinButton( True ).Dock()
193193
.PaneBorder( False ).Resizable().FloatingSize( wx.DefaultSize ). BottomDockable( True ).TopDockable( False )
194-
.LeftDockable( True ).RightDockable( True ) )
194+
.LeftDockable( True ).RightDockable( True ). Caption('Image') )
195195
self.canvasnb.Bind( wx.lib.agw.aui.EVT_AUINOTEBOOK_PAGE_CHANGED, self.on_active_img)
196196
self.canvasnb.Bind( wx.lib.agw.aui.EVT_AUINOTEBOOK_PAGE_CLOSE, self.on_close_img)
197197

@@ -203,7 +203,7 @@ def init_table(self):
203203
self.tablenbwrap.SetSizer( sizer )
204204
self.tablenbwrap.Layout()
205205

206-
self.auimgr.AddPane( self.tablenbwrap, aui.AuiPaneInfo() .Bottom() .CaptionVisible( True ).PinButton( True ).Dock().Hide()
206+
self.auimgr.AddPane( self.tablenbwrap, aui.AuiPaneInfo() .Center() .CaptionVisible( True ).PinButton( True ).Dock()
207207
.MaximizeButton( True ).Resizable().FloatingSize((800, 600)).BestSize(( 120,120 )). Caption('Table') .
208208
BottomDockable( True ).TopDockable( False ).LeftDockable( True ).RightDockable( True ) )
209209
self.tablenb.Bind( wx.lib.agw.aui.EVT_AUINOTEBOOK_PAGE_CHANGED, self.on_active_table)
@@ -218,9 +218,9 @@ def init_mesh(self):
218218
self.meshnbwrap.Layout()
219219

220220
self.auimgr.AddPane( self.meshnbwrap, aui.AuiPaneInfo() .Bottom() .CaptionVisible( True ).PinButton( True ).Float().Hide()
221-
.MaximizeButton( True ).Resizable().FloatingSize((800, 600)).BestSize(( 120,120 )). Caption('Meshes') .
221+
.MaximizeButton( True ).Resizable().FloatingSize((800, 600)).BestSize(( 120,120 )). Caption('Mesh') .
222222
BottomDockable( True ).TopDockable( False ).LeftDockable( True ).RightDockable( True ) )
223-
self.meshnb.Bind( wx.lib.agw.aui.EVT_AUINOTEBOOK_PAGE_CHANGED, self.on_new_mesh)
223+
self.meshnb.Bind( wx.lib.agw.aui.EVT_AUINOTEBOOK_PAGE_CHANGED, self.on_active_mesh)
224224
self.meshnb.Bind( wx.lib.agw.aui.EVT_AUINOTEBOOK_PAGE_CLOSE, self.on_close_mesh)
225225

226226
def add_task(self, task):
@@ -287,14 +287,14 @@ def on_close_table(self, event):
287287
grid = event.GetEventObject().GetPage(event.GetSelection())
288288
App.close_table(self, grid.table.title)
289289

290-
def on_new_mesh(self, event):
291-
self.add_mesh(self.meshnb.canvas().mesh)
292-
self.add_mesh_win(self.meshnb.canvas())
290+
def on_active_mesh(self, event):
291+
self.active_mesh(self.meshnb.canvas().scene3d.name)
292+
# self.add_mesh_win(self.meshnb.canvas())
293293

294294
def on_close_mesh(self, event):
295-
canvas3d = event.GetEventObject().GetPage(event.GetSelection())
296-
self.remove_mesh(canvas3d.mesh)
297-
self.remove_mesh_win(canvas3d)
295+
# canvas3d = event.GetEventObject().GetPage(event.GetSelection())
296+
self.close_mesh(self.meshnb.canvas().scene3d.name)
297+
# self.remove_mesh_win(canvas3d)
298298

299299
def info(self, value):
300300
lang = ConfigManager.get('language')
@@ -385,10 +385,27 @@ def _show_txt(self, cont, title='ImagePy'):
385385
def show_txt(self, cont, title='ImagePy'):
386386
wx.CallAfter(self._show_txt, cont, title)
387387

388-
def _show_mesh(self, mesh=None, title=None):
388+
def _show_mesh(self, obj=None, title='Scene'):
389+
# show a scence or create a new scene
390+
if isinstance(obj, Scene) or obj is None:
391+
canvas = self.meshnb.add_canvas(obj)
392+
App.show_mesh(self, canvas.scene3d, title)
393+
else:
394+
if self.get_mesh() is None:
395+
canvas = self.meshnb.add_canvas(None)
396+
App.show_mesh(self, canvas.scene3d, 'Scene')
397+
scene = self.get_mesh()
398+
scene.add_obj(title, obj)
399+
info = self.auimgr.GetPane(self.meshnbwrap)
400+
info.Show(True)
401+
self.auimgr.Update()
402+
return
403+
404+
389405
if mesh is None:
406+
scene = self.get_mesh()
390407
canvas = self.meshnb.add_canvas()
391-
canvas.mesh.name = 'Surface'
408+
canvas.scene3d.name = 'Surface'
392409
elif hasattr(mesh, 'vts'):
393410
canvas = self.get_mesh_win()
394411
if canvas is None:
@@ -398,14 +415,14 @@ def _show_mesh(self, mesh=None, title=None):
398415
else:
399416
canvas = self.meshnb.add_canvas()
400417
canvas.set_mesh(mesh)
401-
self.add_mesh(canvas.mesh)
402-
self.add_mesh_win(canvas)
418+
# self.add_mesh(canvas.mesh)
419+
# self.add_mesh_win(canvas)
403420

404421
info = self.auimgr.GetPane(self.meshnbwrap)
405422
info.Show(True)
406423
self.auimgr.Update()
407424

408-
def show_mesh(self, mesh=None, title=None):
425+
def show_mesh(self, mesh=None, title='Scene'):
409426
wx.CallAfter(self._show_mesh, mesh, title)
410427

411428
def show_widget(self, panel, title='Widgets'):

imagepy/data/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
[["language", "English", null], ["roi_style", {"color": [255, 255, 0], "fcolor": [255, 255, 255], "fill": false, "lw": 1, "tcolor": [255, 255, 0], "size": 8}, null], ["recent", ["C:/Users/54631/Desktop/\u6d77\u51b0\u62a5\u4ef7/testmacros.mc", "C:\\Users\\Administrator\\Downloads\\\u7d20\u6750\u2014\u8f66\u5934\\\u6d4b\u8bd5-JK1-\u52ff\u5220\\20170201\\In-20170201151126911-\u6842J73220-\u9ec4-qj-1.jpg", "C:/Users/Administrator/Desktop/imagepy/imagepy/plugins/demoplugin/menus/Demos/Macros Demo/Macros Gaussian Invert.mc", "DEM.mc"], null], ["mark_style", {"color": [0, 255, 0], "fcolor": [255, 255, 255], "fill": false, "lw": 1, "tcolor": [255, 0, 0], "size": 8}, null], ["mea_style", {"color": [0, 0, 255], "fcolor": [255, 255, 255], "fill": false, "lw": 2, "tcolor": [0, 255, 0], "size": 12}, null], ["uistyle", "imagepy", null]]
1+
[["uistyle", "imagepy", null], ["mea_style", {"color": [0, 0, 255], "fcolor": [255, 255, 255], "fill": false, "lw": 2, "tcolor": [0, 255, 0], "size": 12}, null], ["mark_style", {"color": [0, 255, 0], "fcolor": [255, 255, 255], "fill": false, "lw": 1, "tcolor": [255, 0, 0], "size": 8}, null], ["recent", ["C:/Users/54631/Desktop/\u6d77\u51b0\u62a5\u4ef7/testmacros.mc", "C:\\Users\\Administrator\\Downloads\\\u7d20\u6750\u2014\u8f66\u5934\\\u6d4b\u8bd5-JK1-\u52ff\u5220\\20170201\\In-20170201151126911-\u6842J73220-\u9ec4-qj-1.jpg", "C:/Users/Administrator/Desktop/imagepy/imagepy/plugins/demoplugin/menus/Demos/Macros Demo/Macros Gaussian Invert.mc", "DEM.mc"], null], ["roi_style", {"color": [255, 255, 0], "fcolor": [255, 255, 255], "fill": false, "lw": 1, "tcolor": [255, 255, 0], "size": 8}, null], ["language", "English", null]]

imagepy/menus/Kit3D/Network 3D/toolkit3d_plgs.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
import networkx as nx
66
import numpy as np
77
import pandas as pd
8-
from sciapp.object import Surface, MarkText
9-
from sciapp.util import surfutil
8+
from sciapp.object import Mesh, TextSet
9+
from sciapp.util import meshutil
1010
norm = np.linalg.norm
1111

1212
class Skeleton3D(Simple):
@@ -57,19 +57,19 @@ def run(self, ips, imgs, para = None):
5757

5858
rs = [para['r']] * len(balls)
5959
cs = tuple(np.array(para['ncolor'])/255.0)
60-
vts, fs, ns, cs = surfutil.build_balls(balls, rs, cs)
61-
self.app.show_mesh(Surface(vts, fs, ns, cs), 'balls')
62-
63-
vts, fs, pos, h, color = surfutil.build_marks(['ID:%s'%i for i in ids], balls, para['r'], para['r'], (1,1,1))
64-
self.app.show_mesh(MarkText(vts, fs, pos, h, color), 'txt')
60+
vts, fs, cs = meshutil.create_balls(balls, rs, cs)
61+
self.app.show_mesh(Mesh(verts=vts, faces=fs, colors=cs), 'balls')
6562

6663
cs = tuple(np.array(para['lcolor'])/255.0)
67-
vts, fs, ns, cs = surfutil.build_lines(xs, ys, zs, cs)
68-
self.app.show_mesh(Surface(vts, fs, ns, cs, mode='grid'), 'path')
64+
vts, fs, cs = meshutil.create_lines(xs, ys, zs, cs)
65+
self.app.show_mesh(Mesh(verts=vts, faces=fs, colors=cs, mode='grid'), 'path')
6966

7067
cs = tuple(np.array(para['pcolor'])/255.0)
71-
vts, fs, ns, cs = surfutil.build_lines(lxs, lys, lzs, cs)
72-
self.app.show_mesh(Surface(vts, fs, ns, cs, mode='grid'), 'lines')
68+
vts, fs, cs = meshutil.create_lines(lxs, lys, lzs, cs)
69+
self.app.show_mesh(Mesh(verts=vts, faces=fs, colors=cs, mode='grid'), 'lines')
70+
71+
self.app.show_mesh(TextSet(['ID:%s'%i for i in ids], verts=balls, size=para['r']*256, colors=(1,1,1)), 'txt')
72+
7373

7474

7575
class Show3DGraphR(Simple):
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Open Url>{'url': 'http://data.imagepy.org/testdata/dem.jpg'}
2-
2D Surface>{'name': 'dem', 'scale': 1, 'sigma': 1, 'h': 0.3}
1+
moon>None
2+
2D Surface>{'name': 'moon', 'sample': 2, 'sigma': 0.7, 'h': 0.3, 'cm': 'Green_Fire_Blue'}
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
from sciapp.action import Simple
2-
from sciapp.object import Surface, MarkText
3-
from sciapp.util import surfutil
2+
from sciapp.object import Mesh
3+
from sciapp.util import meshutil
44
import numpy as np
55

66
class Plugin(Simple):
77
title = 'RGB Points Cloud'
88
note = ['rgb']
99
para = {'name':'undifine', 'num':100, 'r':1}
1010
view = [(str, 'name', 'Name', ''),
11-
(int, 'num', (10,1024), 0, 'number', 'points'),
11+
(int, 'num', (10,10240), 0, 'number', 'points'),
1212
(float, 'r', (0.1,30), 1, 'radius', '')]
1313

1414
def run(self, ips, imgs, para = None):
1515
num,r = para['num'], para['r']
1616
if ips.roi != None: pts = ips.img[ips.get_msk()]
1717
else: pts = ips.img.reshape((-1,3))
1818
pts = pts[::len(pts)//num]
19-
vts, fs, ns, cs = surfutil.build_balls(pts, np.ones(len(pts))*r, pts/255)
20-
self.app.show_mesh(Surface(vts, fs, ns, cs), para['name'])
19+
vts, fs, cs = meshutil.create_balls(pts, np.ones(len(pts))*r, pts/255)
20+
self.app.show_mesh(Mesh(pts, colors=pts/255), para['name'])
2121
(r1,g1,b1),(r2,g2,b2) = (0,0,0),(1,1,1)
2222
rs = (r1,r2,r2,r1,r1,r1,r1,r1,r1,r2,r2,r1,r2,r2,r2,r2)
2323
gs = (g1,g1,g1,g1,g1,g2,g2,g1,g2,g2,g2,g2,g2,g1,g1,g2)
2424
bs = (b1,b1,b2,b2,b1,b1,b2,b2,b2,b2,b1,b1,b1,b1,b2,b2)
25-
vts, fs, ns, cs = surfutil.build_cube((0,0,0),(255,255,255))
26-
cs = list(zip(rs,gs,bs))
27-
self.app.show_mesh(Surface(vts, fs, ns, cs, mode='grid'), 'cube')
25+
vts, fs, ls = meshutil.create_cube((0,0,0),(255,255,255))
26+
cs = np.array(list(zip(rs,gs,bs)))
27+
self.app.show_mesh(Mesh(vts, ls, colors=vts/255, mode='grid'), 'cube')
2828

2929
if __name__ == '__main__':
3030
pass
Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from sciapp.action import Free
2-
from sciapp.object import Surface, MarkText
3-
from sciapp.util import surfutil
2+
from sciapp.object import Mesh
3+
from sciapp.util import meshutil
44
import numpy as np
55

66
class Decoration(Free):
@@ -13,19 +13,15 @@ def run(self, para=None):
1313
r = np.sin(m0*phi)**m1 + np.cos(m2*phi)**m3 + np.sin(m4*theta)**m5 + np.cos(m6*theta)**m7
1414
x = r*np.sin(phi)*np.cos(theta)
1515
y = r*np.cos(phi)
16-
z = r*np.sin(phi)*np.sin(theta)
17-
vts, fs, ns, cs = surfutil.build_mesh(x, y, z)
18-
cs[:] = surfutil.auto_lookup(vts[:,2], surfutil.linear_color('jet'))/255
19-
self.app.show_mesh(Surface(vts, fs, ns, cs), 'decoration')
16+
z = r*np.sin(phi)*np.sin(theta)
17+
vts, fs = meshutil.create_grid_mesh(x, y, z)
18+
mesh = Mesh(vts, fs.astype(np.uint32), vts[:,2], mode='grid', cmap='jet')
19+
self.app.show_mesh(mesh, 'decoration')
2020

2121
class Lines(Free):
2222
title = 'Lines Demo'
2323

2424
def run(self, para=None):
25-
vts = np.array([(0,0,0),(1,1,0),(2,1,0),(1,0,0)], dtype=np.float32)
26-
fs = np.array([(0,1,2),(1,2,3)], dtype=np.uint32)
27-
ns = np.ones((4,3), dtype=np.float32)
28-
2925
n_mer, n_long = 6, 11
3026
pi = np.pi
3127
dphi = pi / 1000.0
@@ -35,20 +31,21 @@ def run(self, para=None):
3531
y = np.sin(mu) * (1 + np.cos(n_long * mu / n_mer) * 0.5)
3632
z = np.sin(n_long * mu / n_mer) * 0.5
3733

38-
vts, fs, ns, cs = surfutil.build_line(x, y, z, (1, 0, 0))
39-
cs[:] = surfutil.auto_lookup(vts[:,2], surfutil.linear_color('jet'))/255
40-
self.app.show_mesh(Surface(vts, fs, ns, cs, mode='grid'), 'line')
34+
vts = np.array([x, y, z]).T.astype(np.float32)
35+
fs = np.arange(len(vts), dtype=np.uint32)
36+
fs = np.array([fs[:-1], fs[1:]]).T
37+
mesh = Mesh(vts, fs, vts[:,2], cmap='jet', mode='grid')
38+
self.app.show_mesh(mesh, 'line')
4139

4240
class Balls(Free):
4341
title = 'Random Balls Demo'
4442

4543
def run(self, para=None):
4644
os = np.random.rand(30).reshape((-1,3))
47-
rs = np.random.rand(10)/5
48-
cs = (np.random.rand(10)*255).astype(np.uint8)
49-
cs = surfutil.linear_color('jet')[cs]/255
50-
51-
vts, fs, ns, cs = surfutil.build_balls(os, rs, cs)
52-
self.app.show_mesh(Surface(vts, fs, ns, cs), 'balls')
45+
rs = np.random.rand(10)/7+0.05
46+
cs = np.random.rand(10)
47+
vts_b, fs_b, cs_b = meshutil.create_balls(os, rs, cs)
48+
mesh = Mesh(verts=vts_b, faces=fs_b, colors=cs_b, cmap='jet')
49+
self.app.show_mesh(mesh, 'balls')
5350

5451
plgs = [Lines, Balls, Decoration]

imagepy/menus/Kit3D/Viewer 3D/surface_plgs.py

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,34 @@
66
"""
77
from sciapp.action import Simple, Filter, Free
88
from scipy.ndimage.filters import gaussian_filter
9-
from sciapp.object import Surface, MarkText
10-
from sciapp.util import surfutil
9+
from sciapp.object import Mesh, Scene, Surface2d, Surface3d, Volume3d
10+
from imagepy.app import ColorManager
11+
from sciapp.util import meshutil
1112

1213
class Show(Free):
1314
title = 'Show Viewer 3D'
15+
para = {'name':'Scene', 'bg':(0,0,0)}
16+
view = [(str, 'name', 'name', ''),
17+
('color', 'bg', 'background', 'color')]
18+
1419
def run(self, para):
15-
self.app.show_mesh()
20+
scene = Scene(bg_color=[i/255 for i in para['bg']])
21+
self.app.show_mesh(scene, para['name'])
1622

1723
class Surface2D(Simple):
1824
title = '2D Surface'
1925
note = ['8-bit', '16-bit', 'float']
20-
para = {'name':'undifine', 'scale':2, 'sigma':2,'h':1}
26+
para = {'name':'undifine', 'sample':2, 'sigma':2,'h':0.3, 'cm':'gray'}
2127
view = [(str, 'name', 'Name', ''),
22-
(int, 'scale', (1,5), 0, 'down scale', 'pix'),
28+
(int, 'sample', (1,10), 0, 'down sample', 'pix'),
2329
(int, 'sigma', (0,30), 0, 'sigma', ''),
24-
(float, 'h', (0.1,10), 1, 'scale z', '')]
30+
(float, 'h', (0.1,10), 1, 'scale z', ''),
31+
('cmap', 'cm', 'color map')]
2532

2633
def run(self, ips, imgs, para = None):
27-
ds, sigma = para['scale'], para['sigma']
28-
vts, fs, ns, cs = surfutil.build_surf2d(ips.img, ds=ds, sigma=para['sigma'], k=para['h'])
29-
self.app.show_mesh(Surface(vts, fs, ns, cs), para['name'])
34+
ds, sigma, cm = para['sample'], para['sigma'], ColorManager.get(para['cm'])
35+
mesh = Surface2d(ips.img, sample=ds, sigma=sigma, k=para['h'], cmap=cm)
36+
self.app.show_mesh(mesh, para['name'])
3037

3138
class Surface3D(Simple):
3239
modal = False
@@ -54,8 +61,8 @@ def cancel(self, ips):
5461
def run(self, ips, imgs, para = None):
5562
ips.lut = self.buflut
5663
cs = tuple([int(i/255.0) for i in para['color']])
57-
vts, fs, ns, cs = surfutil.build_surf3d(ips.imgs, para['ds'], para['thr'], para['step'], cs)
58-
self.app.show_mesh(Surface(vts, fs, ns, cs), para['name'])
64+
surf3d = Surface3d(imgs=ips.imgs, level=para['thr'], sample=para['ds'], step=para['step'], colors=cs)
65+
self.app.show_mesh(surf3d, para['name'])
5966

6067
class ImageCube(Simple):
6168
modal = False
@@ -76,4 +83,21 @@ def run(self, ips, imgs, para = None):
7683
vts, fs, ns, cs = surfutil.build_img_box(imgs, para['color'])
7784
self.app.show_mesh(Surface(vts, fs, ns, cs, mode='grid'), para['name']+'-box')
7885

79-
plgs = [Show, Surface2D, Surface3D, ImageCube]
86+
class Volume3D(Simple):
87+
modal = False
88+
title = '3D Volume'
89+
note = ['8-bit', 'stack3d']
90+
para = {'name':'undifine', 'step':1, 'cm':'gray', 'cube':True}
91+
view = [(str, 'name', 'Name', ''),
92+
(int, 'step', (1,10), 0, 'march step', 'pix'),
93+
('cmap', 'cm', 'color map'),
94+
(bool, 'cube', 'draw outline cube')]
95+
96+
def run(self, ips, imgs, para = None):
97+
cmap = ColorManager.get(para['cm'])
98+
self.app.show_mesh(Volume3d(imgs, step=para['step'], cmap=cmap), para['name'])
99+
if para['cube']:
100+
vts, fs = meshutil.create_bound((0,0,0), imgs.shape)
101+
self.app.show_mesh(Mesh(verts=vts, faces=fs, colors=(1,1,1), mode='grid'), 'box')
102+
103+
plgs = [Show, Surface2D, Surface3D, ImageCube, Volume3D]

0 commit comments

Comments
 (0)