Exemplo n.º 1
0
    def closest_curve_to_point(self, point, curve_list):

        min_dist = 999999

        for i, c in enumerate(curve_list):
            dist = sliceMath.three_d_distance(point, c.seam)
            if min_dist > dist: min_dist, min_i = dist, i

        return i
Exemplo n.º 2
0
    def closest_point_from_points(self, point, point_list):
        """finds closest point from list of point
        """
        min_dist = 99999

        for i, p in enumerate(point_list):
            # dist = self.two_d_distance(p, point)
            dist = sliceMath.three_d_distance(p, point)
            if min_dist > dist:
                min_dist, min_p, min_i = dist, p, i

        return min_p, min_dist
Exemplo n.º 3
0
    def closest_point_from_curve(self, curve, point_list):
        """finds closest point from curve
        """
        min_dist = 99999
        # print min_p

        for p in point_list:
            _, domain = curve.ClosestPoint(p)
            point = curve.PointAt(domain)
            dist = sliceMath.three_d_distance(p, point)
            if min_dist > dist:
                min_dist = dist
                min_p = p

        return min_p, min_dist
Exemplo n.º 4
0
    def shift_seam(self, slice_curve, target_point, shift_ratio=0.01, loops=3):
        """shifts seam of curve towards desired point
        """
        length = slice_curve.curve.GetLength()
        shift = shift_ratio / length
        seam_bool = True
        tuple_list = []

        for i in range(-loops, loops + 1):
            point = slice_curve.curve.PointAt(shift * i)
            dist = sliceMath.three_d_distance(point, target_point)
            tuple_list.append((dist, point, shift * i))

        sorted_list = sorted(tuple_list, key=lambda tup: tup[0])
        seam_point, seam_domain = sorted_list[0][1], sorted_list[0][2]

        seam_success = slice_curve.curve.ChangeClosedCurveSeam(seam_domain)
        set_domain = rg.Interval(0, 1)
        slice_curve.curve.Domain = set_domain
        slice_curve.SCurve = slice_curve.curve
        return seam_success, seam_point
Exemplo n.º 5
0
    def shortest_path_two(self, slice_curves, max_branch_diff=10):
        """finds the shortest path based on max_branch_diff
        """
        slice_curves = self.join_close_curves(slice_curves, 10)

        buffer = 10
        max_list_len = len(slice_curves)
        shortest_path_list = []
        loop_slice = slice_curves[0]
        count_a = 0

        while True:

            # if len(shortest_path_list) >= max_list_len-1: break
            if count_a >= max_list_len - 1: break

            index_list, loop_index = [], []
            slice_curves_dup = slice_curves[:]
            count_b = 0

            for i, slice_curve in enumerate(slice_curves):
                if count_b == max_branch_diff:
                    if len(loop_index) == 0:
                        loop_slice = shortest_path_list[-1]
                        # print shortest_path_list[-1]
                    else:
                        loop_slice = slice_curves[loop_index[0]]
                    trans_p_a = rg.Point3d(shortest_path_list[-1].seam[0],
                                           shortest_path_list[-1].seam[1],
                                           shortest_path_list[-1].seam[2] + 15)
                    trans_p_b = rg.Point3d(loop_slice.seam[0],
                                           loop_slice.seam[1],
                                           loop_slice.seam[2] + 15)
                    trans_curve = rg.PolylineCurve([trans_p_a, trans_p_b])
                    slice_curve_trans = SliceCurve(trans_curve,
                                                   self.line_definition, False)
                    slice_curve_trans.transition_curve = True
                    for f in slice_curve_trans.frames:
                        f.cantiliver = 0
                        f.transition = True
                    shortest_path_list.append(slice_curve_trans)
                    break

                if i == 0: compare_slice = loop_slice
                else: compare_slice = shortest_path_list[-1]

                dist = max(
                    sliceMath.three_d_distance(slice_curve.center,
                                               compare_slice.center),
                    sliceMath.three_d_distance(slice_curve.seam,
                                               compare_slice.seam))

                # if dist<buffer and abs(slice_curve.area-compare_slice.area)<2000 and abs(slice_curve.seam[2]-compare_slice.seam[2])<self.layer_height*1.1:
                if dist < buffer and abs(slice_curve.seam[2] - compare_slice.
                                         seam[2]) < self.layer_height * 1.1:

                    # slice_curve.pop_last_point()
                    # if count != 0:slice_curve.frames.pop(0)
                    # else:slice_curve.frames.pop(-1)
                    shortest_path_list.append(slice_curve)
                    count_a += 1
                    index_list.append(i)
                    count_b += 1

                else:
                    loop_index.append(i)

            if len(loop_index) == 0: loop_slice = shortest_path_list[-1]
            else: loop_slice = slice_curves[loop_index[0]]

            if len(index_list) == 0:
                shortest_path_list.append(slice_curves[0])
                count_a += 1

            slice_curves_dup = [
                i for j, i in enumerate(slice_curves_dup)
                if j not in index_list
            ]
            slice_curves = slice_curves_dup[:]

        return shortest_path_list