def createPolyDataFromMeshArrays(pts, faces):
        pd = vtk.vtkPolyData()
        pd.SetPoints(vtk.vtkPoints())
        pd.GetPoints().SetData(vnp.getVtkFromNumpy(pts.copy()))

        assert len(faces) % 3 == 0
        cells = vtk.vtkCellArray()
        for i in xrange(len(faces) / 3):
            tri = vtk.vtkTriangle()
            tri.GetPointIds().SetId(0, faces[i * 3 + 0])
            tri.GetPointIds().SetId(1, faces[i * 3 + 1])
            tri.GetPointIds().SetId(2, faces[i * 3 + 2])
            cells.InsertNextCell(tri)

        pd.SetPolys(cells)
        return pd
Esempio n. 2
0
    def createPolyDataFromMeshArrays(pts, faces):
        pd = vtk.vtkPolyData()
        pd.SetPoints(vtk.vtkPoints())
        pd.GetPoints().SetData(vnp.getVtkFromNumpy(pts.copy()))

        assert len(faces) % 3 == 0
        cells = vtk.vtkCellArray()
        for i in xrange(len(faces) / 3):
            tri = vtk.vtkTriangle()
            tri.GetPointIds().SetId(0, faces[i * 3 + 0])
            tri.GetPointIds().SetId(1, faces[i * 3 + 1])
            tri.GetPointIds().SetId(2, faces[i * 3 + 2])
            cells.InsertNextCell(tri)

        pd.SetPolys(cells)
        return pd
Esempio n. 3
0
    def createPolyDataFromMeshArrays(pts, faces):
        pd = vtk.vtkPolyData()
        pd.SetPoints(vtk.vtkPoints())
        pd.GetPoints().SetData(vnp.getVtkFromNumpy(pts.copy()))

        cells = vtk.vtkCellArray()
        for face in faces:
            assert len(face) == 3, "Non-triangular faces are not supported."
            tri = vtk.vtkTriangle()
            tri.GetPointIds().SetId(0, face[0])
            tri.GetPointIds().SetId(1, face[1])
            tri.GetPointIds().SetId(2, face[2])
            cells.InsertNextCell(tri)

        pd.SetPolys(cells)
        return pd
Esempio n. 4
0
def assimpMeshToPolyData(mesh):

    verts = mesh.vertices
    faces = mesh.faces

    nfaces = faces.shape[0]
    nverts = verts.shape[0]

    assert verts.shape[1] == 3
    assert faces.shape[1] == 3

    points = vnp.getVtkPointsFromNumpy(verts)

    cells = vtk.vtkCellArray()

    for i in xrange(nfaces):
        face = faces[i]
        tri = vtk.vtkTriangle()
        tri.GetPointIds().SetId(0, face[0])
        tri.GetPointIds().SetId(1, face[1])
        tri.GetPointIds().SetId(2, face[2])
        cells.InsertNextCell(tri)

    polyData = vtk.vtkPolyData()
    polyData.SetPoints(points)
    polyData.SetPolys(cells)


    if mesh.normals.shape[0] > 0:
        assert mesh.normals.shape[0] == nverts
        normals = vnp.getVtkFromNumpy(mesh.normals)
        normals.SetName('normals')
        polyData.GetPointData().AddArray(normals)
        polyData.GetPointData().SetNormals(normals)


    for i, tcoords in enumerate(mesh.texturecoords):
        tcoordArray = assimpTextureCoordsToArray(tcoords)
        tcoordArray.SetName('tcoords_%d' % i)
        polyData.GetPointData().AddArray(tcoordArray)
        if i == 0:
            polyData.GetPointData().SetTCoords(tcoordArray)

    return polyData
Esempio n. 5
0
    def createPolyDataFromMeshArrays(pts, faces):
        pd = vtk.vtkPolyData()
        pd.SetPoints(vtk.vtkPoints())

        if pts.size > 0:
            pd.GetPoints().SetData(vnp.getVtkFromNumpy(pts.copy()))

            cells = vtk.vtkCellArray()
            tri = vtk.vtkTriangle()
            setId = tri.GetPointIds().SetId  # bind the method for convenience
            for face in faces:
                assert len(face) == 3, "Non-triangular faces are not supported."
                setId(0, face[0])
                setId(1, face[1])
                setId(2, face[2])
                cells.InsertNextCell(tri)

            pd.SetPolys(cells)
        return pd