def process(self):

        if not any((s.is_linked for s in self.outputs)):
            return

        calc_tanget = self.outputs['Tanget'].is_linked or self.outputs['Unit Tanget'].is_linked
        norm_tanget = self.outputs['Unit Tanget'].is_linked

        h = self.h

        if self.inputs['Vertices'].is_linked:
            verts = self.inputs['Vertices'].sv_get()
            verts = dataCorrect(verts)
            t_ins = self.inputs['Interval'].sv_get()

            if self.infer_from_integer_input:
                t_ins = [make_range(int(value)) for value in t_ins[0]]

                if len(t_ins) > len(verts):
                    new_verts = verts[:]
                    for i in range(len(t_ins) - len(verts)):
                        new_verts.append(verts[-1])
                    verts = new_verts

            verts_out = []
            tanget_out = []
            norm_tanget_out = []
            for v, t_in in zip(verts, repeat_last(t_ins)):

                t_corr = np.array(t_in).clip(0, 1)

                if self.mode == 'LIN':
                    spline = LinearSpline(v, metric = self.knot_mode, is_cyclic = self.is_cyclic)
                    out = spline.eval(t_corr)
                    verts_out.append(out.tolist())

                    if calc_tanget:
                        tanget_out.append(spline.tangent(t_corr).tolist())

                else:  # SPL
                    spline = CubicSpline(v, metric = self.knot_mode, is_cyclic = self.is_cyclic)
                    out = spline.eval(t_corr)
                    verts_out.append(out.tolist())
                    if calc_tanget:
                        tangent = spline.tangent(t_corr, h)
                        if norm_tanget:
                            norm = np.linalg.norm(tangent, axis=1)
                            norm_tanget_out.append((tangent / norm[:, np.newaxis]).tolist())
                        tanget_out.append(tangent.tolist())

            outputs = self.outputs
            if outputs['Vertices'].is_linked:
                outputs['Vertices'].sv_set(verts_out)
            if outputs['Tanget'].is_linked:
                outputs['Tanget'].sv_set(tanget_out)
            if outputs['Unit Tanget'].is_linked:
                outputs['Unit Tanget'].sv_set(norm_tanget_out)
예제 #2
0
    def process(self):
        if 'Unit Tanget' not in self.outputs:
            return
        if not any((s.is_linked for s in self.outputs)):
            return

        calc_tanget = self.outputs['Tanget'].is_linked or self.outputs['Unit Tanget'].is_linked

        norm_tanget = self.outputs['Unit Tanget'].is_linked

        h = self.h

        if self.inputs['Vertices'].is_linked:
            verts = self.inputs['Vertices'].sv_get()
            verts = dataCorrect(verts)
            t_ins = self.inputs['Interval'].sv_get()
            verts_out = []
            tanget_out = []
            norm_tanget_out = []
            for v, t_in in zip(verts, repeat_last(t_ins)):

                t_corr = np.array(t_in).clip(0, 1)

                if self.mode == 'LIN':
                    spline = LinearSpline(v, metric = self.knot_mode, is_cyclic = self.is_cyclic)
                    out = spline.eval(t_corr)
                    verts_out.append(out.tolist())

                    if calc_tanget:
                        tanget_out.append(spline.tangent(t_corr).tolist())

                else:  # SPL
                    spline = CubicSpline(v, metric = self.knot_mode, is_cyclic = self.is_cyclic)
                    out = spline.eval(t_corr)
                    verts_out.append(out.tolist())
                    if calc_tanget:
                        tangent = spline.tangent(t_corr, h)
                        if norm_tanget:
                            norm = np.linalg.norm(tangent, axis=1)
                            norm_tanget_out.append((tangent / norm[:, np.newaxis]).tolist())
                        tanget_out.append(tangent.tolist())

            outputs = self.outputs
            if outputs['Vertices'].is_linked:
                outputs['Vertices'].sv_set(verts_out)
            if outputs['Tanget'].is_linked:
                outputs['Tanget'].sv_set(tanget_out)
            if outputs['Unit Tanget'].is_linked:
                outputs['Unit Tanget'].sv_set(norm_tanget_out)
예제 #3
0
class LinearSplineTests(SverchokTestCase):
    def setUp(self):
        super().setUp()
        vertices = [(-1, -1, 0), (0, 0, 0), (1, 2, 0), (2, 3, 0)]
        self.spline = LinearSpline(vertices, metric="DISTANCE")

    def test_eval(self):
        t_in = np.array([0.0, 0.1, 0.4, 0.5, 0.7, 1.0])
        result = self.spline.eval(t_in)
        expected_result = np.array([[-1.0, -1.0, 0.0],
                                    [-0.64188612, -0.64188612, 0.0],
                                    [0.27350889, 0.54701779, 0.0],
                                    [0.5, 1.0, 0.0],
                                    [0.95298221, 1.90596443, 0.0],
                                    [2.0, 3.0, 0.0]])
        #info(result)
        self.assert_numpy_arrays_equal(result, expected_result, precision=8)

    def test_tangent(self):
        t_in = np.array([0.0, 0.1, 0.4, 0.5, 0.7, 1.0])
        result = self.spline.tangent(t_in)
        #info(result)
        expected_result = np.array([[-1, -1, 0], [-1, -1, 0], [-1, -2, 0],
                                    [-1, -2, 0], [-1, -2, 0], [-1, -1, 0]])
        self.assert_numpy_arrays_equal(result, expected_result)
예제 #4
0
class LinearSplineTests(SverchokTestCase):
    def setUp(self):
        super().setUp()
        vertices = [(-1, -1, 0), (0, 0, 0), (1, 2, 0), (2, 3, 0)]
        self.spline = LinearSpline(vertices, metric="DISTANCE")

    def test_eval(self):
        t_in = np.array([0.0, 0.1, 0.4, 0.5, 0.7, 1.0])
        result = self.spline.eval(t_in)
        expected_result = np.array(
                [[-1.0,        -1.0,         0.0 ],
                 [-0.64188612, -0.64188612,  0.0 ],
                 [ 0.27350889,  0.54701779,  0.0 ],
                 [ 0.5,         1.0,         0.0 ],
                 [ 0.95298221,  1.90596443,  0.0 ],
                 [ 2.0,         3.0,         0.0 ]])
        #info(result)
        self.assert_numpy_arrays_equal(result, expected_result, precision=8)

    def test_tangent(self):
        t_in = np.array([0.0, 0.1, 0.4, 0.5, 0.7, 1.0])
        result = self.spline.tangent(t_in)
        #info(result)
        expected_result = np.array(
                [[-1, -1,  0],
                 [-1, -1,  0],
                 [-1, -2,  0],
                 [-1, -2,  0],
                 [-1, -2,  0],
                 [-1, -1,  0]])
        self.assert_numpy_arrays_equal(result, expected_result)
예제 #5
0
    def process_data(self, params):
        verts, t_ins = params

        calc_tanget = self.outputs['Tanget'].is_linked or self.outputs[
            'Unit Tanget'].is_linked
        norm_tanget = self.outputs['Unit Tanget'].is_linked
        h = self.h
        verts_out, tanget_out, norm_tanget_out = [], [], []
        for v, t_in in zip(verts, t_ins):
            if self.infer_from_integer_input:
                t_corr = make_range(int(t_in), self.end_point)
            else:
                t_corr = np.array(t_in).clip(0, 1)

            if self.mode == 'LIN':
                spline = LinearSpline(v,
                                      metric=self.knot_mode,
                                      is_cyclic=self.is_cyclic)
                out = spline.eval(t_corr)
                verts_out.append(out if self.output_numpy else out.tolist())

                if calc_tanget:
                    tanget_out.append(
                        spline.tangent(t_corr) if self.
                        output_numpy else spline.tangent(t_corr).tolist())

            else:  # SPL
                spline = CubicSpline(v,
                                     metric=self.knot_mode,
                                     is_cyclic=self.is_cyclic)
                out = spline.eval(t_corr)
                verts_out.append(out if self.output_numpy else out.tolist())
                if calc_tanget:
                    tangent = spline.tangent(t_corr, h)
                    if norm_tanget:
                        norm = np.linalg.norm(tangent, axis=1)
                        tangent_norm = tangent / norm[:, np.newaxis]
                        norm_tanget_out.append(
                            tangent_norm if self.
                            output_numpy else tangent_norm.tolist())
                    tanget_out.append(
                        tangent if self.output_numpy else tangent.tolist())

        return verts_out, tanget_out, norm_tanget_out