• 在网格中查找一个点的领域点


    简介

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

    代码

    #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;
    }
    
    Hope is a good thing,maybe the best of things,and no good thing ever dies.----------- Andy Dufresne
  • 相关阅读:
    shiro 权限集成Ehcache 配置 学习记录(二)
    shiro 集成spring 配置 学习记录(一)
    无网线的情况下,虚拟机和主机通信
    activeMQ集群搭建及高可用
    spring集成activeMQ
    ActiveMQ的两种消息模式,主题、队列
    Weblogic10.3.6部署解决CXF webService 调用报错: “Cannot create a secure XMLInputFactory”
    静态代理和动态代理对比
    Java中的静态代理实现方式
    PHP求解一个值是否为质数
  • 原文地址:https://www.cnblogs.com/eat-too-much/p/11156215.html
Copyright © 2020-2023  润新知