-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
364 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,5 +4,7 @@ | |
"path": "." | ||
} | ||
], | ||
"settings": {} | ||
"settings": { | ||
"python.pythonPath": "/home/yu/anaconda3/bin/python3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/usr/bin/env python3 | ||
|
||
from traitsui.api import Item, RangeEditor, View | ||
from traits.api import HasTraits, Str, Range, Enum, Int | ||
|
||
from traits.api import * | ||
from traitsui.api import * | ||
from tvtk.pyface.scene_editor import SceneEditor | ||
from mayavi.tools.mlab_scene_model import MlabSceneModel | ||
from mayavi.core.ui.mayavi_scene import MayaviScene | ||
|
||
|
||
|
||
|
||
view1 = View( | ||
Item(name='scene', | ||
editor=SceneEditor(scene_class=MayaviScene), # 设置mayavi的编辑器 | ||
resizable=True, | ||
height=250, | ||
width=400 | ||
), | ||
Item(name = 'department', label=u"部门", tooltip=u"在哪个部门干活"), | ||
Item(name = 'last_name', label=u"姓"), | ||
Item(name = 'first_name', label=u"名"), resizable = True, | ||
width = 400, | ||
height = 150) | ||
|
||
class SimpleEmployee(HasTraits): | ||
first_name = Str | ||
last_name = Str | ||
department = Str | ||
employee_number = Str | ||
salary = Int | ||
plotbutton = Button(u"绘图") | ||
scene = Instance(MlabSceneModel, ()) # mayavi场景 | ||
|
||
sam = SimpleEmployee() | ||
sam.configure_traits(view=view1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import numpy as npy | ||
from mayavi import mlab | ||
from mayavi.core.ui.mayavi_scene import MayaviScene | ||
from mayavi.tools.mlab_scene_model import MlabSceneModel | ||
from traits.api import * | ||
from traits.api import Enum, HasTraits, Int, Range, Str | ||
from traitsui.api import * | ||
from traitsui.api import Item, RangeEditor, View | ||
from traitsui.menu import * | ||
from tvtk.pyface.scene_editor import SceneEditor | ||
|
||
from stl2vol import * | ||
|
||
|
||
class DogPlot(HasTraits): | ||
SaveDog = Button(u"绘图测试") | ||
PDog = Button("绘图") | ||
ImportDog = Button("导入") | ||
DogClf = Button("清除绘图") | ||
scene = Instance(MlabSceneModel, ()) # mayavi场景 | ||
DogsName = File('cat3.stl') | ||
DogNumber = Int(50) | ||
DogOutP = File('out') | ||
DogOutC = File('outc.c') | ||
DogInter = Float('1.0') | ||
DogOutShape = Str | ||
DogOutput = Button("导出") | ||
DogCal = Button("计算") | ||
# DogButtons=OKButton | ||
D0 = Float(1) | ||
D0s = Bool | ||
D1 = Float(2) | ||
D1s = Bool | ||
D2 = Float(3) | ||
D2s = Bool | ||
D3 = Float(4) | ||
D3s =Bool | ||
D4 = Float(5) | ||
D4s = Bool | ||
D5 = Float(6) | ||
D5s = Bool | ||
D6 = Float(7) | ||
D6s = Bool | ||
D7 = Float(8) | ||
D7s =Bool | ||
D8 = Float(9) | ||
D8s = Bool | ||
gd=[Item(name='D0'),Item(name='D0s'),Item(name='D1'),Item(name='D1s'),Item(name='D2'),Item(name='D2s'),Item(name='D3'),Item(name='D3s'),Item(name='D4'),Item(name='D4s'),Item(name='D5'),Item(name='D5s'),Item(name='D6'),Item(name='D6s'),Item(name='D7'),Item(name='D7s'),Item(name='D8'),Item(name='D8s')] | ||
|
||
|
||
|
||
out=[Item(name='DogOutP',label='npy输出'),Item(name='DogOutC',label='C输出文件名'),Item(name='DogInter',label='插值系数'),Item(name='DogCal',label='计算'),Item(name='DogOutShape',label='输出规模',style='readonly'),Item(name='DogOutput',label='导出')] | ||
view = View( | ||
HSplit(VGroup( | ||
Item(name='scene', | ||
editor=SceneEditor(scene_class=MayaviScene), # 设置mayavi的编辑器 | ||
resizable=True, | ||
height=600, | ||
width=800 | ||
), | ||
'SaveDog','PDog','DogClf', | ||
show_labels=False | ||
), | ||
VSplit(VGroup(Item(name='DogsName',label='文件名'),Item(name='DogNumber',label='解析度'),Item(name='ImportDog',label="导入STL模型")),VGroup(out),VGroup(gd)), | ||
|
||
),resizable = True,title=u"TraitsUI",buttons=OKCancelButtons) | ||
def _SaveDog_fired(self): | ||
self.plot() | ||
def _PDog_fired(self): | ||
self.lu.DogPlot() | ||
def _ImportDog_fired(self): | ||
mlab.clf() | ||
self.lu=StlDog(self.DogsName,self.DogNumber) | ||
self.DogOutShape=str(self.lu.OutDog.shape) | ||
pass | ||
def _DogClf_fired(self): | ||
mlab.clf() | ||
# self.D0=self.D0+1 | ||
pass | ||
def plot(self): | ||
mlab.clf() | ||
g = self.scene.mlab.test_mesh() | ||
# CloseAction() | ||
def _DogCal_fired(self, parameter_list): | ||
self.Doga1=npy.zeros_like(self.lu.OutDog) | ||
|
||
pass | ||
def Dogcov(self,a,b): | ||
self.nul=[self.D0,self.D1,self.D2,self.D3,self.D4,self.D5,self.D6,self.D7,self.D8] | ||
for idog in range(0,9): | ||
if b==idog: | ||
self.a=self.nul[idog] | ||
pass | ||
pass | ||
|
||
|
||
app = DogPlot(resizable=True) | ||
app.configure_traits() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import matplotlib | ||
matplotlib.use('Agg') | ||
from matplotlib import pyplot as plt | ||
import numpy as np | ||
import imageio | ||
|
||
End=20 | ||
outfilename = "test.gif" | ||
frames=[] | ||
|
||
for name in range(0,End+1): | ||
dogname='./res/p0_'+str(name)+'.npy' | ||
a=np.load(dogname) | ||
plt.imshow(a) | ||
plt.colorbar() | ||
plt.savefig(dogname+'.jpg') | ||
plt.close() | ||
|
||
frames.append(imageio.imread(dogname+'.jpg')) | ||
imageio.mimsave(outfilename, frames,'GIF', duration=0.5) | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,197 @@ | ||
#!/usr/bin/env python3 | ||
import sys | ||
sys.setrecursionlimit(100000000) | ||
import numpy as np | ||
from mesh_vox import read_and_reshape_stl, voxelize | ||
import math | ||
from mayavi import mlab | ||
|
||
def stltrdog(stlpath,resolution): | ||
|
||
|
||
|
||
mesh, bounding_box = read_and_reshape_stl(stlpath, resolution) | ||
|
||
voxels, bounding_box = voxelize(mesh, bounding_box) | ||
resdog=voxels.transpose((2,1,0)) | ||
return resdog | ||
pass | ||
|
||
def showdog(sdog): | ||
pug=np.zeros_like(sdog,dtype='float32') | ||
for idog in range(0,np.shape(sdog)[0]): | ||
for jdog in range(0,np.shape(sdog)[1]): | ||
for kdog in range(0,np.shape(sdog)[2]): | ||
if sdog[idog,jdog,kdog]==True: | ||
# print("OK") | ||
pug[idog,jdog,kdog]=1 | ||
pass | ||
else: | ||
pug[idog,jdog,kdog]=0 | ||
pass | ||
# mlab.imshow(pug[:,:,20]) | ||
# | ||
|
||
|
||
fileddog=mlab.pipeline.scalar_field(pug) | ||
mlab.pipeline.volume(fileddog,vmin=0,vmax=3) | ||
mlab.colorbar() | ||
mlab.show() | ||
pass | ||
|
||
def devidedog(sdog): | ||
pug=np.zeros_like(sdog,dtype='float32') | ||
a=np.where(sdog==True) | ||
numdog=1 | ||
while np.where(sdog==True)[0].shape[0]!=0: | ||
cut=[np.where(sdog==True)[0][0],np.where(sdog==True)[1][0],np.where(sdog==True)[2][0]] | ||
diguidog2(sdog,pug,cut[0],cut[1],cut[2],numdog) | ||
numdog=numdog+1 | ||
# print(numdog) | ||
pass | ||
return pug,numdog | ||
pass | ||
|
||
def diguidog(acat,bcat,idog,jdog,kdog,intdog): | ||
if idog>=1 and idog<=(acat.shape[0]-2) and jdog>=1 and jdog<=(acat.shape[1]-2) and kdog>=1 and kdog<=(acat.shape[2]-2): | ||
if acat[idog,jdog,kdog]==True: | ||
bcat[idog,jdog,kdog]=intdog | ||
acat[idog,jdog,kdog]=False | ||
# print(idog,jdog,kdog) | ||
if acat[idog+1,jdog,kdog]==True: | ||
diguidog(acat,bcat,idog+1,jdog,kdog,intdog) | ||
if acat[idog-1,jdog,kdog]==True: | ||
diguidog(acat,bcat,idog-1,jdog,kdog,intdog) | ||
if acat[idog,jdog+1,kdog]==True: | ||
diguidog(acat,bcat,idog,jdog+1,kdog,intdog) | ||
if acat[idog,jdog-1,kdog]==True: | ||
diguidog(acat,bcat,idog,jdog-1,kdog,intdog) | ||
if acat[idog,jdog,kdog+1]==True: | ||
diguidog(acat,bcat,idog,jdog,kdog+1,intdog) | ||
if acat[idog,jdog,kdog-1]==True: | ||
diguidog(acat,bcat,idog,jdog,kdog-1,intdog) | ||
pass | ||
else: | ||
# print('end') | ||
pass | ||
else: | ||
# print("out") | ||
pass | ||
return 0 | ||
|
||
pass | ||
|
||
|
||
def diguidog2(acat,bcat,idog,jdog,kdog,intdog): | ||
|
||
pflodog=acat[idog,jdog,kdog] | ||
if pflodog==True: | ||
# flagdog=6 | ||
pass | ||
else: | ||
# flagdog=0 | ||
pass | ||
hu=[[idog,jdog,kdog]] | ||
du=[] | ||
num=1 | ||
while hu!=[]: | ||
# flagdog=6 | ||
for ludog in hu: | ||
bcat[ludog[0],ludog[1],ludog[2]]=intdog | ||
acat[ludog[0],ludog[1],ludog[2]]=False | ||
if acat[ludog[0]+1,ludog[1],ludog[2]]==True and ludog[0]+1<=(acat.shape[0]-2): | ||
if [ludog[0]+1,ludog[1],ludog[2]] in du: | ||
# print('重复') | ||
pass | ||
else: | ||
du.append([ludog[0]+1,ludog[1],ludog[2]]) | ||
pass | ||
pass | ||
else: | ||
# flagdog=flagdog-1 | ||
pass | ||
if acat[ludog[0],ludog[1]+1,ludog[2]]==True and ludog[1]+1<=(acat.shape[1]-2): | ||
if [ludog[0],ludog[1]+1,ludog[2]] in du: | ||
pass | ||
else: | ||
du.append([ludog[0],ludog[1]+1,ludog[2]]) | ||
pass | ||
|
||
pass | ||
else: | ||
# flagdog=flagdog-1 | ||
pass | ||
|
||
if acat[ludog[0],ludog[1],ludog[2]+1]==True and (ludog[2]+1)<=(acat.shape[2]-2) and not ([ludog[0],ludog[1],ludog[2]+1] in du): | ||
du.append([ludog[0],ludog[1],ludog[2]+1]) | ||
pass | ||
else: | ||
# flagdog=flagdog-1 | ||
pass | ||
|
||
|
||
if acat[ludog[0]-1,ludog[1],ludog[2]]==True and ludog[0]-1>=(0)and not([ludog[0]-1,ludog[1],ludog[2]] in du): | ||
du.append([ludog[0]-1,ludog[1],ludog[2]] ) | ||
pass | ||
else: | ||
# flagdog=flagdog-1 | ||
pass | ||
|
||
|
||
if acat[ludog[0],ludog[1]-1,ludog[2]]==True and ludog[1]-1>=(0) and not([ludog[0],ludog[1]-1,ludog[2]] in du): | ||
du.append([ludog[0],ludog[1]-1,ludog[2]] ) | ||
pass | ||
else: | ||
# flagdog=flagdog-1 | ||
pass | ||
|
||
if acat[ludog[0],ludog[1],ludog[2]-1]==True and ludog[2]-1>=(0) and not([ludog[0],ludog[1],ludog[2]-1] in du): | ||
du.append([ludog[0],ludog[1],ludog[2]-1]) | ||
pass | ||
else: | ||
# flagdog=flagdog-1 | ||
pass | ||
pass | ||
hu=du | ||
du=[] | ||
print(hu.__len__()) | ||
num=num+1 | ||
pass | ||
|
||
|
||
|
||
pass | ||
|
||
|
||
|
||
pass | ||
|
||
def puttdog(sfdog): | ||
mlab.clf() | ||
cutdog,numpug=devidedog(sfdog) | ||
fileddog=mlab.pipeline.scalar_field(cutdog) | ||
mlab.pipeline.volume(fileddog,vmin=0,vmax=numpug-1) | ||
mlab.colorbar() | ||
# mlab.show() | ||
|
||
|
||
pass | ||
|
||
class StlDog(object): | ||
def __init__(self,Dogname,rse): | ||
self.Dogfile=Dogname | ||
self.DogRes=rse | ||
self.OutDog=stltrdog(self.Dogfile,self.DogRes) | ||
self.cutdog,self.numpug=devidedog(self.OutDog) | ||
|
||
def DogPlot(self): | ||
# puttdog(self.OutDog) | ||
mlab.clf() | ||
fileddog=mlab.pipeline.scalar_field(self.cutdog) | ||
mlab.pipeline.volume(fileddog,vmin=0,vmax=self.numpug-1) | ||
mlab.colorbar() | ||
pass | ||
pass | ||
|
||
# dog=stltrdog('cat3.stl',800) | ||
# puttdog(dog) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/bash | ||
cp ./test/* ./ | ||
python3 cuf.py -t 2dm test.ini | ||
python3 plot.py | ||
display test.gif |