コード例 #1
0
def test_sphere():
    mesh = load_sphere()

    plane_orig = (0, 0.7, 0)
    plane_norm = (0, 0.5, 0.5)
    plane = meshcut.Plane(plane_orig, plane_norm)
    p = meshcut.cross_section_mesh(mesh, plane)
    assert len(p) == 1
    assert len(p[0]) > 10

    plane_orig = (0, 0.75, 0)
    plane_norm = (0, 1, 0)
    plane = meshcut.Plane(plane_orig, plane_norm)
    p = meshcut.cross_section_mesh(mesh, plane)
    assert len(p) == 1
    assert len(p[0]) > 10
コード例 #2
0
def test_plane_not_axis_aligned():
    mesh = load_human()
    plane_orig = (0.7, 0, 0)
    plane_norm = (0.2, 0.5, 0.3)
    plane = meshcut.Plane(plane_orig, plane_norm)

    p = meshcut.cross_section_mesh(mesh, plane)
    assert len(p) == 2
コード例 #3
0
ファイル: pit.py プロジェクト: foobarbecue/meshcut_python3
    def __init__(self, angle, mesh, origin = [0, 0, 0], color=(0,0,0)):
        self.angle = angle
        self.mesh = mesh
        self.origin = origin
        self.color = color

        self.plane = meshcut.Plane(origin, self.get_normal())
        self.sliced = meshcut.cross_section_mesh(mesh, self.plane)
コード例 #4
0
def test_plane_aligned_with_edges():
    mesh = load_human()
    # This will align the plane with some edges, so this is a good test
    # for vertices intersection handling
    plane_orig = (1.28380000591278076172, -0.12510000169277191162, 0)
    plane_norm = (1, 0, 0)
    plane = meshcut.Plane(plane_orig, plane_norm)
    p = meshcut.cross_section_mesh(mesh, plane)
    assert len(p) == 3
コード例 #5
0
def vizualize_all_contours(verts, faces, scale, filename):

    equations = common.loadequation(filename)
    print(equations)
    i = 0
    show_mesh = True
    for equation in equations:
        if equation[0] == 0 and equation[1] != 0 and equation[2] != 0:
            x0 = 0
            y0 = (-equation[3] * scale) / equation[1]
            z0 = (-equation[3] * scale) / equation[2]
            # print(i)
        elif equation[0] == 0 and equation[1] == 0 and equation[2] != 0:
            x0 = 0
            y0 = 0
            z0 = (-equation[3] * scale) / equation[2]
            # print(i)
        elif equation[0] == 0 and equation[1] != 0 and equation[2] == 0:
            x0 = 0
            y0 = (-equation[3] * scale) / equation[1]
            z0 = 0
            # print(i)
        elif equation[0] != 0 and equation[1] == 0 and equation[2] != 0:
            x0 = (-equation[3] * scale) / equation[0]
            y0 = 0
            z0 = (-equation[3] * scale) / equation[2]
            # print(i)
        elif equation[0] != 0 and equation[1] == 0 and equation[2] == 0:
            x0 = (-equation[3] * scale) / equation[0]
            y0 = 0
            z0 = 0
            # print(i)
        elif equation[0] != 0 and equation[1] != 0 and equation[2] == 0:
            x0 = (-equation[3] * scale) / equation[0]
            y0 = (-equation[3] * scale) / equation[1]
            z0 = 0
            # print(i)
        else:
            x0 = (-equation[3] * scale) / equation[0]
            y0 = (-equation[3] * scale) / equation[1]
            z0 = (-equation[3] * scale) / equation[2]
            # print(i)
        plane_orig = (x0, y0, z0)
        plane_norm = (equation[0], equation[1], equation[2])

        if i != 0:
            show_mesh = False
        plane = meshcut.Plane(plane_orig, plane_norm)
        P = show(verts, faces, plane, show_mesh)
        # print(len(P))
        i += 1

    mlab.show()
コード例 #6
0
    def fs2d_plot_data(self, plot_type="mpl"):
        import meshcut

        plane_orig = self._plane_orig
        plane_norm = self._plane_norm

        plane = meshcut.Plane(plane_orig, plane_norm)

        if plot_type == "mayavi":

            mlab.figure(figure=None, bgcolor=(1, 1, 1), size=(800, 800))

        elif plot_type == "mpl":

            fig = plt.figure()

            ax = plt.axes(projection="3d")

        for surface in self._fs._iso_surface:

            verts = surface[0]
            faces = surface[1]

            mesh = meshcut.TriangleMesh(verts, faces)

            P = meshcut.cross_section_mesh(mesh, plane)

            for p in P:
                p = np.array(p)
                if plot_type == "mayavi":
                    mlab.plot3d(
                        p[:, 0],
                        p[:, 1],
                        p[:, 2],
                        tube_radius=None,
                        line_width=3.0,
                        color=(0.0, 0.0, 0.0),
                    )
                elif plot_type == "mpl":
                    ax.plot3D(p[:, 0], p[:, 1], p[:, 2], color="k")

        if plot_type == "mayavi":

            mlab.show()

        elif plot_type == "mpl":

            ax.set_xticks([])
            ax.set_yticks([])
            plt.show()
コード例 #7
0
def test_plane_contain_edge():
    """
    Test with a plane that contains the bottom edge of the mesh
    """
    # Flattened view
    # 1 is connected to 7 and 6 to 0
    #
    #  -- 1 ---- 3 ---- 5 ---- 7 --
    #   / |    / |   /  |   /  |
    #     |  /   | /    | /    |  /
    #  -- 0 ---- 2 ---- 4 ---- 6 --
    #
    # Top view
    #     6 - 4
    #     |   |
    #     0 - 2
    #

    verts = [(0, 0, 0), (0, 1, 0), (1, 0, 0), (1, 1, 0), (1, 0, 1), (1, 1, 1),
             (0, 0, 1), (0, 1, 1)]
    faces = [
        (0, 1, 3),
        (0, 3, 2),
        (2, 3, 5),
        (2, 5, 4),
        (4, 5, 7),
        (4, 7, 6),
        (6, 7, 1),
        (6, 1, 0),
    ]

    mesh = meshcut.TriangleMesh(verts, faces)
    plane_orig = verts[2]
    plane_orig = (plane_orig[0], plane_orig[1], plane_orig[2])
    print('plane_orig', plane_orig)
    # Align exactly with the 0 - 2 - 4 line
    plane_norm = (0, 1, 0)
    plane = meshcut.Plane(plane_orig, plane_norm)

    p = meshcut.cross_section_mesh(mesh, plane)
    assert len(p) == 1
    # We should have the four bottom points in our slice
    assert len(p[0]) == 4
    assert np.all(p[0][:, 1] == 0)
コード例 #8
0
def test_plane_triangles_common_edge_on_plane():
    """
    Test with a plane that contains the middle edge of triangles
    """
    # Flattened view
    # 1 is connected to 8 and 10
    #
    #     2     5    8
    #   /   \ /  \ /   \
    # -1-----3----6----- (back to 1)
    #   \   / \  / \   /
    #     4     7    10
    #
    # Top view
    #      1 - 3
    #      | /
    #      6
    verts = [(0, 0, 0), (0, 1, 0), (1, 0, 0), (1, 1, 0), (1, 0, 1), (1, 1, 1),
             (0, 0, 1), (0, 1, 1)]
    faces = [
        (0, 1, 3),
        (0, 3, 2),
        (2, 3, 5),
        (2, 5, 4),
        (4, 5, 7),
        (4, 7, 6),
        (6, 7, 1),
        (6, 1, 0),
    ]

    mesh = meshcut.TriangleMesh(verts, faces)
    plane_orig = verts[2]
    plane_orig = (plane_orig[0], plane_orig[1], plane_orig[2])
    print('plane_orig', plane_orig)
    # Align exactly with the 0 - 2 - 4 line
    plane_norm = (0, 1, 0)
    plane = meshcut.Plane(plane_orig, plane_norm)

    p = meshcut.cross_section_mesh(mesh, plane)
    assert len(p) == 1
    # We should have the four bottom points in our slice
    assert len(p[0]) == 4
    assert np.all(p[0][:, 1] == 0)
コード例 #9
0
ファイル: test_intersection.py プロジェクト: themmes/meshcut
def test_triangle_plane_intersection_edge_on_plane():
    verts = [
        (0, 0, 0),
        (0, 1, 0),
        (1, 0, 0),
    ]
    faces = [
        (0, 1, 2),
    ]

    mesh = meshcut.TriangleMesh(verts, faces)
    plane = meshcut.Plane(
        orig=(0, 0, 0),
        normal=(0, 1, 0)
    )

    intersections = meshcut.compute_triangle_plane_intersections(
        mesh, 0, plane)

    assert len(intersections) == 2
コード例 #10
0
ファイル: test_intersection.py プロジェクト: themmes/meshcut
def test_triangle_plane_intersection_edge_edge():
    verts = [
        (0, 0, 0),
        (0, 1, 0),
        (1, 0, 0),
    ]
    faces = [
        (0, 1, 2),
    ]

    mesh = meshcut.TriangleMesh(verts, faces)
    plane = meshcut.Plane(
        orig=(0, 0.5, 0),
        normal=(0, 1, 0)
    )

    intersections = meshcut.compute_triangle_plane_intersections(
        mesh, 0, plane)

    assert len(intersections) == 2
    assert intersections[0][0] == meshcut.INTERSECT_EDGE
    assert np.allclose(intersections[0][1][1], 0.5)
    assert intersections[1][0] == meshcut.INTERSECT_EDGE
    assert np.allclose(intersections[1][1][1], 0.5)
コード例 #11
0
                             color=(1, 0, 0),
                             opacity=0.5)

            for p, color in zip(P, itertools.cycle(colors)):
                p = np.array(p)
                mlab.plot3d(p[:, 0],
                            p[:, 1],
                            p[:, 2],
                            tube_radius=None,
                            line_width=3.0,
                            color=color)
        return P

    ##
    plane_orig = (0, 0.75, 0)
    plane_norm = (0, 1, 0)
    plane = meshcut.Plane(plane_orig, plane_norm)
    P = show(plane)
    ##
    # This will align the plane with some edges, so this is a good test
    # for vertices intersection handling
    plane_orig = (0.6, -0.12510000169277191162, 0)
    plane_norm = (0.3, 0.7, -0.2)
    plane_norm /= la.norm(plane_norm)

    plane = meshcut.Plane(plane_orig, plane_norm)
    P = show(plane)
    ##
    mlab.show()
    ##
コード例 #12
0
ファイル: main.py プロジェクト: OmerMachluf/Chopper
        if normal[0] > 0:
            orig[0] = orig[0] + 0.05
        elif normal[0] < 0:
            orig[0] = orig[0] - 0.05

        if normal[1] > 0:
            orig[1] = orig[1] + 0.05
        elif normal[1] < 0:
            orig[1] = orig[1] - 0.05

        if normal[2] > 0:
            orig[2] = orig[2] + 0.05
        elif normal[2] < 0:
            orig[2] = orig[2] - 0.05
        S = meshcut.calculateSPotential(obj.normals, normal)
        plane = meshcut.Plane(tuple(orig), normal)
        modelA, modelB = meshcut.split_model(mesh, plane, S)
        if (modelA is None or modelB is None):
            continue
        ## Add relevant normals -> assert same number as vertices and add the right ones.
        ## Add run by vertices
        modelA.gl_list = glGenLists(1)
        glNewList(modelA.gl_list, GL_COMPILE)
        glEnable(GL_TEXTURE_2D)
        glFrontFace(GL_CCW)
        glBegin(GL_POLYGON)

        for triangle in modelA.tris:
            for i in range(len(triangle)):
                glNormal3fv(modelA.normals[triangle[i]])
                glVertex3fv(modelA.verts[triangle[i]])