Пример #1
0
def intersect_surface_plane_msquares(surface,
                                     plane,
                                     need_points=True,
                                     samples_u=50,
                                     samples_v=50):
    u_min, u_max = surface.get_u_min(), surface.get_u_max()
    v_min, v_max = surface.get_v_min(), surface.get_v_max()
    u_range = np.linspace(u_min, u_max, num=samples_u)
    v_range = np.linspace(v_min, v_max, num=samples_v)
    us, vs = np.meshgrid(u_range, v_range, indexing='ij')
    us, vs = us.flatten(), vs.flatten()

    surface_points = surface.evaluate_array(us, vs)
    normal = np.array(plane.normal)
    p2 = np.apply_along_axis(lambda p: normal.dot(p), 1, surface_points)
    data = p2 + plane.d
    data = data.reshape((samples_u, samples_v))

    contours = measure.find_contours(data, level=0.0)

    u_size = (u_max - u_min) / samples_u
    v_size = (v_max - v_min) / samples_v

    uv_points, _, _ = make_contours(samples_u,
                                    samples_v,
                                    u_min,
                                    u_size,
                                    v_min,
                                    v_size,
                                    0,
                                    contours,
                                    make_faces=False,
                                    connect_bounds=False)

    if need_points:
        points = []
        for uv_i in uv_points:
            us_i = [p[0] for p in uv_i]
            vs_i = [p[1] for p in uv_i]
            ps = surface.evaluate_array(np.array(us_i),
                                        np.array(vs_i)).tolist()
            points.append(ps)
    else:
        points = []

    return uv_points, points
Пример #2
0
        def process(self):
            if not any(socket.is_linked for socket in self.outputs):
                return

            fields_s = self.inputs['Field'].sv_get()
            surface_s = self.inputs['Surface'].sv_get()
            samples_u_s = self.inputs['SamplesU'].sv_get()
            samples_v_s = self.inputs['SamplesV'].sv_get()
            value_s = self.inputs['Value'].sv_get()

            fields_s = ensure_nesting_level(fields_s,
                                            2,
                                            data_types=(SvScalarField, ))
            surface_s = ensure_nesting_level(surface_s,
                                             2,
                                             data_types=(SvSurface, ))
            samples_u_s = ensure_nesting_level(samples_u_s, 2)
            samples_v_s = ensure_nesting_level(samples_v_s, 2)
            value_s = ensure_nesting_level(value_s, 2)

            verts_out = []
            edges_out = []
            uv_verts_out = []
            for field_i, surface_i, samples_u_i, samples_v_i, value_i in zip_long_repeat(
                    fields_s, surface_s, samples_u_s, samples_v_s, value_s):
                for field, surface, samples_u, samples_v, value in zip_long_repeat(
                        field_i, surface_i, samples_u_i, samples_v_i, value_i):
                    surface_verts = []
                    surface_uv = []
                    surface_edges = []

                    u_min, u_max = surface.get_u_min(), surface.get_u_max()
                    v_min, v_max = surface.get_v_min(), surface.get_v_max()

                    u_range = np.linspace(u_min, u_max, num=samples_u)
                    v_range = np.linspace(v_min, v_max, num=samples_v)

                    us, vs = np.meshgrid(u_range, v_range, indexing='ij')
                    us, vs = us.flatten(), vs.flatten()

                    surface_points = surface.evaluate_array(us, vs)
                    xs = surface_points[:, 0]
                    ys = surface_points[:, 1]
                    zs = surface_points[:, 2]

                    field_values = field.evaluate_grid(xs, ys, zs)
                    field_values = field_values.reshape((samples_u, samples_v))

                    contours = measure.find_contours(field_values, level=value)

                    u_size = (u_max - u_min) / samples_u
                    v_size = (v_max - v_min) / samples_v

                    uv_contours, new_edges, _ = make_contours(
                        samples_u,
                        samples_v,
                        u_min,
                        u_size,
                        v_min,
                        v_size,
                        0,
                        contours,
                        make_faces=True,
                        connect_bounds=self.connect_bounds)

                    if uv_contours:
                        for uv_points in uv_contours:
                            us = np.array([p[0] for p in uv_points])
                            vs = np.array([p[1] for p in uv_points])

                            new_verts = surface.evaluate_array(us, vs).tolist()

                            surface_uv.append(uv_points)
                            surface_verts.append(new_verts)
                        surface_edges.extend(new_edges)

                        if self.join:
                            surface_verts, surface_edges, _ = mesh_join(
                                surface_verts, surface_edges,
                                [[]] * len(surface_edges))
                            surface_uv = sum(surface_uv, [])

                        verts_out.append(surface_verts)
                        uv_verts_out.append(surface_uv)
                        edges_out.append(surface_edges)
                    else:
                        verts_out.append([])
                        uv_verts_out.append([])
                        edges_out.append([])

            self.outputs['Vertices'].sv_set(verts_out)
            self.outputs['Edges'].sv_set(edges_out)
            if 'UVVertices' in self.outputs:
                self.outputs['UVVertices'].sv_set(uv_verts_out)
Пример #3
0
        def process(self):
            if not any(socket.is_linked for socket in self.outputs):
                return

            field_s = self.inputs['Field'].sv_get()
            bounds_s = self.inputs['Bounds'].sv_get()
            samples_xy_s = self.inputs['SamplesXY'].sv_get()
            samples_z_s = self.inputs['SamplesZ'].sv_get()
            samples_value_s = self.inputs['ValueSamples'].sv_get()

            verts_out = []
            edges_out = []
            faces_out = []

            inputs = zip_long_repeat(field_s, bounds_s, samples_xy_s,
                                     samples_z_s, samples_value_s)
            for field, bounds, samples_xy, samples_z, samples_value in inputs:
                if isinstance(samples_xy, (list, tuple)):
                    samples_xy = samples_xy[0]
                if isinstance(samples_z, (list, tuple)):
                    samples_z = samples_z[0]
                if isinstance(samples_value, (list, tuple)):
                    samples_value = samples_value[0]

                b1, b2 = self.get_bounds(bounds)
                min_x, max_x = b1[0], b2[0]
                min_y, max_y = b1[1], b2[1]
                min_z, max_z = b1[2], b2[2]

                x_size = (max_x - min_x) / samples_xy
                y_size = (max_y - min_y) / samples_xy

                x_range = np.linspace(min_x, max_x, num=samples_xy)
                y_range = np.linspace(min_y, max_y, num=samples_xy)
                z_range = np.linspace(min_z, max_z, num=samples_z)
                xs, ys, zs = np.meshgrid(x_range,
                                         y_range,
                                         z_range,
                                         indexing='ij')
                xs, ys, zs = xs.flatten(), ys.flatten(), zs.flatten()
                field_values = field.evaluate_grid(xs, ys, zs)
                min_field = field_values.min()
                max_field = field_values.max()
                field_values = field_values.reshape(
                    (samples_xy, samples_xy, samples_z))
                field_stops = np.linspace(min_field,
                                          max_field,
                                          num=samples_value)

                new_verts = []
                new_edges = []
                new_faces = []
                for i in range(samples_z):
                    z_value = zs[i]
                    z_verts = []
                    z_edges = []
                    z_faces = []
                    for j in range(samples_value):
                        value = field_stops[j]
                        contours = measure.find_contours(field_values[:, :, i],
                                                         level=value)

                        value_verts, value_edges, value_faces = make_contours(
                            samples_xy,
                            samples_xy,
                            min_x,
                            x_size,
                            min_y,
                            y_size,
                            z_value,
                            contours,
                            make_faces=self.make_faces,
                            connect_bounds=self.connect_bounds)
                        if value_verts:
                            z_verts.extend(value_verts)
                            z_edges.extend(value_edges)
                            z_faces.extend(value_faces)

                    new_verts.extend(z_verts)
                    new_edges.extend(z_edges)
                    new_faces.extend(z_faces)

                if self.join:
                    new_verts, new_edges, new_faces = mesh_join(
                        new_verts, new_edges, new_faces)

                    verts_out.append(new_verts)
                    edges_out.append(new_edges)
                    faces_out.append(new_faces)
                else:
                    verts_out.extend(new_verts)
                    edges_out.extend(new_edges)
                    faces_out.extend(new_faces)

            self.outputs['Vertices'].sv_set(verts_out)
            self.outputs['Edges'].sv_set(edges_out)
            self.outputs['Faces'].sv_set(faces_out)
Пример #4
0
        def process(self):
            if not any(socket.is_linked for socket in self.outputs):
                return

            fields_s = self.inputs['Field'].sv_get()
            min_x_s = self.inputs['MinX'].sv_get()
            max_x_s = self.inputs['MaxX'].sv_get()
            min_y_s = self.inputs['MinY'].sv_get()
            max_y_s = self.inputs['MaxY'].sv_get()
            value_s = self.inputs['Value'].sv_get()
            z_value_s = self.inputs['Z'].sv_get()
            samples_s = self.inputs['Samples'].sv_get()
            matrix_s = self.inputs['Matrix'].sv_get(default=[Matrix()])

            value_s = ensure_nesting_level(value_s, 2)
            z_value_s = ensure_nesting_level(z_value_s, 2)
            input_level = get_data_nesting_level(fields_s,
                                                 data_types=(SvScalarField, ))
            nested_output = input_level > 1
            fields_s = ensure_nesting_level(fields_s,
                                            2,
                                            data_types=(SvScalarField, ))
            matrix_s = ensure_nesting_level(matrix_s, 2, data_types=(Matrix, ))

            parameters = zip_long_repeat(fields_s, matrix_s, min_x_s, max_x_s,
                                         min_y_s, max_y_s, z_value_s, value_s,
                                         samples_s)

            verts_out = []
            edges_out = []
            faces_out = []
            for field_i, matrix_i, min_x_i, max_x_i, min_y_i, max_y_i, z_value_i, value_i, samples_i in parameters:
                new_verts = []
                new_edges = []
                new_faces = []
                objects = zip_long_repeat(field_i, matrix_i, min_x_i, max_x_i,
                                          min_y_i, max_y_i, z_value_i, value_i,
                                          samples_i)
                for field, matrix, min_x, max_x, min_y, max_y, z_value, value, samples in objects:

                    has_matrix = matrix != Matrix()

                    x_range = np.linspace(min_x, max_x, num=samples)
                    y_range = np.linspace(min_y, max_y, num=samples)
                    z_range = np.array([z_value])
                    xs, ys, zs = np.meshgrid(x_range,
                                             y_range,
                                             z_range,
                                             indexing='ij')
                    xs, ys, zs = xs.flatten(), ys.flatten(), zs.flatten()
                    if has_matrix:
                        xs, ys, zs = self.apply_matrix(matrix, xs, ys, zs)
                    field_values = field.evaluate_grid(xs, ys, zs)
                    field_values = field_values.reshape((samples, samples))

                    contours = measure.find_contours(field_values, level=value)

                    x_size = (max_x - min_x) / samples
                    y_size = (max_y - min_y) / samples

                    value_verts, value_edges, value_faces = make_contours(
                        samples,
                        samples,
                        min_x,
                        x_size,
                        min_y,
                        y_size,
                        z_value,
                        contours,
                        make_faces=self.make_faces,
                        connect_bounds=self.connect_bounds)
                    if has_matrix:
                        new_verts = self.unapply_matrix(matrix, new_verts)

                    if self.join:
                        new_verts.extend(value_verts)
                        new_edges.extend(value_edges)
                        new_faces.extend(value_faces)
                    else:
                        new_verts.append(value_verts)
                        new_edges.append(value_edges)
                        new_faces.append(value_faces)

                if nested_output:
                    verts_out.append(new_verts)
                    edges_out.append(new_edges)
                    faces_out.append(new_faces)
                else:
                    verts_out.extend(new_verts)
                    edges_out.extend(new_edges)
                    faces_out.extend(new_faces)

            self.outputs['Vertices'].sv_set(verts_out)
            self.outputs['Edges'].sv_set(edges_out)
            self.outputs['Faces'].sv_set(faces_out)