程序示例精选
Qt+VTK鼠标拾取点生成拉伸闭合三维体
如需安装运行环境或远程调试,见文章底部个人QQ名片,由专业技术人员远程协助!
前言
这篇博客针对《Qt+VTK鼠标拾取点生成拉伸闭合三维体》编写代码,代码整洁,规则,易读。 学习与应用推荐首选。
运行结果
文章目录
一、所需工具软件
二、使用步骤
1. 主要代码
2. 运行结果
三、在线协助
一、所需工具软件
1. VS2019, Qt
2. C++
二、使用步骤
代码如下(示例):
#include "mainwindow.h"
#include "ui_mainwindow.h"#include <vtkActor.h>
#include <vtkCellArray.h>
#include <vtkInteractorStyleTrackballCamera.h>
#include <vtkNamedColors.h>
#include <vtkNew.h>
#include <vtkObjectFactory.h>
#include <vtkPlaneSource.h>
#include <vtkPoints.h>
#include <vtkPolyData.h>
#include <vtkPolyDataMapper.h>
#include <vtkPropPicker.h>
#include <vtkProperty.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
#include <vtkRendererCollection.h>
#include <vtkSphereSource.h>
#include <vtkSTLReader.h>#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkPolyData.h>
#include <vtkPoints.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkVertexGlyphFilter.h>
#include <vtkUnsignedCharArray.h>
#include <vtkPointData.h>#include <vtkGlyph3D.h>
#include <vtkSphereSource.h>#include <vtkActor.h>
#include <vtkGenericOpenGLRenderWindow.h>
#include <vtkNamedColors.h>
#include <vtkPolyDataMapper.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkSTLReader.h>
#include <vtkClipPolyData.h>
#include <vtkSelectPolyData.h>
#include <Eigen/Dense>
#include <vtkPlane.h>
#include <vtkLookupTable.h>
#include <vtkBooleanOperationPolyDataFilter.h>
#include <vtkDelaunay2D.h>
#include <vtkLinearExtrusionFilter.h>
#include <vtkPolygon.h>namespace {// Handle mouse eventsclass MouseInteractorStyle2 : public vtkInteractorStyleTrackballCamera{public:static MouseInteractorStyle2* New();vtkTypeMacro(MouseInteractorStyle2, vtkInteractorStyleTrackballCamera);vtkNew<vtkNamedColors> colors;virtual void OnLeftButtonDown() override{if (!pickingModeActive){int* clickPos = this->GetInteractor()->GetEventPosition();vtkNew<vtkPropPicker> picker;picker->Pick(clickPos[0], clickPos[1], 0, this->GetDefaultRenderer());double* pos = picker->GetPickPosition();std::cout << "Pick position (world coordinates) is: " << pos[0] << " "<< pos[1] << " " << pos[2] << std::endl;double* newPoint = new double[3];newPoint[0] = pos[0];newPoint[1] = pos[1];newPoint[2] = pos[2];collectedPoints.push_back(newPoint);auto pickedActor = picker->GetActor();if (pickedActor == nullptr){std::cout << "No actor picked." << std::endl;}} // namespaceMainWindow::MainWindow(QWidget *parent): QMainWindow(parent), ui(new Ui::MainWindow)
{ui->setupUi(this);QObject::connect(ui->actionOpen_File_3, &QAction::triggered, this, &MainWindow::on_actionPickPoint_triggered);QObject::connect(ui->actionStart, &QAction::triggered, this, &MainWindow::actionPickPointStart);renderer = vtkSmartPointer<vtkRenderer>::New();renderer->SetBackground(0.1, 0.2, 0.4);ui->widget->GetRenderWindow()->AddRenderer(renderer);
}MainWindow::~MainWindow()
{delete ui;
}void MainWindow::actionPickPointStart()
{pickingModeActive = !pickingModeActive;
}void MainWindow::actionPickPointClose()
{pickingModeActive = !pickingModeActive;
}void MainWindow::actionPickPoint()
{vtkNew<vtkNamedColors> colors;vtkNew<vtkSphereSource> sphereSource;sphereSource->SetRadius(5);sphereSource->Update();vtkNew<vtkPolyDataMapper> mapper;mapper->SetInputConnection(sphereSource->GetOutputPort());vtkNew<vtkActor> actor;actor->SetMapper(mapper);actor->GetProperty()->SetColor(colors->GetColor3d("MistyRose").GetData());// Create the RenderWindow, RenderervtkNew<vtkRenderer> renderer;vtkNew<vtkRenderWindow> renderWindow;renderWindow->AddRenderer(renderer);renderWindow->SetWindowName("PolygonalSurfacePointPlacer");vtkNew<vtkRenderWindowInteractor> interactor;interactor->SetRenderWindow(renderWindow);renderer->AddActor(actor);renderer->SetBackground(colors-}
运行结果
三、在线协助:
如需安装运行环境或远程调试,见文章底部个人 QQ 名片,由专业技术人员远程协助!
1)远程安装运行环境,代码调试
2)Visual Studio, Qt, C++, Python编程语言入门指导
3)界面美化
4)软件制作
5)云服务器申请
6)网站制作
当前文章连接:https://blog.csdn.net/alicema1111/article/details/132666851
个人博客主页:https://blog.csdn.net/alicema1111?type=blog
博主所有文章点这里:https://blog.csdn.net/alicema1111?type=blog
博主推荐:
Python人脸识别考勤打卡系统:
https://blog.csdn.net/alicema1111/article/details/133434445
Python果树水果识别:https://blog.csdn.net/alicema1111/article/details/130862842
Python+Yolov8+Deepsort入口人流量统计:https://blog.csdn.net/alicema1111/article/details/130454430
Python+Qt人脸识别门禁管理系统:https://blog.csdn.net/alicema1111/article/details/130353433
Python+Qt指纹录入识别考勤系统:https://blog.csdn.net/alicema1111/article/details/129338432
Python Yolov5火焰烟雾识别源码分享:https://blog.csdn.net/alicema1111/article/details/128420453
Python+Yolov8路面桥梁墙体裂缝识别:https://blog.csdn.net/alicema1111/article/details/133434445