Commit 618caf6d authored by lode_leroy's avatar lode_leroy

fix speedup shortcuts

git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@53 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent 6d649676
...@@ -7,6 +7,7 @@ from math import sqrt ...@@ -7,6 +7,7 @@ from math import sqrt
class BaseCutter: class BaseCutter:
id = 0 id = 0
vertical = Point(0,0,-1)
def __init__(self, location, radius): def __init__(self, location, radius):
self.location = location self.location = location
...@@ -48,7 +49,7 @@ class BaseCutter: ...@@ -48,7 +49,7 @@ class BaseCutter:
if sqr(c.x-self.location.x)+sqr(c.y-self.location.y)>self.radiussq+self.radius*triangle.radius()+triangle.radiussq(): if sqr(c.x-self.location.x)+sqr(c.y-self.location.y)>self.radiussq+self.radius*triangle.radius()+triangle.radiussq():
return None return None
(cl,d)= self.intersect(Point(0,0,-1), triangle) (cl,d)= self.intersect(BaseCutter.vertical, triangle)
return cl return cl
def push(self, dx, dy, triangle): def push(self, dx, dy, triangle):
......
...@@ -120,7 +120,7 @@ class CylindricalCutter(BaseCutter): ...@@ -120,7 +120,7 @@ class CylindricalCutter(BaseCutter):
if d_t < d: if d_t < d:
d = d_t d = d_t
cl = cl_t cl = cl_t
if cl: if cl and direction.x==0 and direction.y==0:
return (cl,d) return (cl,d)
(cl_e1,d_e1) = self.intersect_circle_edge(direction, triangle.e1) (cl_e1,d_e1) = self.intersect_circle_edge(direction, triangle.e1)
(cl_e2,d_e2) = self.intersect_circle_edge(direction, triangle.e2) (cl_e2,d_e2) = self.intersect_circle_edge(direction, triangle.e2)
...@@ -134,7 +134,7 @@ class CylindricalCutter(BaseCutter): ...@@ -134,7 +134,7 @@ class CylindricalCutter(BaseCutter):
if d_e3 < d: if d_e3 < d:
d = d_e3 d = d_e3
cl = cl_e3 cl = cl_e3
if cl: if cl and direction.x==0 and direction.y==0:
return (cl,d) return (cl,d)
(cl_p1,d_p1) = self.intersect_circle_vertex(direction, triangle.p1) (cl_p1,d_p1) = self.intersect_circle_vertex(direction, triangle.p1)
(cl_p2,d_p2) = self.intersect_circle_vertex(direction, triangle.p2) (cl_p2,d_p2) = self.intersect_circle_vertex(direction, triangle.p2)
...@@ -148,12 +148,12 @@ class CylindricalCutter(BaseCutter): ...@@ -148,12 +148,12 @@ class CylindricalCutter(BaseCutter):
if d_p3 < d: if d_p3 < d:
d = d_p3 d = d_p3
cl = cl_p3 cl = cl_p3
if cl: if cl and direction.x==0 and direction.y==0:
return (cl,d) return (cl,d)
if direction.x != 0 or direction.y != 0: if direction.x != 0 or direction.y != 0:
(cl_e1,d_e1) = self.intersect_cylinder_edge(direction, triangle.e1) (cl_p1,d_p1) = self.intersect_cylinder_vertex(direction, triangle.p1)
(cl_e2,d_e2) = self.intersect_cylinder_edge(direction, triangle.e2) (cl_p2,d_p2) = self.intersect_cylinder_vertex(direction, triangle.p2)
(cl_e3,d_e3) = self.intersect_cylinder_edge(direction, triangle.e3) (cl_p3,d_p3) = self.intersect_cylinder_vertex(direction, triangle.p3)
if d_p1 < d: if d_p1 < d:
d = d_p1 d = d_p1
cl = cl_p1 cl = cl_p1
...@@ -163,11 +163,9 @@ class CylindricalCutter(BaseCutter): ...@@ -163,11 +163,9 @@ class CylindricalCutter(BaseCutter):
if d_p3 < d: if d_p3 < d:
d = d_p3 d = d_p3
cl = cl_p3 cl = cl_p3
if cl: (cl_e1,d_e1) = self.intersect_cylinder_edge(direction, triangle.e1)
return (cl,d) (cl_e2,d_e2) = self.intersect_cylinder_edge(direction, triangle.e2)
(cl_p1,d_p1) = self.intersect_cylinder_vertex(direction, triangle.p1) (cl_e3,d_e3) = self.intersect_cylinder_edge(direction, triangle.e3)
(cl_p2,d_p2) = self.intersect_cylinder_vertex(direction, triangle.p2)
(cl_p3,d_p3) = self.intersect_cylinder_vertex(direction, triangle.p3)
if d_e1 < d: if d_e1 < d:
d = d_e1 d = d_e1
cl = cl_e1 cl = cl_e1
......
...@@ -122,7 +122,7 @@ class SphericalCutter(BaseCutter): ...@@ -122,7 +122,7 @@ class SphericalCutter(BaseCutter):
if d_t < d: if d_t < d:
d = d_t d = d_t
cl = cl_t cl = cl_t
if cl: if cl and direction.x==0 and direction.y==0:
return (cl,d) return (cl,d)
(cl_e1,d_e1) = self.intersect_sphere_edge(direction, triangle.e1) (cl_e1,d_e1) = self.intersect_sphere_edge(direction, triangle.e1)
(cl_e2,d_e2) = self.intersect_sphere_edge(direction, triangle.e2) (cl_e2,d_e2) = self.intersect_sphere_edge(direction, triangle.e2)
...@@ -136,7 +136,7 @@ class SphericalCutter(BaseCutter): ...@@ -136,7 +136,7 @@ class SphericalCutter(BaseCutter):
if d_e3 < d: if d_e3 < d:
d = d_e3 d = d_e3
cl = cl_e3 cl = cl_e3
if cl: if cl and direction.x==0 and direction.y==0:
return (cl,d) return (cl,d)
(cl_p1,d_p1) = self.intersect_sphere_vertex(direction, triangle.p1) (cl_p1,d_p1) = self.intersect_sphere_vertex(direction, triangle.p1)
(cl_p2,d_p2) = self.intersect_sphere_vertex(direction, triangle.p2) (cl_p2,d_p2) = self.intersect_sphere_vertex(direction, triangle.p2)
...@@ -150,12 +150,12 @@ class SphericalCutter(BaseCutter): ...@@ -150,12 +150,12 @@ class SphericalCutter(BaseCutter):
if d_p3 < d: if d_p3 < d:
d = d_p3 d = d_p3
cl = cl_p3 cl = cl_p3
if cl: if cl and direction.x==0 and direction.y==0:
return (cl,d) return (cl,d)
if direction.x != 0 or direction.y != 0: if direction.x != 0 or direction.y != 0:
(cl_e1,d_e1) = self.intersect_cylinder_edge(direction, triangle.e1) (cl_p1,d_p1) = self.intersect_cylinder_vertex(direction, triangle.p1)
(cl_e2,d_e2) = self.intersect_cylinder_edge(direction, triangle.e2) (cl_p2,d_p2) = self.intersect_cylinder_vertex(direction, triangle.p2)
(cl_e3,d_e3) = self.intersect_cylinder_edge(direction, triangle.e3) (cl_p3,d_p3) = self.intersect_cylinder_vertex(direction, triangle.p3)
if d_p1 < d: if d_p1 < d:
d = d_p1 d = d_p1
cl = cl_p1 cl = cl_p1
...@@ -165,11 +165,9 @@ class SphericalCutter(BaseCutter): ...@@ -165,11 +165,9 @@ class SphericalCutter(BaseCutter):
if d_p3 < d: if d_p3 < d:
d = d_p3 d = d_p3
cl = cl_p3 cl = cl_p3
if cl: (cl_e1,d_e1) = self.intersect_cylinder_edge(direction, triangle.e1)
return (cl,d) (cl_e2,d_e2) = self.intersect_cylinder_edge(direction, triangle.e2)
(cl_p1,d_p1) = self.intersect_cylinder_vertex(direction, triangle.p1) (cl_e3,d_e3) = self.intersect_cylinder_edge(direction, triangle.e3)
(cl_p2,d_p2) = self.intersect_cylinder_vertex(direction, triangle.p2)
(cl_p3,d_p3) = self.intersect_cylinder_vertex(direction, triangle.p3)
if d_e1 < d: if d_e1 < d:
d = d_e1 d = d_e1
cl = cl_e1 cl = cl_e1
......
...@@ -186,8 +186,6 @@ class ToroidalCutter(BaseCutter): ...@@ -186,8 +186,6 @@ class ToroidalCutter(BaseCutter):
if d_t < d: if d_t < d:
d = d_t d = d_t
cl = cl_t cl = cl_t
if cl:
return (cl,d)
(cl_e1,d_e1) = self.intersect_torus_edge(direction, triangle.e1) (cl_e1,d_e1) = self.intersect_torus_edge(direction, triangle.e1)
(cl_e2,d_e2) = self.intersect_torus_edge(direction, triangle.e2) (cl_e2,d_e2) = self.intersect_torus_edge(direction, triangle.e2)
(cl_e3,d_e3) = self.intersect_torus_edge(direction, triangle.e3) (cl_e3,d_e3) = self.intersect_torus_edge(direction, triangle.e3)
...@@ -200,8 +198,6 @@ class ToroidalCutter(BaseCutter): ...@@ -200,8 +198,6 @@ class ToroidalCutter(BaseCutter):
if d_e3 < d: if d_e3 < d:
d = d_e3 d = d_e3
cl = cl_e3 cl = cl_e3
if cl:
return (cl,d)
(cl_p1,d_p1) = self.intersect_torus_vertex(direction, triangle.p1) (cl_p1,d_p1) = self.intersect_torus_vertex(direction, triangle.p1)
(cl_p2,d_p2) = self.intersect_torus_vertex(direction, triangle.p2) (cl_p2,d_p2) = self.intersect_torus_vertex(direction, triangle.p2)
(cl_p3,d_p3) = self.intersect_torus_vertex(direction, triangle.p3) (cl_p3,d_p3) = self.intersect_torus_vertex(direction, triangle.p3)
...@@ -214,18 +210,13 @@ class ToroidalCutter(BaseCutter): ...@@ -214,18 +210,13 @@ class ToroidalCutter(BaseCutter):
if d_p3 < d: if d_p3 < d:
d = d_p3 d = d_p3
cl = cl_p3 cl = cl_p3
if cl:
return (cl,d)
(cl_t,d_t) = self.intersect_circle_triangle(direction, triangle) (cl_t,d_t) = self.intersect_circle_triangle(direction, triangle)
(cl_p1,d_p1) = self.intersect_circle_vertex(direction, triangle.p1)
(cl_p2,d_p2) = self.intersect_circle_vertex(direction, triangle.p2)
(cl_p3,d_p3) = self.intersect_circle_vertex(direction, triangle.p3)
(cl_e1,d_e1) = self.intersect_circle_edge(direction, triangle.e1)
(cl_e2,d_e2) = self.intersect_circle_edge(direction, triangle.e2)
(cl_e3,d_e3) = self.intersect_circle_edge(direction, triangle.e3)
if d_t < d: if d_t < d:
d = d_t d = d_t
cl = cl_t cl = cl_t
(cl_p1,d_p1) = self.intersect_circle_vertex(direction, triangle.p1)
(cl_p2,d_p2) = self.intersect_circle_vertex(direction, triangle.p2)
(cl_p3,d_p3) = self.intersect_circle_vertex(direction, triangle.p3)
if d_p1 < d: if d_p1 < d:
d = d_p1 d = d_p1
cl = cl_p1 cl = cl_p1
...@@ -235,6 +226,9 @@ class ToroidalCutter(BaseCutter): ...@@ -235,6 +226,9 @@ class ToroidalCutter(BaseCutter):
if d_p3 < d: if d_p3 < d:
d = d_p3 d = d_p3
cl = cl_p3 cl = cl_p3
(cl_e1,d_e1) = self.intersect_circle_edge(direction, triangle.e1)
(cl_e2,d_e2) = self.intersect_circle_edge(direction, triangle.e2)
(cl_e3,d_e3) = self.intersect_circle_edge(direction, triangle.e3)
if d_e1 < d: if d_e1 < d:
d = d_e1 d = d_e1
cl = cl_e1 cl = cl_e1
...@@ -248,9 +242,6 @@ class ToroidalCutter(BaseCutter): ...@@ -248,9 +242,6 @@ class ToroidalCutter(BaseCutter):
(cl_p1,d_p1) = self.intersect_cylinder_vertex(direction, triangle.p1) (cl_p1,d_p1) = self.intersect_cylinder_vertex(direction, triangle.p1)
(cl_p2,d_p2) = self.intersect_cylinder_vertex(direction, triangle.p2) (cl_p2,d_p2) = self.intersect_cylinder_vertex(direction, triangle.p2)
(cl_p3,d_p3) = self.intersect_cylinder_vertex(direction, triangle.p3) (cl_p3,d_p3) = self.intersect_cylinder_vertex(direction, triangle.p3)
(cl_e1,d_e1) = self.intersect_cylinder_edge(direction, triangle.e1)
(cl_e2,d_e2) = self.intersect_cylinder_edge(direction, triangle.e2)
(cl_e3,d_e3) = self.intersect_cylinder_edge(direction, triangle.e3)
if d_p1 < d: if d_p1 < d:
d = d_p1 d = d_p1
cl = cl_p1 cl = cl_p1
...@@ -260,6 +251,9 @@ class ToroidalCutter(BaseCutter): ...@@ -260,6 +251,9 @@ class ToroidalCutter(BaseCutter):
if d_p3 < d: if d_p3 < d:
d = d_p3 d = d_p3
cl = cl_p3 cl = cl_p3
(cl_e1,d_e1) = self.intersect_cylinder_edge(direction, triangle.e1)
(cl_e2,d_e2) = self.intersect_cylinder_edge(direction, triangle.e2)
(cl_e3,d_e3) = self.intersect_cylinder_edge(direction, triangle.e3)
if d_e1 < d: if d_e1 < d:
d = d_e1 d = d_e1
cl = cl_e1 cl = cl_e1
......
...@@ -43,7 +43,7 @@ def UniqueEdge(p1, p2): ...@@ -43,7 +43,7 @@ def UniqueEdge(p1, p2):
return e return e
def ImportModel(filename): def ImportModel(filename, use_kdtree=True):
global vertices, edges, kdtree global vertices, edges, kdtree
vertices = 0 vertices = 0
edges = 0 edges = 0
...@@ -60,6 +60,7 @@ def ImportModel(filename): ...@@ -60,6 +60,7 @@ def ImportModel(filename):
endloop = re.compile("\s*endloop\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+") 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+")
if use_kdtree:
kdtree = PointKdtree([],3,1,epsilon) kdtree = PointKdtree([],3,1,epsilon)
model = Model() model = Model()
...@@ -127,6 +128,7 @@ def ImportModel(filename): ...@@ -127,6 +128,7 @@ def ImportModel(filename):
if m: if m:
continue continue
if use_kdtree:
model.p_kdtree = kdtree model.p_kdtree = kdtree
model.t_kdtree = TriangleKdtree(model.triangles()) model.t_kdtree = TriangleKdtree(model.triangles())
......
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