Commit 3657baf9 authored by lode_leroy's avatar lode_leroy

bugfix

git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@51 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent d5e6de17
...@@ -4,8 +4,11 @@ from pycam.Geometry.utils import * ...@@ -4,8 +4,11 @@ from pycam.Geometry.utils import *
from pycam.Geometry.Path import * from pycam.Geometry.Path import *
from pycam.Geometry.Point import * from pycam.Geometry.Point import *
from pycam.Exporters.SVGExporter import SVGExporter
DEBUG_POLYGONEXTRACTOR=False DEBUG_POLYGONEXTRACTOR=False
DEBUG_POLYGONEXTRACTOR2=False DEBUG_POLYGONEXTRACTOR2=False
DEBUG_POLYGONEXTRACTOR3=False
class PolygonExtractor: class PolygonExtractor:
CONTOUR=1 CONTOUR=1
...@@ -24,10 +27,19 @@ class PolygonExtractor: ...@@ -24,10 +27,19 @@ class PolygonExtractor:
self.prev_line = [] self.prev_line = []
self.curr_line = [] self.curr_line = []
if DEBUG_POLYGONEXTRACTOR3:
self.svg = SVGExporter("test-%d.svg" % dir)
if dir == 0:
self.svg.fill("red")
else:
self.svg.fill("blue")
if self.policy == PolygonExtractor.CONTOUR and dir == 1 and self.hor_path_list: if self.policy == PolygonExtractor.CONTOUR and dir == 1 and self.hor_path_list:
self.last_x = -INFINITE self.last_x = -INFINITE
self.delta_x = 0 self.delta_x = 0
self.convert_hor_path_list() self.convert_hor_path_list()
if DEBUG_POLYGONEXTRACTOR3:
self.cont = SVGExporter("test-2.svg")
self.cont.fill("green")
def end_direction(self): def end_direction(self):
if self.policy == PolygonExtractor.CONTOUR and self.hor_path_list: if self.policy == PolygonExtractor.CONTOUR and self.hor_path_list:
...@@ -36,8 +48,12 @@ class PolygonExtractor: ...@@ -36,8 +48,12 @@ class PolygonExtractor:
self.new_scanline() self.new_scanline()
self.end_scanline() self.end_scanline()
if DEBUG_POLYGONEXTRACTOR3:
self.svg.close()
if self.policy == PolygonExtractor.CONTOUR and self.hor_path_list: if self.policy == PolygonExtractor.CONTOUR and self.hor_path_list:
for path in self.all_path_list: for path in self.all_path_list:
if DEBUG_POLYGONEXTRACTOR2: print "points=", path.points
i = 0 i = 0
while i < len(path.points)-1: while i < len(path.points)-1:
if path.points[i].x > path.points[i+1].x: if path.points[i].x > path.points[i+1].x:
...@@ -93,11 +109,28 @@ class PolygonExtractor: ...@@ -93,11 +109,28 @@ class PolygonExtractor:
if self.current_dir==0: if self.current_dir==0:
self.hor_path_list = path_list self.hor_path_list = path_list
elif self.current_dir==1: elif self.current_dir==1:
if self.policy == PolygonExtractor.CONTOUR and self.hor_path_list and self.ver_path_list: if self.policy == PolygonExtractor.CONTOUR and self.hor_path_list and path_list:
self.merge_path_list = path_list self.merge_path_list = path_list
else: else:
self.ver_path_list = path_list self.ver_path_list = path_list
if DEBUG_POLYGONEXTRACTOR3:
self.svg = SVGExporter("test-3.svg")
for path in path_list:
prev = None
for p in path.points:
if p.dir == 0:
self.svg.fill("red")
else:
self.svg.fill("blue")
self.svg.AddDot(p.x, p.y)
self.svg.AddText(p.x, p.y, str(p.id))
if prev:
self.svg.AddLine(p.x, p.y, prev.x, prev.y)
prev = p
self.svg.close()
self.cont.close()
def finish(self): def finish(self):
pass pass
...@@ -105,6 +138,10 @@ class PolygonExtractor: ...@@ -105,6 +138,10 @@ class PolygonExtractor:
self.curr_line = [] self.curr_line = []
def append(self, p): def append(self, p):
if DEBUG_POLYGONEXTRACTOR3:
p.dir = self.current_dir
self.svg.AddDot(p.x, p.y)
self.svg.AddText(p.x, p.y, str(p.id))
self.curr_line.append(p) self.curr_line.append(p)
def end_scanline(self): def end_scanline(self):
...@@ -112,14 +149,17 @@ class PolygonExtractor: ...@@ -112,14 +149,17 @@ class PolygonExtractor:
self.process_hor_scanline(self.curr_line) self.process_hor_scanline(self.curr_line)
elif self.current_dir==1: elif self.current_dir==1:
if self.policy == PolygonExtractor.CONTOUR and self.hor_path_list: if self.policy == PolygonExtractor.CONTOUR and self.hor_path_list:
next_x = 0 next_x = -INFINITE
if len(self.curr_line)>0: if len(self.curr_line)>0:
next_x = self.curr_line[0].x next_x = self.curr_line[0].x
self.delta_x = next_x - self.last_x self.delta_x = next_x - self.last_x
self.last_x = next_x self.last_x = next_x
else: else:
next_x = self.last_x + self.delta_x next_x = self.last_x + self.delta_x
if next_x > -INFINITE:
self.process_virtual_hor_scanline(next_x) self.process_virtual_hor_scanline(next_x)
if DEBUG_POLYGONEXTRACTOR2:
print "scanline =", self.curr_line
self.process_ver_scanline(self.curr_line) self.process_ver_scanline(self.curr_line)
def process_hor_scanline(self, scanline): def process_hor_scanline(self, scanline):
...@@ -148,7 +188,7 @@ class PolygonExtractor: ...@@ -148,7 +188,7 @@ class PolygonExtractor:
if DEBUG_POLYGONEXTRACTOR: print "active points: ", if DEBUG_POLYGONEXTRACTOR: print "active points: ",
for point in scanline: for point in scanline:
if DEBUG_POLYGONEXTRACTOR: print "(%g,%g)" % (point.x, point.y), if DEBUG_POLYGONEXTRACTOR: print "%d(%g,%g)" % (point.id, point.x, point.y),
if DEBUG_POLYGONEXTRACTOR: print if DEBUG_POLYGONEXTRACTOR: print
prev_point = Iterator(self.prev_line) prev_point = Iterator(self.prev_line)
...@@ -332,7 +372,23 @@ class PolygonExtractor: ...@@ -332,7 +372,23 @@ class PolygonExtractor:
self.prev_line = scanline self.prev_line = scanline
def process_ver_scanline(self, scanline, next_x=-INFINITE): def process_ver_scanline(self, scanline):
if DEBUG_POLYGONEXTRACTOR3:
prev = None
for p in scanline:
if p.dir == 0:
self.cont.fill("red")
else:
self.cont.fill("blue")
self.cont.AddDot(p.x,p.y)
self.cont.fill("black")
self.cont.AddText(p.x,p.y, str(p.id))
if prev:
self.cont.AddLine(prev.x,prev.y,p.x,p.y)
prev = p
if DEBUG_POLYGONEXTRACTOR:
last = 0 last = 0
inside = False inside = False
s = "" s = ""
...@@ -344,7 +400,7 @@ class PolygonExtractor: ...@@ -344,7 +400,7 @@ class PolygonExtractor:
s += " " * int(next-last) s += " " * int(next-last)
last = next last = next
inside = not inside inside = not inside
if DEBUG_POLYGONEXTRACTOR: print s print s
if DEBUG_POLYGONEXTRACTOR: print "active paths: ", if DEBUG_POLYGONEXTRACTOR: print "active paths: ",
for path in self.curr_path_list: for path in self.curr_path_list:
...@@ -358,7 +414,7 @@ class PolygonExtractor: ...@@ -358,7 +414,7 @@ class PolygonExtractor:
if DEBUG_POLYGONEXTRACTOR: print "active points: ", if DEBUG_POLYGONEXTRACTOR: print "active points: ",
for point in scanline: for point in scanline:
if DEBUG_POLYGONEXTRACTOR: print "(%g,%g)" % (point.x, point.y), if DEBUG_POLYGONEXTRACTOR: print "%d(%g,%g)" % (point.id, point.x, point.y),
if DEBUG_POLYGONEXTRACTOR: print if DEBUG_POLYGONEXTRACTOR: print
prev_point = Iterator(self.prev_line) prev_point = Iterator(self.prev_line)
...@@ -620,12 +676,20 @@ class PolygonExtractor: ...@@ -620,12 +676,20 @@ class PolygonExtractor:
def process_virtual_hor_scanline(self, next_x): def process_virtual_hor_scanline(self, next_x):
_next_x = next_x
while next_x <= _next_x:
next_x = INFINITE
if len(self.ver_hor_path_list)>0 and self.ver_hor_path_list[0].points[0].x < next_x: if len(self.ver_hor_path_list)>0 and self.ver_hor_path_list[0].points[0].x < next_x:
next_x = self.ver_hor_path_list[0].points[0].x next_x = self.ver_hor_path_list[0].points[0].x
if len(self.act_hor_path_list)>0 and self.act_hor_path_list[0].points[0].x < next_x: if len(self.act_hor_path_list)>0 and self.act_hor_path_list[0].points[0].x < next_x:
next_x = self.act_hor_path_list[0].points[0].x next_x = self.act_hor_path_list[0].points[0].x
if next_x >= _next_x:
return
if DEBUG_POLYGONEXTRACTOR2: if DEBUG_POLYGONEXTRACTOR2:
print "ver_hor_path_list =", self.ver_hor_path_list print "ver_hor_path_list =", self.ver_hor_path_list
print "act_hor_path_list =", self.act_hor_path_list print "act_hor_path_list =", self.act_hor_path_list
...@@ -637,7 +701,6 @@ class PolygonExtractor: ...@@ -637,7 +701,6 @@ class PolygonExtractor:
self.ver_hor_path_list = self.ver_hor_path_list[1:] self.ver_hor_path_list = self.ver_hor_path_list[1:]
self.act_hor_path_list.sort(cmp=lambda a,b:cmp(a.points[0].x,b.points[0].x)) self.act_hor_path_list.sort(cmp=lambda a,b:cmp(a.points[0].x,b.points[0].x))
while len(self.act_hor_path_list)>0 and self.act_hor_path_list[0].points[0].x <= next_x:
scanline = [] scanline = []
i = 0 i = 0
while i < len(self.act_hor_path_list): while i < len(self.act_hor_path_list):
...@@ -657,9 +720,12 @@ class PolygonExtractor: ...@@ -657,9 +720,12 @@ class PolygonExtractor:
repeat = True repeat = True
i += 1 i += 1
self.act_hor_path_list.sort(cmp=lambda a,b:cmp(a.points[0].x,b.points[0].x)) self.act_hor_path_list.sort(cmp=lambda a,b:cmp(a.points[0].x,b.points[0].x))
if len(scanline)==0:
return
scanline.sort(cmp=lambda a,b:cmp(a.y,b.y)) scanline.sort(cmp=lambda a,b:cmp(a.y,b.y))
if DEBUG_POLYGONEXTRACTOR2: if DEBUG_POLYGONEXTRACTOR2:
print "scanline =", scanline print "scanline' =", scanline
print "ver_hor_path_list =", self.ver_hor_path_list print "ver_hor_path_list =", self.ver_hor_path_list
print "act_hor_path_list =", self.act_hor_path_list print "act_hor_path_list =", self.act_hor_path_list
self.process_ver_scanline(scanline) self.process_ver_scanline(scanline)
......
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