首页 > 其他 > 详细

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

时间:2019-07-09 12:39:46      阅读:108      评论:0      收藏:0      [点我收藏+]

简介

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

代码

#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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!