1

在我的示例中,我得到了一些形成立方体并存储在Eigen::MatrixXd容器中的点,例如:

  // Inline mesh of a cube
  const Eigen::MatrixXd cubeV= (Eigen::MatrixXd(8,3)<<
  0.0,0.0,0.0,
  0.0,0.0,1.0,
  0.0,1.0,0.0,
  0.0,1.0,1.0,
  1.0,0.0,0.0,
  1.0,0.0,1.0,
  1.0,1.0,0.0,
  1.0,1.0,1.0).finished();

现在我想在 cgal 库中处理这些点,例如基于本教程。但是,您可以看到 cgal 函数的输入点采用以下形式:

std::vector<Pwn> points;

其中Pwn对应于:

// Types
typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
typedef Kernel::Point_3 Point;
typedef Kernel::Vector_3 Vector;
typedef std::pair<Point, Vector> Pwn;

或在表单的第二个示例中:

PointList points;

再次PointList对应于:

// Types
typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
typedef Kernel::FT FT;
typedef Kernel::Point_3 Point;
typedef CGAL::Point_with_normal_3<Kernel> Point_with_normal;
typedef Kernel::Sphere_3 Sphere;
typedef std::vector<Point_with_normal> PointList;

因此,我想问我如何将我的Eigen::MatrixXd结构转换为PwnPointList以便我可以将它们与 cgal 功能一起使用。我知道我可以制作 for 循环并单独推回每个点,但我的猜测是应该有一种更有效或更简洁的方法来代替它。

4

1 回答 1

2

如果您更仔细地阅读示例,您会发现您不必将点和法线打包在std::vector. 您只需要传递与ReadablePropertyMap概念匹配的点和法线容器。因此,您必须实现一个小包装器来存储对 a 的引用, MatrixXd并使用get(const your_wrapper&,int)自由函数将行转换为 aPoint_3Vector_3。由于MatrixXd默认情况下 a 是按列排列的,因此您必须为此任务执行复制并按值返回。因此,最好按列组织您的点或使用 aMatrix<double,Dynamic,3,RowMajor>以便当您访问一个点时,其坐标按顺序存储在内存中。在这种情况下,您甚至可以考虑做一个丑陋的 reinterpret_cast 以通过引用返回......

于 2018-06-07T14:46:31.077 回答