查找一个顶点的一层领域边

简介

查找一个顶点的一层领域边

代码一

这个代码使用了太多的auto,其实不利于阅读,代码二,把auto更改了。

#include <iostream>
#include <vector>
// -------------------- OpenMesh
using namespace std;
#include <OpenMesh/Core/IO/MeshIO.hh>
#include <OpenMesh/Core/Mesh/TriMesh_ArrayKernelT.hh>
typedef OpenMesh::TriMesh_ArrayKernelT<>MyMesh;

int main()
{
	MyMesh mesh;
	// read mesh from stdin
	int a, x0, y0;
	if (!OpenMesh::IO::read_mesh(mesh, "output8.off"))
	{
		cerr << "Error: cannot write mesh to " << endl;
		return 1;
	}
	cout << "请输入您要查找邻域的顶点坐标:" << 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 (auto vh_it = mesh.voh_begin(*v_it); vh_it != mesh.voh_end(*v_it); ++vh_it) // 半边迭代器
			{
				auto h = mesh.next_halfedge_handle(*vh_it);// 这个顶点的下一条半边
				auto to_v = mesh.to_vertex_handle(h);// 下一条半边相对的点(handle)
				auto from_v = mesh.from_vertex_handle(h);// 下一条半边开始的点(handle)
				auto topoint = mesh.point(to_v);// 把handle转换为点的结构返回出去
				auto frompoint = mesh.point(from_v);// 同上
				cout << "邻域边两端顶点1坐标x:" << frompoint.data()[0] << "  y:" << frompoint.data()[1] << "  z:" << frompoint.data()[2] << endl;
				cout << "邻域边两端顶点2坐标x:" << topoint.data()[0] << "  y:" << topoint.data()[1] << "  z:" << topoint.data()[2] << endl;
				cout << "
" << endl;
			}
		else continue;
	}
	cin >> a;
	// write mesh to stdout
	if (!OpenMesh::IO::write_mesh(mesh, "output9.off"))
	{
		cerr << "Error: cannot write mesh to " << endl;
		return 1;
	}
	return 0;
}

代码二

#include <iostream>
#include <vector>
// -------------------- OpenMesh
using namespace std;
#include <OpenMesh/Core/IO/MeshIO.hh>
#include <OpenMesh/Core/Mesh/TriMesh_ArrayKernelT.hh>
typedef OpenMesh::TriMesh_ArrayKernelT<>MyMesh;

int main()
{
	MyMesh mesh;
	// read mesh from stdin
	int a, x0, y0;
	if (!OpenMesh::IO::read_mesh(mesh, "output8.off"))
	{
		cerr << "Error: cannot write mesh to " << endl;
		return 1;
	}
	cout << "请输入您要查找邻域的顶点坐标:" << 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  
		OpenMesh::Vec3f point = mesh.point(*v_it);
		if (point.data()[0] == x0 && point.data()[1] == y0)//找到对应的点
			for (auto vh_it = mesh.voh_begin(*v_it); vh_it != mesh.voh_end(*v_it); ++vh_it) // 半边迭代器
			{
				auto h = mesh.next_halfedge_handle(*vh_it);// 这个顶点的下一条半边
				OpenMesh::ArrayKernel::VertexHandle to_v = mesh.to_vertex_handle(h);// 下一条半边相对的点(handle)
				OpenMesh::ArrayKernel::VertexHandle from_v = mesh.from_vertex_handle(h);// 下一条半边开始的点(handle)
				OpenMesh::Vec3f topoint = mesh.point(to_v);// 把handle转换为点的结构返回出去
				OpenMesh::Vec3f frompoint = mesh.point(from_v);// 同上
				cout << "邻域边两端顶点1坐标x:" << frompoint.data()[0] << "  y:" << frompoint.data()[1] << "  z:" << frompoint.data()[2] << endl;
				cout << "邻域边两端顶点2坐标x:" << topoint.data()[0] << "  y:" << topoint.data()[1] << "  z:" << topoint.data()[2] << endl;
				cout << "
" << endl;
			}
		else continue;
	}
	cin >> a;
	// write mesh to stdout
	if (!OpenMesh::IO::write_mesh(mesh, "output9.off"))
	{
		cerr << "Error: cannot write mesh to " << endl;
		return 1;
	}
	return 0;
}
Hope is a good thing,maybe the best of things,and no good thing ever dies.----------- Andy Dufresne
原文地址:https://www.cnblogs.com/eat-too-much/p/11157035.html