一直想实现对stl模型的某个方向进行平面切割
通过滑动slider然后对模型进行某一个方向的面切割。同时可以用鼠标对模型进行移动缩放,旋转等操作。然后可以加一些颜色点云显示等操作。
stl加载:
QString selectFilePath = QFileDialog::getOpenFileName(this, QString("choose STL file"), QString(""), QString("file(*.stl)"));
if (selectFilePath.isEmpty())
{
ui.textBrowser->append("The address of the STL file you choose is null!");
return;
}
// 原始图像
reader = vtkSmartPointer<vtkSTLReader>::New();
reader->SetFileName(selectFilePath.toStdString().c_str());
reader->Update();
//将source转换成mapper
mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(reader->GetOutputPort());
//送入渲染引擎进行显示
actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
//渲染
renderer = vtkSmartPointer<vtkRenderer>::New();
renderer->AddActor(actor);
renderer->SetBackground(.0, .0, .0);
//设置渲染窗口
vtkSmartPointer<vtkRenderWindow> window = vtkSmartPointer<vtkRenderWindow>::New();
ui.qvtkWidget->SetRenderWindow(window);
ui.qvtkWidget->GetRenderWindow()->AddRenderer(renderer);
//ok
ui.textBrowser->append(QString("upload the file:") + selectFilePath + QString(" succeed !"));