在下列代码中如何表示与v_it及vv_it相邻的两个点float smoothCot() { float err = -1; cogs.clear(); v_end = mesh.vertices_end(); // for (v_it = mesh.vertices_begin(); v_it != v_end; ++v_it) { cog[0] = cog[1] = cog[2] = valence = 0.0; //cout << valence<<"1" << endl; for (vv_it = mesh.vv_iter(*v_it); vv_it.is_valid(); ++vv_it) { double cot_weight = 0.0; MyMesh::HalfedgeHandle heh = mesh.find_halfedge(*v_it, *vv_it); if (!mesh.is_boundary(heh)) { MyMesh::HalfedgeHandle prev_heh = mesh.prev_halfedge_handle(heh); MyMesh::HalfedgeHandle next_heh = mesh.next_halfedge_handle(heh); MyMesh::VertexHandle prev_vh = mesh.to_vertex_handle(prev_heh); MyMesh::VertexHandle next_vh = mesh.to_vertex_handle(next_heh); MyMesh::Point prev_p = mesh.point(prev_vh); MyMesh::Point curr_pi = mesh.point(*v_it); MyMesh::Point curr_pj = mesh.point(*vv_it); MyMesh::Point next_p = mesh.point(next_vh); double cot_alpha = cot(curr_pi - prev_p, curr_pj - prev_p); double cot_beta = cot(curr_pi - next_p, curr_pj - next_p); cot_weight = cot_alpha + cot_beta; //cout << cot_weight<<"2" << endl; } cog += cot_weight *( mesh.point(*vv_it)-mesh.point(*v_it)); valence += cot_weight; //cout << valence<<"3" << endl; } cogs.push_back(cog / valence); } for (v_it = mesh.vertices_begin(), cog_it = cogs.begin(); v_it != v_end; ++v_it, ++cog_it) { if (!mesh.is_boundary(*v_it)) { MyMesh::Point p = mesh.point(*v_it); //*cog_it += mesh.point(*v_it); err = max(err, (p - *cog_it).norm()); mesh.set_point(*v_it, *cog_it); } } return err; }

时间: 2024-04-02 07:31:03 浏览: 13
与v_it及vv_it相邻的两个点可以表示为prev_vh和next_vh,分别表示v_it的前一个点和后一个点的VertexHandle。在代码中,可以使用mesh.to_vertex_handle()函数将HalfedgeHandle转换为VertexHandle,从而获取前一个点和后一个点的VertexHandle,再使用mesh.point()函数获取点的坐标,即可计算cot_alpha和cot_beta的值。
相关问题

在下列代码中如何表示与v_it及vv_it相邻的两个点,请写出具体代码:float smoothCot() { float err = -1; cogs.clear(); v_end = mesh.vertices_end(); // for (v_it = mesh.vertices_begin(); v_it != v_end; ++v_it) { cog[0] = cog[1] = cog[2] = valence = 0.0; //cout << valence<<"1" << endl; for (vv_it = mesh.vv_iter(*v_it); vv_it.is_valid(); ++vv_it) { double cot_weight = 0.0; MyMesh::HalfedgeHandle heh = mesh.find_halfedge(*v_it, *vv_it); if (!mesh.is_boundary(heh)) { MyMesh::HalfedgeHandle prev_heh = mesh.prev_halfedge_handle(heh); MyMesh::HalfedgeHandle next_heh = mesh.next_halfedge_handle(heh); MyMesh::VertexHandle prev_vh = mesh.to_vertex_handle(prev_heh); MyMesh::VertexHandle next_vh = mesh.to_vertex_handle(next_heh); MyMesh::Point prev_p = mesh.point(prev_vh); MyMesh::Point curr_pi = mesh.point(*v_it); MyMesh::Point curr_pj = mesh.point(*vv_it); MyMesh::Point next_p = mesh.point(next_vh); double cot_alpha = cot(curr_pi - prev_p, curr_pj - prev_p); double cot_beta = cot(curr_pi - next_p, curr_pj - next_p); cot_weight = cot_alpha + cot_beta; //cout << cot_weight<<"2" << endl; } cog += cot_weight *( mesh.point(*vv_it)-mesh.point(*v_it)); valence += cot_weight; //cout << valence<<"3" << endl; } cogs.push_back(cog / valence); } for (v_it = mesh.vertices_begin(), cog_it = cogs.begin(); v_it != v_end; ++v_it, ++cog_it) { if (!mesh.is_boundary(*v_it)) { MyMesh::Point p = mesh.point(*v_it); //*cog_it += mesh.point(*v_it); err = max(err, (p - *cog_it).norm()); mesh.set_point(*v_it, *cog_it); } } return err; }

具体代码如下: ``` MyMesh::HalfedgeHandle prev_heh = mesh.prev_halfedge_handle(heh); MyMesh::HalfedgeHandle next_heh = mesh.next_halfedge_handle(heh); MyMesh::VertexHandle prev_vh = mesh.to_vertex_handle(prev_heh); MyMesh::VertexHandle next_vh = mesh.to_vertex_handle(next_heh); MyMesh::Point prev_p = mesh.point(prev_vh); MyMesh::Point next_p = mesh.point(next_vh); ``` 其中,prev_heh和next_heh分别表示heh的前一个半边和后一个半边的HalfedgeHandle,使用mesh.prev_halfedge_handle()和mesh.next_halfedge_handle()函数获取;prev_vh和next_vh分别表示heh的前一个点和后一个点的VertexHandle,使用mesh.to_vertex_handle()函数将HalfedgeHandle转换为VertexHandle获取;prev_p和next_p分别表示heh的前一个点和后一个点的坐标,使用mesh.point()函数获取。

请将下列代码改为可在vs中运行的版本:double cot(MyMesh::Point a, MyMesh::Point b) { return dot(a, b) / cross(a, b).norm(); } //cot平滑 float smoothCot() { float err = -1; cogs.clear(); v_end = mesh.vertices_end(); // for (v_it = mesh.vertices_begin(); v_it != v_end; ++v_it) { cog[0] = cog[1] = cog[2] = valence = 0.0; for (vv_it = mesh.vv_iter(*v_it); vv_it.is_valid(); ++vv_it) { double cot_weight = 0.0; MyMesh::HalfedgeHandle heh = mesh.find_halfedge(*v_it, *vv_it); if (!mesh.is_boundary(heh)) { MyMesh::HalfedgeHandle prev_heh = mesh.prev_halfedge_handle(heh); MyMesh::HalfedgeHandle next_heh = mesh.next_halfedge_handle(heh); MyMesh::VertexHandle prev_vh = mesh.to_vertex_handle(prev_heh); MyMesh::VertexHandle next_vh = mesh.to_vertex_handle(next_heh); MyMesh::Point prev_p = mesh.point(prev_vh); MyMesh::Point curr_p = mesh.point(*v_it); MyMesh::Point next_p = mesh.point(next_vh); double cot_alpha = cot(prev_p - curr_p, next_p - curr_p); double cot_beta = cot(curr_p - prev_p, next_p - prev_p); cot_weight = cot_alpha + cot_beta; } cog += cot_weight * mesh.point(*vv_it); valence += cot_weight; } cogs.push_back(cog / valence); } for (v_it = mesh.vertices_begin(), cog_it = cogs.begin(); v_it != v_end; ++v_it, ++cog_it) { if (!mesh.is_boundary(*v_it)) { MyMesh::Point p = mesh.point(*v_it); err = max(err, (p - *cog_it).norm()); mesh.set_point(*v_it, *cog_it); } } return err; } void smoothCot(float threshold) { float err; do { err = smoothCot(); cout << "err:" << err << endl; } while (err >= threshold); }

这段代码需要引入MyMesh库,你需要提供该库的头文件和实现文件。同时,需要将该代码放到合适的函数中,比如main函数中。下面是改为可在VS中运行的版本: ```c++ #include <iostream> #include "MyMesh.h" // MyMesh库的头文件 using namespace std; MyMesh mesh; // 定义一个MyMesh对象 MyMesh::VertexIter v_it, v_end; MyMesh::VertexVertexIter vv_it; vector<MyMesh::Point> cogs; vector<MyMesh::Point>::iterator cog_it; // 计算cot值 double cot(MyMesh::Point a, MyMesh::Point b) { return dot(a, b) / cross(a, b).norm(); } // 平滑cot float smoothCot() { float err = -1; cogs.clear(); v_end = mesh.vertices_end(); for (v_it = mesh.vertices_begin(); v_it != v_end; ++v_it) { MyMesh::Point cog(0, 0, 0); // 初始化为0 float valence = 0.0; for (vv_it = mesh.vv_iter(*v_it); vv_it.is_valid(); ++vv_it) { double cot_weight = 0.0; MyMesh::HalfedgeHandle heh = mesh.find_halfedge(*v_it, *vv_it); if (!mesh.is_boundary(heh)) { MyMesh::HalfedgeHandle prev_heh = mesh.prev_halfedge_handle(heh); MyMesh::HalfedgeHandle next_heh = mesh.next_halfedge_handle(heh); MyMesh::VertexHandle prev_vh = mesh.to_vertex_handle(prev_heh); MyMesh::VertexHandle next_vh = mesh.to_vertex_handle(next_heh); MyMesh::Point prev_p = mesh.point(prev_vh); MyMesh::Point curr_p = mesh.point(*v_it); MyMesh::Point next_p = mesh.point(next_vh); double cot_alpha = cot(prev_p - curr_p, next_p - curr_p); double cot_beta = cot(curr_p - prev_p, next_p - prev_p); cot_weight = cot_alpha + cot_beta; } cog += cot_weight * mesh.point(*vv_it); valence += cot_weight; } cogs.push_back(cog / valence); } for (v_it = mesh.vertices_begin(), cog_it = cogs.begin(); v_it != v_end; ++v_it, ++cog_it) { if (!mesh.is_boundary(*v_it)) { MyMesh::Point p = mesh.point(*v_it); err = max(err, (p - *cog_it).norm()); mesh.set_point(*v_it, *cog_it); } } return err; } // 迭代平滑cot值,直到err小于阈值 void smoothCot(float threshold) { float err; do { err = smoothCot(); cout << "err:" << err << endl; } while (err >= threshold); } int main() { // 读取.obj文件,这里需要提供.obj文件的路径 OpenMesh::IO::read_mesh(mesh, "path/to/your/file.obj"); // 平滑cot值 smoothCot(0.1); // 保存平滑后的模型到.obj文件,这里需要提供.obj文件的保存路径 OpenMesh::IO::write_mesh(mesh, "path/to/your/smoothed/file.obj"); return 0; } ```

相关推荐

下列代码出现nan int错误,请解决:float smoothCot() { float err = -1; cogs.clear(); v_end = mesh.vertices_end(); // for (v_it = mesh.vertices_begin(); v_it != v_end; ++v_it) { cog[0] = cog[1] = cog[2] = valence = 0.0; //cout << valence<<"1" << endl; for (vv_it = mesh.vv_iter(*v_it); vv_it.is_valid(); ++vv_it) { double cot_weight = 0.0; MyMesh::HalfedgeHandle heh = mesh.find_halfedge(*v_it, *vv_it); if (!mesh.is_boundary(heh)) { MyMesh::HalfedgeHandle prev_heh = mesh.prev_halfedge_handle(heh); MyMesh::HalfedgeHandle next_heh = mesh.next_halfedge_handle(heh); MyMesh::VertexHandle prev_vh = mesh.to_vertex_handle(prev_heh); MyMesh::VertexHandle next_vh = mesh.to_vertex_handle(next_heh); MyMesh::Point prev_p = mesh.point(prev_vh); MyMesh::Point curr_pi = mesh.point(*v_it); MyMesh::Point curr_pj = mesh.point(*vv_it); MyMesh::Point next_p = mesh.point(next_vh); double cot_alpha = cot(curr_pi - prev_p, curr_pj - prev_p); double cot_beta = cot(curr_pi - next_p, curr_pj - next_p); cot_weight = cot_alpha + cot_beta; //cout << cot_weight<<"2" << endl; } cog += cot_weight *( mesh.point(*vv_it)-mesh.point(*v_it)); valence += cot_weight; //cout << valence<<"3" << endl; } cogs.push_back(cog / valence); } for (v_it = mesh.vertices_begin(), cog_it = cogs.begin(); v_it != v_end; ++v_it, ++cog_it) { if (!mesh.is_boundary(*v_it)) { MyMesh::Point p = mesh.point(*v_it); //*cog_it += mesh.point(*v_it); err = max(err, (p - *cog_it).norm()); mesh.set_point(*v_it, *cog_it); } } return err; }

为什么在下列代码中如何表示与*v_it与prev_vh表示的是同一个点:float smoothCot() { float err = -1; cogs.clear(); v_end = mesh.vertices_end(); // for (v_it = mesh.vertices_begin(); v_it != v_end; ++v_it) { cog[0] = cog[1] = cog[2] = valence = 0.0; //cout << valence<<"1" << endl; for (vv_it = mesh.vv_iter(*v_it); vv_it.is_valid(); ++vv_it) { double cot_weight = 0.0; MyMesh::HalfedgeHandle heh = mesh.find_halfedge(*v_it, *vv_it); if (!mesh.is_boundary(heh)) { MyMesh::HalfedgeHandle prev_heh = mesh.prev_halfedge_handle(heh); MyMesh::HalfedgeHandle next_heh = mesh.next_halfedge_handle(heh); MyMesh::VertexHandle prev_vh = mesh.to_vertex_handle(prev_heh); MyMesh::VertexHandle next_vh = mesh.to_vertex_handle(next_heh); MyMesh::Point prev_p = mesh.point(prev_vh); MyMesh::Point curr_pi = mesh.point(*v_it); MyMesh::Point curr_pj = mesh.point(*vv_it); MyMesh::Point next_p = mesh.point(next_vh); double cot_alpha = cot(curr_pi - prev_p, curr_pj - prev_p); double cot_beta = cot(curr_pi - next_p, curr_pj - next_p); cot_weight = cot_alpha + cot_beta; //cout << cot_weight<<"2" << endl; } cog += cot_weight *( mesh.point(*vv_it)-mesh.point(*v_it)); valence += cot_weight; //cout << valence<<"3" << endl; } cogs.push_back(cog / valence); } for (v_it = mesh.vertices_begin(), cog_it = cogs.begin(); v_it != v_end; ++v_it, ++cog_it) { if (!mesh.is_boundary(*v_it)) { MyMesh::Point p = mesh.point(*v_it); //*cog_it += mesh.point(*v_it); err = max(err, (p - *cog_it).norm()); mesh.set_point(*v_it, *cog_it); } } return err; }

为什么在下列代码中如何表示与curr_pi与prev_p表示的是同一个点:float smoothCot() { float err = -1; cogs.clear(); v_end = mesh.vertices_end(); // for (v_it = mesh.vertices_begin(); v_it != v_end; ++v_it) { cog[0] = cog[1] = cog[2] = valence = 0.0; //cout << valence<<"1" << endl; for (vv_it = mesh.vv_iter(*v_it); vv_it.is_valid(); ++vv_it) { double cot_weight = 0.0; MyMesh::HalfedgeHandle heh = mesh.find_halfedge(*v_it, *vv_it); if (!mesh.is_boundary(heh)) { MyMesh::HalfedgeHandle prev_heh = mesh.prev_halfedge_handle(heh); MyMesh::HalfedgeHandle next_heh = mesh.next_halfedge_handle(heh); MyMesh::VertexHandle prev_vh = mesh.to_vertex_handle(prev_heh); MyMesh::VertexHandle next_vh = mesh.to_vertex_handle(next_heh); MyMesh::Point prev_p = mesh.point(prev_vh); MyMesh::Point curr_pi = mesh.point(*v_it); MyMesh::Point curr_pj = mesh.point(*vv_it); MyMesh::Point next_p = mesh.point(next_vh); double cot_alpha = cot(curr_pi - prev_p, curr_pj - prev_p); double cot_beta = cot(curr_pi - next_p, curr_pj - next_p); cot_weight = cot_alpha + cot_beta; //cout << cot_weight<<"2" << endl; } cog += cot_weight *( mesh.point(*vv_it)-mesh.point(*v_it)); valence += cot_weight; //cout << valence<<"3" << endl; } cogs.push_back(cog / valence); } for (v_it = mesh.vertices_begin(), cog_it = cogs.begin(); v_it != v_end; ++v_it, ++cog_it) { if (!mesh.is_boundary(*v_it)) { MyMesh::Point p = mesh.point(*v_it); //*cog_it += mesh.point(*v_it); err = max(err, (p - *cog_it).norm()); mesh.set_point(*v_it, *cog_it); } } return err; }

请逐行解释下列代码:double cot(MyMesh::Point a, MyMesh::Point b) { return dot(a, b) / cross(a, b).norm(); } //cot平滑 float smoothCot() { float err = -1; cogs.clear(); v_end = mesh.vertices_end(); // for (v_it = mesh.vertices_begin(); v_it != v_end; ++v_it) { cog[0] = cog[1] = cog[2] = valence = 0.0; for (vv_it = mesh.vv_iter(*v_it); vv_it.is_valid(); ++vv_it) { double cot_weight = 0.0; MyMesh::HalfedgeHandle heh = mesh.find_halfedge(*v_it, *vv_it); if (!mesh.is_boundary(heh)) { MyMesh::HalfedgeHandle prev_heh = mesh.prev_halfedge_handle(heh); MyMesh::HalfedgeHandle next_heh = mesh.next_halfedge_handle(heh); MyMesh::VertexHandle prev_vh = mesh.to_vertex_handle(prev_heh); MyMesh::VertexHandle next_vh = mesh.to_vertex_handle(next_heh); MyMesh::Point prev_p = mesh.point(prev_vh); MyMesh::Point curr_p = mesh.point(*v_it); MyMesh::Point next_p = mesh.point(next_vh); double cot_alpha = cot(prev_p - curr_p, next_p - curr_p); double cot_beta = cot(curr_p - prev_p, next_p - prev_p); cot_weight = cot_alpha + cot_beta; } cog += cot_weight * mesh.point(*vv_it); valence += cot_weight; } cogs.push_back(cog / valence); } for (v_it = mesh.vertices_begin(), cog_it = cogs.begin(); v_it != v_end; ++v_it, ++cog_it) { if (!mesh.is_boundary(*v_it)) { MyMesh::Point p = mesh.point(*v_it); err = max(err, (p - *cog_it).norm()); mesh.set_point(*v_it, *cog_it); } } return err; } void smoothCot(float threshold) { float err; do { err = smoothCot(); cout << "err:" << err << endl; } while (err >= threshold); }

最新推荐

recommend-type

解决vue net :ERR_CONNECTION_REFUSED报错问题

主要介绍了解决vue net :ERR_CONNECTION_REFUSED报错问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
recommend-type

解决安装wordpress时出现ERR_TOO_MANY_REDIRECTS重定向次数过多问题 原创

本文主要介绍了如何解决安装wordpress时出现ERR_TOO_MANY_REDIRECTS重定向次数过多导致无法安装的问题
recommend-type

MySQL复制出错 Last_SQL_Errno:1146的解决方法

主要介绍了MySQL复制出错 Last_SQL_Errno:1146的解决方法,需要的朋友可以参考下
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

实现实时数据湖架构:Kafka与Hive集成

![实现实时数据湖架构:Kafka与Hive集成](https://img-blog.csdnimg.cn/img_convert/10eb2e6972b3b6086286fc64c0b3ee41.jpeg) # 1. 实时数据湖架构概述** 实时数据湖是一种现代数据管理架构,它允许企业以低延迟的方式收集、存储和处理大量数据。与传统数据仓库不同,实时数据湖不依赖于预先定义的模式,而是采用灵活的架构,可以处理各种数据类型和格式。这种架构为企业提供了以下优势: - **实时洞察:**实时数据湖允许企业访问最新的数据,从而做出更明智的决策。 - **数据民主化:**实时数据湖使各种利益相关者都可
recommend-type

用 Python 画一个可以动的爱心

好的,我可以帮助您使用Python来绘制一个动态的爱心。您可以使用turtle库来实现。以下是实现代码: ```python import turtle import math # 设置画布和画笔 canvas = turtle.Screen() canvas.bgcolor("black") pencil = turtle.Turtle() pencil.speed(0) pencil.color("red", "pink") pencil.pensize(3) # 定义爱心函数 def draw_love(heart_size, x_offset=0, y_offset=0):
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。
recommend-type

"互动学习:行动中的多样性与论文攻读经历"

多样性她- 事实上SCI NCES你的时间表ECOLEDO C Tora SC和NCESPOUR l’Ingén学习互动,互动学习以行动为中心的强化学习学会互动,互动学习,以行动为中心的强化学习计算机科学博士论文于2021年9月28日在Villeneuve d'Asq公开支持马修·瑟林评审团主席法布里斯·勒菲弗尔阿维尼翁大学教授论文指导奥利维尔·皮耶昆谷歌研究教授:智囊团论文联合主任菲利普·普雷教授,大学。里尔/CRISTAL/因里亚报告员奥利维耶·西格德索邦大学报告员卢多维奇·德诺耶教授,Facebook /索邦大学审查员越南圣迈IMT Atlantic高级讲师邀请弗洛里安·斯特鲁布博士,Deepmind对于那些及时看到自己错误的人...3谢谢你首先,我要感谢我的两位博士生导师Olivier和Philippe。奥利维尔,"站在巨人的肩膀上"这句话对你来说完全有意义了。从科学上讲,你知道在这篇论文的(许多)错误中,你是我可以依
recommend-type

实现实时监控告警系统:Kafka与Grafana整合

![实现实时监控告警系统:Kafka与Grafana整合](https://imgconvert.csdnimg.cn/aHR0cHM6Ly9tbWJpei5xcGljLmNuL21tYml6X2pwZy9BVldpY3ladXVDbEZpY1pLWmw2bUVaWXFUcEdLT1VDdkxRSmQxZXB5R1lxaWNlUjA2c0hFek5Qc3FyRktudFF1VDMxQVl3QTRXV2lhSWFRMEFRc0I1cW1ZOGcvNjQw?x-oss-process=image/format,png) # 1.1 Kafka集群架构 Kafka集群由多个称为代理的服务器组成,这