pyvista / fast-simplification

Fast Quadratic Mesh Simplification
https://pyvista.github.io/fast-simplification/
MIT License
110 stars 15 forks source link

[BUGS]: return_collapses #46

Closed zhuyuanxiang closed 2 months ago

zhuyuanxiang commented 2 months ago

Environmental: python=3.8.19, vedo=2024.5.1, vtk=9.3.1, fast-simplication=0.1.7 os=Windows11 mesh's vertices number > 50000, cells number > 100000 Code:

        mesh = vedo.file_io.load(file_name_path.as_posix())
        vertices, cells = mesh.vertices, mesh.cells
        vertices_num, cells_num = len(vertices), len(cells)
        vertices_out, cells_out, collapse_index = fast_simplification.simplify(
            vertices, cells, target_count=20000, agg=3, return_collapses=True
        )
        vertices_out_num = vertices_out.shape[0]
        collapse_len = collapse_index.shape[0]

Then, it is a error that collapse_len <(vertices_num-vertices_out_num), because collapse_len's meaning is how many points is collapsed, and collapse_len should greater than (vertices_num-vertices_out_num).

Now, I need use this index for collapse the labels, please give me some help! Thanks!

akaszynski commented 2 months ago

Pinging @Louis-Pujol

Louis-Pujol commented 2 months ago

Hi @zhuyuanxiang,

During the decimation, there is indeed two operations :

If you look at the replay function implementation, after the collapses are redone, we clean the mesh by removing isolated points.

Then, collapse_len is not exactly the difference between number of points before and after decimation but rather a minorant of that number, so having collapse_len <(vertices_num-vertices_out_num) does not sound wrong to me.

I have written higher-level interface around fast-simplification for another project (scikit-shapes), the possibility are illustrated in the Multiscaling section of the gallery of examples.

You can have a look at the code for the Decimation and Multiscaling classes to figure out how fast-simplification is used there.

zhuyuanxiang commented 2 months ago

Hi, @Louis-Pujol

Thks for your help!

Now, I know the reason about collapse_len <(vertices_num-vertices_out_num), but I need the isolated_points in the _map_isolated_points() for collapse the labels in the pointdata. I hope how to do it.

If I could get a new simplify() to get the isolated_points, or I could use the replay_simplification() to simpily the mesh and modify it for return the isolated_points?

Maybe I know how to do it! I found the test_relay.py in the project and get the method to obtain indice_mapping which can map the all vertices to the decimated mesh, so I will try to use this function and reply the result ASAP.

BTW: I have not found isolated_points in another project scikit-shapes too.

Louis-Pujol commented 2 months ago

Hi @zhuyuanxiang,

replay_simplification() has been designed to perform both operations: concatenation and cleaning of isolated points. The output consists of three arrays:

So, if you use replay_simplification(), you don't need to worry about isolated points, as they are just an intermediate step in the global decimation process. I think indice_mapping is the output you will need to collapse the labels. In scikit-shapes, we use it to transfer data (landmarks or signals) from fine meshes to coarse meshes.

zhuyuanxiang commented 2 months ago

Hi, @Louis-Pujol :

Thks for your conduct. Now I known what to do and how to do. I will follow your step to implement my algorithm. It's my luck to have your help. Wish you health and happiness.

Yours sincerely friend ZhuYuanxiang.Tom

Louis-Pujol commented 2 months ago

You're welcome ! I wish you all the best too