meshpro / pygalmesh

:spider_web: A Python interface to CGAL's meshing tools
GNU General Public License v3.0
580 stars 57 forks source link

surface remesh does not work properly #167

Open JianqiangDing opened 2 years ago

JianqiangDing commented 2 years ago

Hi, Nico Schlömer,

Am I doing something wrong? I just clone the latest pygalmesh, but I do not pass all the unit tests, here is a screenshot of the output

image

I just clone the repo, check into the main directory then run "pytest". Could you please help me to figure out what's wrong with the surface_remesh API? (I just got a SIGSEGV here, if necessary, I can show you an MWE, but you can just check if all the tests work properly or not

any kind of suggestion would be helpful :)

nschloe commented 2 years ago

An MWE is always useful. SIGSEGVs are suspicious though, pointing towards something in CGAL itself.

JianqiangDing commented 2 years ago

I am sorry, So you can pass all the tests by default??(by just clone repo, cd dir, run pytest

nschloe commented 2 years ago

Yeah, tests run on my system and on github-actions. CGAL behaves slightly differently from machine to machine, so perhaps you'd just have to adapt the tolerances slightly.

JianqiangDing commented 2 years ago

big thanks for your quick response, totally agree with you, It might be some problems that happened to CGAL, cause the first two tests passed which are only call meshio APIs(if I understand the code right), while the following tests call CGAL APIs.I'll check CGAL first.

thank you again for your kind advice (really useful library)

nschloe commented 2 years ago

Closing since this is probably not a CGAL bug, but feel free to continue posting here.

JianqiangDing commented 2 years ago

Hi, Nico Schlömer,

Firstly, I just figure out the problem I faced several days ago because you upload two test mesh cases as large files using git-lfs (which is not necessary right now I think, cause they are small files, probably you can fix this or point out in doc that the repo using git-lfs maintaining mesh data)

Secondly, here is an MWE that crashed with SIGSEGV

import meshio
import pygalmesh
import numpy as np

def init_mesh():
    points = np.array(
        [
            [0.0, 0.0, 1.0],
            [0.0, 1.0, 0.0],
            [-1.0, 0.0, 0.0],
            [1.0, 0.0, 0.0],
            [0.0, -1.0, 0.0],
        ],
        dtype=float,
    )
    triangles = np.array(
        [[0, 1, 2], [0, 1, 3], [4, 0, 2], [4, 0, 3], [4, 1, 3], [4, 1, 2]], dtype=int
    )
    cells = [("triangle", triangles)]
    return meshio.Mesh(points, cells)

if __name__ == "__main__":
    temp_mesh_name = "temp_file_mesh_name"
    suffix = ".obj"
    temp_mesh_file = temp_mesh_name + suffix
    mesh = init_mesh()
    mesh.write(temp_mesh_file)
    remesh = pygalmesh.remesh_surface(
        temp_mesh_file,
        max_edge_size_at_feature_edges=0.025,
        min_facet_angle=25,
        max_radius_surface_delaunay_ball=0.1,
        max_facet_distance=0.001,
        verbose=True,
    )

And a screenshot

image

Is this an issue about parameters setting? (I am not familiar with this remeshing method, any suggestion from you would be helpful, thanks

nschloe commented 2 years ago

Alright, I also see the segfault on my machine. The full error:

CGAL::Polyhedron_incremental_builder_3<HDS>::
lookup_halfedge(): input error: facet 1 shares a halfedge from vertex 0 to vertex 1 with facet 0.

Polyhedron_scan_OFF<Traits>::
operator()(): input error: facet 2 has fewer than 3 vertices.
Inserting protection balls...
  refine_balls = true
  min_balls_radius = 0
  min_balls_weight = 0
insert_corners() done. Nb of points in triangulation: 0
insert_balls_on_edges() done. Nb of points in triangulation: 0
refine_balls() done. Nb of points in triangulation: 0

[1]    702209 segmentation fault (core dumped)  python3 bb.py

That smells like a CGAL bug, perhaps @lrineau has an idea here?

JianqiangDing commented 2 years ago

How about subdividing triangles to ensure having enough triangles, then using optimesh to upgrade the whole quality? (as another way to do remeshing)Does this idea make sense? (seems optimesh just care about the angles but the max_allowed_edge_length :))

I am afraid this procedure may break original sharp edges, am I right?

nschloe commented 2 years ago

Your initial mesh is so rough that it will be hard for any algorithm to achieve something meaningful.