2016-11-17 1 views
1

기존 응용 프로그램을 C#에서 C++/Qt로 변환하려고합니다. 기존 코드는 MIConvexHull 라이브러리를 사용하여 3 차원 공간에서 점 집합의 볼록 선체를 계산합니다. Faces 함수를 사용하여면의 목록을 가져온 다음 각면의 개별 정점을 얻기 위해 반복합니다. CGAL 라이브러리를 사용하여이 작업을 수행하려고하지만이 작업을 수행하는 분명한 방법이없는 것 같습니다. convex_hull_ 3 함수를 사용하여 convex hull을 생성하지만 거기에서 무엇을 해야할지 명확하지 않습니다.CGAL Convex Hull (Qt 포함)

결과물 인 다면체 객체의 패싯을 반복해야합니다. 각 패싯에 대해 꼭 꼭지점을 반복해야합니다. 각 꼭지점마다 QVector3D 객체를 형성하기 위해 x, y 및 z 좌표를 추출해야합니다.

다음은 기존 C# 코드의 코드 단편입니다. 이 경우 baseContour는 3D 정점의 목록입니다.

var triangulationFaces = MIConvexHull.ConvexHull.Create(baseContour).Faces; 
var triangulationPoints = new List<Point3D>(); 
var triangulationIndices = new List<int>(); 
int i = 0; 
foreach (var f in triangulationFaces) 
{ 
    var x = f.Vertices.Select(p => new Point3D(p.Position[0], p.Position[1], p.Position[2])).ToList(); 
    triangulationPoints.AddRange(x); 
    triangulationIndices.Add(3 * i); 
    triangulationIndices.Add(3 * i + 1); 
    triangulationIndices.Add(3 * i + 2); 
    i++; 
} 

나는 CGAL 라이브러리로이를 수행하는 방법을 놓치고 있습니다. 저는 꽤 많은 문서를 읽었습니다. 그러나 당신이 이미 전산 기하학에 대한 대학원 수준의 지식을 가지고 있다고 가정하는 것으로 보입니다. 올바른 방향으로 나를 가리켜 줄만한 것이라면 감사하겠습니다.

답변

0

사용자 설명서에는 example가 있습니다.

은 당신이 원하는 일을하는 데 사용 :

#include <CGAL/Exact_predicates_inexact_constructions_kernel.h> 
#include <CGAL/Polyhedron_3.h> 
#include <CGAL/boost/graph/graph_traits_Polyhedron_3.h> 
#include <CGAL/Unique_hash_map.h> 
#include <CGAL/convex_hull_3.h> 
#include <vector> 
#include <fstream> 
#include <boost/foreach.hpp> 

typedef CGAL::Exact_predicates_inexact_constructions_kernel K; 
typedef CGAL::Polyhedron_3<K>      Polyhedron_3; 
typedef K::Point_3     Point_3; 

typedef boost::graph_traits<Polyhedron_3>::vertex_descriptor vertex_descriptor; 
typedef boost::graph_traits<Polyhedron_3>::face_descriptor face_descriptor; 

int main(int argc, char* argv[]) 
{ 
    // get the input points from a file 
    std::ifstream in(argv[1]); 
    std::vector<Point_3> points; 
    Point_3 p; 
    while(in >> p){ 
    points.push_back(p); 
    } 

    // define polyhedron to hold convex hull 
    Polyhedron_3 poly; 

    // compute convex hull of non-collinear points 
    CGAL::convex_hull_3(points.begin(), points.end(), poly); 

    std::cout << "The convex hull contains " 
      << num_vertices(poly) << " vertices" 
      << " and " << num_faces(poly) << " faces" << std::endl; 

    // A hash map that will associate an index to each vertex 
    CGAL::Unique_hash_map<vertex_descriptor,int> index; 

    int i = 0; 

    // In case your compiler supports C++11 you can replace 
    // use the next line instead of the line with BOOST_FOREACH 
    // for(vertex_descriptor vd : vertices(poly)){ 
    BOOST_FOREACH(vertex_descriptor vd, vertices(poly)){ 
    std::cout << vd->point() << std::endl; 
    index[vd]= i++; 
    } 

    // loop over the faces and for each face loop over the vertices 
    // Again you can replace with for(.. : ..) 
    BOOST_FOREACH(face_descriptor fd, faces(poly)){ 
    BOOST_FOREACH(vertex_descriptor vd, vertices_around_face(halfedge(fd,poly),poly)){ 
     std::cout << index[vd] << " "; 
    } 
    std::cout << std::endl; 
    } 
    return 0; 
} 
관련 문제