【问题标题】:How to get polygon faces from CGAL convex hull如何从 CGAL 凸包中获取多边形面
【发布时间】:2015-02-16 07:55:44
【问题描述】:

我使用CGAL 中的 3D 凸包估计器实现来计算一组点的凸多面体。下面是代码:

#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/point_generators_3.h>
#include <CGAL/algorithm.h>
#include <CGAL/Polyhedron_3.h>
#include <CGAL/convex_hull_3.h>
#include <vector>
#include <iostream>

typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
typedef Kernel::Point_3 Point_3;
typedef CGAL::Polyhedron_3<Kernel> Polyhedron;
typedef Polyhedron::Facet_iterator Facet_iterator;
typedef Polyhedron::Halfedge_around_facet_circulator Halfedge_facet_circulator;

int main()
{
  std::vector<Point_3> points;

  points.push_back(Point_3(2.0f, 3.535533905932738f, 3.535533905932737f));
  points.push_back(Point_3(4.0f, 2.0f, 0.0f));
  points.push_back(Point_3(0.0f, 2.0f, 0.0f));
  points.push_back(Point_3(1.0f, 0.0f, 0.0f));
  points.push_back(Point_3(4.0f, 1.414213562373095f, 1.414213562373095f));
  points.push_back(Point_3(0.0f, 1.414213562373095f, 1.414213562373095f));
  points.push_back(Point_3(3.0f, 0.0f, 0.0f));
  points.push_back(Point_3(2.0f, 5.0f, 0.0f));

  Polyhedron P;

  CGAL::convex_hull_3(points.begin(), points.end(), P);

  std::cout << "- Number of vertices  = " << P.size_of_vertices()    << std::endl;
  std::cout << "- Number of edges     = " << P.size_of_halfedges()/2 << std::endl;
  std::cout << "- Number of faces     = " << P.size_of_facets()      << std::endl;

  for ( Facet_iterator i = P.facets_begin(); i != P.facets_end(); ++i)
  {
    Halfedge_facet_circulator j = i->facet_begin();
    CGAL_assertion( CGAL::circulator_size(j) >= 3);
    std::cout << CGAL::circulator_size(j) << ' ';
    do{
      std::cout << ' ' << std::distance(P.vertices_begin(), j->vertex());
    }while ( ++j != i->facet_begin());

    std::cout << std::endl;
  }
  return 0;
}

但是,输出是多面体面的三角剖分:

有没有办法强制CGAL 用多边形而不是一组三角形来表示面?

【问题讨论】:

    标签: cgal convex-hull


    【解决方案1】:

    没有办法做到开箱即用。您需要测试每条边的四个点是否共面。

    【讨论】:

    • 这仍然是真的(2017 年 7 月)吗?如果是这样,这将是一种耻辱,并且会让我放弃 CGAL 凸包,转而支持 QHull 库...... :(
    • CGAL 是一个开源项目。欢迎您提交pull request。如果有足够的兴趣,您还可以打开一个issue,而不是其他开发人员可能会实施的。
    • 当然。关键是我不明白为什么这还没有实现,对于首先实现/维护凸包代码的人来说应该很容易。另一方面,你是对的:也许没有足够的兴趣......
    • 这是由于用于存储凸包的底层结构的约束。这应该在将结果导出到人脸图模型时完成。
    • 是的,这是我的第一个猜测,但据我所知,这不是在导出方法中完成的吗?在导出方法中,我正是预料到的那种行为。
    猜你喜欢
    • 2013-05-26
    • 2022-01-17
    • 1970-01-01
    • 1970-01-01
    • 2012-08-04
    • 2021-05-21
    • 1970-01-01
    • 2018-01-09
    • 1970-01-01
    相关资源
    最近更新 更多