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

时间:2016-11-17 19:32:10

标签: c++ boost cgal point-clouds assimp

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

由于我有数百万这些积分(有一天可能有数十亿),如果我能提供帮助,我不想创建一个新的CGAL Point_3数组。

documentation说:

  

如果这些包的用户实现相应的属性映射,则可以使用其他类型来表示位置和法线。

这似乎意味着我可以通过创建将aiVector3D映射到Point_3的属性地图来实现我想要的效果,但在阅读了CGAL和Boost的文档后,它&# 39;我不清楚我将如何解决这个问题。

我是否正确地认为这是要走的路?如果是这样,我该怎么做?

1 个答案:

答案 0 :(得分:1)

这是否效率更高或更低(对于某些有效的意义),这是我想出的将aiVector3D映射到CGAL::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);
}