vtkPoints *pPoints = vtkPoints::New(); //此处构建pPoints数据 vtkPolyLine *polyLine = vtkPolyLine::New(); polyLine->GetPointIds()->SetNumberOfIds(pPoints->GetNumberOfPoints()); for(int i = 0; i < pPoints->GetNumberOfPoints(); i++) { polyLine->GetPointIds()->SetId(i, i); } vtkUnstructuredGrid *grid = vtkUnstructuredGrid::New(); grid->Allocate(1, 1); grid->InsertNextCell(polyLine->GetCellType(), polyLine->GetPointIds()); grid->SetPoints(pPoints); vtkDataSetMapper *mapper = vtkDataSetMapper::New(); mapper->SetInputData(grid); vtkActor *actor = vtkActor::New(); actor->SetMapper(mapper); actor->GetProperty()->SetColor(1.0, 0.0, 0.0); //设置颜色
然后将actor加入到render中显示