Esempio n. 1
0
    def _Tesselateor(self, shape, mesh_quality=1.0):
        from OCC.Core.Visualization import Tesselator
        tess = Tesselator(shape)
        tess.Compute(compute_edges=False,
                     mesh_quality=mesh_quality,
                     uv_coords=False,
                     parallel=True)
        vertices = []
        for i in range(0, tess.ObjGetVertexCount()):
            vertices.append(tess.GetVertex(i))
        normals = []
        for i in range(0, tess.ObjGetNormalCount()):
            normals.append(tess.GetNormal(i))
        triangles = []
        for i in range(0, tess.ObjGetTriangleCount()):
            triangles.append(tess.GetTriangleIndex(i))

        return (vertices, normals, triangles)
Esempio n. 2
0
def draw_shape_mpl(shape):
    """
    Draw a TopoDS_Shape with matplotlib
    """

    tess = Tesselator(shape)

    triangles = []
    edges = []

    # get the triangles
    triangle_count = tess.ObjGetTriangleCount()
    for i_triangle in range(0, triangle_count):
        i1, i2, i3 = tess.GetTriangleIndex(i_triangle)
        triangles.append(
            [tess.GetVertex(i1),
             tess.GetVertex(i2),
             tess.GetVertex(i3)])

    # get the edges
    edge_count = tess.ObjGetEdgeCount()
    for i_edge in range(0, edge_count):
        vertex_count = tess.ObjEdgeGetVertexCount(i_edge)
        edge = []
        for i_vertex in range(0, vertex_count):
            vertex = tess.GetEdgeVertex(i_edge, i_vertex)
            edge.append(vertex)
        edges.append(edge)

    # plot it
    fig = plt.figure()
    ax = Axes3D(fig)

    ax.add_collection3d(Poly3DCollection(triangles, linewidths=0.2, alpha=0.5))
    ax.add_collection3d(Line3DCollection(edges, colors='w', linewidths=1.0))

    ax.get_xaxis().set_visible(True)
    ax.get_yaxis().set_visible(True)
    ax.set_autoscale_on(True)
    plt.show()