Tetrahedra outside the domain (polyline stitching) in CGAL 3D mesh generation
## Issue Details
**Unexpected behavior**
<img width="1687" height="252" alt="Image" src="https://github.com/user-attachments/assets/c0cf6517-3999-47fc-9434-8abb0d73ef5e" />
<img width="1504" height="627" alt="Image" src="https://github.com/user-attachments/assets/b12dffef-f19c-433d-ab92-3936c9a41ecd" />
I am generating a 3D volume mesh from a surface mesh using:
```
MeshCriteria(
CGAL::parameters::facet_size(longestSurfaceEdge)
.cell_size(longestSurfaceEdge)
.facet_distance(facetDistance)
.edge_min_size(0.1 * minTubeLength)
.edge_size(longestSurfaceEdge)
.cell_radius_edge_ratio(2)
.facet_angle(30)
);
using Kernel = CGAL::Exact_predicates_inexact_constructions_kernel;
using MeshDomain = CGAL::Polyhedral_mesh_domain_with_features_3<Kernel>;
MeshDomain domain(surface);
domain.add_features(<"the red polylines seen below">);
C3t3 c3t3 = CGAL::make_mesh_3<C3t3>(
domain, criteria, CGAL::parameters::no_exude().no_perturb());
struct FacetDistance {
FacetDistance(double insideValue, double outsideValue,
CGAL::AABB_tree<Traits>* domainAndTubeTree,
CGAL::AABB_tree<Traits>* crackTree)
: insideValue(insideValue)
, outsideValue(outsideValue)
, domainAndTubeTree(domainAndTubeTree)
, crackTree(crackTree)
{
} double operator()(
const Point_3& p, int dimension, const MeshDomain::Index& /*index*/) const
{
if (dimension != 2)
LOG_ERROR(
"Querying facet distance parameter with dimension not equal to 2!"); auto domainDistance = domainAndTubeTree->squared_distance(p);
auto tubeCrackDistance = crackTree->squared_distance(p);
bool isTubeCrack = domainDistance >= tubeCrackDistance;
return isTubeCrack ? insideValue : outsideValue;
}
private:
double insideValue;
double outsideValue;
CGAL::AABB_tree<Traits>* domainAndTubeTree;
CGAL::AABB_tree<Traits>* crackTree;
};
```
**The cells circled in red are the problem. They lie outside the domain. This is caused by adding polylines.**
This is the surface mesh of the domain:
<img width="1730" height="373" alt="Image" src="https://github.com/user-attachments/assets/ac855a3d-4046-4884-bab2-948d3b269cf4" />
In red you can see the polylines that are added. The two polylines along the crack/slit are just two polylines. Each only has two corners, at the ends of the crack/slit. Other points are added as intermediate points of the polyline.
### Questions
1. How to fix the cells that are outside the domain? I can make the sampling parameter edge_min_size small enough for the cells to disappear, as you can see below. But then I have really small cells, which is not wanted. Is there a better way? They could also be removed in postprocessing.
<img width="1735" height="280" alt="Image" src="https://github.com/user-attachments/assets/cab884c0-db9f-4e14-85ac-513624df8c44" />
2. How to have larger facets inside the crack/slit?
- For the crack/slit surfaces to be recognized as separate surfaces, I need to set facet_distance parameter to be small enough on the crack/slit surface patches. This is done with a sizing field which is defined above.
- This works, but causes the facets on the surface to be very small, as you can see below (on the transparent plot). I do not want such small facets on the surface as it is flat, so they are unnecessary. I tried setting facet_min_size to be larger, but then the two surfaces were no longer recognized as separate and were meshed over.
<img width="1682" height="938" alt="Image" src="https://github.com/user-attachments/assets/aee5967e-a0b9-4efb-8e3a-25206be907a7" />
## Environment
* Operating system: Linux 64 bit
* Compiler: g++ (GCC) 14.2.0
* Release or debug mode: Debug
* Specific flags used: CGAL::Sequential_tag (for CGAL::Mesh_triangulation_3<>), -DCGAL_DISABLE_GMP=1
* CGAL version: 6.1
* Boost version: 1.89.0
* Other libraries versions if used (Eigen, TBB, etc.): /
2 条评论