我有一个由外部库加载的点数组,Assimp , 在它自己的 aiVector3D
类(它没有组件访问器函数,只有对成员变量的公共(public)访问),我想使用 CGAL 的点集处理库来处理这些点。
因为我有数以百万计的这些点(有一天可能会达到数十亿),我不想创建一个新的 CGAL 数组 Point_3
如果我能帮上忙。
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 的文档后,我不清楚我将如何处理这个问题。
我认为这是正确的方法吗?如果可以,我该怎么做?
最佳答案
无论这是否更有效(对于某种有效的含义),这是我想出的映射 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);
}
关于c++ - 如何使用 CGAL Point_3 以外的类进行点集处理?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40663495/