vtk中绘制线和绘制点集

绘制线:

    void InitLineActor(vtkPoints* points,vtkActor* lactor,double color[3]){
        vtkSmartPointer<vtkPolyLine> polyLine =
          vtkSmartPointer<vtkPolyLine>::New();
        polyLine->GetPointIds()->SetNumberOfIds(points->GetNumberOfPoints());
        for(unsigned int i = 0; i < points->GetNumberOfPoints(); i++)
        {
          polyLine->GetPointIds()->SetId(i,i);
        }

        vtkSmartPointer<vtkCellArray> cells =
          vtkSmartPointer<vtkCellArray>::New();
        cells->InsertNextCell(polyLine);
        vtkSmartPointer<vtkPolyData> polyData =
          vtkSmartPointer<vtkPolyData>::New();
        polyData->SetPoints(points);
        polyData->SetLines(cells);
        vtkSmartPointer<vtkPolyDataMapper> mapper =
          vtkSmartPointer<vtkPolyDataMapper>::New();
        mapper->SetInputData(polyData);

        lactor->SetMapper(mapper);
        lactor->GetProperty()->SetLineWidth(1);
        lactor->GetProperty()->SetColor(color);
    }

绘制点集:

    void DrawPoints(){
        vtkSmartPointer<vtkVertex> vertex =
          vtkSmartPointer<vtkVertex>::New();
        vertex->GetPointIds()->SetNumberOfIds(clickPoints2->GetNumberOfPoints());
        for(int i=0; i<clickPoints2->GetNumberOfPoints(); i++){
            vertex->GetPointIds()->SetId(i, i);
        }

        vtkSmartPointer<vtkCellArray> vertices =
          vtkSmartPointer<vtkCellArray>::New();
        vertices->InsertNextCell(vertex);

        vtkSmartPointer<vtkPolyData> polydata =
          vtkSmartPointer<vtkPolyData>::New();
        polydata->SetPoints(clickPoints2);
//        polydata->SetVerts(vertices);

        vtkSmartPointer<vtkVertexGlyphFilter> glyphFilter =
            vtkSmartPointer<vtkVertexGlyphFilter>::New();
        glyphFilter->SetInputData(polydata);
        glyphFilter->Update();

        // Setup actor and mapper
        vtkSmartPointer<vtkPolyDataMapper> mapper =
          vtkSmartPointer<vtkPolyDataMapper>::New();
        mapper->SetInputData(glyphFilter->GetOutput());

        projectActor->SetMapper(mapper);
        projectActor->GetProperty()->SetPointSize(2.5);
        projectActor->GetProperty()->SetColor(0,0,1);
        projectActor->GetProperty()->SetOpacity(0.1);

        this->DefaultRenderer->AddActor(projectActor);
        this->DefaultRenderer->GetRenderWindow()->Render();
    }

猜你喜欢

转载自blog.csdn.net/yuxing55555/article/details/81671834