CGAL:如何高效计算多面体面片的面积?

4

我有一个所有面都是三角形的多面体。 我知道在CGAL中,Triangle_3类通过'squared_area'方法提供了计算三角形面积的功能。 有没有办法将此应用于多面体面? 或者有什么想法可以计算每个面的面积?


不熟悉CGAL,但三角形的一个优点是可以确定它们是平面的,因此它们具有相当明显和明确定义的面积。一旦你有超过3个角,平面性可能会成为一个问题。如果您确定它们是平面的,则可以尝试使用类似链接的东西来查找面积。 - Arunas
我刚刚重新阅读了这个问题 - 你是指“多面体面”还是“多边形面”? - Arunas
多面体的面.. 无论如何,我得到了正确的答案.. 谢谢你尝试帮助我.. :) - sandeep p
2个回答

10

这里是一个例子:

#include <CGAL/Simple_cartesian.h>
#include <CGAL/Polyhedron_3.h>
#include <numeric>
#include <functional>
#include <boost/iterator/transform_iterator.hpp>

typedef CGAL::Simple_cartesian<double> K;
typedef CGAL::Polyhedron_3<K> Polyhedron;

struct Compute_area:
  public std::unary_function<const Polyhedron::Facet, double>
{
  double operator()(const Polyhedron::Facet& f) const{
    return K::Compute_area_3()(
      f.halfedge()->vertex()->point(),
      f.halfedge()->next()->vertex()->point(),
      f.halfedge()->opposite()->vertex()->point() );
  }
};

int main()
{
  Polyhedron p;
  p.make_tetrahedron(
    K::Point_3(0,0,0),
    K::Point_3(0,1,0),
    K::Point_3(1,1,0),
    K::Point_3(1,1,3)
  );

CGAL_assertion( p.is_pure_triangle() );

  Compute_area ca;

  std::cout <<
    std::accumulate(
      boost::make_transform_iterator(p.facets_begin(), ca),
      boost::make_transform_iterator(p.facets_end(), ca),
      0.)
  << std::endl;
}

编辑 在最新版本的CGAL中,有一个叫做CGAL::Polygon_mesh_processing::area()的免费函数可用。


1

扩展@sloriot的回答,因为std::unary_function在C++11中已被弃用,并将从C++14开始删除。然而,unary_function不再需要,Compute_area可以简单地实现为

struct Compute_area
{
   double operator()(const Polyhedron::Facet& f) const {
   return K::Compute_area_3()(
     f.halfedge()->vertex()->point(),
     f.halfedge()->next()->vertex()->point(),
     f.halfedge()->opposite()->vertex()->point() );
    }
};                                                                              

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接