Ejemplo n.º 1
0
    def test_blend_third(self):
        p0 = np.array([0, 0, 0])
        p1 = np.array([3, 0, 0])
        v0 = np.array([3, 3, 0])
        v1 = np.array([3, 3, 0])
        a0 = np.array([0, 0, 1])
        a1 = np.array([0, 0, 1])
        k0 = np.array([1, 1, 0])
        k1 = np.array([1, 1, 0])
        curve = SvBezierCurve.blend_third_derivatives(p0, v0, a0, k0, p1, v1, a1, k1)

        v0r = curve.tangent(0)
        v1r = curve.tangent(1)

        a0r = curve.second_derivative(0)
        a1r = curve.second_derivative(1)

        k0r = curve.third_derivative_array(np.array([0]))[0]
        k1r = curve.third_derivative_array(np.array([1]))[0]

        self.assert_numpy_arrays_equal(v0r, v0, precision=6)
        self.assert_numpy_arrays_equal(v1r, v1, precision=6)
        self.assert_numpy_arrays_equal(a0r, a0, precision=6)
        self.assert_numpy_arrays_equal(a1r, a1, precision=6)
        self.assert_numpy_arrays_equal(k0r, k0, precision=6)
        self.assert_numpy_arrays_equal(k1r, k1, precision=6)
Ejemplo n.º 2
0
    def process(self):
        if not any(socket.is_linked for socket in self.outputs):
            return

        output_src = self.output_src or self.concat

        curves_out = []
        controls_out = []
        is_first = True
        for curve1, curve2, factor1, factor2 in self.get_inputs():
            _, t_max_1 = curve1.get_u_bounds()
            t_min_2, _ = curve2.get_u_bounds()

            curve1_end = curve1.evaluate(t_max_1)
            curve2_begin = curve2.evaluate(t_min_2)

            smooth = int(self.smooth_mode)

            if smooth == 0:
                new_curve = SvLine.from_two_points(curve1_end, curve2_begin)
                new_controls = [curve1_end, curve2_begin]
            elif smooth == 1:
                tangent_1_end = curve1.tangent(t_max_1)
                tangent_2_begin = curve2.tangent(t_min_2)

                tangent1 = factor1 * tangent_1_end
                tangent2 = factor2 * tangent_2_begin

                new_curve = SvCubicBezierCurve(
                        curve1_end,
                        curve1_end + tangent1 / 3.0,
                        curve2_begin - tangent2 / 3.0,
                        curve2_begin
                    )
                new_controls = [new_curve.p0.tolist(), new_curve.p1.tolist(),
                                new_curve.p2.tolist(), new_curve.p3.tolist()]
            elif smooth == 2:
                tangent_1_end = curve1.tangent(t_max_1)
                tangent_2_begin = curve2.tangent(t_min_2)
                second_1_end = curve1.second_derivative(t_max_1)
                second_2_begin = curve2.second_derivative(t_min_2)

                new_curve = SvBezierCurve.blend_second_derivatives(
                                curve1_end, tangent_1_end, second_1_end,
                                curve2_begin, tangent_2_begin, second_2_begin)
                new_controls = [p.tolist() for p in new_curve.points]
            elif smooth == 3:
                tangent_1_end = curve1.tangent(t_max_1)
                tangent_2_begin = curve2.tangent(t_min_2)
                second_1_end = curve1.second_derivative(t_max_1)
                second_2_begin = curve2.second_derivative(t_min_2)
                third_1_end = curve1.third_derivative_array(np.array([t_max_1]))[0]
                third_2_begin = curve2.third_derivative_array(np.array([t_min_2]))[0]

                new_curve = SvBezierCurve.blend_third_derivatives(
                                curve1_end, tangent_1_end, second_1_end, third_1_end,
                                curve2_begin, tangent_2_begin, second_2_begin, third_2_begin)
                new_controls = [p.tolist() for p in new_curve.points]
            else:
                raise Exception("Unsupported smooth level")

            if self.mode == 'N' and not self.cyclic and output_src and is_first:
                curves_out.append(curve1)
            curves_out.append(new_curve)
            if self.mode == 'N' and output_src:
                curves_out.append(curve2)
            controls_out.append(new_controls)

            is_first = False

        if self.concat:
            curves_out = [SvConcatCurve(curves_out)]

        self.outputs['Curve'].sv_set(curves_out)
        self.outputs['ControlPoints'].sv_set(controls_out)
Ejemplo n.º 3
0
    def process(self):
        if not any(socket.is_linked for socket in self.outputs):
            return

        output_src = self.output_src or self.concat

        curves_out = []
        controls_out = []
        is_first = True

        for params in self.get_inputs():
            new_curves = []
            new_controls = []
            for curve1, curve2, factor1, factor2, parameter in params:
                _, t_max_1 = curve1.get_u_bounds()
                t_min_2, _ = curve2.get_u_bounds()

                curve1_end = curve1.evaluate(t_max_1)
                curve2_begin = curve2.evaluate(t_min_2)

                smooth = self.smooth_mode

                if smooth == '0':
                    new_curve = SvLine.from_two_points(curve1_end,
                                                       curve2_begin)
                    controls = [curve1_end, curve2_begin]
                elif smooth == '1':
                    tangent_1_end = curve1.tangent(t_max_1)
                    tangent_2_begin = curve2.tangent(t_min_2)

                    tangent1 = factor1 * tangent_1_end
                    tangent2 = factor2 * tangent_2_begin

                    new_curve = SvCubicBezierCurve(
                        curve1_end, curve1_end + tangent1 / 3.0,
                        curve2_begin - tangent2 / 3.0, curve2_begin)
                    controls = [
                        new_curve.p0.tolist(),
                        new_curve.p1.tolist(),
                        new_curve.p2.tolist(),
                        new_curve.p3.tolist()
                    ]
                elif smooth == '1b':
                    tangent_1_end = curve1.tangent(t_max_1)
                    tangent_2_begin = curve2.tangent(t_min_2)

                    new_curve = SvBiArc.calc(
                        curve1_end,
                        curve2_begin,
                        tangent_1_end,
                        tangent_2_begin,
                        parameter,
                        planar_tolerance=self.planar_tolerance)

                    controls = [new_curve.junction.tolist()]
                elif smooth == '2':
                    tangent_1_end = curve1.tangent(t_max_1)
                    tangent_2_begin = curve2.tangent(t_min_2)
                    second_1_end = curve1.second_derivative(t_max_1)
                    second_2_begin = curve2.second_derivative(t_min_2)

                    new_curve = SvBezierCurve.blend_second_derivatives(
                        curve1_end, tangent_1_end, second_1_end, curve2_begin,
                        tangent_2_begin, second_2_begin)
                    controls = [p.tolist() for p in new_curve.points]
                elif smooth == '3':
                    tangent_1_end = curve1.tangent(t_max_1)
                    tangent_2_begin = curve2.tangent(t_min_2)
                    second_1_end = curve1.second_derivative(t_max_1)
                    second_2_begin = curve2.second_derivative(t_min_2)
                    third_1_end = curve1.third_derivative_array(
                        np.array([t_max_1]))[0]
                    third_2_begin = curve2.third_derivative_array(
                        np.array([t_min_2]))[0]

                    new_curve = SvBezierCurve.blend_third_derivatives(
                        curve1_end, tangent_1_end, second_1_end, third_1_end,
                        curve2_begin, tangent_2_begin, second_2_begin,
                        third_2_begin)
                    controls = [p.tolist() for p in new_curve.points]
                else:
                    raise Exception("Unsupported smooth level")

                if self.mode == 'N' and not self.cyclic and output_src and is_first:
                    new_curves.append(curve1)
                new_curves.append(new_curve)
                if self.mode == 'N' and output_src:
                    new_curves.append(curve2)
                new_controls.append(controls)

                is_first = False

                if self.concat:
                    new_curves = [concatenate_curves(new_curves)]

            if self.join:
                curves_out.extend(new_curves)
                controls_out.extend(new_controls)
            else:
                curves_out.append(new_curves)
                controls_out.append(new_controls)

        self.outputs['Curve'].sv_set(curves_out)
        self.outputs['ControlPoints'].sv_set(controls_out)