Commit 8f1d8ccb authored by lode_leroy's avatar lode_leroy

support binary STL

git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@54 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent 618caf6d
......@@ -163,6 +163,7 @@ class PolygonExtractor:
self.process_ver_scanline(self.curr_line)
def process_hor_scanline(self, scanline):
if DEBUG_POLYGONEXTRACTOR:
last = 0
inside = False
s = ""
......@@ -174,7 +175,7 @@ class PolygonExtractor:
s += " " * int(next-last)
last = next
inside = not inside
if DEBUG_POLYGONEXTRACTOR: print s
print s
if DEBUG_POLYGONEXTRACTOR: print "active paths: ",
for path in self.curr_path_list:
......
import re
from struct import unpack
from pycam.Geometry import *
from pycam.Geometry.PointKdtree import PointKdtree
......@@ -49,16 +50,14 @@ def ImportModel(filename, use_kdtree=True):
edges = 0
kdtree = None
f = file(filename,"r")
solid = re.compile("\s*solid\s+(\w+)\s+.*")
solid_AOI = re.compile("\s*solid\s+\"([\w\-]+)\"; Produced by Art of Illusion.*")
endsolid = re.compile("\s*endsolid\s+")
facet = re.compile("\s*facet\s+")
normal = re.compile("\s*facet\s+normal\s+(?P<x>[-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?)\s+(?P<y>[-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?)\s+(?P<z>[-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?)\s+")
endfacet = re.compile("\s*endfacet\s+")
loop = re.compile("\s*outer\s+loop\s+")
endloop = re.compile("\s*endloop\s+")
vertex = re.compile("\s*vertex\s+(?P<x>[-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?)\s+(?P<y>[-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?)\s+(?P<z>[-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?)\s+")
f = open(filename,"rb")
header = f.read(80)
binary = False
if header[0:5] == "solid":
binary = False
f.seek(0)
else:
binary = True
if use_kdtree:
kdtree = PointKdtree([],3,1,epsilon)
......@@ -68,8 +67,58 @@ def ImportModel(filename, use_kdtree=True):
p1 = None
p2 = None
p3 = None
if binary:
numfacets = unpack("<I",f.read(4))[0]
for i in range(1,numfacets):
a1 = unpack("<f",f.read(4))[0]
a2 = unpack("<f",f.read(4))[0]
a3 = unpack("<f",f.read(4))[0]
n = Point(float(a1),float(a2),float(a3))
v11 = unpack("<f",f.read(4))[0]
v12 = unpack("<f",f.read(4))[0]
v13 = unpack("<f",f.read(4))[0]
p1 = UniqueVertex(float(v11),float(v12),float(v13))
v21 = unpack("<f",f.read(4))[0]
v22 = unpack("<f",f.read(4))[0]
v23 = unpack("<f",f.read(4))[0]
p2 = UniqueVertex(float(v21),float(v22),float(v23))
v31 = unpack("<f",f.read(4))[0]
v32 = unpack("<f",f.read(4))[0]
v33 = unpack("<f",f.read(4))[0]
p3 = UniqueVertex(float(v31),float(v32),float(v33))
attribs = unpack("<H",f.read(2))
if n.dot(p3.sub(p1).cross(p2.sub(p1)))>0:
t = Triangle(p1, p2, p3, UniqueEdge(p1,p2), UniqueEdge(p2,p3), UniqueEdge(p3,p1))
else:
t = Triangle(p1, p3, p2, UniqueEdge(p1,p3), UniqueEdge(p3,p2), UniqueEdge(p2,p1))
t._normal = n
if t.normal().z < 0:
continue
model.append(t)
else:
AOI = False
solid = re.compile("\s*solid\s+(\w+)\s+.*")
solid_AOI = re.compile("\s*solid\s+\"([\w\-]+)\"; Produced by Art of Illusion.*")
endsolid = re.compile("\s*endsolid\s+")
facet = re.compile("\s*facet\s+")
normal = re.compile("\s*facet\s+normal\s+(?P<x>[-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?)\s+(?P<y>[-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?)\s+(?P<z>[-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?)\s+")
endfacet = re.compile("\s*endfacet\s+")
loop = re.compile("\s*outer\s+loop\s+")
endloop = re.compile("\s*endloop\s+")
vertex = re.compile("\s*vertex\s+(?P<x>[-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?)\s+(?P<y>[-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?)\s+(?P<z>[-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?)\s+")
for line in f:
m = solid_AOI.match(line)
if m:
......
......@@ -129,7 +129,7 @@ class PushCutter:
p = Point(minx, y, 10)
for i in range(0,100):
p.x = minx + float(i)/100*float(maxx-minx)
self.svg.AddDot(p.x, zmax)
self.svg.AddDot(p.x, z)
self.svg.fill('black')
......@@ -155,6 +155,7 @@ class PushCutter:
if DEBUG_PUSHCUTTER: print "< cl=",cl,",d=",-d,",t=",t.id,",t.n=",t.normal(),",n=",n
hits.append(Hit(cl,t,-d,backward))
hits.append(Hit(cl.sub(backward_small),t,-d+epsilon,backward))
hits.append(Hit(cl.add(backward_small),t,-d-epsilon,backward))
if DEBUG_PUSHCUTTER3: self.svg.AddDot(cl.x, cl.z)
else:
if DEBUG_PUSHCUTTER: print "< cl=",cl,",0",",t=",t.id
......@@ -163,6 +164,7 @@ class PushCutter:
if cl:
if DEBUG_PUSHCUTTER: print "> cl=",cl,",d=",d,",t=",t.id,",t.n=",t.normal(),",n=",n
hits.append(Hit(cl,t,d,forward))
hits.append(Hit(cl.add(forward_small),t,d+epsilon,forward))
hits.append(Hit(cl.sub(forward_small),t,d-epsilon,forward))
if DEBUG_PUSHCUTTER3: self.svg.AddDot(cl.x, cl.z)
else:
......
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