Subject: CGAL users discussion list
List archive
- From: Yaoyu Hu <>
- To:
- Subject: [cgal-discuss] Surface mesh cannot be smoothed after removing faces
- Date: Mon, 13 Jul 2020 21:35:48 -0400
- Authentication-results: mail3-smtp-sop.national.inria.fr; spf=None ; spf=Pass ; spf=None
- Ironport-phdr: 9a23:rrzn4RTs1Bme1wxHShbUXOl3L9psv+yvbD5Q0YIujvd0So/mwa69bRWN2/xhgRfzUJnB7Loc0qyK6v6mAz1LvcrJmUtBWaQEbwUCh8QSkl5oK+++Imq/EsTXaTcnFt9JTl5v8iLzG0FUHMHjew+a+SXqvnYdFRrlKAV6OPn+FJLMgMSrzeCy/IDYbxlViDanbr5+MRS7oR/PusQSjodvJak8wQbVr3VVfOhb2XlmLk+JkRbm4cew8p9j8yBOtP8k6sVNT6b0cbkmQLJBFDgpPHw768PttRnYUAuA/WAcXXkMkhpJGAfK8hf3VYrsvyTgt+p93C6aPdDqTb0xRD+v4btnRAPuhSwaMTMy7WPZhdFqjK9Drx2vpxJxzY3Jbo+LKPVzZabdcc8ASGdbQspdSy5MD4WhZIUPFeoBOuNYopH/qFQUqhu/BRSsD/7txD9Vm3T72q060/khEA7c2wwhH88OvGnQodj2NaofSu+1zKzSwjXCa/Nawyvy6I/Nch04p/yHQL1/f9bLx0Y1CwPFkkufqZbjPz6NyOgBrmiV4ep9WO6xiGMqtRx9ryagyMoviYTHiIYYx1DL+Ch6wIs7Jd+1RkFlbNOnH5ZdtSCXOo95TM4jX2xluiA3waAFt56jZCUG1ogryhrFZ/GEc4WE+AzvWPiMLTtihH9odrSyjAuo/0e60O3zTMy03U5KriVbltnMsWgA1xnJ5ciGTvtx50mg2SyS2wzK5OFJIU45mbDUK54mxb4wmZ4TvlrZEiDqn0X2ibeadkQi+ue29+TqeqvqqoOYOoNuiQzzMr4iltKhDeglKAQDX2aW9fy51LL5/E35RLtKjucxkqncqJ3aJdkbp66jDA9S0ocj9guzAjOl3dkZhnQHI1dFdwiGj4jtIV3BPPf4DfKnj1S2jDhr3+zGPqHmApjVMnfDn63ufbJk50FByQoz1sxQ549PCrEaO//zQU/wtNnADhAjKQC0wuDnCM981owEQ26PDLWZY+vutgqD6esrZuWNf4QIoy3VKv4/5veog2Vqt0UaePyY1JwGdTiYA7wyI1iIaH39n45QQTkisQ83Teisg1qHB20AL02uVr4xs2loQLmtCp3OE9j00e6xmRyjF5gTXVhoT1WFEHPmbYKBAq5eZyebI8snmTsBB+H4Ft0RkCq2vQq/8IJJa+rZ/ipC6MDm3dlxovLJzFQ8qGcyAMOa3GWACWpzmzFQHmNk7OVEuUV4j2y7/+1gmfUBTI5c4vpIVkExMpuOl+E=
Hi Everyone,
I am new to CGAL and I am running into an issue when I am trying to smooth a surface mesh which I just performed a face removal.
The surface mesh is loaded from a file as a CGAL::Surface_mesh object. The original mesh has some defects such as small dangling faces and self-intersected faces. I decided to deal with the self-interactions first. I collected all the self-intersections by using CGAL::Polygon_mesh_processing::self_intersections() function. And I insert the face descriptors into an std::set. Then I loop over all the face descriptors saved in the std::set and do a remove_face(). After that, a call to collect_garbage() is issued on the Surface_mesh object.
So far so good. However, when I try to continue performing other operations on the Surface_mesh object, I get an exception from CGAL. The operation I'd like to do is a smoothing by CGAL::Polygon_mesh_processing::smooth_mesh(). The exception I got is as follows:
=== Terminal output begins. ===
terminate called after throwing an instance of 'CGAL::Assertion_exception'
what(): CGAL ERROR: assertion violation!
Expr: _idx < data_.size()
what(): CGAL ERROR: assertion violation!
Expr: _idx < data_.size()
File: /path/to/cgal/Surface_mesh/include/CGAL/Surface_mesh/Properties.h
Line: 195
=== Terminal output ends. ===
I am using Ubuntu 18.04 and CGAL 5.0.2 cloned from the Github repo.
You could find the sample code and the original mesh as the attachments.
My questions are
(1) What is the correct procedure to remove faces from a Surface_mesh object and make the downstream process works correctly? I also tried Euler operations but got no luck. There will be the same exception.
(2) In the original mesh, there are som small faces dangling around the top and bottom borders. How can I robustly remove those dangling faces? I tried to use face area to do thresholding on all the faces. It sort of works but later I still get the above exceptions in the smoothing section.
Regards and thank you!
Yaoyu
// // Created by yaoyu on 7/13/20. // #include <fstream> #include <iostream> #include <set> #include <string> #include <vector> #include <CGAL/Exact_predicates_inexact_constructions_kernel.h> #include <CGAL/Surface_mesh.h> #include <CGAL/Polygon_mesh_processing/border.h> #include <CGAL/Polygon_mesh_processing/detect_features.h> #include <CGAL/Polygon_mesh_processing/self_intersections.h> #include <CGAL/Polygon_mesh_processing/smooth_mesh.h> #include <CGAL/boost/graph/Euler_operations.h> #include <CGAL/boost/graph/iterator.h> typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel_t; typedef Kernel_t::Point_3 Point_t; typedef CGAL::Surface_mesh<Point_t> Mesh_t; typedef Mesh_t::Vertex_index VertexIdx_t; typedef Mesh_t::Face_index FaceIdx_t; typedef Mesh_t::Halfedge_index HalfedgeIdx_t; typedef boost::graph_traits<Mesh_t>::face_descriptor FaceDesc_t; typedef boost::graph_traits<Mesh_t>::edge_descriptor EdgeDesc; namespace pmp = CGAL::Polygon_mesh_processing; static void smooth_mesh( Mesh_t &mesh ) { typedef boost::property_map<Mesh_t, CGAL::edge_is_feature_t>::type EIFMap; EIFMap eif = get( CGAL::edge_is_feature, mesh ); pmp::detect_sharp_edges( mesh, 60, eif ); int sharpCount = 0; for ( EdgeDesc e : edges(mesh) ) { if ( get(eif, e) ) { sharpCount++; } } std::cout << "sharpCount = " << sharpCount << "\n"; const unsigned int nbIters = 10; std::cout << "Smoothing...\n"; pmp::smooth_mesh( mesh, pmp::parameters::number_of_iterations(nbIters) .use_safety_constraints(false) .edge_is_constrained_map(eif) ); std::cout << "Smoothing done. \n"; } int main( int argc, char **argv ) { std::cout << "Hello, RemoveFaces! \n"; // Load the mesh. Mesh_t surfaceMesh; std::ifstream ifs( argv[1], std::ios::binary ); if ( !ifs ) { throw std::runtime_error("Cannot open file. "); } CGAL::read_off( ifs, surfaceMesh ); ifs.close(); // Loop over all the intersected faces and remove them. std::cout << "Collecting intersected faces. \n"; std::vector< std::pair< FaceDesc_t, FaceDesc_t > > intersectedFacePairs; pmp::self_intersections( surfaceMesh, std::back_inserter( intersectedFacePairs ) ); std::set<FaceDesc_t> intersectedFaceSet; for ( const auto &p : intersectedFacePairs ) { intersectedFaceSet.insert(p.first); intersectedFaceSet.insert(p.second); } std::cout << intersectedFaceSet.size() << " faces to be removed. \n"; std::cout << "Begin removing intersected faces. \n"; for ( const auto &f : intersectedFaceSet ) { // for ( HalfedgeIdx_t h : CGAL::halfedges_around_face( surfaceMesh.halfedge(f), surfaceMesh ) ) { // if ( !surfaceMesh.is_border(h) ) CGAL::Euler::remove_face(h, surfaceMesh); // } surfaceMesh.remove_face(f); } surfaceMesh.collect_garbage(); // Smoothing. smooth_mesh( surfaceMesh ); return 0; }
Attachment:
InitialConverted.off
Description: Binary data
- [cgal-discuss] Surface mesh cannot be smoothed after removing faces, Yaoyu Hu, 07/14/2020
- Re: [cgal-discuss] Surface mesh cannot be smoothed after removing faces, Maxime Gimeno, 07/15/2020
- Re: [cgal-discuss] Surface mesh cannot be smoothed after removing faces, Mael Rouxel-Labbé, 07/15/2020
- Re: [cgal-discuss] Surface mesh cannot be smoothed after removing faces, Yaoyu Hu, 07/15/2020
- Re: [cgal-discuss] Surface mesh cannot be smoothed after removing faces, Mael Rouxel-Labbé, 07/16/2020
- Re: [cgal-discuss] Surface mesh cannot be smoothed after removing faces, Yaoyu Hu, 07/15/2020
- Re: [cgal-discuss] Surface mesh cannot be smoothed after removing faces, Mael Rouxel-Labbé, 07/15/2020
- Re: [cgal-discuss] Surface mesh cannot be smoothed after removing faces, Maxime Gimeno, 07/15/2020
Archive powered by MHonArc 2.6.19+.