LiangliangNan / Easy3D

A lightweight, easy-to-use, and efficient C++ library for processing and rendering 3D data
GNU General Public License v3.0
1.37k stars 245 forks source link

using Delaunay2D #141

Closed Wallens6 closed 2 years ago

Wallens6 commented 2 years ago

Hi.I was generating a TIN with Delaunay2D, and I found that the algorithm itself was fast, but it was slow to add faces to SurfaceMesh. Do you have any suggestions in this regard?

LiangliangNan commented 2 years ago

Thanks for your observation! Can you elaborate on how big your input is, and how much time Delaunay2D and mesh building take respectively? Besides, can you also show the code of your mesh building?

Wallens6 commented 2 years ago

Thanks for your reply. Here is my code of Surface reconstruction: ` SurfaceMesh surfaceReconstruction(PointCloud cloud) { std::cout << "number of vertices:" << cloud->n_vertices() << std::endl; StopWatch sw; auto *mesh = new SurfaceMesh; mesh->set_name(cloud->name());

    const std::vector<vec3> &pts = cloud->points();
    std::vector<vec2> points;
    for (auto pt: pts) {
        points.emplace_back(pt);
        mesh->add_vertex(pt);
    }
    auto colors = cloud->get_vertex_property<vec3>("v:color").vector();
    auto &col = mesh->add_vertex_property<vec3>("v:color").vector();
    col = colors;

    Delaunay2 delaunay;
    delaunay.set_vertices(points);

    int triangles = (int) delaunay.nb_triangles();
    std::cout << "number of triangles: " << triangles
              << ",Delaunay2D cost " << sw.time_string() << std::endl;
    sw.start();

    for (int i = 0; i < triangles; i++) {
        std::vector<SurfaceMesh::Vertex> vts(3);
        for (int j = 0; j < 3; j++) {
            const int v = delaunay.cell_vertex(i, j);
            vts[j] = SurfaceMesh::Vertex(v);
        }
        mesh->add_face(vts);
    }
    std::cout << "add faces to mesh cost " << sw.time_string() << std::endl;
    return mesh;
}

`

and its output: number of vertices:380586 number of triangles: 597495,Delaunay2D cost 1.4s add faces to mesh cost 11.3s

LiangliangNan commented 2 years ago

I did a quick test (in Release mode) using your code and got the following:

number of vertices: 362271
number of triangles: 724483, Delaunay2D cost 415.1ms
add faces to mesh cost 225.3ms

it is interesting in my test building the mesh is faster.

Can you try to run the code in Release mode and see if it is different?

Wallens6 commented 2 years ago

!!!! Thank you so much. It's fast as yours in Release mode.

LiangliangNan commented 2 years ago

Glad to hear that. I am going to close this issue. Good luck with your project!