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

简介

查找一条边的领域顶点

代码

#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!\n" << 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 :\n";
    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;
}

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值