VTK系列——vtkPoints 显示

vtkPoints 是由点云组成的数组,不包含任何的vertex, 直接放进vtkPolyData 中进行显示是看不到的。两种显示方式可参考以下代码。

1)C++ 版

    vtkSmartPointer points_actor=
            vtkSmartPointer::New();

    vtkSmartPointer polyvertex=
                vtkSmartPointer::New();
    int Num=points->GetNumberOfPoints();
    polyvertex->SetNumberOfCells(Num);
    for(vtkIdType i=0;iInsertNextCell(1,cell);
    }

    vtkSmartPointer polydata_surf=
                vtkSmartPointer::New();
    polydata_surf->SetPoints(points);
    polydata_surf->SetVerts(polyvertex);

    vtkSmartPointer points_map =
            vtkSmartPointer::New();

    points_map->SetInputData(polydata_surf);
    points_actor->SetMapper(points_map);

    render->AddActor(points_actor);

2) C++ 版

    vtkSmartPointer polydata =
        vtkSmartPointer::New();
    polydata->SetPoints(points);
    vtkSmartPointer vertexFilter =                 
        vtkSmartPointer::New();
    vertexFilter->SetInputData(polydata);
    vertexFilter->Update();
    
    vtkSmartPointer mapper =
        vtkSmartPointer::New();
    mapper->SetInputData(vertexFilter->GetOutput());
    mapper->Update();

    vtkSmartPointeractor = 
        vtkSmartPointer::New();
    actor->SetMapper(mapper);
    render->AddActor(actor);

3) python 版

def PointsDisplay(points):
    Points = vtk.vtkPoints()
    vertices = vtk.vtkCellArray()
    for v in points:
        point_tmp = [v[0], v[1], v[2]]
        id=Points.InsertNextPoint(point_tmp)
        vertices.InsertNextCell(1)
        vertices.InsertCellPoint(id)

    polydata = vtk.vtkPolyData()
    polydata.SetPoints(Points)
    polydata.SetVerts(vertices)
    Mapper = vtk.vtkPolyDataMapper()
    Mapper.SetInputData(polydata)
    Actor = vtk.vtkActor()
    Actor.SetMapper(Mapper)
    Actor.GetProperty().SetColor(1, 0, 0)
    
    ren1 = vtk.vtkRenderer()
    ren1.AddActor(Actor)
    # ren1.AddActor(ref_Actor)
    ren1.SetBackground(0.1, 0.2, 0.4)
    renWin = vtk.vtkRenderWindow()
    renWin.AddRenderer(ren1)
    # renWin.SetFullScreen(True)
    renWin.SetSize(300, 300)
    renWin.Render()
    iren = vtk.vtkRenderWindowInteractor()
    iren.SetRenderWindow(renWin)
    iren.Initialize()
    iren.Start()

 

你可能感兴趣的:(VTK系列——vtkPoints 显示)