将下列代码改为cot平滑://加权拉普拉斯平滑 float smooth() { 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) { cog += mesh.point(*vv_it); ++valence; } 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; }
时间: 2024-04-02 07:33:20 浏览: 185
以下是将代码修改为cot平滑的方法:
1. 首先,需要使用边界角的cot权重计算每个顶点的权重。
2. 然后,使用cot权重对每个顶点的邻域点进行加权计算,得到平滑后的坐标。
3. 最后,根据平滑后的坐标更新每个顶点的位置。
修改后的代码如下:
float smooth() {
float err = -1;
cogs.clear();
v_end = mesh.vertices_end();
//cot平滑
for (v_it = mesh.vertices_begin(); v_it != v_end; ++v_it) {
cog[0] = cog[1] = cog[2] = weight_sum = 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);
weight_sum += cot_weight;
}
cogs.push_back(cog / weight_sum);
}
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函数的定义如下:
double cot(MyMesh::Point a, MyMesh::Point b) {
return dot(a, b) / cross(a, b).norm();
}
注意,这里使用的是边界角的cot权重,因此在计算cot权重时需要判断当前边是否为边界。
阅读全文
相关推荐
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)