Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

triangulate_refine_and_fair_hole not working #7283

Closed
9and3 opened this issue Feb 22, 2023 · 7 comments
Closed

triangulate_refine_and_fair_hole not working #7283

9and3 opened this issue Feb 22, 2023 · 7 comments

Comments

@9and3
Copy link

9and3 commented Feb 22, 2023

Issue Details

Hello CGAL community!

I am trying to fill some holes in several meshes with the wonderful CGAL::Polygon_mesh_processing::triangulate_refine_and_fair_hole(). Unfortunately for all the meshes I am trying to patch it does not close not even one hole.

I've seen a similar issue reporting the bad quality of the mesh as the source of the inefficiency of the hole filler function. This is way I cleaned out the mesh via converting the mesh back to a polygon soup (polygon_mesh_to_polygon_soup), cleaning the soup (repair_polygon_soup), before converting back to a polygon mesh (orient_polygon_soup + polygon_soup_to_polygon_mesh). But still no hole filling.

Please find attached 3 examples of mesh objects I am trying to patch, as well few images down below.
↓↓↓CGAL_mesh_fill_holes_data.zip↓↓↓

Many thanks in advance for any help or hint you can provide! 🙌

Screenshot from 2023-02-22 16-39-55
Screenshot from 2023-02-22 16-39-57
Screenshot from 2023-02-22 16-40-14

Source Code

#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Surface_mesh.h>

#include <CGAL/Polygon_mesh_processing/triangulate_hole.h>
#include <CGAL/Polygon_mesh_processing/border.h>
#include <CGAL/Polygon_mesh_processing/IO/polygon_mesh_io.h>

#include <boost/lexical_cast.hpp>

#include <CGAL/Polyhedron_3.h>
#include <CGAL/Polyhedron_items_with_id_3.h>
#include <CGAL/Polygon_mesh_processing/orient_polygon_soup.h>
#include <CGAL/Polygon_mesh_processing/polygon_soup_to_polygon_mesh.h>
#include <CGAL/Polygon_mesh_processing/polygon_mesh_to_polygon_soup.h>
#include <CGAL/Polygon_mesh_processing/repair_polygon_soup.h>

#include <CGAL/Polygon_mesh_processing/orientation.h>
#include <CGAL/IO/polygon_soup_io.h>

#include <iostream>
#include <fstream>
#include <iterator>
#include <string>
#include <tuple>
#include <vector>

typedef CGAL::Exact_predicates_inexact_constructions_kernel  K;
typedef K::Point_3                                                                                Point_3;
typedef CGAL::Surface_mesh<Point_3>                                           Mesh_srf;
typedef boost::graph_traits<Mesh_srf>::vertex_descriptor          vertex_descriptor;
typedef boost::graph_traits<Mesh_srf>::halfedge_descriptor     halfedge_descriptor;
typedef boost::graph_traits<Mesh_srf>::face_descriptor              face_descriptor;

namespace PMP = CGAL::Polygon_mesh_processing;

void fillHoles(Mesh_srf &cgalMesh)
{
  // cleaning
  std::vector<Point_3> points;
  std::vector<std::vector<std::size_t> > polygons;
  PMP::polygon_mesh_to_polygon_soup(cgalMesh, points, polygons);
  size_t nbrRmvPoints = 0;
  nbrRmvPoints = PMP::merge_duplicate_points_in_polygon_soup(points, polygons);
  PMP::repair_polygon_soup(points, polygons);
  PMP::orient_polygon_soup(points, polygons);
  Mesh_srf meshOut;
  PMP::polygon_soup_to_polygon_mesh(points, polygons, meshOut);
  cgalMesh = meshOut;

  // hole filler
  double max_hole_diam   = -1.0;
  int max_num_hole_edges = -1;
  unsigned int nb_holes = 0;
  std::vector<halfedge_descriptor> border_cycles;
  PMP::extract_boundary_cycles(cgalMesh, std::back_inserter(border_cycles));
  for(halfedge_descriptor h : border_cycles)
  {
      std::vector<face_descriptor>  patch_facets;
      std::vector<vertex_descriptor> patch_vertices;
      bool success = std::get<0>(PMP::triangulate_refine_and_fair_hole(cgalMesh,
                                                                      h,
                                                                      std::back_inserter(patch_facets),
                                                                      std::back_inserter(patch_vertices)));
      ++nb_holes;
  }
};

Environment

  • Operating system (Windows/Mac/Linux, 32/64 bits): Ubuntu 22.04 LTS
  • Compiler: gcc
  • Release or debug mode: release
  • Specific flags used (if any): /
  • CGAL version: 5.5.1
  • Boost version: 1.74.0.3ubuntu7
  • Other libraries versions if used (Eigen, TBB, etc.): /
@stla
Copy link

stla commented Feb 27, 2023

Hello,

For me this feature works fine.

I tried your mesh piece_1.off and according to CGAL it has no border, hence no hole to fill.

@stla
Copy link

stla commented Feb 27, 2023

Also tried with VCG, same conclusion: no border.

@sloriot
Copy link
Member

sloriot commented Feb 27, 2023

It indeed seems that all your faces are duplicated.

@stla
Copy link

stla commented Feb 27, 2023

I checked with VCG. @sloriot is right: all faces are duplicated. After removing the duplicates, five boundary cycles are found.

@stla
Copy link

stla commented Feb 27, 2023

You can read the file as a polygon soup and convert it to a polygon mesh after cleaning, then there's no duplicate face.

std::vector<Point_3> points;
std::vector<std::vector<size_t>> faces;
std::ifstream infile;
infile.open(filename);
bool ok = CGAL::IO::read_OFF(infile, points, faces);
infile.close()
......

@9and3
Copy link
Author

9and3 commented Mar 1, 2023

Hello! Thank you so much for you feedback! Indeed passing through CGAL::IO::read_OFF() it works:) Then it's a cleaning problem or an in-memory mesh to polygon soup conversion problem. I was wondering if the cleaning block in the code I posted shouldn't already take care of converting the mesh in polygon soup, cleaning it and re-converting it into a mesh? What would be the procedure to clean the polygon soup (I also tried PMP::merge_duplicate_polygons_in_polygon_soup() with no success)? Btw thanks a lot again for the hint!

@9and3
Copy link
Author

9and3 commented Mar 10, 2023

By creating the polygon soup from the start without going through mesh -> polygon soup -> cleaning -> cvt2mesh it works. Thanks for your time!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants