Commit 46b75a3d authored by lode_leroy's avatar lode_leroy

git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@14 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent 406b32f2
BRLCAD=/opt/brlcad/bin
BRLCAD=c:/Software/BRL-CAD/bin
MGED=$(BRLCAD)/mged
G-STL=$(BRLCAD)/g-stl
VER=0.1.4
all:
.PHONY: dist
dist:
(cd ..; tar zcf pycam/pycam.tgz pycam/*{Makefile,TXT} pycam/*.py pycam/tests/*.py pycam/pycam/*/*.py pycam/pycam/*.py pycam/Samples/*/*.stl)
dist-ver:
(cd ..; tar zcf pycam-$(VER)/pycam-$(VER).tgz pycam-$(VER)/*{Makefile,TXT} pycam-$(VER)/*.py pycam-$(VER)/tests/*.py pycam-$(VER)/pycam/*/*.py pycam-$(VER)/pycam/*.py pycam-$(VER)/Samples/*/*.stl)
test:
rm -f test.g; $(MGED) test.g < test.txt; $(MGED) test.g
test0:
rm -f test.g; $(MGED) test.g < cutter0.txt; $(MGED) test.g
test1:
rm -f test.g; $(MGED) test.g < cutter1.txt; $(MGED) test.g
test2:
rm -f test.g; $(MGED) test.g < cutter2.txt; $(MGED) test.g
test3:
rm -f test.g; $(MGED) test.g < cutter3.txt; $(MGED) test.g
TestModel.stl:
./Tests/MGEDExporterTest.py
rm -f TestModel.g
$(MGED) TestModel.g < TestModel.txt
$(G-STL) -o TestModel.stl TestModel.g model0
import sys
import os
sys.path.insert(0, os.path.join(sys.prefix, "PyOpenGL-3.0.0b5-py2.5.egg"))
sys.path.insert(0, os.path.join(sys.prefix, "setuptools-0.6c8-py2.5.egg"))
from pycam.Gui.SimpleGui import SimpleGui
from pycam.Importers.TestModel import TestModel
gui = SimpleGui()
gui.model = TestModel()
gui.mainloop()
import sys
import os
sys.path.insert(0, os.path.join(sys.prefix, "PyOpenGL-3.0.0b5-py2.5.egg"))
sys.path.insert(0, os.path.join(sys.prefix, "setuptools-0.6c8-py2.5.egg"))
from pycam.Gui.SimpleGui import SimpleGui
from pycam.Importers.TestModel import TestModel
gui = SimpleGui()
gui.model = TestModel()
gui.mainloop()
from pycam.PathProcessors import *
from pycam.Geometry import *
from pycam.Geometry.utils import *
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)
class PushCutter:
def __init__(self, cutter, model, pathextractor=None):
self.cutter = cutter
self.model = model
self.pa = pathextractor
def GenerateToolPath(self, minx, maxx, miny, maxy, minz, maxz, dx, dy, dz):
if dx==0:
forward = Point(1,0,0)
backward = Point(-1,0,0)
elif dy == 0:
forward = Point(0,1,0)
backward = Point(0,-1,0)
z = maxz
c = self.cutter
model = self.model
paths = []
while z >= minz:
self.pa.new_direction(0)
x = minx
y = miny
while x<=maxx and y<=maxy:
self.pa.new_scanline()
# find all hits along scan line
hits = []
prev = Point(x,y,z)
c.moveto(prev)
for t in model.triangles():
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
hits.append(Hit(cl,t,-d,backward))
if n<=0:
(cl,d) = c.intersect(forward, t)
if cl:
# print "> cl=",cl,",d=",d,",t=",t
hits.append(Hit(cl,t,d,forward))
# 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
# 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):
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 zmax <= z+epsilon:
break
if dx == 0:
x = maxx
if dy == 0:
y = maxy
next = Point(x,y,z)
self.pa.append(prev)
self.pa.append(next)
if dx != 0:
x += dx
else:
x = minx
if dy != 0:
y += dy
else:
y = miny
self.pa.end_scanline()
self.pa.end_direction()
self.pa.finish()
paths += self.pa.paths
z -= dz
return paths
from pycam.PathProcessors import *
from pycam.Geometry import *
from pycam.Geometry.utils import *
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)
class PushCutter:
def __init__(self, cutter, model, pathextractor=None):
self.cutter = cutter
self.model = model
self.pa = pathextractor
def GenerateToolPath(self, minx, maxx, miny, maxy, minz, maxz, dx, dy, dz):
if dx==0:
forward = Point(1,0,0)
backward = Point(-1,0,0)
elif dy == 0:
forward = Point(0,1,0)
backward = Point(0,-1,0)
z = maxz
c = self.cutter
model = self.model
paths = []
while z >= minz:
self.pa.new_direction(0)
x = minx
y = miny
while x<=maxx and y<=maxy:
self.pa.new_scanline()
# find all hits along scan line
hits = []
prev = Point(x,y,z)
c.moveto(prev)
for t in model.triangles():
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
hits.append(Hit(cl,t,-d,backward))
if n<=0:
(cl,d) = c.intersect(forward, t)
if cl:
# print "> cl=",cl,",d=",d,",t=",t
hits.append(Hit(cl,t,d,forward))
# 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
# 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):
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 zmax <= z+epsilon:
break
if dx == 0:
x = maxx
if dy == 0:
y = maxy
next = Point(x,y,z)
self.pa.append(prev)
self.pa.append(next)
if dx != 0:
x += dx
else:
x = minx
if dy != 0:
y += dy
else:
y = miny
self.pa.end_scanline()
self.pa.end_direction()
self.pa.finish()
paths += self.pa.paths
z -= dz
return paths
__all__ = [ "Utils", "Geometry", "Cutters", "PathGenerators", "PathProcessors", "Importers", "Exporters", "Gui"]
import pycam.Utils
import pycam.Geometry
import pycam.Cutters
import pycam.PathGenerators
import pycam.PathProcessors
import pycam.Importers
import pycam.Exporters
import pycam.Gui
__all__=["Cutters","Exporters","Geometry","Gui","Importers","PathGenerators","PathProcessors","Utils"]
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