程序示例精选
VS+QT+VTK三维曲面网格点选切割
如需安装运行环境或远程调试,见文章底部个人QQ名片,由专业技术人员远程协助!
前言
这篇博客针对<<VS+QT+VTK三维曲面网格点选切割>>编写代码,代码整洁,规则,易读。 学习与应用推荐首选。
功能:读取三维网格数据,通过单击网格表面点选需要切除的部分。
文章目录
一、所需工具软件
二、使用步骤
1. 引入库
2. 代码实现
3. 运行结果
三、在线协助
一、所需工具软件
1. VS, Qt
2. VTK
二、使用步骤
1.引入库
#include <iostream>
#include <fstream>
#include <vtkSelectPolyData.h>
#include <vtkSmartPointer.h>
#include <vtkPolyDataMapper.h>
#include <vtkDataSetMapper.h>
#include <vtkActor.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkRendererCollection.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkIdTypeArray.h>
#include <vtkPolyData.h>
#include <vtkCellArray.h>
#include <vtkSphereSource.h>
#include <vtkCellPicker.h>
#include <vtkInteractorStyleTrackballCamera.h>
#include <vtkProperty.h>
#include <vtkSelectionNode.h>
#include <vtkSelection.h>
#include <vtkExtractSelection.h>
#include <vtkObjectFactory.h>
#include <vtkPointData.h>
#include <iostream>
#include <vector>
2. 代码实现
代码如下:
class CellPickerInteractorStyle : public vtkInteractorStyleTrackballCamera
{
public:
static CellPickerInteractorStyle* New();
CellPickerInteractorStyle()
{
selectedMapper = vtkSmartPointer<vtkDataSetMapper>::New();
selectedActor = vtkSmartPointer<vtkActor>::New();
polyData = vtkPolyData::New();
//xvec.resize(5);
//yvec.resize(5);
//zvec.resize(5);
last_picked_actor = NULL;
}
virtual void OnLeftButtonDown()
{
//打印鼠标左键像素位置
if (this->Interactor->GetControlKey())
{
std::cout << "Picking pixel: " << this->Interactor->GetEventPosition()[0]
<< " " << this->Interactor->GetEventPosition()[1] << std::endl;
//注册拾取点函数
this->Interactor->GetPicker()->Pick(
this->Interactor->GetEventPosition()[0],
this->Interactor->GetEventPosition()[1], 0, // always zero.
this->Interactor->GetRenderWindow()->GetRenderers()->GetFirstRenderer()
);
//打印拾取点空间位置
this->Interactor->GetPicker()->GetPickPosition(picked);
cout << "Picked value: " << picked[0] << " " << picked[1] << " " << picked[2] << endl;
//获取此次的标记点。
this->last_picked_actor = GetActor();
markPoint.push_back(last_picked_actor);
if (this->last_picked_actor)
{
//标记出来
this->last_picked_actor->SetScale(0.02);
this->last_picked_actor->GetProperty()->SetColor(1.0, 0.0, 0.0);
this->Interactor->GetRenderWindow()->GetRenderers()->GetFirstRenderer()->AddActor(this->last_picked_actor);
}
}
vtkInteractorStyleTrackballCamera::OnLeftButtonDown();
}
};
int main(int, char* [])
{
// Read a stl file.
reader1->SetFileName("bunny.stl");
reader1->Update();
TheStlPoly->DeepCopy(reader1->GetOutput());
// Create a mapper and actor
vtkSmartPointer<vtkPolyDataMapper> mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputData(TheStlPoly);
actor->SetMapper(mapper);
actor->GetProperty()->SetOpacity(1);
// Create a renderer, render window, and interactor
vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->Render();
renderWindow->SetWindowName("PointPicker");
renderWindow->AddRenderer(renderer);
vtkNew<vtkNamedColors> colors;
renderer->SetBackground(colors->GetColor3d("CadetBlue").GetData());
vtkSmartPointer<CellPickerInteractorStyle> pointPicker = vtkSmartPointer<CellPickerInteractorStyle>::New();
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = vtkSmartPointer<vtkRenderWindowInteractor>::New();
renderWindowInteractor->SetInteractorStyle(pointPicker);
renderWindowInteractor->SetRenderWindow(renderWindow);
// Add the actor to the scene
renderer->AddActor(actor);
//renderer->SetBackground(0, 0, 0);
// Render and interact
renderWindow->Render();
renderWindowInteractor->Start();
return EXIT_SUCCESS;
}
3. 运行结果
三、在线协助:
如需安装运行环境或远程调试,见文章底部个人 QQ 名片,由专业技术人员远程协助!
1)远程安装运行环境,代码调试
2)Qt, C++, Python入门指导
3)界面美化
4)软件制作
当前文章连接:Python+Qt桌面端与网页端人工客服沟通工具_alicema1111的博客-CSDN博客
博主推荐文章:python人脸识别统计人数qt窗体-CSDN博客
博主推荐文章:Python Yolov5火焰烟雾识别源码分享-CSDN博客
Python OpenCV识别行人入口进出人数统计_python识别人数-CSDN博客
个人博客主页:alicema1111的博客_CSDN博客-Python,C++,网页领域博主
博主所有文章点这里:alicema1111的博客_CSDN博客-Python,C++,网页领域博主