CGAL + 使用 EdgeIterator 查找边长

CGAL + Find edge length using EdgeIterator

我是 CGAL 的新手,正在尝试找出网格中每条边的长度。我没有看到任何成员函数或 length 成员函数,也没有看到任何可以轻松获取边缘两侧点的方法。

这是我到目前为止的进展。如何获取边两端的点或边本身的大小?

#include <iostream>
#include <string>
#include <CGAL/Cartesian.h>
#include <CGAL/Filtered_kernel.h>
#include <CGAL/Polyhedron_3.h>
#include <CGAL/IO/Polyhedron_iostream.h>
typedef double Real;
typedef CGAL::Cartesian<Real> Kernel0;
// Use a filtered kernel so that all predicates are exact.
typedef CGAL::Filtered_kernel<Kernel0> Kernel;
typedef CGAL::Polyhedron_3<Kernel> Polyhedron;
typedef Kernel::Point_3 Point;

void Edge_Analysis(Polyhedron mesh){
  float mean = 0, min, max, length;
  int count = 0; bool init = true;
  for (Polyhedron::Edge_const_iterator edgeIter = mesh.edges_begin(); edgeIter != mesh.edges_end(); ++edgeIter){

      Point a = edgeIter.prev()->vertex()->point();
      Point b = edgeIter.vertex()->point();
      length = CGAL::sqrt(CGAL::squared_distance(a, b));
      ++count;
      if (init){
          mean = min = max = length;
          init = false;
      }
      else{
          if (length < min) min = length;
          if (length > max) max = length;
      }
      mean += length;
  }
  mean /= count;
  std::cout << min << " " << max << " " << mean << "\n";
}

int main(int argc, char **argv){

  Polyhedron mesh;

  // Read the input mesh from standard input in OFF format.
  if (!(std::cin >> mesh)) {
    std::cerr << "Cannot read input mesh\n";
    return 1;
  }
  Edge_Analysis(mesh);
return 0;
}

为了编译应该修正的唯一错误是:

  const Point& a = edgeIter->prev()->vertex()->point();
  const Point& b = edgeIter->vertex()->point();

您应该使用 CGAL::Exact_predicates_inexact_constructions_kernel 而不是 Kernel。如果你想避免不需要的副本,你应该在 mesh 上使用 const ref。