コード例 #1
0
pd = vtk.vtkPolyData()
pd.SetPoints(pts)
pd.SetPolys(tris)

# Display the control mesh
meshMapper = vtk.vtkPolyDataMapper()
meshMapper.SetInputData(pd)

meshActor = vtk.vtkActor()
meshActor.SetMapper(meshMapper)
meshActor.GetProperty().SetRepresentationToWireframe()
meshActor.GetProperty().SetColor(0, 0, 0)

# Okay now let's do the intitial weight generation
deform = vtk.vtkDeformPointSet()
deform.SetInputConnection(ele.GetOutputPort())
deform.SetControlMeshData(pd)
deform.Update()  # this creates the initial weights

# Now move one point and deform
pts.SetPoint(5, 0, 0, 3)
pts.Modified()
deform.Update()

# Display the warped sphere
sphereMapper = vtk.vtkPolyDataMapper()
sphereMapper.SetInputConnection(deform.GetOutputPort())

sphereActor = vtk.vtkActor()
sphereActor.SetMapper(sphereMapper)
コード例 #2
0
def main():
    input = vtk.vtkPolyData()
    #double bounds[6]

    argc = 1
    if(argc == 1):

        # Create a sphere to warp
        sphere = vtk.vtkSphereSource()
        sphere.SetThetaResolution(51)
        sphere.SetPhiResolution(17)
        sphere.Update()
        bounds = sphere.GetOutput().GetBounds()

        # Generate some scalars on the polydata
        ele = vtk.vtkElevationFilter()
        ele.SetInputConnection(sphere.GetOutputPort())
        ele.SetLowPoint(0,0,-0.5)
        ele.SetHighPoint(0,0,0.5)
        ele.SetLowPoint((bounds[1] + bounds[0]) / 2.0,
                         (bounds[3] + bounds[2]) / 2.0,
                         -bounds[5])
        ele.SetHighPoint((bounds[1] + bounds[0]) / 2.0,
                          (bounds[3] + bounds[2]) / 2.0,
                          bounds[5])

        ele.Update()
        input.ShallowCopy(ele.GetOutput())

    else:
        inputFilename = argv[1]

        reader = vtk.vtkXMLPolyDataReader()
        reader.SetFileName(inputFilename)
        reader.Update()

        input.ShallowCopy(reader.GetOutput())
        bounds = input.GetBounds()


    # Now create a control mesh, in this case a octagon that encloses
    # the point set

    pts = vtk.vtkPoints()
    pts.SetNumberOfPoints(6)
    pts.SetPoint(0,
                  bounds[0] - .1 * (bounds[1] - bounds[0]),
                  (bounds[3] + bounds[2]) / 2.0,
                  (bounds[5] + bounds[4]) / 2.0)
    pts.SetPoint(1,
                  bounds[1] + .1 * (bounds[1] - bounds[0]),
                  (bounds[3] + bounds[2]) / 2.0,
                  (bounds[5] + bounds[4]) / 2.0)
    pts.SetPoint(2,
                  (bounds[1] + bounds[0]) / 2.0,
                  bounds[2] - .1 * (bounds[3] - bounds[2]),
                  (bounds[5] + bounds[4]) / 2.0)
    pts.SetPoint(3,
                  (bounds[1] + bounds[0]) / 2.0,
                  bounds[3] + .1 * (bounds[3] - bounds[2]),
                  (bounds[5] + bounds[4]) / 2.0)
    pts.SetPoint(4,
                  (bounds[1] + bounds[0]) / 2.0,
                  (bounds[3] + bounds[2]) / 2.0,
                  bounds[4] - .1 * (bounds[5] - bounds[4]))
    pts.SetPoint(5,
                  (bounds[1] + bounds[0]) / 2.0,
                  (bounds[3] + bounds[2]) / 2.0,
                  bounds[5] + .1 * (bounds[5] - bounds[4]))

    tris = vtk.vtkCellArray()
    tris.InsertNextCell(3)
    tris.InsertCellPoint(2)
    tris.InsertCellPoint(0)
    tris.InsertCellPoint(4)

    tris.InsertNextCell(3)
    tris.InsertCellPoint(1)
    tris.InsertCellPoint(2)
    tris.InsertCellPoint(4)

    tris.InsertNextCell(3)
    tris.InsertCellPoint(3)
    tris.InsertCellPoint(1)
    tris.InsertCellPoint(4)

    tris.InsertNextCell(3)
    tris.InsertCellPoint(0)
    tris.InsertCellPoint(3)
    tris.InsertCellPoint(4)

    tris.InsertNextCell(3)
    tris.InsertCellPoint(0)
    tris.InsertCellPoint(2)
    tris.InsertCellPoint(5)

    tris.InsertNextCell(3)
    tris.InsertCellPoint(2)
    tris.InsertCellPoint(1)
    tris.InsertCellPoint(5)

    tris.InsertNextCell(3)
    tris.InsertCellPoint(1)
    tris.InsertCellPoint(3)
    tris.InsertCellPoint(5)

    tris.InsertNextCell(3)
    tris.InsertCellPoint(3)
    tris.InsertCellPoint(0)
    tris.InsertCellPoint(5)

    pd = vtk.vtkPolyData()
    pd.SetPoints(pts)
    pd.SetPolys(tris)

    # Display the control mesh
    meshMapper = vtk.vtkPolyDataMapper()
    meshMapper.SetInputData(pd)
    meshActor = vtk.vtkActor()
    meshActor.SetMapper(meshMapper)
    meshActor.GetProperty().SetRepresentationToWireframe()
    meshActor.GetProperty().SetColor(0,0,0)

    # Do the intitial weight generation
    deform = vtk.vtkDeformPointSet()
    deform.SetInputData(input)
    deform.SetControlMeshData(pd)
    deform.Update() # this creates the initial weights

    # Now move one point and deform
    #double controlPoint[3]
    controlPoint = pts.GetPoint(5)
    pts.SetPoint(5, controlPoint[0],
                  controlPoint[1],
                  bounds[5] + .8 * (bounds[5] - bounds[4]))
    pts.Modified()

    # Display the warped polydata
    polyMapper = vtk.vtkPolyDataMapper()
    polyMapper.SetInputConnection(deform.GetOutputPort())
    polyActor = vtk.vtkActor()
    polyActor.SetMapper(polyMapper)

    renderer = vtk.vtkRenderer()
    renWin = vtk.vtkRenderWindow()
    renWin.AddRenderer(renderer)
    iren = vtk.vtkRenderWindowInteractor()
    iren.SetRenderWindow(renWin)

    renderer.AddActor(polyActor)
    renderer.AddActor(meshActor)

    renderer.GetActiveCamera().SetPosition(1,1,1)
    renderer.ResetCamera()
    renderer.SetBackground(.2, .3, .4)

    renWin.SetSize(300,300)
    renWin.Render()

    iren.Start()

    return
コード例 #3
0
def main():
    input_data = vtk.vtkPolyData()
    #double bounds[6]

    argc = 1
    if argc == 1:

        # Create a sphere to warp
        sphere = vtk.vtkSphereSource()
        sphere.SetThetaResolution(51)
        sphere.SetPhiResolution(17)
        sphere.Update()
        bounds = sphere.GetOutput().GetBounds()

        # Generate some scalars on the polydata
        ele = vtk.vtkElevationFilter()
        ele.SetInputConnection(sphere.GetOutputPort())
        ele.SetLowPoint(0, 0, -0.5)
        ele.SetHighPoint(0, 0, 0.5)
        ele.SetLowPoint((bounds[1] + bounds[0]) / 2.0,
                        (bounds[3] + bounds[2]) / 2.0, -bounds[5])
        ele.SetHighPoint((bounds[1] + bounds[0]) / 2.0,
                         (bounds[3] + bounds[2]) / 2.0, bounds[5])

        ele.Update()
        input_data.ShallowCopy(ele.GetOutput())

    else:
        input_filename = sys.argv[1]

        reader = vtk.vtkXMLPolyDataReader()
        reader.SetFileName(input_filename)
        reader.Update()

        input_data.ShallowCopy(reader.GetOutput())
        bounds = input_data.GetBounds()

    # Now create a control mesh, in this case a octagon that encloses
    # the point set

    points = vtk.vtkPoints()
    points.SetNumberOfPoints(6)
    points.SetPoint(0, bounds[0] - .1 * (bounds[1] - bounds[0]),
                    (bounds[3] + bounds[2]) / 2.0,
                    (bounds[5] + bounds[4]) / 2.0)
    points.SetPoint(1, bounds[1] + .1 * (bounds[1] - bounds[0]),
                    (bounds[3] + bounds[2]) / 2.0,
                    (bounds[5] + bounds[4]) / 2.0)
    points.SetPoint(2, (bounds[1] + bounds[0]) / 2.0,
                    bounds[2] - .1 * (bounds[3] - bounds[2]),
                    (bounds[5] + bounds[4]) / 2.0)
    points.SetPoint(3, (bounds[1] + bounds[0]) / 2.0,
                    bounds[3] + .1 * (bounds[3] - bounds[2]),
                    (bounds[5] + bounds[4]) / 2.0)
    points.SetPoint(4, (bounds[1] + bounds[0]) / 2.0,
                    (bounds[3] + bounds[2]) / 2.0,
                    bounds[4] - .1 * (bounds[5] - bounds[4]))
    points.SetPoint(5, (bounds[1] + bounds[0]) / 2.0,
                    (bounds[3] + bounds[2]) / 2.0,
                    bounds[5] + .1 * (bounds[5] - bounds[4]))

    tris = vtk.vtkCellArray()
    tris.InsertNextCell(3)
    tris.InsertCellPoint(2)
    tris.InsertCellPoint(0)
    tris.InsertCellPoint(4)

    tris.InsertNextCell(3)
    tris.InsertCellPoint(1)
    tris.InsertCellPoint(2)
    tris.InsertCellPoint(4)

    tris.InsertNextCell(3)
    tris.InsertCellPoint(3)
    tris.InsertCellPoint(1)
    tris.InsertCellPoint(4)

    tris.InsertNextCell(3)
    tris.InsertCellPoint(0)
    tris.InsertCellPoint(3)
    tris.InsertCellPoint(4)

    tris.InsertNextCell(3)
    tris.InsertCellPoint(0)
    tris.InsertCellPoint(2)
    tris.InsertCellPoint(5)

    tris.InsertNextCell(3)
    tris.InsertCellPoint(2)
    tris.InsertCellPoint(1)
    tris.InsertCellPoint(5)

    tris.InsertNextCell(3)
    tris.InsertCellPoint(1)
    tris.InsertCellPoint(3)
    tris.InsertCellPoint(5)

    tris.InsertNextCell(3)
    tris.InsertCellPoint(3)
    tris.InsertCellPoint(0)
    tris.InsertCellPoint(5)

    polydata = vtk.vtkPolyData()
    polydata.SetPoints(points)
    polydata.SetPolys(tris)

    # Display the control mesh
    mesh_mapper = vtk.vtkPolyDataMapper()
    mesh_mapper.SetInputData(polydata)
    mesh_actor = vtk.vtkActor()
    mesh_actor.SetMapper(mesh_mapper)
    mesh_actor.GetProperty().SetRepresentationToWireframe()
    mesh_actor.GetProperty().SetColor(0, 0, 0)

    # Do the intitial weight generation
    deform = vtk.vtkDeformPointSet()
    deform.SetInputData(input_data)
    deform.SetControlMeshData(polydata)
    deform.Update()  # this creates the initial weights

    # Now move one point and deform
    control_point = points.GetPoint(5)
    points.SetPoint(5, control_point[0], control_point[1],
                    bounds[5] + .8 * (bounds[5] - bounds[4]))
    points.Modified()

    # Display the warped polydata
    poly_mapper = vtk.vtkPolyDataMapper()
    poly_mapper.SetInputConnection(deform.GetOutputPort())
    poly_actor = vtk.vtkActor()
    poly_actor.SetMapper(poly_mapper)

    renderer = vtk.vtkRenderer()
    ren_win = vtk.vtkRenderWindow()
    ren_win.AddRenderer(renderer)
    iren = vtk.vtkRenderWindowInteractor()
    iren.SetRenderWindow(ren_win)

    renderer.AddActor(poly_actor)
    renderer.AddActor(mesh_actor)

    renderer.GetActiveCamera().SetPosition(1, 1, 1)
    renderer.ResetCamera()
    renderer.SetBackground(.2, .3, .4)

    ren_win.SetSize(300, 300)
    ren_win.Render()

    iren.Start()
コード例 #4
0
def main():
    colors = vtk.vtkNamedColors()

    # Set the background color.
    # colors.SetColor('bkg', [0.2, 0.3, 0.4, 1.0])

    # Create a sphere to deform
    sphere = vtk.vtkSphereSource()
    sphere.SetThetaResolution(51)
    sphere.SetPhiResolution(17)
    sphere.Update()
    bounds = sphere.GetOutput().GetBounds()

    # Create a filter to color the sphere
    ele = vtk.vtkElevationFilter()
    ele.SetInputConnection(sphere.GetOutputPort())
    ele.SetLowPoint(0, 0, -0.5)
    ele.SetHighPoint(0, 0, 0.5)
    ele.SetLowPoint((bounds[1] + bounds[0]) / 2.0,
                    (bounds[3] + bounds[2]) / 2.0, -bounds[5])
    ele.SetHighPoint((bounds[1] + bounds[0]) / 2.0,
                     (bounds[3] + bounds[2]) / 2.0, bounds[5])
    ele.Update()

    # Create a mesh to deform the sphere
    pts = vtk.vtkPoints()
    pts.SetNumberOfPoints(6)
    pts.SetPoint(0, bounds[0] - 0.1 * (bounds[1] - bounds[0]),
                 (bounds[3] + bounds[2]) / 2.0, (bounds[5] + bounds[4]) / 2.0)
    pts.SetPoint(1, bounds[1] + 0.1 * (bounds[1] - bounds[0]),
                 (bounds[3] + bounds[2]) / 2.0, (bounds[5] + bounds[4]) / 2.0)
    pts.SetPoint(2, (bounds[1] + bounds[0]) / 2.0,
                 bounds[2] - 0.1 * (bounds[3] - bounds[2]),
                 (bounds[5] + bounds[4]) / 2.0)
    pts.SetPoint(3, (bounds[1] + bounds[0]) / 2.0,
                 bounds[3] + 0.1 * (bounds[3] - bounds[2]),
                 (bounds[5] + bounds[4]) / 2.0)
    pts.SetPoint(4, (bounds[1] + bounds[0]) / 2.0,
                 (bounds[3] + bounds[2]) / 2.0,
                 bounds[4] - 0.1 * (bounds[5] - bounds[4]))
    pts.SetPoint(5, (bounds[1] + bounds[0]) / 2.0,
                 (bounds[3] + bounds[2]) / 2.0,
                 bounds[5] + 0.1 * (bounds[5] - bounds[4]))
    tris = vtk.vtkCellArray()

    cells = [[2, 0, 4], [1, 2, 4], [3, 1, 4], [0, 3, 4], [0, 2, 5], [2, 1, 5],
             [1, 3, 5], [3, 0, 5]]

    for cell in cells:
        tris.InsertNextCell(3)
        for c in cell:
            tris.InsertCellPoint(c)

    pd = vtk.vtkPolyData()
    pd.SetPoints(pts)
    pd.SetPolys(tris)

    meshMapper = vtk.vtkPolyDataMapper()
    meshMapper.SetInputData(pd)
    meshActor = vtk.vtkActor()
    meshActor.SetMapper(meshMapper)
    meshActor.GetProperty().SetRepresentationToWireframe()
    meshActor.GetProperty().SetColor(colors.GetColor3d('Black'))

    deform = vtk.vtkDeformPointSet()
    deform.SetInputData(ele.GetOutput())
    deform.SetControlMeshData(pd)
    deform.Update()

    controlPoint = pts.GetPoint(5)
    pts.SetPoint(5, controlPoint[0], controlPoint[1],
                 bounds[5] + .8 * (bounds[5] - bounds[4]))
    pts.Modified()

    polyMapper = vtk.vtkPolyDataMapper()
    polyMapper.SetInputConnection(deform.GetOutputPort())
    polyActor = vtk.vtkActor()
    polyActor.SetMapper(polyMapper)

    renderer = vtk.vtkRenderer()
    renWin = vtk.vtkRenderWindow()
    renWin.AddRenderer(renderer)
    iren = vtk.vtkRenderWindowInteractor()
    iren.SetRenderWindow(renWin)

    renderer.AddActor(polyActor)
    renderer.AddActor(meshActor)

    renderer.GetActiveCamera().SetPosition(1, 1, 1)
    renderer.ResetCamera()
    renderer.SetBackground(colors.GetColor3d('DarkSlateGray'))

    renWin.SetSize(300, 300)
    renWin.SetWindowName('DeformPointSet')
    renWin.Render()

    iren.Start()