CGAL / cgal

The public CGAL repository, see the README below
https://github.com/CGAL/cgal#readme
Other
4.87k stars 1.38k forks source link

corefine_and_compute_union intersection_nodes check_no_duplicates failed #7071

Closed TLCZhaoxi closed 1 year ago

TLCZhaoxi commented 1 year ago

Issue Details

I tried to calculate the boolen operation Union of two meshes with default parameters. In Debug Mode, CGAL::Assertion_exception was throwed, which indicated that some nodes are duplicated. As follow: terminate called after throwing an instance of 'CGAL::Assertion_exception' what(): CGAL ERROR: assertion violation! Expr: enodes.size() == std::set<typename Exact_kernel::Point_3>(enodes.begin(), enodes.end()).size() File: /opt/install/CProjX/Hemodynamics_Library/include/CGAL/Polygon_mesh_processing/internal/Corefinement/intersection_nodes.h Line: 316 In Release Mode, The function of 'corefine_and_compute_union' return false;

Meshes are uploaded here: Meshes.zip

Source Code

SurfaceMesh::Property_map<edge_descriptor, bool> is_constrained_map = unionMesh.add_property_map<edge_descriptor, bool>("e:is_constrained", false).first; bool isValid = PMP::corefine_and_compute_union(msh1, msh2, unionMesh, CGAL::parameters::default_values(), CGAL::parameters::default_values(), CGAL::parameters::edge_is_constrained_map(is_constrained_map)); if (!isValid) { std::cerr << "Mesh Union Failed" << std::endl; return false; }

Environment

TLCZhaoxi commented 1 year ago

I tried to use VTK to calculate the BooleanOperationUnion of the two meshes and got a result. But the results has a lot of errors. The error result is here: union.zip

sloriot commented 1 year ago

Your meshes have some self-intersections and boundary edges: Screenshot from 2022-11-23 09-27-24 Screenshot from 2022-11-23 09-32-56

A simple call to stitch_borders() on each mesh before the operations is enough to fix those issues. Most likely it is a problem in the generation algorithm.

Out of curiosity, what are those meshes? Trajectories?

TLCZhaoxi commented 1 year ago

These two meshes was generated based on VTK TubeFilter, which is two wires of an expanded flow diverter. The flow diverter is an device implant into the neuro-aneurysm's parent artery to stop the blood flow flushing onto the wall of aneurysm.

Anyway, I will check the mesh again, and do as what you said. Thanks.

TLCZhaoxi commented 1 year ago

@sloriot I check the two meshes again, but I didnot found any border edges. Here is my meshes in both off and stl format. Desktop.zip Could you help to check them again? And I will check the borders and call stitch_boarders() before the boolean union. I will submit the result soon.

TLCZhaoxi commented 1 year ago

@sloriot Thanks a lot, I checked my meshes with code. They do have some border edges. And the stitch_borders() do solve the problem. Although the results seems not so good, but that is another problem. Thanks a lot! snapshot00

sloriot commented 1 year ago

I guess you called some remeshing after the boolop Screenshot from 2022-11-23 10-25-58

TLCZhaoxi commented 1 year ago

@sloriot Yes, I do call some remeshing. I want to optimize the angle of triangles around the intersected area of boolean operation. But that change the shape of the model.

sloriot commented 1 year ago

You need to also protect sharp features. You can do it locally but globally (more expensive though) should be fine too. https://doc.cgal.org/latest/Polygon_mesh_processing/group__PMP__detect__features__grp.html#gadd3d18c0a9773463cd57902f85d0b23d

TLCZhaoxi commented 1 year ago

@sloriot I am trying to optimize the triangles after boolean operation like this: typedef boost::property_map<SurfaceMesh, CGAL::edge_is_feature_t>::type EIFMap; EIFMap eif = get(CGAL::edge_is_feature, unionMesh); PMP::detect_sharp_edges(unionMesh, 10.0, eif); PMP::isotropic_remeshing(unionMesh.faces(), constrainedRemeshSize, unionMesh, CGAL::parameters::edge_is_constrained_map(eif).protect_constraints(true)); This code really do something, but maybe too much edges are protected. That lead the optimization is not enough. image There are a lot of sharp angles still.

afabri commented 1 year ago

Can you try to add the named property relax_constraints.

TLCZhaoxi commented 1 year ago

I did just like what you said, It is better. But maybe still not perfect. image

sloriot commented 1 year ago

Try adding more iterations?

TLCZhaoxi commented 1 year ago

I make the remesh after boolen union locally with a smaller size. The sharp edges was set to be constrained(collapse false, relax true). The iteration number was set to be 20. It seems better. image Maybe it can be better?

TLCZhaoxi commented 1 year ago

And I do find some edges collapse, as shown below image Even the collapse was set to be false.

TLCZhaoxi commented 1 year ago

The collapse edge is because of I did not expand the local selected faces, after I did that, Everythind seems much better now! image

TLCZhaoxi commented 1 year ago

Everything is good, but the mesh data is quite large right now....

TLCZhaoxi commented 1 year ago

And the generation time is also quite long.

sloriot commented 1 year ago

You can try to reduce the number of iterations now that you've set up options according to your needs. Also sharp edge detection could be reduced to the selection and target edge could be adapted.