Commit 59f31c22 authored by sumpfralle's avatar sumpfralle

simplify all generated toolpath to avoid multiple points on a straight line

(this avoids a severe slow-down of the machine in case of too many small steps)


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@526 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent b19845dd
...@@ -21,6 +21,7 @@ along with PyCAM. If not, see <http://www.gnu.org/licenses/>. ...@@ -21,6 +21,7 @@ along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
""" """
from pycam.Geometry.PolygonExtractor import PolygonExtractor from pycam.Geometry.PolygonExtractor import PolygonExtractor
from pycam.Toolpath import simplify_toolpath
class ContourCutter: class ContourCutter:
def __init__(self): def __init__(self):
...@@ -62,6 +63,7 @@ class ContourCutter: ...@@ -62,6 +63,7 @@ class ContourCutter:
if paths: if paths:
for p in paths: for p in paths:
p.append(p.points[0]) p.append(p.points[0])
simplify_toolpath(p)
if paths: if paths:
self.paths.extend(paths) self.paths.extend(paths)
self.pe = None self.pe = None
......
...@@ -21,15 +21,9 @@ You should have received a copy of the GNU General Public License ...@@ -21,15 +21,9 @@ You should have received a copy of the GNU General Public License
along with PyCAM. If not, see <http://www.gnu.org/licenses/>. along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
""" """
from pycam.Toolpath import simplify_toolpath
from pycam.Geometry.Path import Path from pycam.Geometry.Path import Path
def _check_colinearity(p1, p2, p3):
v1 = p2.sub(p1)
v2 = p3.sub(p2)
v1.normalize()
v2.normalize()
# compare if the normalized distances between p1-p2 and p2-p3 are equal
return v1 == v2
class PathAccumulator: class PathAccumulator:
def __init__(self, zigzag=False): def __init__(self, zigzag=False):
...@@ -41,12 +35,6 @@ class PathAccumulator: ...@@ -41,12 +35,6 @@ class PathAccumulator:
def append(self, p): def append(self, p):
if self.curr_path == None: if self.curr_path == None:
self.curr_path = Path() self.curr_path = Path()
if (len(self.curr_path.points) >= 2) and \
(_check_colinearity(self.curr_path.points[-2],
self.curr_path.points[-1], p)):
# remove the previous point since it is in line with its
# predecessor and the new point
self.curr_path.points.pop()
self.curr_path.append(p) self.curr_path.append(p)
def new_direction(self, direction): def new_direction(self, direction):
...@@ -63,10 +51,12 @@ class PathAccumulator: ...@@ -63,10 +51,12 @@ class PathAccumulator:
def end_scanline(self): def end_scanline(self):
if self.curr_path: if self.curr_path:
if self.zigzag and (self.scanline%2 == 0): if self.zigzag and (self.scanline % 2 == 0):
self.curr_path.reverse() self.curr_path.reverse()
simplify_toolpath(self.curr_path)
self.paths.append(self.curr_path) self.paths.append(self.curr_path)
self.curr_path = None self.curr_path = None
def finish(self): def finish(self):
pass pass
...@@ -23,6 +23,7 @@ along with PyCAM. If not, see <http://www.gnu.org/licenses/>. ...@@ -23,6 +23,7 @@ along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
from pycam.Geometry.Path import Path from pycam.Geometry.Path import Path
from pycam.Geometry.PolygonExtractor import PolygonExtractor from pycam.Geometry.PolygonExtractor import PolygonExtractor
from pycam.Toolpath import simplify_toolpath
class PolygonCutter: class PolygonCutter:
...@@ -67,5 +68,7 @@ class PolygonCutter: ...@@ -67,5 +68,7 @@ class PolygonCutter:
p.append(points[i]) p.append(points[i])
paths.append(p) paths.append(p)
if paths: if paths:
for p in paths:
simplify_toolpath(p)
self.paths.extend(paths) self.paths.extend(paths)
...@@ -21,6 +21,7 @@ along with PyCAM. If not, see <http://www.gnu.org/licenses/>. ...@@ -21,6 +21,7 @@ along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
""" """
from pycam.Geometry.Path import Path from pycam.Geometry.Path import Path
from pycam.Toolpath import simplify_toolpath
class SimpleCutter: class SimpleCutter:
def __init__(self): def __init__(self):
...@@ -37,6 +38,7 @@ class SimpleCutter: ...@@ -37,6 +38,7 @@ class SimpleCutter:
self.curr_path = None self.curr_path = None
curr_path.append(p) curr_path.append(p)
if self.curr_path == None: if self.curr_path == None:
simplify_toolpath(curr_path)
self.paths.append(curr_path) self.paths.append(curr_path)
def new_direction(self, direction): def new_direction(self, direction):
......
...@@ -21,6 +21,7 @@ along with PyCAM. If not, see <http://www.gnu.org/licenses/>. ...@@ -21,6 +21,7 @@ along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
""" """
from pycam.Geometry.Path import Path from pycam.Geometry.Path import Path
from pycam.Toolpath import simplify_toolpath
class ZigZagCutter: class ZigZagCutter:
def __init__(self): def __init__(self):
...@@ -58,7 +59,9 @@ class ZigZagCutter: ...@@ -58,7 +59,9 @@ class ZigZagCutter:
self.curr_scanline = [] self.curr_scanline = []
def end_scanline(self): def end_scanline(self):
self.paths += self.curr_scanline for path in self.curr_scanline:
simplify_toolpath(path)
self.paths.append(path)
self.curr_scanline = None self.curr_scanline = None
def finish(self): def finish(self):
......
...@@ -20,7 +20,7 @@ You should have received a copy of the GNU General Public License ...@@ -20,7 +20,7 @@ You should have received a copy of the GNU General Public License
along with PyCAM. If not, see <http://www.gnu.org/licenses/>. along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
""" """
__all__ = ["ToolPathList", "ToolPath", "Generator"] __all__ = ["simplify_toolpath", "ToolPathList", "ToolPath", "Generator"]
from pycam.Geometry.Point import Point from pycam.Geometry.Point import Point
import pycam.Utils.log import pycam.Utils.log
...@@ -29,6 +29,36 @@ import os ...@@ -29,6 +29,36 @@ import os
log = pycam.Utils.log.get_logger() log = pycam.Utils.log.get_logger()
def _check_colinearity(p1, p2, p3):
v1 = p2.sub(p1)
v2 = p3.sub(p2)
v1.normalize()
v2.normalize()
# compare if the normalized distances between p1-p2 and p2-p3 are equal
return v1 == v2
def simplify_toolpath(path):
""" remove multiple points in a line from a toolpath
If A, B, C and D are on a straight line, then B and C will be removed.
This reduces memory consumption and avoids a severe slow-down of the machine
when moving along very small steps.
The toolpath is simplified _in_place_.
@value path: a single separate segment of a toolpath
@type path: pycam.Geometry.Path.Path
"""
index = 1
points = path.points
while index < len(points) - 1:
if _check_colinearity(points[index-1], points[index], points[index+1]):
points.pop(index)
# don't increase the counter - otherwise we skip one point
else:
index += 1
class ToolPathList(list): class ToolPathList(list):
def add_toolpath(self, toolpath, name, toolpath_settings): def add_toolpath(self, toolpath, name, toolpath_settings):
......
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