Esempio n. 1
0
    def GenerateToolPath(self, callback=None):
        triangles = self.model.triangles()
        equations = {}

        # patching Point
        Point.__hash__ = lambda self: hash(' '.join(
            [str(self.x), str(self.y), str(self.z)]))
        Point.__eq__ = lambda self, other : _is_near(self.x, other.x) \
                                        and _is_near(self.y, other.y) \
                                        and _is_near(self.z, other.z)

        #patching Line
        def equation2D(x1, y1, x2, y2):
            if abs(x1 - x2) < epsilon:  # care of floating-point imprecision
                return "x=%s" % x1
            else:
                a = (y2 - y1) / (x2 - x1)
                return "y=%sx+%s" % (a, y2 - a * x2)
        Line.__hash__ = lambda self : hash(' '.join([
                equation2D(self.p1.x, self.p1.y, self.p2.x, self.p2.y), \
                equation2D(self.p1.x, self.p1.z, self.p2.x, self.p2.z), \
                equation2D(self.p1.y, self.p1.z, self.p2.y, self.p2.z)]))
        Line.__eq__ = lambda self, other: hash(self) == hash(other)

        for height in self.grid.iterate_on_layers():
            equations.clear()
            planeInf = Plane(Point(0, 0, height), self.grid.up_vector)
            planeSup = Plane(Point(0, 0, INFINITE), self.grid.up_vector)
            lines = [ligne for triangle in triangles for ligne in \
                self.triangleBetweenTwoPlanes(triangle, planeInf, planeSup)]
            for line in lines:
                if line not in equations:
                    equations[line] = [line]
                else:
                    equations[line].append(line)
            to_project = []
            for equation in iter(equations):
                lines = equations[equation]
                uniques = self.mergeRiddanceLines(lines)
                to_project.extend(uniques)
            for line in to_project:
                projection = planeInf.get_line_projection(line)
                self.grid.discretise_line(projection)
            #self.grid.display_complete_layer(height)
        #self.grid.draw_contour_PBM()
        self.pa.initialise(self.grid)
        self.pa.do_path()
        self.grid.free()
        del self.grid
        return self.pa.paths
Esempio n. 2
0
    def GenerateToolPath(self, callback=None) :
        triangles = self.model.triangles()
        equations = {}

        # patching Point
        Point.__hash__ = lambda self : hash(' '.join(
                                [str(self.x), str(self.y), str(self.z)]))
        Point.__eq__ = lambda self, other : _is_near(self.x, other.x) \
                                        and _is_near(self.y, other.y) \
                                        and _is_near(self.z, other.z)

        #patching Line
        def equation2D(x1, y1, x2, y2):
            if abs(x1 - x2) < epsilon : # care of floating-point imprecision
                return "x=%s" % x1
            else:
                a = (y2-y1)/(x2-x1)
                return "y=%sx+%s" % (a, y2-a*x2)
        Line.__hash__ = lambda self : hash(' '.join([
                equation2D(self.p1.x, self.p1.y, self.p2.x, self.p2.y), \
                equation2D(self.p1.x, self.p1.z, self.p2.x, self.p2.z), \
                equation2D(self.p1.y, self.p1.z, self.p2.y, self.p2.z)]))
        Line.__eq__ = lambda self, other : hash(self) == hash(other)

        for height in self.grid.iterate_on_layers() :
            equations.clear()
            planeInf = Plane(Point(0, 0, height), self.grid.up_vector)
            planeSup = Plane(Point(0, 0, INFINITE), self.grid.up_vector)
            lines = [ligne for triangle in triangles for ligne in \
                self.triangleBetweenTwoPlanes(triangle, planeInf, planeSup)]
            for line in lines :
                if line not in equations :
                    equations[line] = [line]
                else :
                    equations[line].append(line)
            to_project = []
            for equation in iter(equations) :
                lines = equations[equation]
                uniques = self.mergeRiddanceLines(lines)
                to_project.extend(uniques)
            for line in to_project :
                projection = planeInf.get_line_projection(line)
                self.grid.discretise_line(projection)
            #self.grid.display_complete_layer(height)
        #self.grid.draw_contour_PBM()
        self.pa.initialise(self.grid)
        self.pa.do_path()
        self.grid.free()
        del self.grid
        return self.pa.paths
Esempio n. 3
0
def get_shifted_waterline(up_vector, waterline, cutter_location):
    # Project the waterline and the cutter location down to the slice plane.
    # This is necessary for calculating the horizontal distance between the
    # cutter and the triangle waterline.
    plane = Plane(cutter_location, up_vector)
    wl_proj = plane.get_line_projection(waterline)
    if wl_proj.len < epsilon:
        return None
    offset = wl_proj.dist_to_point(cutter_location)
    if offset < epsilon:
        return wl_proj
    # shift both ends of the waterline towards the cutter location
    shift = cutter_location.sub(wl_proj.closest_point(cutter_location))
    # increase the shift width slightly to avoid "touch" collisions
    shift = shift.mul(1.0 + epsilon)
    shifted_waterline = Line(wl_proj.p1.add(shift), wl_proj.p2.add(shift))
    return shifted_waterline