본문으로 바로가기

폴리곤 메시 처리 라이브러리중 PMP 라이브러리가 있음..
https://www.pmp-library.org/


OpenMesh 와 비교하여 비교적 심플한 사용법과..상당히 구조적으로 잘 짜여져 있음..
근데 사실.. half edge 의 특성상 half edge 한개가 2개 이상의 face를 공유할수 없는 문제로..
실제 mesh 편집 프로그램에서는 사용하기가 어렵다..

예를 들어 Solid 메시는 한개의 half edge를 두고 2개 이상을 공유해야 하는 문제가 허다하고..
shell 메세중.. 2개이상을 지원해야 하는 경우도 종종있다..

암튼.. 난 이런 사실을 모른체.. 이걸 써야겠다하고.. 맘먹고 테스트해본 코드임..
그냥 이런 라이브러리가 있구나.. 하는 정도만.. 기억할것임.
지금은 직접 만들어 쓰고 있다..

#include <SurfaceMesh.h>
 
int main(void)
{
    pmp::SurfaceMesh mesh;
 
    pmp::Vertex v0,v1,v2,v3;
 
    // add 4 vertices
    v0 = mesh.add_vertex(pmp::Point(0,0,0));
    v1 = mesh.add_vertex(pmp::Point(1,0,0));
    v2 = mesh.add_vertex(pmp::Point(0,1,0));
    v3 = mesh.add_vertex(pmp::Point(0,0,1));
 
    // temp 노드 셋팅
    pmp::VertexProperty<bool> vtmp;
    vtmp = mesh.add_vertex_property<bool>("v:temp", false);
    vtmp[v0] = true;
    vtmp[v2] = true;
     
    // solver id 셋팅
    pmp::VertexProperty<unsigned int> vsolver;
    vsolver = mesh.add_vertex_property<unsigned int>("v:solver");
    vsolver[v0] = 100;
    vsolver[v1] = 101;
    vsolver[v2] = 102;
    vsolver[v3] = 103;
    //mesh.remove_vertex_property(vsolver);
 
    auto points = mesh.get_vertex_property<bool>("v:temp");
 
    for (auto v : mesh.vertices())
    {
        if ( points[v] ) {
            printf("%d : temp node, solver id: %d\n", v.idx(), vsolver[v]);
        } else {
            printf("%d : node, solver id: %d\n", v.idx(), vsolver[v]);
        }
    }
 
    // add 4 triangular faces
    pmp::Face f0 = mesh.add_triangle(v0,v1,v3);
    mesh.add_triangle(v1,v2,v3);
    mesh.add_triangle(v2,v0,v3);
    mesh.add_triangle(v0,v2,v1);
     
    // face에 대한 solver id 셋팅
    pmp::FaceProperty<unsigned int> fsolver;
    fsolver = mesh.add_face_property<unsigned int>("f:solver");
    fsolver[f0] = 10000;
     
    // face에 대한 part id 셋팅
    pmp::FaceProperty<unsigned int> fpart;
    fpart = mesh.add_face_property<unsigned int>("f:part");
    fpart[f0] = 1001;
 
    // part 1001 번에 대한 opengl 출력용 tri indices
    std::map<unsigned int, std::vector<unsigned int>> indices;
    std::map<pmp::Face, unsigned int> offset;
    offset[f0].push_back(indices[1001].size());
    indices[1001].push_back(v0.idx());
    indices[1001].push_back(v1.idx());
    indices[1001].push_back(v3.idx());
    offset[f1].push_back(indices[1001].size());
    indices[1001].push_back(v1.idx());
    indices[1001].push_back(v2.idx());
    indices[1001].push_back(v3.idx());
 
    std::cout << "vertices: " << mesh.n_vertices() << std::endl;
    std::cout << "edges: "    << mesh.n_edges()    << std::endl;
    std::cout << "faces: "    << mesh.n_faces()    << std::endl;
}

'블로그 (Blog) > 개발로그 (Devlogs)' 카테고리의 다른 글

‘좋은 Mesh’에 대한 5가지 오해  (0) 2024.03.12
robin hood hashing  (0) 2024.03.12
LMDB  (0) 2024.03.09
Crypto++ 을 이용한 암호화/복호화 예제  (0) 2024.03.09
pacman 패키지 삭제하기  (0) 2024.03.09