Ejemplo n.º 1
0
        def process(self):
            if not any(socket.is_linked for socket in self.outputs):
                return

            curves_s = self.inputs['Curve'].sv_get()
            curves_s = ensure_nesting_level(curves_s,
                                            2,
                                            data_types=(SvCurve, ))
            src_point_s = self.inputs['Point'].sv_get()
            src_point_s = ensure_nesting_level(src_point_s, 4)

            points_out = []
            t_out = []
            for curves, src_points_i in zip_long_repeat(curves_s, src_point_s):
                for curve, src_points in zip_long_repeat(curves, src_points_i):
                    new_points = []
                    new_t = []
                    for src_point in src_points:
                        src_point = np.array(src_point)
                        result = ortho_project_curve(src_point,
                                                     curve,
                                                     init_samples=self.samples)
                        if self.nearest:
                            t = result.nearest_u
                            point = result.nearest.tolist()
                            new_t.append(t)
                            new_points.append(point)
                        else:
                            new_t.extend(result.us)
                            new_points.extend(result.points)
                    points_out.append(new_points)
                    t_out.append(new_t)

            self.outputs['Point'].sv_set(points_out)
            self.outputs['T'].sv_set(t_out)
Ejemplo n.º 2
0
        def process(self):
            if not any(socket.is_linked for socket in self.outputs):
                return

            curves_s = self.inputs['Curve'].sv_get()
            curves_s = ensure_nesting_level(curves_s,
                                            2,
                                            data_types=(SvCurve, ))
            frames_s = self.inputs['Frames'].sv_get()
            # list of frames per curve
            frames_s = ensure_nesting_level(frames_s, 3, data_types=(Matrix, ))
            ts_s = self.inputs['T'].sv_get()
            # list of T values per curve
            ts_s = ensure_nesting_level(ts_s, 3)

            tolerance = 10**(-self.accuracy)

            frames_out = []
            for curves, frames_i, ts_i in zip_long_repeat(
                    curves_s, frames_s, ts_s):
                for curve, frames, ts in zip_long_repeat(
                        curves, frames_i, ts_i):
                    new_frames = interpolate_frames(curve,
                                                    frames,
                                                    self.z_axis,
                                                    ts,
                                                    init_samples=self.samples +
                                                    1,
                                                    tolerance=tolerance)
                    if self.join:
                        frames_out.extend(new_frames)
                    else:
                        frames_out.append(new_frames)

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

            surfaces_s = self.inputs['Surface'].sv_get()
            surfaces_s = ensure_nesting_level(surfaces_s,
                                              2,
                                              data_types=(SvSurface, ))
            curves_s = self.inputs['Curve'].sv_get()
            curves_s = ensure_nesting_level(curves_s,
                                            2,
                                            data_types=(SvCurve, ))

            tolerance = 10**(-self.accuracy)

            points_out = []
            u_out = []
            for surfaces, curves in zip_long_repeat(surfaces_s, curves_s):
                for surface, curve in zip_long_repeat(surfaces, curves):
                    result = intersect_curve_surface(
                        curve,
                        surface,
                        init_samples=self.curve_samples,
                        raycast_samples=self.raycast_samples,
                        tolerance=tolerance,
                        raycast_method=self.raycast_method)
                    new_points = [p[1] for p in result]
                    new_u = [p[0] for p in result]
                    points_out.append(new_points)
                    u_out.append(new_u)

            self.outputs['Point'].sv_set(points_out)
            self.outputs['T'].sv_set(u_out)
Ejemplo n.º 4
0
    def process(self):
        if not any(socket.is_linked for socket in self.outputs):
            return

        surface_s = self.inputs['Surface'].sv_get()
        umin_s = self.inputs['NewUMin'].sv_get()
        umax_s = self.inputs['NewUMax'].sv_get()
        vmin_s = self.inputs['NewVMin'].sv_get()
        vmax_s = self.inputs['NewVMax'].sv_get()

        surface_s = ensure_nesting_level(surface_s,
                                         2,
                                         data_types=(SvSurface, ))
        umin_s = ensure_nesting_level(umin_s, 2)
        umax_s = ensure_nesting_level(umax_s, 2)
        vmin_s = ensure_nesting_level(vmin_s, 2)
        vmax_s = ensure_nesting_level(vmax_s, 2)

        surface_out = []
        for surfaces, umins, umaxs, vmins, vmaxs in zip_long_repeat(
                surface_s, umin_s, umax_s, vmin_s, vmax_s):
            new_surfaces = []
            for surface, u_min, u_max, v_min, v_max in zip_long_repeat(
                    surfaces, umins, umaxs, vmins, vmaxs):
                new_surface = SvReparametrizedSurface(surface, u_min, u_max,
                                                      v_min, v_max)
                new_surfaces.append(new_surface)
            surface_out.append(new_surfaces)

        self.outputs['Surface'].sv_set(surface_out)
Ejemplo n.º 5
0
    def process(self):
        if not any(socket.is_linked for socket in self.outputs):
            return

        face_surfaces_s = self.inputs['SolidFace'].sv_get()
        face_surfaces_s = ensure_nesting_level(face_surfaces_s,
                                               2,
                                               data_types=(SvSurface, ))
        offset_s = self.inputs['Vector'].sv_get()
        offset_s = ensure_nesting_level(offset_s, 3)

        solids_out = []
        for face_surfaces, offsets in zip_long_repeat(face_surfaces_s,
                                                      offset_s):
            #new_solids = []
            for face_surface, offset in zip_long_repeat(
                    face_surfaces, offsets):
                if not is_solid_face_surface(face_surface):
                    # face_surface is an instance of SvSurface,
                    # but not a instance of SvFreeCadNurbsSurface
                    self.debug(
                        "Surface %s is not a face of a solid, will convert automatically",
                        face_surface)
                    face_surface = surface_to_freecad(
                        face_surface, make_face=True)  # SvFreeCadNurbsSurface

                fc_face = face_surface.face
                fc_offset = Base.Vector(*offset)
                shape = fc_face.extrude(fc_offset)
                solids_out.append(shape)
            #solids_out.append(new_solids)

        self.outputs['Solid'].sv_set(solids_out)
Ejemplo n.º 6
0
    def process(self):
        if not any(socket.is_linked for socket in self.outputs):
            return

        solids_s = self.inputs['Solid'].sv_get()
        input_level = get_data_nesting_level(solids_s,
                                             data_types=(Part.Shape, ))
        solids_s = ensure_nesting_level(solids_s, 2, data_types=(Part.Shape, ))
        thickness_s = self.inputs['Thickness'].sv_get()
        thickness_s = ensure_nesting_level(thickness_s, 2)
        if self.inputs['FaceMask'].is_linked:
            mask_s = self.inputs['FaceMask'].sv_get()
            mask_s = ensure_nesting_level(mask_s, 3)
        else:
            mask_s = [[[True]]]

        solids_out = []
        for params in zip_long_repeat(solids_s, thickness_s, mask_s):
            new_solids = []
            for solid, thickness, mask in zip_long_repeat(*params):
                new_solid = self.make_solid(solid, thickness, mask)
                new_solids.append(new_solid)
            if input_level == 2:
                solids_out.append(new_solids)
            else:
                solids_out.extend(new_solids)

        self.outputs['Solid'].sv_set(solids_out)
Ejemplo n.º 7
0
    def process(self):
        if not any(socket.is_linked for socket in self.outputs):
            return

        curve_s = self.inputs['Curve'].sv_get()
        segments_s = self.inputs['Segments'].sv_get()
        split_s = self.inputs['Split'].sv_get()

        curves_level = get_data_nesting_level(curve_s, data_types=(SvCurve, ))
        curve_s = ensure_nesting_level(curve_s, 2, data_types=(SvCurve, ))
        segments_s = ensure_nesting_level(segments_s, 2)
        split_s = ensure_nesting_level(split_s, 3)

        curves_out = []
        for curves, segments_i, split_i in zip_long_repeat(
                curve_s, segments_s, split_s):
            curves_list = []
            for curve, segments, splits in zip_long_repeat(
                    curves, segments_i, split_i):
                new_curves = []
                t_min, t_max = curve.get_u_bounds()
                if self.mode == 'EVEN':
                    splits = self._cut(t_min, t_max, segments)
                #splits = [t_min] + splits + [t_max]
                new_curves = split_curve(curve, splits, self.rescale)
                if self.join:
                    curves_list.extend(new_curves)
                else:
                    curves_list.append(new_curves)
            if curves_level == 2:
                curves_out.append(curves_list)
            else:
                curves_out.extend(curves_list)
        self.outputs['Curves'].sv_set(curves_out)
Ejemplo n.º 8
0
    def process(self):
        if not any(socket.is_linked for socket in self.outputs):
            return

        curve_s = self.inputs['Curve'].sv_get()
        knot_s = self.inputs['Knot'].sv_get()
        count_s = self.inputs['Count'].sv_get()

        input_level = get_data_nesting_level(curve_s, data_types=(SvCurve, ))
        flat_output = input_level < 2
        curve_s = ensure_nesting_level(curve_s, 2, data_types=(SvCurve, ))
        knot_s = ensure_nesting_level(knot_s, 3)
        count_s = ensure_nesting_level(count_s, 3)

        curves_out = []
        for curves, knots_i, counts_i in zip_long_repeat(
                curve_s, knot_s, count_s):
            new_curves = []
            for curve, knots, counts in zip_long_repeat(
                    curves, knots_i, counts_i):
                curve = SvNurbsCurve.to_nurbs(curve)
                if curve is None:
                    raise Exception("One of curves is not NURBS")
                for knot, count in zip_long_repeat(knots, counts):
                    curve = curve.insert_knot(knot,
                                              count,
                                              if_possible=self.if_possible)
                new_curves.append(curve)
            if flat_output:
                curves_out.extend(new_curves)
            else:
                curves_out.append(new_curves)

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

            surface_s = self.inputs['Surface'].sv_get()
            surface_s = ensure_nesting_level(surface_s, 2, data_types=(SvSurface,))
            fields_s = self.inputs['Field'].sv_get()
            fields_s = ensure_nesting_level(fields_s, 2, data_types=(SvScalarField,))
            if self.inputs['StartUV'].is_linked:
                start_s = self.inputs['StartUV'].sv_get()
                start_s = ensure_nesting_level(start_s, 4)
            else:
                start_s = [[[None]]]

            uv_out = []
            point_out = []
            for surfaces, fields, start_i in zip_long_repeat(surface_s, fields_s, start_s):
                new_uv = []
                new_points = []
                for surface, field, starts in zip_long_repeat(surfaces, fields, start_i):
                    uvs = self.solve(surface, field, starts)
                    uv_points = [(u, v, 0) for u,v in uvs]

                    us = uvs[:,0]
                    vs = uvs[:,1]
                    points = surface.evaluate_array(us, vs)

                    new_uv.extend(uv_points)
                    new_points.extend(points.tolist())
                uv_out.append(new_uv)
                point_out.append(new_points)

            self.outputs['Point'].sv_set(point_out)
            self.outputs['UVPoint'].sv_set(uv_out)
Ejemplo n.º 10
0
    def get_inputs(self):
        factor1_s = self.inputs['Factor1'].sv_get()
        factor2_s = self.inputs['Factor2'].sv_get()

        factor1_s = ensure_nesting_level(factor1_s, 2)
        factor2_s = ensure_nesting_level(factor2_s, 2)

        if self.mode == 'TWO':
            curve1_s = self.inputs['Curve1'].sv_get()
            curve2_s = self.inputs['Curve2'].sv_get()
            if isinstance(curve1_s[0], SvCurve):
                curve1_s = [curve1_s]
            if isinstance(curve2_s[0], SvCurve):
                curve2_s = [curve2_s]
            for curve1s, curve2s, factor1s, factor2s in zip_long_repeat(curve1_s, curve2_s, factor1_s, factor2_s):
                for curve1, curve2, factor1, factor2 in zip_long_repeat(curve1s, curve2s, factor1s, factor2s):
                    yield curve1, curve2, factor1, factor2
        else:
            curves_s = self.inputs['Curves'].sv_get()
            if isinstance(curves_s[0], SvCurve):
                curves_s = [curves_s]
            for curves, factor1s, factor2s in zip_long_repeat(curves_s, factor1_s, factor2_s):
                factor1s = repeat_last_for_length(factor1s, len(curves))
                factor2s = repeat_last_for_length(factor2s, len(curves))
                for curve1, curve2, factor1, factor2 in zip(curves, curves[1:], factor1s, factor2s):
                    yield curve1, curve2, factor1, factor2
                if self.cyclic:
                    yield curves[-1], curves[0], factor1s[-1], factor2s[-1]
Ejemplo n.º 11
0
    def process(self):
        if not any(socket.is_linked for socket in self.outputs):
            return

        curve_s = self.inputs['Curve'].sv_get()
        tmin_s = self.inputs['TMin'].sv_get()
        tmax_s = self.inputs['TMax'].sv_get()

        tmin_s = ensure_nesting_level(tmin_s, 2)
        tmax_s = ensure_nesting_level(tmax_s, 2)
        if isinstance(curve_s[0], SvCurve):
            curve_s = [curve_s]

        curve_out = []
        for curves, tmins, tmaxs in zip_long_repeat(curve_s, tmin_s, tmax_s):
            new_curves = []
            for curve, t_min, t_max in zip_long_repeat(curves, tmins, tmaxs):
                new_curve = curve_segment(curve, t_min, t_max, self.rescale)
                new_curves.append(new_curve)
            if self.join:
                curve_out.extend(new_curves)
            else:
                curve_out.append(new_curves)

        self.outputs['Segment'].sv_set(curve_out)
Ejemplo n.º 12
0
        def process(self):
            if not any(socket.is_linked for socket in self.outputs):
                return

            surfaces_s = self.inputs['Surface'].sv_get()
            surfaces_s = ensure_nesting_level(surfaces_s,
                                              2,
                                              data_types=(SvSurface, ))
            src_point_s = self.inputs['Point'].sv_get()
            src_point_s = ensure_nesting_level(src_point_s, 4)

            points_out = []
            uv_out = []
            for surfaces, src_points_i in zip_long_repeat(
                    surfaces_s, src_point_s):
                for surface, src_points in zip_long_repeat(
                        surfaces, src_points_i):
                    new_points = []
                    new_uv = []
                    for src_point in src_points:
                        src_point = np.array(src_point)
                        u, v, point = ortho_project_surface(
                            src_point, surface, init_samples=self.samples)
                        new_uv.append((u, v, 0))
                        new_points.append(point)
                    points_out.append(new_points)
                    uv_out.append(new_uv)

            self.outputs['Point'].sv_set(points_out)
            self.outputs['UVPoint'].sv_set(uv_out)
Ejemplo n.º 13
0
    def process(self):
        if not any(socket.is_linked for socket in self.outputs):
            return

        vertices_s = self.inputs['Vertices'].sv_get()
        vertices_s = ensure_nesting_level(vertices_s, 4)
        fields_s = self.inputs['Field'].sv_get()
        fields_s = ensure_nesting_level(fields_s,
                                        2,
                                        data_types=(SvScalarField, ))

        values_out = []
        for fields, vertices_i in zip_long_repeat(fields_s, vertices_s):
            for field, vertices in zip_long_repeat(fields, vertices_i):
                if len(vertices) == 0:
                    new_values = []
                elif len(vertices) == 1:
                    vertex = vertices[0]
                    value = field.evaluate(*vertex)
                    new_values = [value]
                else:
                    XYZ = np.array(vertices)
                    xs = XYZ[:, 0]
                    ys = XYZ[:, 1]
                    zs = XYZ[:, 2]
                    new_values = field.evaluate_grid(xs, ys, zs).tolist()
                values_out.append(new_values)

        self.outputs['Value'].sv_set(values_out)
Ejemplo n.º 14
0
    def process(self):
        if not any(socket.is_linked for socket in self.outputs):
            return

        profile_s = self.inputs['Curve'].sv_get()
        resolution_s = self.inputs['Resolution'].sv_get()
        radius_s = self.inputs['Radius'].sv_get()

        profile_s = ensure_nesting_level(profile_s, 2, data_types=(SvCurve, ))
        resolution_s = ensure_nesting_level(resolution_s, 2)
        radius_s = ensure_nesting_level(radius_s, 2)

        surface_out = []
        for profiles, radiuses, resolutions in zip_long_repeat(
                profile_s, radius_s, resolution_s):
            new_surfaces = []
            for profile, radius, resolution in zip_long_repeat(
                    profiles, radiuses, resolutions):
                surface = SvConstPipeSurface(profile,
                                             radius,
                                             algorithm=self.algorithm,
                                             resolution=resolution)
                new_surfaces.append(surface)
            surface_out.append(new_surfaces)
        self.outputs['Surface'].sv_set(surface_out)
Ejemplo n.º 15
0
    def process(self):
        if not any(socket.is_linked for socket in self.outputs):
            return

        profile_s = self.inputs['Profile'].sv_get()
        taper_s = self.inputs['Taper'].sv_get()
        point_s = self.inputs['Point'].sv_get()
        direction_s = self.inputs['Direction'].sv_get()

        if isinstance(profile_s[0], SvCurve):
            profile_s = [profile_s]
        if isinstance(taper_s[0], SvCurve):
            taper_s = [taper_s]

        point_s = ensure_nesting_level(point_s, 3)
        direction_s = ensure_nesting_level(direction_s, 3)

        surface_out = []
        for profiles, tapers, points, directions in zip_long_repeat(
                profile_s, taper_s, point_s, direction_s):
            for profile, taper, point, direction in zip_long_repeat(
                    profiles, tapers, points, directions):
                surface = SvTaperSweepSurface(profile, taper, np.array(point),
                                              np.array(direction))
                surface_out.append(surface)

        self.outputs['Surface'].sv_set(surface_out)
Ejemplo n.º 16
0
    def process(self):
        if not any(socket.is_linked for socket in self.outputs):
            return

        point_s = self.inputs['Point'].sv_get()
        direction_s = self.inputs['Direction'].sv_get()
        curve_s = self.inputs['Profile'].sv_get()
        v_min_s = self.inputs['AngleFrom'].sv_get()
        v_max_s = self.inputs['AngleTo'].sv_get()

        if isinstance(curve_s[0], SvCurve):
            curve_s = [curve_s]
        point_s = ensure_nesting_level(point_s, 3)
        direction_s = ensure_nesting_level(direction_s, 3)
        v_min_s = ensure_nesting_level(v_min_s, 2)
        v_max_s = ensure_nesting_level(v_max_s, 2)

        surface_out = []
        for curves, points, directions, v_mins, v_maxs in zip_long_repeat(
                curve_s, point_s, direction_s, v_min_s, v_max_s):
            for curve, point, direction, v_min, v_max in zip_long_repeat(
                    curves, points, directions, v_mins, v_maxs):
                origin = self.origin == 'GLOBAL'
                surface = SvRevolutionSurface.build(curve,
                                                    np.array(point),
                                                    np.array(direction),
                                                    v_min,
                                                    v_max,
                                                    global_origin=origin)
                surface_out.append(surface)

        self.outputs['Surface'].sv_set(surface_out)
Ejemplo n.º 17
0
    def process(self):
        if not any(socket.is_linked for socket in self.outputs):
            return

        face1_surfaces_s = self.inputs['SolidFace1'].sv_get()
        face1_surfaces_s = ensure_nesting_level(face1_surfaces_s,
                                                2,
                                                data_types=(SvSurface, ))
        face2_surfaces_s = self.inputs['SolidFace2'].sv_get()
        face2_surfaces_s = ensure_nesting_level(face2_surfaces_s,
                                                2,
                                                data_types=(SvSurface, ))

        solids_out = []
        for face1_surfaces, face2_surfaces in zip_long_repeat(
                face1_surfaces_s, face2_surfaces_s):
            for face1_surface, face2_surface in zip_long_repeat(
                    face1_surfaces, face2_surfaces):
                if not is_solid_face_surface(face1_surface):
                    face1_surface = surface_to_freecad(
                        face1_surface, make_face=True)  # SvFreeCadNurbsSurface
                if not is_solid_face_surface(face2_surface):
                    face2_surface = surface_to_freecad(
                        face2_surface, make_face=True)  # SvFreeCadNurbsSurface

                solid = self.make_solid(face1_surface, face2_surface)
                solids_out.append(solid)

        self.outputs['Solid'].sv_set(solids_out)
Ejemplo n.º 18
0
    def process(self):
        if not any(socket.is_linked for socket in self.outputs):
            return

        t_min_s = self.inputs['TMin'].sv_get()
        t_max_s = self.inputs['TMax'].sv_get()
        t_min_s = ensure_nesting_level(t_min_s, 2)
        t_max_s = ensure_nesting_level(t_max_s, 2)

        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([t_min_s, t_max_s] + input_values)
        else:
            parameters = [t_min_s, t_max_s]

        curves_out = []
        for t_mins, t_maxs, *objects in zip(*parameters):
            if var_names:
                var_values_s = zip_long_repeat(t_mins, t_maxs, *objects)
            else:
                var_values_s = zip_long_repeat(t_mins, t_maxs)
            for t_min, t_max, *var_values in var_values_s:
                variables = dict(zip(var_names, var_values))
                function = self.make_function(variables)
                if self.use_numpy_function:
                    function_vector = self.make_function_vector(variables)
                else:
                    function_vector = None
                new_curve = SvLambdaCurve(function, function_vector)
                new_curve.u_bounds = (t_min, t_max)
                curves_out.append(new_curve)

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

        field_s = self.inputs['Field'].sv_get()
        verts_s = self.inputs['Vertices'].sv_get()
        iso_value_s = self.inputs['IsoValue'].sv_get()

        field_s = ensure_nesting_level(field_s,
                                       2,
                                       data_types=(SvScalarField, ))
        verts_s = ensure_nesting_level(verts_s, 4)
        iso_value_s = ensure_nesting_level(iso_value_s, 2)

        verts_out = []

        threshold = 10**(-self.accuracy)

        for fields, verts_i, iso_value_i in zip_long_repeat(
                field_s, verts_s, iso_value_s):
            for field, verts, iso_value in zip_long_repeat(
                    fields, verts_i, iso_value_i):
                verts = np.array(verts)
                new_verts = solve(field,
                                  verts,
                                  iso_value,
                                  maxiter=self.maxiter,
                                  threshold=threshold).tolist()
                verts_out.append(new_verts)

        self.outputs['Vertices'].sv_set(verts_out)
Ejemplo n.º 20
0
        def process(self):
            if not any(socket.is_linked for socket in self.outputs):
                return

            radiuses_s = self.inputs['Radiuses'].sv_get()
            radiuses_s = ensure_nesting_level(radiuses_s, 3)
            center_s = self.inputs['Center'].sv_get()
            center_s = ensure_nesting_level(center_s, 3)
            major_radius_s = self.inputs['MajorRadius'].sv_get()
            major_radius_s = ensure_nesting_level(major_radius_s, 2)

            curves_out = []
            centers_out = []
            radius_out = []
            for radiuses, centers, major_radiuses in zip_long_repeat(radiuses_s, center_s, major_radius_s):
                for radiuses, center, major_radius in zip_long_repeat(radiuses, centers, major_radiuses):
                    center_2d = self.to_2d(center)
                    enclosure = circlify.Circle(x=center_2d[0], y=center_2d[1], r=major_radius)
                    circles = circlify.circlify(radiuses, target_enclosure=enclosure, show_enclosure=self.show_enclosure)
                    curves = [self.circle_to_curve(center, circle) for circle in circles]
                    curves_out.extend(curves)
                    centers_out.append([tuple(curve.center) for curve in curves])
                    radius_out.append([curve.radius for curve in curves])

            self.outputs['Circles'].sv_set(curves_out)
            self.outputs['Centers'].sv_set(centers_out)
            self.outputs['Radiuses'].sv_set(radius_out)
Ejemplo n.º 21
0
    def process(self):
        if not any(socket.is_linked for socket in self.outputs):
            return

        surface_s = self.inputs['Surface'].sv_get()
        u_min_s = self.inputs['UMin'].sv_get()
        u_max_s = self.inputs['UMax'].sv_get()
        v_min_s = self.inputs['VMin'].sv_get()
        v_max_s = self.inputs['VMax'].sv_get()

        u_min_s = ensure_nesting_level(u_min_s, 2)
        u_max_s = ensure_nesting_level(u_max_s, 2)
        v_min_s = ensure_nesting_level(v_min_s, 2)
        v_max_s = ensure_nesting_level(v_max_s, 2)

        if isinstance(surface_s[0], SvSurface):
            surface_s = [surface_s]

        surface_out = []
        for surfaces, u_mins, u_maxs, v_mins, v_maxs in zip_long_repeat(
                surface_s, u_min_s, u_max_s, v_min_s, v_max_s):
            for surface, u_min, u_max, v_min, v_max in zip_long_repeat(
                    surfaces, u_mins, u_maxs, v_mins, v_maxs):
                new_surface = SvSurfaceSubdomain(surface, (u_min, u_max),
                                                 (v_min, v_max))
                surface_out.append(new_surface)

        self.outputs['Surface'].sv_set(surface_out)
Ejemplo n.º 22
0
    def process(self):
        if not any(socket.is_linked for socket in self.outputs):
            return

        face_surfaces_s = self.inputs['SolidFace'].sv_get()
        face_surfaces_s = ensure_nesting_level(face_surfaces_s, 2, data_types=(SvSurface,))
        offset_s = self.inputs['Offset'].sv_get()
        offset_s = ensure_nesting_level(offset_s, 2)
        tolerance_s = self.inputs['Tolerance'].sv_get()
        tolerance_s = ensure_nesting_level(tolerance_s, 2)

        solids_out = []
        for face_surfaces, offsets, tolerances in zip_long_repeat(face_surfaces_s, offset_s, tolerance_s):
            #new_solids = []
            for face_surface, offset, tolerance in zip_long_repeat(face_surfaces, offsets, tolerances):
                if not is_solid_face_surface(face_surface):
                    # face_surface is an instance of SvSurface,
                    # but not a instance of SvFreeCadNurbsSurface
                    self.debug("Surface %s is not a face of a solid, will convert automatically", face_surface)
                    face_surface = surface_to_freecad(face_surface, make_face=True) # SvFreeCadNurbsSurface

                continuity = face_surface.get_min_continuity()
                if continuity >= 0 and continuity < 1:
                    raise Exception("This node requires at least C1 continuity of the surface; only C0 is guaranteed by surface's knotvector")
                fc_face = face_surface.face
                shape = fc_face.makeOffsetShape(offset, tolerance, fill=True)
                solids_out.append(shape)
            #solids_out.append(new_solids)

        self.outputs['Solid'].sv_set(solids_out)
Ejemplo n.º 23
0
        def process(self):
            if not any(socket.is_linked for socket in self.outputs):
                return

            curve_s = self.inputs['Curve'].sv_get()
            center_s = self.inputs['Center'].sv_get()
            direction_s = self.inputs['Direction'].sv_get()
            radius_s = self.inputs['Radius'].sv_get()
            coeff_s = self.inputs['Coefficient'].sv_get()

            if isinstance(curve_s[0], SvCurve):
                curve_s = [curve_s]
            center_s = ensure_nesting_level(center_s, 3)
            direction_s = ensure_nesting_level(direction_s, 3)
            radius_s = ensure_nesting_level(radius_s, 2)
            coeff_s = ensure_nesting_level(coeff_s, 2)

            curves_out = []
            for curves, centers, directions, radiuses, coeffs in zip_long_repeat(curve_s, center_s, direction_s, radius_s, coeff_s):
                for curve, center, direction, radius, coeff in zip_long_repeat(curves, centers, directions, radiuses, coeffs):
                    if self.use_nurbs:
                        new_curve = self._cast_nurbs(curve, np.array(center), np.array(direction), radius, coeff)
                    else:
                        new_curve = self._cast_generic(curve, np.array(center), np.array(direction), radius, coeff)
                    curves_out.append(new_curve)

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

        curve_s = self.inputs['Curve'].sv_get()
        offset_s = self.inputs['Offset'].sv_get()
        vector_s = self.inputs['Vector'].sv_get()
        resolution_s = self.inputs['Resolution'].sv_get()

        curve_s = ensure_nesting_level(curve_s, 2, data_types=(SvCurve,))
        offset_s = ensure_nesting_level(offset_s, 2)
        vector_s = ensure_nesting_level(vector_s, 3)
        resolution_s = ensure_nesting_level(resolution_s, 2)

        curve_out = []
        for curves, offsets, vectors, resolutions in zip_long_repeat(curve_s, offset_s, vector_s, resolution_s):
            new_curves = []
            for curve, offset, vector, resolution in zip_long_repeat(curves, offsets, vectors, resolutions):
                if self.mode == 'X':
                    vector = [offset, 0, 0]
                elif self.mode == 'Y':
                    vector = [0, offset, 0]
                vector = np.array(vector)

                new_curve = SvOffsetCurve(curve, vector, algorithm=self.algorithm, resolution=resolution)
                new_curves.append(new_curve)
            curve_out.append(new_curves)

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

        surface_s = self.inputs['Surface'].sv_get()
        knot_s = self.inputs['Knot'].sv_get()
        count_s = self.inputs['Count'].sv_get()

        input_level = get_data_nesting_level(surface_s, data_types=(SvSurface,))
        flat_output = input_level < 2
        surface_s = ensure_nesting_level(surface_s, 2, data_types=(SvSurface,))
        knot_s = ensure_nesting_level(knot_s, 3)
        count_s = ensure_nesting_level(count_s, 3)

        surfaces_out = []
        for surfaces, knots_i, counts_i in zip_long_repeat(surface_s, knot_s, count_s):
            new_surfaces = []
            for surface, knots, counts in zip_long_repeat(surfaces, knots_i, counts_i):
                surface = SvNurbsSurface.get(surface)
                if surface is None:
                    raise Exception("One of surfaces is not NURBS")
                for knot, count in zip_long_repeat(knots, counts):
                    surface = surface.insert_knot(self.direction, knot, count, if_possible=self.if_possible)
                new_surfaces.append(surface)
            if flat_output:
                surfaces_out.extend(new_surfaces)
            else:
                surfaces_out.append(new_surfaces)

        self.outputs['Surface'].sv_set(surfaces_out)
Ejemplo n.º 26
0
    def process(self):
        if not any(socket.is_linked for socket in self.outputs):
            return

        face_surface_s = self.inputs['Profile'].sv_get()
        face_surface_s = ensure_nesting_level(face_surface_s,
                                              2,
                                              data_types=(SvSurface, ))
        curve_s = self.inputs['Path'].sv_get()
        curve_s = ensure_nesting_level(curve_s, 2, data_types=(SvCurve, ))

        solid_out = []
        for face_surfaces, curves in zip_long_repeat(face_surface_s, curve_s):
            for face_surface, curve in zip_long_repeat(face_surfaces, curves):
                if not is_solid_face_surface(face_surface):
                    face_surface = surface_to_freecad(face_surface,
                                                      make_face=True)
                curve = curve_to_freecad_nurbs(curve)
                if curve is None:
                    raise Exception("Path curve is not a NURBS!")

                solid = self.make_solid(face_surface.face, curve.curve)
                solid_out.append(solid)

        self.outputs['Solid'].sv_set(solid_out)
Ejemplo n.º 27
0
    def process(self):
        if not any(socket.is_linked for socket in self.outputs):
            return

        curve_s = self.inputs['Curve'].sv_get()
        t_before_s = self.inputs['StartExt'].sv_get()
        t_after_s = self.inputs['EndExt'].sv_get()

        t_before_s = ensure_nesting_level(t_before_s, 2)
        t_after_s = ensure_nesting_level(t_after_s, 2)
        curve_s = ensure_nesting_level(curve_s, 2, data_types=(SvCurve, ))

        start_out = []
        end_out = []
        curve_out = []
        for curves, t_before_i, t_after_i in zip_long_repeat(
                curve_s, t_before_s, t_after_s):
            for curve, t_before, t_after in zip_long_repeat(
                    curves, t_before_i, t_after_i):
                start_extent, end_extent = self.extend_curve(
                    curve, t_before, t_after)
                start_out.append(start_extent)
                end_out.append(end_extent)
                curves = []
                if start_extent is not None:
                    curves.append(start_extent)
                curves.append(curve)
                if end_extent is not None:
                    curves.append(end_extent)
                new_curve = concatenate_curves(curves)
                curve_out.append(new_curve)

        self.outputs['StartExtent'].sv_set(start_out)
        self.outputs['EndExtent'].sv_set(end_out)
        self.outputs['ExtendedCurve'].sv_set(curve_out)
Ejemplo n.º 28
0
        def process(self):
            if not any(socket.is_linked for socket in self.outputs):
                return

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

            vertices_s = ensure_nesting_level(vertices_s, 3)
            degree_s = ensure_nesting_level(degree_s, 2)

            curve_out = []
            points_out = []
            for vertices, degree in zip_long_repeat(vertices_s, degree_s):
                if isinstance(degree, (tuple, list)):
                    degree = degree[0]

                n = len(vertices)
                npoints = degree + 1
                vertices = np.array(vertices)

                #xdata = np.linspace(0, 1, num=n)
                xdata = Spline.create_knots(vertices, metric=self.metric)
                ydata = np.ravel(vertices)

                p0 = init_guess(vertices, npoints)
                popt, pcov = curve_fit(goal, xdata, ydata, p0)
                control_points = popt.reshape((npoints, 3))
                curve = SvBezierCurve(control_points)
                curve_out.append(curve)
                points_out.append(control_points.tolist())

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

        amplitudes_s = self.inputs['Amplitudes'].sv_get()
        omega_s = self.inputs['Omega'].sv_get()
        input_level = get_data_nesting_level(amplitudes_s)
        amplitudes_s = ensure_nesting_level(amplitudes_s, 4)
        omega_s = ensure_nesting_level(omega_s, 2)

        nested_output = input_level > 3

        curves_out = []

        for params in zip_long_repeat(amplitudes_s, omega_s):
            new_curves = []
            for amplitudes, omega in zip_long_repeat(*params):
                if len(amplitudes) < 2:
                    raise Exception(
                        "At least 2 amplitude vectors are required")
                start = np.array(amplitudes[0])
                amplitudes = np.array(amplitudes[1:])
                curve = SvFourierCurve(omega, start, amplitudes)
                new_curves.append(curve)

            if nested_output:
                curves_out.append(new_curves)
            else:
                curves_out.extend(new_curves)

        self.outputs['Curve'].sv_set(curves_out)
Ejemplo n.º 30
0
    def get_input(self):
        if self.input_mode == 'LIST':
            curve_list_s = self.inputs['Curves'].sv_get()
            curve_list_s = ensure_nesting_level(curve_list_s,
                                                2,
                                                data_types=(SvCurve, ))
            for curves in curve_list_s:
                if len(curves) != 4:
                    raise Exception(
                        "List of curves must contain exactly 4 curve objects!")
                yield curves
        else:
            curve1_s = self.inputs['Curve1'].sv_get()
            curve2_s = self.inputs['Curve2'].sv_get()
            curve3_s = self.inputs['Curve3'].sv_get()
            curve4_s = self.inputs['Curve4'].sv_get()

            curve1_s = ensure_nesting_level(curve1_s,
                                            1,
                                            data_types=(SvCurve, ))
            curve2_s = ensure_nesting_level(curve2_s,
                                            1,
                                            data_types=(SvCurve, ))
            curve3_s = ensure_nesting_level(curve3_s,
                                            1,
                                            data_types=(SvCurve, ))
            curve4_s = ensure_nesting_level(curve4_s,
                                            1,
                                            data_types=(SvCurve, ))

            for curve1, curve2, curve3, curve4 in zip_long_repeat(
                    curve1_s, curve2_s, curve3_s, curve4_s):
                yield [curve1, curve2, curve3, curve4]
Ejemplo n.º 31
0
    def process(self):
        if not any(socket.is_linked for socket in self.outputs):
            return
        if not self.inputs['Vertices'].is_linked:
            return

        vertices_s = self.inputs['Vertices'].sv_get()
        vertices_s = ensure_nesting_level(vertices_s, 4)
        surfaces = self.inputs['Surface'].sv_get()
        surfaces = ensure_nesting_level(surfaces, 4)

        objects = match_long_repeat([vertices_s, surfaces])

        result_vertices = []

        for vertices, surface in zip(*objects):
            if self.transpose:
                surface = transpose_list(surface)
            #print("Surface: {} of {} of {}".format(type(surface), type(surface[0]), type(surface[0][0])))
            spline = self.build_spline(surface)
            # uv_coords will be list[m] of lists[n] of 2-tuples of floats
            # number of "rows" and "columns" in uv_coords will match so of vertices.
            src_size_u, src_size_v, uv_coords = self.get_uv(vertices)
            if self.autoscale:
                u_index, v_index = self.get_other_axes()
                surface_flattened = [v for col in surface for v in col]
                scale_u = diameter(surface_flattened, u_index) / src_size_u
                scale_v = diameter(surface_flattened, v_index) / src_size_v
                scale_z = sqrt(scale_u * scale_v)
            else:
                scale_z = 1.0
            if self.flip:
                scale_z = - scale_z
            new_vertices = []
            for uv_row, vertices_row in zip(uv_coords,vertices):
                new_row = []
                for ((u, v), src_vertex) in zip(uv_row, vertices_row):
                    #print("UV: ({}, {}), SRC: {}".format(u, v, src_vertex))
                    spline_vertex = np.array(spline.eval(u, v))
                    spline_normal = np.array(spline.normal(u, v, h=self.normal_precision))
                    #print("Spline: M {}, N {}".format(spline_vertex, spline_normal))
                    # Coordinate of source vertex corresponding to orientation axis
                    z = src_vertex[self.orient_axis]
                    new_vertex = tuple(spline_vertex + scale_z * z * spline_normal)
                    new_row.append(new_vertex)
                new_vertices.append(new_row)
            result_vertices.append(new_vertices)

        if not self.grouped:
            result_vertices = result_vertices[0]
        self.outputs['Vertices'].sv_set(result_vertices)
Ejemplo n.º 32
0
    def process(self):
        if not any(socket.is_linked for socket in self.outputs):
            return
        if not self.inputs['Vertices'].is_linked:
            return

        vertices_s = self.inputs['Vertices'].sv_get()
        paths = self.inputs['Path'].sv_get()
        paths = ensure_nesting_level(paths, 3)

        objects = match_long_repeat([vertices_s, paths])

        result_vertices = []
        result_spline = []

        for vertices, path in zip(*objects):
            # Scale orientation coordinate of input vertices to [0, 1] range
            # these values are used to calculate points on the spline
            t_values = np.array([vertex[self.orient_axis] for vertex in vertices])
            m = t_values.min()
            M = t_values.max()
            object_size = M - m
            if object_size > 0.00001:
                t_values = (t_values - m) / object_size
            else:
                raise Exception("Size of provided object along axis {} is too small".format(self.orient_axis_))

            if self.flip:
                t_values = 1.0 - t_values

            spline = self.build_spline(path)
            scale = spline.length(t_values) / object_size
            # These are points lying on the spline
            # (a projection of object to spline)
            spline_vertices = [Vector(v) for v in spline.eval(t_values).tolist()]
            spline_tangents = [Vector(v) for v in spline.tangent(t_values, h=self.tangent_precision).tolist()]

            new_vertices = []
            for src_vertex, spline_vertex, spline_tangent in zip(vertices, spline_vertices, spline_tangents):
                # Scaling and rotation matrix
                matrix = self.get_matrix(spline_tangent, scale)
                # Source vertex projected to plane orthogonal to orientation axis
                src_vertex_projection = Vector(src_vertex)
                src_vertex_projection[self.orient_axis] = 0
                # Scale and rotate the projection, then move it towards spline vertex
                new_vertex = matrix * Vector(src_vertex_projection) + spline_vertex
                new_vertices.append(new_vertex)

            result_vertices.append(new_vertices)

        self.outputs['Vertices'].sv_set(Vector_degenerate(result_vertices))