简介

在网格中查找这个点的领域节点。

代码

#include <iostream>
#include <OpenMesh/Core/IO/MeshIO.hh>
#include <OpenMesh/Core/Mesh/TriMesh_ArrayKernelT.hh>
using namespace std;
typedef OpenMesh::TriMesh_ArrayKernelT<> MyMesh;
int main()
{
	MyMesh mesh;
	int m, n, a, x0, y0;
	cout << "网格长度m="; cin >> m;
	cout << "网格宽度n="; cin >> n;
	double length = 1;
	MyMesh::VertexHandle **vhandle = new MyMesh::VertexHandle*[m];
	for (int i = 0; i < m; i++) {
		vhandle[i] = new MyMesh::VertexHandle[n];
	}
	vector<MyMesh::VertexHandle>  face_vhandles;
	double x = -m * length / 2;
	double y = -n * length / 2;
	for (int i = 0; i < m; i++) {
		for (int j = 0; j < n; j++) {
			vhandle[i][j] = mesh.add_vertex(MyMesh::Point(x + i * length, y + j * length, 0));
		}
	}
	// generate (quadrilateral) faces
	for (int i = 0; i < m - 1; i++) {
		for (int j = 0; j < n - 1; j++) {
			face_vhandles.clear();
			face_vhandles.push_back(vhandle[i + 1][j]);
			face_vhandles.push_back(vhandle[i][j + 1]);
			face_vhandles.push_back(vhandle[i][j]);
			mesh.add_face(face_vhandles);

			face_vhandles.clear();
			face_vhandles.push_back(vhandle[i + 1][j]);
			face_vhandles.push_back(vhandle[i + 1][j + 1]);
			face_vhandles.push_back(vhandle[i][j + 1]);
			mesh.add_face(face_vhandles);

		}
	}
	cout << "请输入您要查找邻域的顶点坐标,坐标范围是(" << -m / 2 << "," << -n / 2 << ")-(" << m / 2 - 1 << "," << n / 2 - 1 << "):" << endl;
	cout << "x="; cin >> x0;
	cout << "y="; cin >> y0;
	for (MyMesh::VertexIter v_it = mesh.vertices_begin(); v_it != mesh.vertices_end(); ++v_it)
	{
		// circulate around the current vertex  
		auto point = mesh.point(*v_it);
		if (point.data()[0] == x0 && point.data()[1] == y0)// 找到对应的点
			for (MyMesh::VertexVertexIter vv_it = mesh.vv_begin(*v_it); vv_it != mesh.vv_end(*v_it); ++vv_it){ // GU: 应该是网格中的某一个点领域点的集合
				// do something with e.g. mesh.point(*vv_it)  
				auto point = mesh.point(*vv_it);
				cout << "邻域顶点坐标x:" << point.data()[0] << "  y:" << point.data()[1] << "  z:" << point.data()[2] << endl;
			}
		else { 
			continue; 
		}
	}
	cin >> a;
	// write mesh to output.obj
	if (!OpenMesh::IO::write_mesh(mesh, "output8.off"))
	{
		cerr << "Cannot write mesh to file 'output8.off'" << endl;
		return 1;
	}
	return 0;
}
posted on 2019-07-09 11:27  HDU李少帅  阅读(335)  评论(0编辑  收藏  举报