添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
失落的鸡蛋面  ·  Unity Sentis ...·  5 月前    · 
卖萌的紫菜  ·  星教育 - 安徽财经网·  10 月前    · 
好帅的遥控器  ·  Qt Plotting Widget ...·  11 月前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I am using open3d-cpp to process some pointclouds. However, the raw input is a float array (say float pts[3000] , containing 1000 points), and I didn't find an efficient way to transform it into an open3d::geometry::Pointcloud , as the only parameterized constructor of Pointcloud is a copy constructor and only takes std::vector<Eigen::Vector3d> as input.

I made a naive converter, but I think it is not quite efficient, the first step is converting the float array ( arr of size 40000*3 ) into a double array, then do the following:

    long t01 = CurrTimeMS;
    Eigen::Vector3d *vv = reinterpret_cast<Eigen::Vector3d *>(arr);
    vector<Eigen::Vector3d> vec(vv, vv+40000);
    geometry::PointCloud pcd(vec);
    long t02 = CurrTimeMS;
    std::cout << "pcd init took " << t02-t01 << " ms.\n";
    cout << (void *) vv << " " << (void *) vec.data() << " " << (void *) pcd.points_.data() << endl;

It turned out taking me 3-4ms, and because std::vector(T *start, T *end) is also a copy constructor, this code does 3 times of memory copy (all three addressed are different), which is not optimal.
Is there any more efficient way to create Pointcloud directly from memory?

It looks like the points_ member of geometry::PointCloud is public, so you could create an empty pointcloud and directly copy your values into it (you can also do the conversion on-the-fly). – chtz Nov 7, 2022 at 8:32

I end up finding a relatively efficient approach.

std::shared_ptr<open3d::geometry::PointCloud> convert2pcd(float *data, size_t N, size_t dim=3) {
    assert(dim > 2);
    double *dd = new double[N*3];
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < 3; ++j) {
            dd[i*3+j] = (double) data[i*dim+j];
    Eigen::Vector3d *vv = reinterpret_cast<Eigen::Vector3d *>(dd);
    auto pcd = std::make_shared<open3d::geometry::PointCloud>();
    pcd->points_.assign(vv, vv+N);
    delete[] dd;
    return pcd;

which still takes me around 2-3ms.

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.