c++ - 如何使用 CGAL Point_3 以外的类进行点集处理?

标签 c++ boost cgal point-clouds assimp

我有一个由外部库加载的点数组,Assimp , 在它自己的 aiVector3D类(它没有组件访问器函数,只有对成员变量的公共(public)访问),我想使用 CGAL 的点集处理库来处理这些点。

因为我有数以百万计的这些点(有一天可能会达到数十亿),我不想创建一个新的 CGAL 数组 Point_3如果我能帮上忙。

documentation说:

Users of this package may use other types to represent positions and normals if they implement the corresponding property maps.

这似乎意味着我可以通过创建映射 aiVector3D 的属性映射来实现我想要的。至 Point_3 ,但在阅读了 CGAL 和 Boost 的文档后,我不清楚我将如何处理这个问题。

我认为这是正确的方法吗?如果可以,我该怎么做?

最佳答案

无论这是否更有效(对于某种有效的含义),这是我想出的映射 aiVector3DCGAL::Point_3 (使用 CGAL::Simple_cartesian<double> 内核),包括转换。

template <typename T>
struct AItoP {
    AItoP(const aiScene* scene, const aiNode* node) :
            _scene(scene),
            _node(node),
            _mesh(0)
    {
        _mesh = _scene->mMeshes[node->mMeshes[0]];
        _xform = _node->mTransformation * _scene->mRootNode->mTransformation;
    }

    T operator()(const size_t& x) const {
        aiVector3t<double> v(_mesh->mVertices[x].x, _mesh->mVertices[x].y, _mesh->mVertices[x].z);
        v *= _xform;

        return T(v.x, v.y, v.z);
    }
private:
    const aiScene* _scene;
    const aiNode* _node;
    const aiMesh* _mesh;
    aiMatrix4x4t<double> _xform;
};

...

#include <boost/property_map/function_property_map.hpp>

void my_processing_function() {
    std::vector<std::size_t> indices(mesh->mNumVertices);
    for(std::size_t i = 0; i < mesh->mNumVertices; ++i){
        indices[i] = i;
    }

    double cell_size = 0.05;
    std::vector<std::size_t>::iterator end;
    end = CGAL::grid_simplify_point_set(indices.begin(),
            indices.end(),
            make_function_property_map<const size_t&, Point, AItoP<Point> >(AItoP<Point>(_scene, node)),
            cell_size);
}

关于c++ - 如何使用 CGAL Point_3 以外的类进行点集处理?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40663495/

相关文章:

c++ - 你如何制作一个异构的 boost::map?

c++ - 检查哪个网格元素在原始多边形内

c++ - 获取顶点索引以保存三角剖分

c++ - 从右值对象返回一个成员

Boost程序选项检测是否使用默认值

c++ - 我可以在 Windows 中为 Linux 平台创建应用程序吗?

c++ - 文件/ifstream 的双向迭代器

iphone - 为 iOS/备用 2D cad 库编译 CGAL?

c++ - 我的复制构造函数失败..如何复制指向对象的指针

c++ - 删除指针内存并确认