通过VTK显示STL模型

void showStlModel(const std::string& modelPath){
    vtkSmartPointer stlReader = vtkSmartPointer::New();
    stlReader->SetFileName(modelPath.c_str());//modelPath是stl模型在电脑里面的存储路径
    stlReader->Update();

    if (!_cellLocator) {
        _cellLocator = vtkSmartPointer::New();
    }
    _cellLocator->SetDataSet(stlReader->GetOutput());
    _cellLocator->BuildLocator();

    if (!_stlModel) {
        _stlModel = vtkSmartPointer::New();
    }
    _stlModel = stlReader->GetOutput();
    auto normals = vtkSmartPointer::New();
    normals->SetInputData(_stlModel);
    normals->Update();
    _stlModel = normals->GetOutput();
    auto modelMapper = vtkSmartPointer::New();
    _modelActor->SetMapper(modelMapper);
    modelMapper->SetInputConnection(stlReader->GetOutputPort());
    _qvtkWidget->GetRenderWindow()->Render();
}

 

你可能感兴趣的:(vtk)