2016-11-17 4 views
1

Я пытаюсь преобразовать существующее приложение из C# в C++/Qt. Существующий код использует библиотеку MIConvexHull для вычисления выпуклой оболочки набора точек в трехмерном пространстве. Он использует функцию Faces для получения списка лиц, а затем пересекает их, чтобы получить отдельные вершины для каждой грани. Я хочу сделать это с помощью библиотеки CGAL, но, похоже, нет очевидного способа сделать это. Создание выпуклой оболочки с помощью функции convex_hull_ 3, но оттуда не очевидно, что делать.CGAL Convex Hull, с Qt

Мне нужно выполнить итерацию по граням получаемого объекта многогранника. Для каждого аспекта мне нужно итерации по вершинам. Для каждой вершины мне нужно извлечь координаты x, y и z, чтобы сформировать объект QVector3D.

Вот фрагмент кода существующего кода C#. В этом случае baseContour представляет собой список трехмерных вершин.

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; 
} 
Смежные вопросы