gpt4 book ai didi

c++ - 将 Eigen::MatrixXd 矩阵转换为 cgal 容器类型

转载 作者:行者123 更新时间:2023-11-30 03:22:56 30 4
gpt4 key购买 nike

在我的示例中,我得到了一些形成立方体的点并存储在 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 库中处理这些点,例如基于 this tutorial .但是,您可以看到 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 循环并单独推回每个点,但我猜应该有更有效或更简洁的方法来代替。

最佳答案

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

关于c++ - 将 Eigen::MatrixXd 矩阵转换为 cgal 容器类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50742495/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com