Commit 64583df0 authored by lode_leroy's avatar lode_leroy

bugfix, debug output

git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@31 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent 317cf3d4
......@@ -2,12 +2,19 @@ from pycam.PathProcessors import *
from pycam.Geometry import *
from pycam.Geometry.utils import *
from pycam.Exporters.SVGExporter import SVGExporter
DEBUG_PUSHCUTTER = False
DEBUG_PUSHCUTTER2 = False
DEBUG_PUSHCUTTER3 = False
class Hit:
def __init__(self, cl, t, d, dir):
self.cl = cl
self.t = t
self.d = d
self.dir = dir
def cmp(a,b):
return cmp(a.d, b.d)
......@@ -29,6 +36,9 @@ class PushCutter:
else:
self.pa.dy = dx
if DEBUG_PUSHCUTTER2 or DEBUG_PUSHCUTTER3:
self.svg = SVGExporter("test.svg")
z = maxz
paths = []
......@@ -48,9 +58,30 @@ class PushCutter:
paths += self.pa.paths
z -= dz
if DEBUG_PUSHCUTTER2:
self.svg.fill('none')
self.svg.stroke('black')
self.svg.AddPathList(paths)
if hasattr(self,"svg"):
self.svg.close()
return paths
def DropCutterTest(self, point, model):
zmax = -INFINITE
tmax = None
c = self.cutter
c.moveto(point)
for t in model.triangles():
if t.normal().z < 0: continue
cl = c.drop(t)
if cl and cl.z > zmax and cl.z < INFINITE:
zmax = cl.z
tmax = t
return (zmax, tmax)
def GenerateToolPathSlice(self, minx, maxx, miny, maxy, z, dx, dy):
global DEBUG_PUSHCUTTER, DEBUG_PUSHCUTTER2, DEBUG_PUSHCUTTER3
c = self.cutter
model = self.model
......@@ -63,8 +94,43 @@ class PushCutter:
x = minx
y = miny
line = 0
while x<=maxx and y<=maxy:
self.pa.new_scanline()
if False:
line += 1
if line == 13:
DEBUG_PUSHCUTTER=True
DEBUG_PUSHCUTTER2=True
DEBUG_PUSHCUTTER3=True
p = Path()
self.svg.stroke('orange')
p.append(Point(minx,y-0.05,z))
p.append(Point(maxx,y-0.05,z))
p.append(Point(maxx,y+0.05,z))
p.append(Point(minx,y+0.05,z))
p.append(Point(minx,y-0.05,z))
self.svg.AddPath(p)
else:
DEBUG_PUSHCUTTER=False
DEBUG_PUSHCUTTER2=True
DEBUG_PUSHCUTTER3=False
if DEBUG_PUSHCUTTER3:
self.svg.stroke('gray')
self.svg.AddLine(minx, z, maxx, z)
self.svg.fill('lightgreen')
p = Point(minx, y, 10)
for i in range(0,100):
p.x = minx + float(i)/100*float(maxx-minx)
(zmax, tmax) = self.DropCutterTest(p, model)
if DEBUG_PUSHCUTTER: print "v cl=",p,",zmax=",zmax
self.svg.AddDot(p.x, zmax)
self.svg.fill('black')
# find all hits along scan line
hits = []
......@@ -72,65 +138,111 @@ class PushCutter:
c.moveto(prev)
for t in model.triangles():
if t.normal().z < 0: continue;
#if t.normal().z < 0: continue;
# normals point outward... and we want to approach the model from the outside!
n = t.normal().dot(forward)
if n>=0:
(cl,d) = c.intersect(backward, t)
if cl:
# print "< cl=",cl,",d=",-d,",t=",t
#if DEBUG_PUSHCUTTER: print "< cl=",cl,",d=",-d,",t=",t
hits.append(Hit(cl,t,-d,backward))
if DEBUG_PUSHCUTTER3: self.svg.AddDot(cl.x, cl.z)
if n<=0:
(cl,d) = c.intersect(forward, t)
if cl:
# print "> cl=",cl,",d=",d,",t=",t
#if DEBUG_PUSHCUTTER: print "> cl=",cl,",d=",d,",t=",t
hits.append(Hit(cl,t,d,forward))
if DEBUG_PUSHCUTTER3: self.svg.AddDot(cl.x, cl.z)
# sort along the scan direction
hits.sort(Hit.cmp)
# remove duplicates (typically edges)
i = 1
while i < len(hits):
while i<len(hits) and abs(hits[i].d - hits[i-1].d)<epsilon:
del hits[i]
i += 1
# # remove duplicates (typically edges)
# i = 1
# while i < len(hits):
# while i<len(hits) and abs(hits[i].d - hits[i-1].d)<epsilon:
# del hits[i]
# i += 1
if DEBUG_PUSHCUTTER or DEBUG_PUSHCUTTER3:
for h in hits:
(zmax, tmax) = self.DropCutterTest(h.cl, model)
if DEBUG_PUSHCUTTER: print " cl=",h.cl,",d=",h.d,",zmax=",zmax
if DEBUG_PUSHCUTTER3:
self.svg.stroke('gray')
self.svg.AddLine(h.cl.x, -1, h.cl.x, zmax)
# find parts of scanline where model is below z-level
i = 0
while i < len(hits):
next = hits[i].cl
self.pa.append(prev)
self.pa.append(next)
i += 1
# find next hit cutter location that is below z-level
while i < len(hits):
(zmax, tmax) = self.DropCutterTest(prev, model)
if DEBUG_PUSHCUTTER: print "1", prev, "z=",zmax
if zmax <= z+epsilon:
break
if DEBUG_PUSHCUTTER3:
self.svg.stroke('lightred')
self.svg.AddLine(prev.x, prev.z, prev.x, zmax)
prev = hits[i].cl
c.moveto(prev)
c.moveto(prev.sub(hits[i].dir.mul(epsilon)))
zmax = -INFINITE
for t in model.triangles():
if t.normal().z < 0: continue;
cl = c.drop(t)
if cl and cl.z > zmax and cl.z < INFINITE:
zmax = cl.z
i += 1
if DEBUG_PUSHCUTTER3:
self.svg.stroke('red')
self.svg.AddLine(prev.x, prev.z, prev.x, zmax)
# find next hit cutter location that is above z-level
while i < len(hits):
next = hits[i].cl
(zmax, tmax) = self.DropCutterTest(next, model)
if DEBUG_PUSHCUTTER: print "2", next, "z=",zmax
i += 1
if zmax <= z+epsilon:
if zmax >= z-epsilon:
break
if DEBUG_PUSHCUTTER3:
self.svg.stroke('lightblue')
self.svg.AddLine(next.x, next.z, next.x, zmax)
if DEBUG_PUSHCUTTER3:
self.svg.stroke('blue')
self.svg.AddLine(next.x, next.z, next.x, zmax)
if i < len(hits):
self.pa.append(prev)
self.pa.append(next)
if DEBUG_PUSHCUTTER: print "C ", prev, next, "z=",zmax
if DEBUG_PUSHCUTTER3:
self.svg.stroke('red')
self.svg.AddLine(prev.x, z-0.1, next.x, z-0.1)
prev = hits[i].cl
if dx == 0:
x = maxx
if dy == 0:
y = maxy
next = Point(x,y,z)
(zmax, tmax) = self.DropCutterTest(next, model)
if DEBUG_PUSHCUTTER: print "3 ", next, "z=",zmax
self.pa.append(prev)
self.pa.append(next)
if zmax <= z+epsilon:
self.pa.append(prev)
self.pa.append(next)
if DEBUG_PUSHCUTTER: print "C ", prev, next, "z=",zmax
if DEBUG_PUSHCUTTER3:
self.svg.stroke('red')
self.svg.AddLine(prev.x, z-0.1, next.x, z-0.1)
if dx != 0:
x += dx
......@@ -142,4 +254,6 @@ class PushCutter:
y = miny
self.pa.end_scanline()
if DEBUG_PUSHCUTTER: print
if DEBUG_PUSHCUTTER: print
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment