VS+C++VTK-VCG三维网格模型鼠标框选拉普拉斯局部平滑

news2024/9/22 9:47:23

程序示例精选
VS+C++VTK-VCG三维网格模型鼠标框选拉普拉斯局部平滑
如需安装运行环境或远程调试,见文章底部个人QQ名片,由专业技术人员远程协助!

前言

这篇博客针对《VS+C++VTK-VCG三维网格模型鼠标框选拉普拉斯局部平滑》编写代码,代码整洁,规则,易读。 学习与应用推荐首选。


文章目录

一、所需工具软件
二、使用步骤
       1. 主要代码
       2. 运行结果
三、在线协助

一、所需工具软件

       1. Visual Studio
       2. C++, VTK, VCG

二、使用步骤

代码如下(示例):





#include <vtkSTLReader.h>
#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingOpenGL2)
VTK_MODULE_INIT(vtkInteractionStyle);
VTK_MODULE_INIT(vtkRenderingFreeType);
#include "vtkDICOMImageReader.h"
#include "vtkFixedPointVolumeRayCastMapper.h"
#include "vtkColorTransferFunction.h"
#include "vtkPiecewiseFunction.h"
#include "vtkVolumeProperty.h"
#include "vtkVolume.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkImageMapToColors.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkCutter.h"
#include "vtkPlane.h"
#include "vtkImageActor.h"
#include "vtkImageData.h"
#include "vtkImageCast.h"
#include "vtkPointData.h"
#include "vtkImageShiftScale.h"
#include "vtkPolyDataToImageStencil.h"
#include "vtkImageStencil.h"
#include "vtkLookupTable.h"
#include "vtkImagePlaneWidget.h"
#include "vtkCellArray.h"
#include "vtkType.h"
#include "vtkPlaneWidget.h"
using namespace vcg;
using namespace std;

class MyFace;
class MyVertex;

struct MyUsedTypes : public UsedTypes<Use<MyVertex>::AsVertexType, Use<MyFace>::AsFaceType> {};
class MyVertex : public Vertex<MyUsedTypes, vertex::VFAdj, vertex::Coord3f, vertex::Normal3f, vertex::BitFlags> {};
class MyFace : public Face<MyUsedTypes, face::VFAdj, face::Normal3f, face::VertexRef, face::BitFlags> {};
class MyMesh : public vcg::tri::TriMesh<vector<MyVertex>, vector<MyFace>> {};

// 加载选定的点的函数
void LoadSelectedPoints(const string& filename, vector<Point3f>& selectedPoints) {
    ifstream file(filename);
    if (!file.is_open()) {
        cerr << "Could not open the file: " << filename << endl;
        return;
    }

    string line;
    while (getline(file, line)) {
        stringstream ss(line);
        float x, y, z;
        if (ss >> x >> y >> z) { // 读取 x, y, z 坐标
            selectedPoints.emplace_back(x, y, z);
        }
    }
    file.close();
}
// 文件复制函数
bool CopyFile(const std::string& source, const std::string& destination)
{
    std::ifstream src(source, std::ios::binary);
    std::ofstream dest(destination, std::ios::binary);
    if (!src || !dest) {
        std::cerr << "文件复制失败:" << source << " 到 " << destination << std::endl;
        return false;
    }
    dest << src.rdbuf();
    return true;
}

int main(int, char* [])
{
    /*MyMesh m;*/
    int mask;
    if (tri::io::ImporterSTL<MyMesh>::Open(m, "eros.stl", mask) != tri::io::Importer<MyMesh>::E_NOERROR) {
        std::cerr << "Error while opening the file" << std::endl;
        return 0;
    )
    vtkNew<vtkNamedColors> colors;

    //vtkNew<vtkPointSource> pointSource;
    //pointSource->SetNumberOfPoints(20);
    //pointSource->Update();

    // 代码中的适当位置加入以下内容
    std::string originalFilename = "eros.stl";
    std::string tempFilename = "customer_model_1temp.stl";
    // 复制文件
    if (!CopyFile(originalFilename, tempFilename)) {
        std::cerr << "复制文件失败,请检查文件路径。" << std::endl;
        return 0;
    }

    std::string inputFilename = "customer_model_1temp.stl";
    vtkSmartPointer<vtkSTLReader> reader = vtkSmartPointer<vtkSTLReader>::New();
    reader->SetFileName(inputFilename.c_str());
    reader->Update();

    vtkNew<vtkIdFilter> idFilter;
    idFilter->SetInputConnection(reader->GetOutputPort());
#if VTK890
    idFilter->SetCellIdsArrayName("OriginalIds");
    idFilter->SetPointIdsArrayName("OriginalIds");
#else
    idFilter->SetIdsArrayName("OriginalIds");
#endif
    idFilter->Update();

    vtkNew<vtkDataSetSurfaceFilter> surfaceFilter;
    surfaceFilter->SetInputConnection(idFilter->GetOutputPort());
    surfaceFilter->Update();

    vtkPolyData* input = surfaceFilter->GetOutput();

    // Create a mapper and actor
    vtkNew<vtkPolyDataMapper> mapper;
    mapper->SetInputData(input);
    mapper->ScalarVisibilityOff();

    vtkNew<vtkActor> actor;
    actor->SetMapper(mapper);
    actor->GetProperty()->SetPointSize(3);
    //actor->GetProperty()->SetColor(colors->GetColor3d("Gold").GetData());
    actor->GetProperty()->SetColor(0.60784313725, 0.60784313725, 0.60784313725);

    actor->GetProperty()->SetEdgeColor(0, 0, 1); // 设置边缘颜色为蓝色
    actor->GetProperty()->SetEdgeVisibility(1);

    // Visualize
    vtkNew<vtkRenderer> renderer;
    vtkNew<vtkRenderWindow> renderWindow;
    renderWindow->AddRenderer(renderer);
    renderWindow->SetWindowName("HighlightSelectedPoints");

    vtkNew<vtkAreaPicker> areaPicker;
    vtkNew<vtkRenderWindowInteractor> renderWindowInteractor;
    renderWindowInteractor->SetPicker(areaPicker);
    renderWindowInteractor->SetRenderWindow(renderWindow);

    renderer->AddActor(actor);
    renderer->SetBackground(colors->GetColor3d("Black").GetData());

    renderWindow->Render();

    vtkNew<InteractorStyle> style;
    style->SetPoints(input);
    renderWindowInteractor->SetInteractorStyle(style);

    renderWindowInteractor->Start();

    return EXIT_SUCCESS;
}





运行结果

平滑之前

平滑之后
在这里插入图片描述

三、在线协助:

如需安装运行环境或远程调试,见文章底部个人 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
Python+Yolov5道路障碍物识别:https://blog.csdn.net/alicema1111/article/details/129589741
Python+Yolov5跌倒检测 摔倒检测 人物目标行为 人体特征识别:https://blog.csdn.net/alicema1111/article/details/129272048

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2097392.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

鸿蒙(API 12 Beta3版)【媒体资源使用指导】Media Library Kit媒体文件管理服务

应用可以通过photoAccessHelper的接口&#xff0c;对媒体资源&#xff08;图片、视频&#xff09;进行相关操作。 说明 在进行功能开发前&#xff0c;请开发者查阅[开发准备]&#xff0c;了解如何获取相册管理模块实例和如何申请相册管理模块功能开发相关权限。文档中使用到p…

AI圈内爆火的大模型黑书,建议学习大模型的朋友都去死磕这本书!

书籍介绍 今天给大家推荐一本丹尼斯罗斯曼(Denis Rothman)编写的关于大语言模型&#xff08;LLM&#xff09;权威教程<<大模型应用解决方案> 基于GPT-3、ChatGPT、GPT-4等Transformer架构的自然语言处理>&#xff01;Google工程总监Antonio Gulli作序&#xff0c;…

上海亚商投顾:创业板指放量大涨 两市成交额超8700亿

上海亚商投顾前言&#xff1a;无惧大盘涨跌&#xff0c;解密龙虎榜资金&#xff0c;跟踪一线游资和机构资金动向&#xff0c;识别短期热点和强势个股。 一.市场情绪 三大指数8月30日全线反弹&#xff0c;沪指盘中涨超1.5%&#xff0c;深成指一度涨逾3%&#xff0c;创业板指午后…

hexo博客加密

查了很多教程&#xff0c;总结如下&#x1f447; 1.安装encrypt插件 npm install --save hexo-blog-encrypt 注意上面这个插件要安在博客文件夹里&#xff0c;我当时安好了设密码然后博客还和原来一样&#xff0c;后来发现安错地方了。 2.修改_config.yml文件 加上下面的配…

C++初学(19)

19.1、文本IO 如果你需要写入一千份以上的数据&#xff0c;如果手打那可太浪费时间了。这种情况下&#xff0c;应该让程序直接读取文件&#xff1b;同样的&#xff0c;让程序将输入写入到文件也是更加方便。 文本I/O的概念&#xff1a;使用cin进行输入时&#xff0c;程序将输…

【高阶数据结构】B树、B+树、B*树

B树、B树、B*树 1. 常见的搜索结构2. B树概念3. B树的插入分析4. B树的插入实现4.1 B树的节点设计4.2 B树的部分插入实现14.3 B树的查找4.4 B树的部分插入实现24.5 插入key的过程4.7 B树的插入完整代码4.8 B树的简单验证4.9 B树的删除4.10 B树的性能分析 5. B树6. B*树7. 总结8…

欧科云链OKLink受邀参与WebX ,旗下EaaS助力项目方“弯道超车”

8 月 27 日&#xff0c;作为亚洲顶级区块链行业盛会 WebX 的 side event 之一的 OKJ Night 在东京盛大拉开帷幕&#xff0c;会上正式宣布 OKCoin Japan 升级为 OKJ&#xff0c;进一步以合规的形式推动区块链产业在日蓬勃发展。日本首相为本次活动发来贺电。 OKLink 非常荣幸作为…

吹爆上海交大的大模型实战教程!!非常详细收藏我这一篇就够了

各位好&#xff0c;这里是DASOU 今天分享一个上海交大的免费的大模型课程&#xff0c;有相关教程文档和Slides&#xff0c;目前是1.6K星标&#xff0c;还是挺火的 项目动机 《动手学大模型》系列编程实践教程&#xff0c;由上海交通大学2024年春季《人工智能安全技术》课程&…

哈希基础概念即使用(C++)

目录 1. unordered系列关联式容器 1.1 unordered_map 1.1.1 unordered_map的文档介绍 1.1.2 unordered_map的接口说明 1. unordered_map的构造 2. unordered_map的容量 3. unordered_map的迭代器 4. unordered_map的元素访问 5. unordered_map的查询 6. unordered_map的修改操作…

为Jekyll站添加“相关文章“功能

想为本博客添加相关文章功能&#xff0c;因为本站是通过Jekyll搭建的静态站&#xff0c;所以首先想到通过Jekyll相关插件解决&#xff0c;没想到搜遍全网居然未找到可用的插件&#xff0c;无奈最后手敲实现&#xff0c;以下记录折腾过程。 全文详见个人独立博客&#xff1a;ht…

armbian cups 远程打印机 1022

使用 CUPS Web 浏览器界面设置和管理打印机 - Oracle Solaris 管理&#xff1a;常见任务 N1刷armbian变身打印服务器&#xff0c;支持全平台无线打印PC扫描_存储设备_什么值得买 (smzdm.com) 第 6 章 使用 Web 界面向 CUPS 添加打印机 | Red Hat Product Documentation apt…

poi中导入excel时,获取下拉选项、解析从子表引用的下拉选项

我们导入excel表&#xff0c;解析数据时&#xff0c;有的时候需要把单元格是下拉框的所有下拉项拿到&#xff0c;有的下拉项是直接在单元格里面添加的下拉列表&#xff0c;还有的下拉项则是从其它表引用过来的&#xff0c;如下图&#xff1a; 那我们要怎么读取这两种不同方式添…

Python 通过邮件合并(Mail Merge)批量生成Word文档

目录 使用工具 创建邮件合并模板 使用 Python 在 Word 中执行邮件合并 使用 Python 在 Word 中通过邮件合并一次性生成多个文档 使用 Python 获取 Word 中的合并域的名称 邮件合并是 Microsoft Word 中一项非常有用的功能&#xff0c;它让用户能够将事先设计好的模板与数据…

华为云征文 | 华为云Flexus云服务器X实例全面使用操作指南

文章目录 一、华为云Flexus云服务器X实例⛅华为云Flexus云服务器X实例特点☁️为什么选择华为云Flexus云服务器X实例&#xff1f;☀️基于业务负载&#xff0c;灵活调配产品价格 二、快速上手华为云Flexus云服务器X实例⚡注册华为云账号⌚进入Flexus云服务器X实例介绍页面⏰购买…

苹果手机怎么开定位?2个神操作,快速打开定位

网上一直流行着这样一句玩笑话&#xff1a;“出门不开定位导航&#xff0c;就会变成下一个失踪人口。” 这句话也从侧面反映出手机的定位服务对于大部分用户来说非常重要。那么&#xff0c;对于苹果用户来说&#xff0c;苹果手机怎么开定位呢&#xff1f;今天&#xff0c;小编…

利用固定窗口计数算法限流,精准控制第三方 API 调用频率

文章目录 使用场景使用固定窗口计数算法管理调用频率使用测试一秒钟执行五次适用场景 使用场景 在调用第三方 API 时&#xff0c;我们通常会在 API 文档中看到对接口访问频率的限制。为了确保不超出这些限制&#xff0c;使用限流算法来控制 API 调用频率是至关重要的。 在作为…

Spike-in:微生态16S扩增子绝对定量重磅上线!

16S扩增子测序是一种广泛应用于微生物群落分析的技术&#xff0c;主要用于研究环境样本中微生物的种类、丰度及其生态关系。 然而&#xff0c;传统的16S扩增子测序通常只能提供相对丰度数据&#xff0c;无法准确反映样本中各微生物的绝对数量&#xff0c;导致在一定程度上掩盖…

论文理解【LLM-agent】—— 【Reflexion】Language Agents with Verbal Reinforcement Learning

文章链接&#xff1a;Reflexion: Language Agents with Verbal Reinforcement Learning代码&#xff1a;GitHub - noahshinn/reflexion发表&#xff1a;NIPS 2023领域&#xff1a;LLM agent一句话总结&#xff1a;传统强化学习 Agent 通过和环境交互进行试错学习&#xff0c;但…

python-比身高

题目描述 班上有n个同学。现在同学们排成了一队&#xff0c;每个同学都想知道在自己前面有多少个同学比自己高。现在告诉你班上同学们排好队后每个同学的身高&#xff0c;请告诉每个人在他们前面有多少人比他们高。输入&#xff1a; 输入共两行。 第一行一个整数n。 第二行n个整…

实战|任意用户漏洞挖掘分享

吉祥知识星球http://mp.weixin.qq.com/s?__bizMzkwNjY1Mzc0Nw&mid2247485367&idx1&sn837891059c360ad60db7e9ac980a3321&chksmc0e47eebf793f7fdb8fcd7eed8ce29160cf79ba303b59858ba3a6660c6dac536774afb2a6330&scene21#wechat_redirect 《网安面试指南》…