0%

OpenMesh基础文档

自动摘要: [OpenMesh入门文档V1.0.pdf](https://www.yuque.com/attachments/yuque/0/2022/pdf/22210919/1649985040908df5 ……..

OpenMesh入门文档V1.0.pdf

半边结构

洞的表达

元素总数

1
2
3
4
5
int n_vertices = mesh->n_vertices();
int n_edges = mesh->n_edges();
int n_halfedges = mesh->n_halfedges();
int n_faces = mesh->n_faces();

索引和handle转换

1
2
3
4
CTriMesh::VertexHandle vh;
int idx = vh.idx(); //handle转索引
vh = mesh->vertex_handle(idx); //索引转handle

点坐标

1
CTriMesh::Point p = mesh->point(vh);

法向量

1
2
3
4
5
6
CTriMesh::Normal n = mesh->normal(vh);
CTriMesh::Normal n = mesh->normal(fh);
//访问法向量前,必须调用如下语句:
//mesh->request_vertex_normals();
//mesh->request_face_normals();

边界判断(点、面)

1
2
mesh->is_boundary(vh);
mesh->is_boundary(fh);

遍历

1
2
3
4
5
6
7
CTriMesh::VertexIter       CTriMesh::EdgeIter   
CTriMesh::HalfedgeIter CTriMesh::FaceIter
for(auto v_it = mesh->vertices_begin();
v_it != mesh->vertices_end(); ++v_it)
{
CTriMesh::VertexHandle vh = *v_it;
}

半边结构相关

半边起点和终点

1
2
3
CTriMesh::HalfedgeHandle heh;
CTriMesh::VertexHandle vh1 = mesh->from_vertex_handle(heh);
CTriMesh::VertexHandle vh2 = mesh->to_vertex_handle(heh);

得到半边所在的面(唯一的面)

1
2
CTriMesh::FaceHandle fh = mesh->face_handle(heh);

得到上一条和下一条半边

1
2
3
CTriMesh::HalfedgeHandle heh2 = mesh->prev_halfedge_handle(heh);
CTriMesh::HalfedgeHandle heh2 = mesh->next_halfedge_handle(heh);

得到对向的半边

1
2
CTriMesh::HalfedgeHandle heh2 = mesh->opposite_halfedge_handle(heh);

邻域遍历

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
CTriMesh::VertexVertexIter        //点周围的点
CTriMesh::VertexOHalfedgeIter //点出发的半边
CTriMesh::VertexFaceIter //点周围的面
CTriMesh::FaceVertexIter //面的三个顶点
CTriMesh::FaceHalfedgeIter //面的三个半边
CTriMesh::FaceFaceIter //面周围的面
//有些遍历器提供CW和CCW,例如VertexOHalfedgeCCWIter



for(CTriMesh::VertexVertexIter vv_it = mesh->vv_begin(vh);
vv_it != mesh->vv_end(); ++vv_it)

for(CTriMesh::VertexVertexIter vv_it = mesh->vv_iter(vh);
vv_it.is_valid(); ++vv_it)

//以上两种写法一样

内置属性

1
2
3
4
5
6
7
8
selected、locked、feature、tagged、tagged2、deleted
//使用系统属性前必须先调用如下代码:
mesh->request_vertex_status();
mesh->request_face_status();
mesh_->status(vh).set_selected(true)
bool is_selected = mesh_->status(vh).selected();
mesh->release_vertex_status();

自定义属性

1
2
3
4
5
6
7
8
9
//任何类型(包括类)都可以作为属性值
//点、边、半边、面、Mesh都可以设置自定义属性
OpenMesh::VPropHandleT<int> valences; //定义点属性
OpenMesh::FPropHandleT<int> valences; //定义面属性
mesh->add_property(valence);
mesh_->BaseKernel::property(valences, vh) = 1;
int value = mesh_->BaseKernel::property(valences, vh);
mesh->remove_property(valence);

向量运算

1
2
3
4
5
6
单位化:    n.normalized();

内积: float d = v1 | v2; (VCG是*)

叉积: CTriMesh::Normal v3 = v1 % v2 (VCG是^)

边/半边转换

1
2
3
CTriMesh::EdgeHandle eh=mesh->edge_handle(heh);
CTriMesh::HalfedgeHandle heh1=mesh->halfedge_handle(eh, 0);

边的长度

1
2
float edge_len = mesh->calc_edge_length(heh);

两点之间的距离

1
2
CTriMesh::Point p1, p2;    
float len = (p1 – p2).norm();

增加点:

1
2
CTriMesh::Point p(0.0f, 0.0f, 0.0f);
CTriMesh::VertexHandle vh = mesh->add_vertex(p);

增加面:

1
2
CTriMesh::FaceHandle fh = mesh->add_face(vh1, vh2, vh3);

删除点和面

1
2
3
mesh->delete_vertex(vh);
mesh->delete_face(fh);

回收已删除的点、面(类似VCG的compact)

1
mesh->garbage_collection(true)

点周围一领域的点数(点的度)

1
int valence = mesh->valence(vh);

边拆分成两段

1
mesh->split(heh,vh);

边翻转

1
2
mesh->is_flip_ok(heh);
mesh->flip(heh);

边折叠

1
2
mesh->is_collapse_ok(heh);   //不是很完美,我们需要从VCG充实
mesh->collapse(heh);

内置算法

简化:Decumater

细分:Subdivision

1
2
3
4
5
6
7
8
9
10
11
12
13
14
// Uniform subdivision
OpenMesh::SUbdivision::Uniform::LoopT
OpenMesh::SUbdivision::Uniform::Sqrt3T
OpenMesh::SUbdivision::Uniform::ModifiedButterflyT
OpenMesh::SUbdivision::Uniform::InterpolatingSqrt3LGT
OpenMesh::SUbdivision::Uniform::CompositeT
OpenMesh::SUbdivision::Uniform::CatmullClarkT
OpenMesh::SUbdivision::Uniform::MidpointT

// Adaptive subdvison
OpenMesh::SUbdivision::Adaptive::CompositeT

// Simple subdvison
OpenMesh::SUbdivision::Uniform::LongestEdgeT

平滑:Smoother

1
2
3
OpenMesh::Smoother::SmootherT
OpenMesh::Smoother::LaplaceSmootherT
OpenMesh::Smoother::jacobiLaplaceSmootherT

OpenMesh8.1新功能

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
for (auto vh : mesh.vertices())
{
std::vector<OpenMesh::VertexHandle> opposite_vertices;
for (auto heh : mesh.voh_range(vh))
{
opposite_vertices.push_back(mesh.to_vertex_handle(mesh.next_halfedge_handle(mesh.opposite_halfedge_handle(mesh.next_halfedge_handle(heh)))));
}
}

//smart Handle用法
for (auto vh : mesh.vertices())
{
std::vector<OpenMesh::VertexHandle> opposite_vertices;
for (auto heh : vh.outgoing_halfedges())
opposite_vertices.push_back(heh.next().opp().next().to());
}



欢迎关注我的其它发布渠道