Example #1
0
    def process(self):
        if not any(o.is_linked for o in self.outputs):
            return

        vertices_s = self.inputs['Vertices'].sv_get(default=[[]])
        level = get_data_nesting_level(vertices_s)
        if level < 2 or level > 4:
            raise TypeError(
                f"Required nesting level is 2 to 4, provided data nesting level is {level}"
            )
        if level == 2:
            vertices_s = [vertices_s]
            level = 3
        if level == 3:
            vertices_s = [vertices_s]

        out_curves = []
        for vertices_group in vertices_s:
            new_curves = []
            for vertices in vertices_group:
                spline = self.build_spline(vertices)
                curve = SvSplineCurve(spline)
                new_curves.append(curve)
            if level == 4:
                out_curves.append(new_curves)
            else:
                out_curves.extend(new_curves)

        self.outputs['Curve'].sv_set(out_curves)
Example #2
0
    def process(self):
        if not any(o.is_linked for o in self.outputs):
            return

        verts_s = self.inputs['Vertices'].sv_get()
        threshold_s = self.inputs['AngneThreshold'].sv_get()

        verts_s = ensure_nesting_level(verts_s, 4)
        threshold_s = ensure_nesting_level(threshold_s, 2)

        curve_out = []
        for verts_i, threshold_i in zip_long_repeat(verts_s, threshold_s):
            for verts, threshold in zip_long_repeat(verts_i, threshold_i):
                verts = [Vector(v) for v in verts]

                if self.is_cyclic:
                    verts.append(verts[0])

                segments = [[verts[0]]]
                for v1, v2, v3 in zip(verts, verts[1:], verts[2:]):
                    dv1 = v2 - v1
                    dv2 = v2 - v3
                    angle = dv1.angle(dv2)
                    if angle < threshold:
                        segments[-1].append(v2)
                        segment = [v2]
                        segments.append(segment)
                    else:
                        segments[-1].append(v2)
                if not self.is_cyclic:
                    segments[-1].append(verts[-1])

                if self.is_cyclic:
                    v1, v2, v3 = verts[-2], verts[0], verts[1]
                    dv1 = v2 - v1
                    dv2 = v2 - v3
                    angle = dv1.angle(dv2)
                    if angle < threshold:
                        segments[-1].append(verts[-1])
                    else:
                        first_segment = segments[0]
                        segments = segments[1:]
                        segments[-1].extend(first_segment)

                new_curves = [
                    SvSplineCurve.from_points(segment, metric=self.metric)
                    for segment in segments
                ]
                if self.concat:
                    new_curves = [SvConcatCurve(new_curves)]
                curve_out.append(new_curves)

        self.outputs['Curve'].sv_set(curve_out)
Example #3
0
    def make_curve(self, control_points):
        curves = []
        for series in control_points:
            xs = [p.x for p in series]
            min_x = xs[0]
            max_x = xs[-1]
            series = np.array([p.to_tuple() for p in series])
            xs = np.array(xs)

            if self.mode == 'SPL':
                spline = CubicSpline(series, tknots=xs, is_cyclic=False)
            else:
                spline = LinearSpline(series, tknots=xs, is_cyclic=False)
            curve = SvSplineCurve(spline)
            curve.u_bounds = (series[0][0], series[-1][0])
            curves.append(curve)

        if len(curves) == 1:
            return curves[0]
        else:
            return SvConcatCurve(curves)
Example #4
0
    def process(self):
        if not any(o.is_linked for o in self.outputs):
            return

        vertices_s = self.inputs['Vertices'].sv_get(default=[[]])

        out_curves = []
        for vertices in vertices_s:
            spline = self.build_spline(vertices)
            curve = SvSplineCurve(spline)
            out_curves.append(curve)

        self.outputs['Curve'].sv_set(out_curves)
    def process(self):
        if not any(socket.is_linked for socket in self.outputs):
            return

        x_s = self.inputs['x'].sv_get()

        var_names = self.get_variables()
        inputs = self.get_input()
        input_values = [inputs.get(name, [[0]]) for name in var_names]
        if var_names:
            parameters = match_long_repeat([x_s] + input_values)
        else:
            parameters = [x_s]

        y_out = []
        curve_out = []
        ct_points_out = []
        for xs_in, *objects in zip(*parameters):
            if var_names:
                var_values_s = zip_long_repeat(*objects)
            else:
                var_values_s = [[]]
            for var_values in var_values_s:
                variables = dict(zip(var_names, var_values))
                control_points = self.make_points(variables)
                spline = self.make_spline(control_points)
                ys = self.eval_spline(spline, xs_in)
                curve = SvSplineCurve(spline)
                curve.u_bounds = (control_points[0][0], control_points[-1][0])
                y_out.append(ys)
                curve_out.append(curve)
                ct_points_out.append(control_points)

        self.outputs['Result'].sv_set(y_out)
        self.outputs['Curve'].sv_set(curve_out)
        self.outputs['ControlPoints'].sv_set(ct_points_out)
Example #6
0
    def process(self):
        if not any(o.is_linked for o in self.outputs):
            return

        vertices_s = self.inputs['Vertices'].sv_get(default=[[]])

        out_curves = []
        for vertices in vertices_s:
            if self.concat:
                spline = LinearSpline(vertices,
                                      metric=self.metric,
                                      is_cyclic=self.is_cyclic)
                curve = SvSplineCurve(spline)
                out_curves.append(curve)
            else:
                curves = self.make_edges(vertices, is_cyclic=self.is_cyclic)
                out_curves.append(curves)

        self.outputs['Curve'].sv_set(out_curves)
Example #7
0
 def make(vertices):
     spline = CubicSpline(vertices,
                          metric='DISTANCE',
                          is_cyclic=self.is_cyclic)
     return SvSplineCurve(spline)