查找一条边的领域顶点 总觉得不完善

简介

查找一条边的领域顶点

代码

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

//查找一条边的领域点  TODO  不知道边的输入表示

int main()
{
	MyMesh mesh;
	// read mesh from stdin
	int a, x0, y0, x1, y1;
	if (!OpenMesh::IO::read_mesh(mesh, "C:/Users/lee/Desktop/output8.off"))
	{
		cerr << "Error: cannot read mesh!
" << endl;
		return 1;
	}
	cout << "请输入您要查找邻域的边起始坐标:" << endl;
	cout << "x="; cin >> x0;
	cout << "y="; cin >> y0;
	cout << "请输入您要查找邻域的边终止坐标:" << endl;
	cout << "x="; cin >> x1;
	cout << "y="; cin >> y1;
	vector<OpenMesh::Vec3f> vPoint;
	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) || (point.data()[0] == x1 && point.data()[1] == y1))// 找到匹配的点
			for (MyMesh::VertexOHalfedgeIter vo_it = mesh.voh_begin(*v_it); vo_it != mesh.voh_end(*v_it); ++vo_it)//这个顶点所带有的半边迭代器
			{
				// 将所有的半边的to边所对应的点放入集合中
				OpenMesh::ArrayKernel::VertexHandle to_v = mesh.to_vertex_handle(*vo_it);
				OpenMesh::Vec3f topoint = mesh.point(to_v);
				if ((topoint[0] == x1 && topoint[1] == y1) || (topoint[0] == x0 && topoint[1] == y0) ){
					continue;
				}
				vPoint.push_back(topoint);
			}
		else continue;
	}
	// 去重
	sort(vPoint.begin(), vPoint.end());
	vPoint.erase(unique(vPoint.begin(), vPoint.end()), vPoint.end());
	std::cout << "edge's neighbor points are :
";
	for (int i = 0, size = vPoint.size(); i < size; i++) {
		std::cout << "point (" << vPoint[i][0] << "," << vPoint[i][1] << ")" << std::endl;
	}


	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/11157614.html