Commit cfa6bfb7 authored by sumpfralle's avatar sumpfralle

renamed "LineGroup" to "Polygon"

switch from line-based polygon to point-based approach


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@562 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent 263a23f0
This diff is collapsed.
...@@ -23,7 +23,8 @@ along with PyCAM. If not, see <http://www.gnu.org/licenses/>. ...@@ -23,7 +23,8 @@ along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
import pycam.Exporters.STLExporter import pycam.Exporters.STLExporter
from pycam.Geometry.Triangle import Triangle from pycam.Geometry.Triangle import Triangle
from pycam.Geometry.Line import Line, LineGroup from pycam.Geometry.Line import Line
from pycam.Geometry.Polygon import Polygon
from pycam.Geometry.Point import Point from pycam.Geometry.Point import Point
from pycam.Geometry.TriangleKdtree import TriangleKdtree from pycam.Geometry.TriangleKdtree import TriangleKdtree
from pycam.Geometry.Matrix import TRANSFORMATIONS from pycam.Geometry.Matrix import TRANSFORMATIONS
...@@ -229,25 +230,25 @@ class ContourModel(BaseModel): ...@@ -229,25 +230,25 @@ class ContourModel(BaseModel):
break break
else: else:
# add a single line as part of a new group # add a single line as part of a new group
new_line_group = LineGroup() new_line_group = Polygon()
new_line_group.append(item) new_line_group.append(item)
self._line_groups.append(new_line_group) self._line_groups.append(new_line_group)
elif isinstance(item, LineGroup): elif isinstance(item, Polygon):
self._line_groups.append(item) self._line_groups.append(item)
else: else:
# ignore any non-supported items # ignore any non-supported items
pass pass
def get_lines(self): def get_num_of_lines(self):
return sum([group.get_lines() for group in self._line_groups], []) return sum([len(group) for group in self._line_groups])
def get_line_groups(self): def get_polygons(self):
return self._line_groups return self._line_groups
def get_cropped_model(self, minx, maxx, miny, maxy, minz, maxz): def get_cropped_model(self, minx, maxx, miny, maxy, minz, maxz):
new_line_groups = [] new_line_groups = []
for group in self._line_groups: for group in self._line_groups:
new_groups = group.get_cropped_line_groups(minx, maxx, miny, maxy, new_groups = group.get_cropped_polygons(minx, maxx, miny, maxy,
minz, maxz) minz, maxz)
if not new_groups is None: if not new_groups is None:
new_line_groups.extend(new_groups) new_line_groups.extend(new_groups)
...@@ -277,7 +278,7 @@ class ContourModel(BaseModel): ...@@ -277,7 +278,7 @@ class ContourModel(BaseModel):
return self._cached_offset_models[offset] return self._cached_offset_models[offset]
result = ContourModel() result = ContourModel()
for group in self._line_groups: for group in self._line_groups:
new_groups = group.get_offset_line_groups(offset) new_groups = group.get_offset_polygons(offset)
if not new_groups is None: if not new_groups is None:
for new_group in new_groups: for new_group in new_groups:
result.append(new_group) result.append(new_group)
...@@ -320,8 +321,8 @@ class ContourModel(BaseModel): ...@@ -320,8 +321,8 @@ class ContourModel(BaseModel):
# check if both groups overlap - otherwise skip this pair # check if both groups overlap - otherwise skip this pair
if check_bounds_of_groups(group1, group2): if check_bounds_of_groups(group1, group2):
# check each pair of lines for intersections # check each pair of lines for intersections
for line1 in group1.next(): for line1 in group1.get_lines():
for line2 in group2.next(): for line2 in group2.get_lines():
intersection, factor = line1.get_intersection(line2) intersection, factor = line1.get_intersection(line2)
if intersection: if intersection:
# return just the place of intersection # return just the place of intersection
......
...@@ -20,10 +20,11 @@ You should have received a copy of the GNU General Public License ...@@ -20,10 +20,11 @@ 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.Geometry import TransformableContainer
from pycam.Geometry.utils import INFINITE from pycam.Geometry.utils import INFINITE
from pycam.Geometry.Point import Point from pycam.Geometry.Point import Point
class Plane: class Plane(TransformableContainer):
id = 0 id = 0
def __init__(self, p, n): def __init__(self, p, n):
self.id = Plane.id self.id = Plane.id
...@@ -34,6 +35,18 @@ class Plane: ...@@ -34,6 +35,18 @@ class Plane:
def __repr__(self): def __repr__(self):
return "Plane<%s,%s>" % (self.p, self.n) return "Plane<%s,%s>" % (self.p, self.n)
def next(self):
yield self.p
yield self.n
def get_children_count(self):
# a plane always consists of two points
return 2
def reset_cache():
# nothing to be done (but required for TransformableContainer)
pass
def intersect_point(self, direction, point): def intersect_point(self, direction, point):
if direction.norm != 1: if direction.norm != 1:
# calculations will go wrong, if the direction is not a unit vector # calculations will go wrong, if the direction is not a unit vector
......
This diff is collapsed.
...@@ -23,7 +23,7 @@ along with PyCAM. If not, see <http://www.gnu.org/licenses/>. ...@@ -23,7 +23,7 @@ along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
__all__ = ["utils", "Line", "Model", "Path", "Plane", "Point", "Triangle", __all__ = ["utils", "Line", "Model", "Path", "Plane", "Point", "Triangle",
"PolygonExtractor", "TriangleKdtree", "intersection", "kdtree", "PolygonExtractor", "TriangleKdtree", "intersection", "kdtree",
"Matrix"] "Matrix", "Polygon"]
class TransformableContainer(object): class TransformableContainer(object):
......
...@@ -63,11 +63,11 @@ class EngraveCutter: ...@@ -63,11 +63,11 @@ class EngraveCutter:
num_of_layers = len(z_steps) num_of_layers = len(z_steps)
current_layer = 0 current_layer = 0
num_of_lines = len(self.contour_model.get_lines()) num_of_lines = self.contour_model.get_num_of_lines()
progress_counter = ProgressCounter(len(z_steps) * num_of_lines, progress_counter = ProgressCounter(len(z_steps) * num_of_lines,
draw_callback) draw_callback)
line_groups = self.contour_model.get_line_groups() line_groups = self.contour_model.get_polygons()
# push slices for all layers above ground # push slices for all layers above ground
for z in z_steps[:-1]: for z in z_steps[:-1]:
...@@ -104,7 +104,7 @@ class EngraveCutter: ...@@ -104,7 +104,7 @@ class EngraveCutter:
% (current_layer, num_of_layers)) % (current_layer, num_of_layers))
# process the final layer with a drop cutter # process the final layer with a drop cutter
for line_group in self.contour_model.get_line_groups(): for line_group in self.contour_model.get_polygons():
self.pa_drop.new_direction(0) self.pa_drop.new_direction(0)
self.pa_drop.new_scanline() self.pa_drop.new_scanline()
for line in line_group.get_lines(): for line in line_group.get_lines():
...@@ -148,7 +148,7 @@ class EngraveCutter: ...@@ -148,7 +148,7 @@ class EngraveCutter:
pa.new_scanline() pa.new_scanline()
p1 = Point(line.p1.x, line.p1.y, minz) p1 = Point(line.p1.x, line.p1.y, minz)
p2 = Point(line.p2.x, line.p2.y, minz) p2 = Point(line.p2.x, line.p2.y, minz)
distance = line.len() distance = line.len
# we want to have at least five steps each # we want to have at least five steps each
num_of_steps = max(5, 1 + int(math.ceil(distance / horiz_step))) num_of_steps = max(5, 1 + int(math.ceil(distance / horiz_step)))
# steps may be negative # steps may be negative
......
...@@ -255,11 +255,11 @@ def get_max_height_triangles(model, cutter, x, y, minz, maxz, order=None, ...@@ -255,11 +255,11 @@ def get_max_height_triangles(model, cutter, x, y, minz, maxz, order=None,
# TODO: check if this path is ever in use (e.g. "intersect_lines" is not # TODO: check if this path is ever in use (e.g. "intersect_lines" is not
# defined) # defined)
nl = range(3) nl = range(3)
nl[0] = -getattr(last_pos["triangle"].normal(), order[0]) nl[0] = -getattr(last_pos["triangle"].normal, order[0])
nl[2] = last_pos["triangle"].normal().z nl[2] = last_pos["triangle"].normal.z
nm = range(3) nm = range(3)
nm[0] = -getattr(triangle_max.normal(), order[0]) nm[0] = -getattr(triangle_max.normal, order[0])
nm[2] = triangle_max.normal().z nm[2] = triangle_max.normal.z
last = range(3) last = range(3)
last[0] = getattr(last_pos["cut"], order[0]) last[0] = getattr(last_pos["cut"], order[0])
last[2] = last_pos["cut"].z last[2] = last_pos["cut"].z
......
...@@ -169,7 +169,7 @@ def generate_toolpath(model, tool_settings=None, ...@@ -169,7 +169,7 @@ def generate_toolpath(model, tool_settings=None,
if not callback is None: if not callback is None:
callback(text="Preparing contour model with offset ...") callback(text="Preparing contour model with offset ...")
progress_callback = ProgressCounter( progress_callback = ProgressCounter(
len(contour_model.get_line_groups()), callback).increment len(contour_model.get_polygons()), callback).increment
else: else:
progress_callback = None progress_callback = None
contour_model = contour_model.get_offset_model(engrave_offset, contour_model = contour_model.get_offset_model(engrave_offset,
...@@ -182,7 +182,7 @@ def generate_toolpath(model, tool_settings=None, ...@@ -182,7 +182,7 @@ def generate_toolpath(model, tool_settings=None,
# quit requested # quit requested
return None return None
progress_callback = ProgressCounter( progress_callback = ProgressCounter(
len(contour_model.get_line_groups()), callback).increment len(contour_model.get_polygons()), callback).increment
else: else:
progress_callback = None progress_callback = None
result = contour_model.check_for_collisions(callback=progress_callback) result = contour_model.check_for_collisions(callback=progress_callback)
......
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