performance updates

pull/258/head
Joe Marshall 2024-01-31 15:00:20 +00:00
rodzic dd220598ad
commit b08e7e2348
10 zmienionych plików z 5703 dodań i 6326 usunięć

Wyświetl plik

@ -191,6 +191,17 @@ class camPathChunk:
return dist2d(pos, self._points[0])
def xyDistanceWithin(self,other,cutoff):
if self.poly is None:
self.update_poly()
if other.poly is None:
other.update_poly()
if not self.poly.is_empty and not other.poly.is_empty:
return self.poly.dwithin(other.poly,cutoff)
else:
return _internalXyDistanceTo(self._points,other._points,cutoff)<cutoff
# if cutoff is set, then the first distance < cutoff is returned
def xyDistanceTo(self,other,cutoff=0):
if self.poly is None:
@ -828,10 +839,7 @@ def parentChildDist(parents, children, o, distance=None):
for parent in parents:
isrelation = False
if parent != child:
d = parent.xyDistanceTo(child,cutoff=dlim)
if d< dlim:
isrelation = True
if isrelation:
if parent.xyDistanceWithin(child,cutoff=dlim):
parent.children.append(child)
child.parents.append(parent)

Wyświetl plik

@ -549,11 +549,7 @@ async def getPath(context, operation): # should do all path calculations.
pr.enable()
await getPath3axis(context, operation)
pr.disable()
s = io.StringIO()
sortby = pstats.SortKey.CALLS
ps = pstats.Stats(pr, stream=s).sort_stats(sortby)
ps.print_stats()
print(s.getvalue())
pr.dump_stats(time.strftime("blendercam_%Y%m%d_%H%M.prof"))
else:
await getPath3axis(context, operation)

Wyświetl plik

@ -19,10 +19,11 @@
#
# ***** END GPL LICENCE BLOCK *****
import numpy
import math
import time
import numpy
import os
import random
import time
import curve_simplify
import mathutils
@ -1027,6 +1028,22 @@ def getResolution(o):
# that's because blender doesn't allow accessing pixels in render :(
def _backup_render_settings(pairs):
properties=[]
for owner,struct_name in pairs:
obj = getattr(owner,struct_name)
obj_dict={}
for k in dir(obj):
if not k.startswith("_"):
obj_dict[k]=getattr(obj,k)
properties.append(obj_dict)
def _restore_render_settings(pairs,properties):
for (owner,struct_name),obj_dict in zip(pairs,properties):
obj = getattr(owner,struct_name)
for k,v in obj_dict.items():
setattr(obj,k,v)
def renderSampleImage(o):
t = time.time()
simple.progress('getting zbuffer')
@ -1066,44 +1083,42 @@ def renderSampleImage(o):
r = s.render
r.resolution_x = resx
r.resolution_y = resy
if bpy.app.background:
# in CI we use cycles because it
# works without opengl support
r.engine = 'CYCLES'
cycles_settings=s.cycles.items()
s.cycles.samples = 1
bpy.context.view_layer.samples=1
vl_settings=bpy.context.view_layer.cycles
vl_settings.use_denoising=False
else:
r.engine = 'BLENDER_EEVEE'
# use cycles for everything because
# it renders okay on github actions
r.engine = 'CYCLES'
s.cycles.samples = 1
bpy.context.view_layer.samples=1
vl_settings=bpy.context.view_layer.cycles
vl_settings.use_denoising=False
n.links.clear()
n.nodes.clear()
n1 = n.nodes.new('CompositorNodeRLayers')
s.view_layers[n1.layer].use_pass_z=True
n2 = n.nodes.new('CompositorNodeViewer')
n3 = n.nodes.new('CompositorNodeComposite')
n.links.new(n1.outputs[n1.outputs.find('Depth')], n2.inputs[n2.inputs.find('Image')])
n.links.new(n1.outputs[n1.outputs.find('Depth')], n3.inputs[n3.inputs.find('Image')])
n.nodes.active = n2
node_in = n.nodes.new('CompositorNodeRLayers')
s.view_layers[node_in.layer].use_pass_mist=True
# s.view_layers[node_in.layer].use_pass_z=True
mist_settings=s.world.mist_settings
s.world.mist_settings.depth=10.0
s.world.mist_settings.start=0
s.world.mist_settings.falloff="LINEAR"
s.world.mist_settings.height=0
s.world.mist_settings.intensity=0
node_out = n.nodes.new("CompositorNodeOutputFile")
node_out.base_path = os.path.dirname(iname)
node_out.format.file_format = 'OPEN_EXR'
node_out.format.color_mode = 'RGB'
node_out.format.color_depth = '32'
node_out.file_slots.new(os.path.basename(iname))
print(node_out,node_out.inputs)
n.links.new(node_in.outputs[node_in.outputs.find('Mist')], node_out.inputs[-1])
###################
# resize operation image
o.offset_image= numpy.full(shape=(resx,resy),fill_value=-10,dtype=numpy.double)
# various settings for faster render
r.resolution_percentage = 100
ff = r.image_settings.file_format
cm = r.image_settings.color_mode
r.image_settings.file_format = 'OPEN_EXR'
r.image_settings.color_mode = 'BW'
r.image_settings.color_depth = '32'
# camera settings
camera = s.camera
if camera is None:
@ -1116,6 +1131,7 @@ def renderSampleImage(o):
camera.data.ortho_scale = max(resx * o.optimisation.pixsize, resy * o.optimisation.pixsize)
camera.location = (o.min.x + sx / 2, o.min.y + sy / 2, 1)
camera.rotation_euler = (0, 0, 0)
camera.data.clip_end = 10.0
# if not o.render_all:#removed in 0.3
h = []
@ -1129,26 +1145,23 @@ def renderSampleImage(o):
bpy.ops.render.render()
n.nodes.remove(node_out)
n.nodes.remove(node_in)
os.replace(iname+"0002.exr",iname)
# if not o.render_all:
for id, obs in enumerate(s.objects):
obs.hide_render = h[id]
imgs = bpy.data.images
for isearch in imgs:
if len(isearch.name) >= 13:
if isearch.name[:13] == 'Render Result':
i = isearch
# progress(iname)
i.save_render(iname)
r.image_settings.file_format = ff
r.image_settings.color_mode = cm
i = bpy.data.images.load(iname)
bpy.context.scene.render.engine = 'BLENDERCAM_RENDER'
a = imagetonumpy(i)
a = 1.0 - a
a = 10.0 * a
a= 1.0 - a
o.zbuffer_image = a
o.update_zbufferimage_tag = False

Wyświetl plik

@ -1,4 +1,4 @@
(Created with grbl post processor 2024/01/26 22:12)
(Created with grbl post processor 2024/01/31 14:46)
G21
(G-code generated with BlenderCAM and NC library)
G17G90
@ -376,7 +376,7 @@ X-20Y65
Y-64.999
X-18Y-65.999
Y65
Y66Z-6.899
Y66Z-6.9
G0Z2
X-16
G1Z-6.912F500
@ -427,7 +427,7 @@ G1Z-6.912F500
Y-65.999F1000
X18
Y65
Y66Z-6.899
Y66Z-6.9
G0Z2
X20Y65
G1Z-6.912F500

Wyświetl plik

@ -1,4 +1,4 @@
(Created with grbl post processor 2024/01/26 22:14)
(Created with grbl post processor 2024/01/31 14:47)
G21
(G-code generated with BlenderCAM and NC library)
G17G90
@ -12076,8 +12076,8 @@ G1Z-6.9F500
Y26.499F1000
G0Z10
X-60Y-33
G1Z-6.858F500
Y-32.616Z-6.9F1000
G1Z-6.859F500
Y-32.618Z-6.9F1000
Y32.999
G0Z10
X-57Y-37.5
@ -12101,8 +12101,8 @@ G1Z-6.9F500
Y51.499F1000
G0Z10
X-42Y-54
G1Z-6.855F500
Y-53.61Z-6.9F1000
G1Z-6.856F500
Y-53.612Z-6.9F1000
Y53.999
G0Z10
X-39Y-56
@ -12115,12 +12115,12 @@ Y57.999F1000
G0Z10
X-33Y-60
G1Z-6.855F500
Y-59.608Z-6.9F1000
Y-59.61Z-6.9F1000
Y59.999
G0Z10
X-30Y-61.5
G1Z-6.854F500
Y-61.108Z-6.9F1000
G1Z-6.855F500
Y-61.11Z-6.9F1000
Y61.499
G0Z10
X-27Y-62.5
@ -12137,7 +12137,7 @@ Y64.999F1000
G0Z10
X-18Y-66
G1Z-6.854F500
Y-65.607Z-6.9F1000
Y-65.609Z-6.9F1000
Y65.999
G0Z10
X-15Y-66.5
@ -12157,18 +12157,18 @@ G1Z-6.9F500
Y67.999F1000
G0Z10
X-3Y-68.5
G1Z-6.853F500
Y-68.106Z-6.9F1000
G1Z-6.854F500
Y-68.108Z-6.9F1000
Y68.499
G0Z10
X0Y-68.5
G1Z-6.853F500
Y-68.106Z-6.9F1000
G1Z-6.854F500
Y-68.108Z-6.9F1000
Y68.499
G0Z10
X3Y-68.5
G1Z-6.853F500
Y-68.106Z-6.9F1000
G1Z-6.854F500
Y-68.108Z-6.9F1000
Y68.499
G0Z10
X6Y-68
@ -12189,7 +12189,7 @@ Y66.499F1000
G0Z10
X18Y-66
G1Z-6.854F500
Y-65.606Z-6.9F1000
Y-65.609Z-6.9F1000
Y65.999
G0Z10
X21Y-65
@ -12205,13 +12205,13 @@ G1Z-6.9F500
Y62.499F1000
G0Z10
X30Y-61.5
G1Z-6.854F500
Y-61.108Z-6.9F1000
G1Z-6.855F500
Y-61.11Z-6.9F1000
Y61.499
G0Z10
X33Y-60
G1Z-6.854F500
Y-59.606Z-6.9F1000
Y-59.608Z-6.9F1000
Y59.999
G0Z10
X36Y-58
@ -12223,8 +12223,8 @@ G1Z-6.9F500
Y55.999F1000
G0Z10
X42Y-54
G1Z-6.855F500
Y-53.61Z-6.9F1000
G1Z-6.856F500
Y-53.612Z-6.9F1000
Y53.999
G0Z10
X45Y-51.5
@ -12249,7 +12249,7 @@ Y37.499F1000
G0Z10
X60Y-33
G1Z-6.857F500
Y-32.613Z-6.9F1000
Y-32.615Z-6.9F1000
Y32.999
G0Z10
X63Y-26.5
@ -12268,7 +12268,7 @@ X-63Y-26.5
G1Z-6.912F500
Y26.499F1000
G0Z10
X-60Y-32.616
X-60Y-32.618
G1Z-6.9F500
Y-32.5Z-6.912F1000
Y32.999
@ -12293,7 +12293,7 @@ X-45Y-51.5
G1Z-6.912F500
Y51.499F1000
G0Z10
X-42Y-53.61
X-42Y-53.612
G1Z-6.9F500
Y-53.5Z-6.912F1000
Y53.999
@ -12306,12 +12306,12 @@ X-36Y-58
G1Z-6.912F500
Y57.999F1000
G0Z10
X-33Y-59.608
X-33Y-59.61
G1Z-6.9F500
Y-59.5Z-6.912F1000
Y59.999
G0Z10
X-30Y-61.108
X-30Y-61.11
G1Z-6.9F500
Y-61Z-6.912F1000
Y61.499
@ -12328,7 +12328,7 @@ X-21Y-65
G1Z-6.912F500
Y64.999F1000
G0Z10
X-18Y-65.607
X-18Y-65.609
G1Z-6.9F500
Y-65.5Z-6.912F1000
Y65.999
@ -12349,17 +12349,17 @@ X-6Y-68
G1Z-6.912F500
Y67.999F1000
G0Z10
X-3Y-68.106
X-3Y-68.108
G1Z-6.9F500
Y-68Z-6.912F1000
Y68.499
G0Z10
X0Y-68.106
X0Y-68.108
G1Z-6.9F500
Y-68Z-6.912F1000
Y68.499
G0Z10
X3Y-68.106
X3Y-68.108
G1Z-6.9F500
Y-68Z-6.912F1000
Y68.499
@ -12380,7 +12380,7 @@ X15Y-66.5
G1Z-6.912F500
Y66.499F1000
G0Z10
X18Y-65.606
X18Y-65.609
G1Z-6.9F500
Y-65.5Z-6.912F1000
Y65.999
@ -12397,12 +12397,12 @@ X27Y-62.5
G1Z-6.912F500
Y62.499F1000
G0Z10
X30Y-61.108
X30Y-61.11
G1Z-6.9F500
Y-61Z-6.912F1000
Y61.499
G0Z10
X33Y-59.606
X33Y-59.608
G1Z-6.9F500
Y-59.5Z-6.912F1000
Y59.499
@ -12416,7 +12416,7 @@ X39Y-56
G1Z-6.912F500
Y55.999F1000
G0Z10
X42Y-53.61
X42Y-53.612
G1Z-6.9F500
Y-53.5Z-6.912F1000
Y53.999
@ -12443,7 +12443,7 @@ X57Y-37.5
G1Z-6.912F500
Y37.499F1000
G0Z10
X60Y-32.613
X60Y-32.615
G1Z-6.9F500
Y-32.5Z-6.912F1000
Y32.499

Wyświetl plik

@ -1,4 +1,4 @@
(Created with grbl post processor 2024/01/26 22:14)
(Created with grbl post processor 2024/01/31 14:47)
G21
(G-code generated with BlenderCAM and NC library)
G17G90
@ -9818,7 +9818,7 @@ X-63.228Y-26.188
X-63.038Y-26.651
X-62.845Y-27.112
X-62.71Y-27.429
X-62.649Y-27.572Z-4.459
X-62.649Y-27.572Z-4.46
X-62.558Y-27.78Z-5.1F500
X-62.449Y-28.03F1000
X-62.358Y-28.233
@ -9834,7 +9834,7 @@ X-61.252Y-30.601
X-61.179Y-30.748Z-4.212
X-60.956Y-31.196Z-3.124
X-60.73Y-31.642Z-4.801F500
X-60.696Y-31.707Z-5.1
X-60.697Y-31.707Z-5.1
X-60.5Y-32.086F1000
X-60.268Y-32.528
X-60.144Y-32.759
@ -9846,7 +9846,7 @@ X-59.056Y-34.715Z-3.04F500
X-58.804Y-35.147Z-3.493
X-58.548Y-35.577Z-3.529F1000
X-58.29Y-36.005Z-0.607
X-58.029Y-36.431Z-3.328F500
X-58.029Y-36.431Z-3.329F500
X-57.764Y-36.856Z-1.063F1000
X-57.497Y-37.278Z-1.622F500
G0Z10
@ -9860,14 +9860,14 @@ G1Z-0.868F500
X-55.247Y-40.585Z-0.529F1000
X-54.952Y-40.989Z-0.346
X-54.655Y-41.391Z-0.273
X-54.354Y-41.79Z-0.288
X-54.354Y-41.79Z-0.289
X-54.051Y-42.188Z-0.398
G0Z10
X-51.191Y-45.662
G1Z-0.209F500
G0Z10
X-50.188Y-46.777
G1Z-0.168
G1Z-0.169
G0Z10
X0.75Y0
G1Z-6.912
@ -19672,7 +19672,7 @@ X-64.624Y-22.44
X-64.461Y-22.913
X-64.295Y-23.385
X-64.126Y-23.855Z-5.888
X-63.953Y-24.324Z-5.986
X-63.953Y-24.324Z-5.987
X-63.777Y-24.792Z-6.912F500
X-63.598Y-25.259F1000
X-63.414Y-25.724Z-5.876
@ -19697,9 +19697,9 @@ X-61.616Y-29.849Z-5.791
X-61.399Y-30.299Z-6.912
X-61.252Y-30.601Z-5.1F1000
G0Z10
X-60.696Y-31.707
X-60.697Y-31.707
G1Z-5.1F500
X-60.5Y-32.086Z-6.844
X-60.5Y-32.086Z-6.845
X-60.268Y-32.528Z-5.547F1000
X-60.144Y-32.759Z-5.1
G0Z10

Wyświetl plik

@ -1,4 +1,4 @@
(Created with grbl post processor 2024/01/29 13:19)
(Created with grbl post processor 2024/01/31 14:43)
G21
(G-code generated with BlenderCAM and NC library)
G17G90
@ -6,66 +6,6 @@ S12000M03
G00 Z10.0
G0X0Y0Z10
X7.474Y26.574
G1Z-2.1F500
X6.774Y27.074F1000
X6.575Y27.474
Y28.574
X6.774Y28.974
X7.474Y29.474
X8.574
X9.275Y28.974
X9.474Y28.574
Y27.474
X9.275Y27.074
X8.574Y26.574
X7.474
G0Z10
X27.074Y9.275
G1Z-2.1F500
X26.574Y8.574F1000
Y7.474
X27.074Y6.774
X27.474Y6.575
X28.574
X28.974Y6.774
X29.474Y7.474
Y8.474
X28.974Y9.275
X28.574Y9.474
X27.474
X27.074Y9.275
G0Z10
X46.774Y27.074
G1Z-2.1F500
X47.474Y26.574F1000
X48.574
X49.075Y26.874
X49.474Y27.474
Y28.475
X49.275Y28.974
X48.574Y29.474
X47.474
X46.974Y29.174
X46.574Y28.574
Y27.474
X46.774Y27.074
G0Z10
X29.174Y46.974
G1Z-2.1F500
X29.474Y47.474F1000
Y48.474
X28.974Y49.275
X28.574Y49.474
X27.474
X27.074Y49.275
X26.574Y48.574
Y47.474
X26.874Y46.974
X27.474Y46.574
X28.574
X29.174Y46.974
G0Z10
X10.774Y9.574
G1Z-3.1F500
X10.975F1000
@ -306,7 +246,7 @@ G1Z-5.1F500
X17.974Y20.374F1000
X16.874Y22.074
X15.774Y24.874
X15.374Y27.474
X15.374Y27.375
X15.474Y29.575
X16.074Y32.074
X16.974Y34.174
@ -330,7 +270,7 @@ X37.474Y19.675
X35.675Y17.974
X33.974Y16.874
X31.174Y15.774
X28.574Y15.374
X28.674Y15.374
X26.474Y15.474
X23.975Y16.074
X21.875Y16.974
@ -348,12 +288,14 @@ X28.974Y-0.325
X31.974Y-0.125
X35.574Y0.574
X38.774Y1.674
X41.575Y3.174
X42.274Y3.374
X45.274Y5.374
X48.874Y8.675
Y8.874
X50.674Y10.774
X52.674Y13.774
X52.874Y14.474
X54.374Y17.275
X55.474Y20.474
X56.074Y23.474
@ -376,12 +318,14 @@ X27.074Y56.374
X24.075Y56.174
X20.474Y55.474
X17.275Y54.374
X14.474Y52.874
X13.774Y52.674
X10.774Y50.674
X7.174Y47.374
Y47.174
X5.374Y45.274
X3.374Y42.274
X3.174Y41.575
X1.674Y38.774
X0.574Y35.574
X-0.025Y32.575
@ -595,9 +539,8 @@ X17.275Y25.274
X16.874Y27.974
X17.275Y30.774
X17.774Y32.274
X19.074Y34.575
X20.174Y35.675
Y35.875
X18.475Y33.675
X20.174Y35.875
X20.374
X21.775Y37.175
X23.774Y38.275
@ -614,8 +557,7 @@ Y26.774
X38.275Y23.774
X37.374Y22.074
X35.875Y20.174
X35.675
X34.575Y19.074
X33.675Y18.475
X32.274Y17.774
X30.774Y17.275
X28.074Y16.874

Wyświetl plik

@ -454,6 +454,9 @@ async def sampleChunks(o, pathSamples, layers):
ob = bpy.data.objects[o.object_name]
zinvert = ob.location.z + maxz # ob.bound_box[6][2]
print(f"Total sample points {totlen}")
n = 0
last_percent = -1
# timing for optimisation
@ -472,15 +475,16 @@ async def sampleChunks(o, pathSamples, layers):
# threads_count=4
# for t in range(0,threads):
for s in patternchunk.get_points():
our_points=patternchunk.get_points_np()
ambient_contains=shapely.contains(o.ambient,shapely.points(our_points[:,0:2]))
for s,in_ambient in zip(our_points,ambient_contains):
if o.strategy != 'WATERLINE' and int(100 * n / totlen) != last_percent:
last_percent = int(100 * n / totlen)
await progress_async('sampling paths ', last_percent)
n += 1
x = s[0]
y = s[1]
if not o.ambient.contains(sgeometry.Point(x, y)):
if not in_ambient:
newsample = (x, y, 1)
else:
if o.optimisation.use_opencamlib and o.optimisation.use_exact: