CGAL:如何有效地计算多面体的刻面面积?

san*_*p p 4 c++ area cgal computational-geometry

我有一个多面体,其面是三角形.我知道在CGAL中,Triangle_3类提供了'squared_area'方法,通过它我们可以计算三角形的面积.有什么方法可以将它应用于多面体面吗?或者有关如何计算每个方面面积的任何想法?

slo*_*iot 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;
}
Run Code Online (Sandbox Code Playgroud)