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

简介

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

代码

#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;
}

转载于:https://www.cnblogs.com/eat-too-much/p/11156215.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值