@@ -417,12 +417,31 @@ vtkSmartPointer<vtkPolyData> MeshWarper::remove_zero_area_triangles(vtkSmartPoin
417417 // Create a new cell array to store triangles
418418 auto new_triangles = vtkSmartPointer<vtkCellArray>::New ();
419419
420- // Get the triangle cells from the input mesh
421- vtkCellArray* triangles = mesh->GetPolys ();
422-
423420 // Iterate through all cells
424421 auto cell_point_ids = vtkSmartPointer<vtkIdList>::New ();
425422
423+ // First pass: find max area to establish scale
424+ double max_area = 0.0 ;
425+ for (vtkIdType cellId = 0 ; cellId < mesh->GetNumberOfCells (); cellId++) {
426+ mesh->GetCellPoints (cellId, cell_point_ids);
427+ if (cell_point_ids->GetNumberOfIds () == 3 ) {
428+ double p0[3 ], p1[3 ], p2[3 ];
429+ points->GetPoint (cell_point_ids->GetId (0 ), p0);
430+ points->GetPoint (cell_point_ids->GetId (1 ), p1);
431+ points->GetPoint (cell_point_ids->GetId (2 ), p2);
432+ double area = vtkTriangle::TriangleArea (p0, p1, p2);
433+ if (area > max_area) {
434+ max_area = area;
435+ }
436+ }
437+ }
438+
439+ // Use relative epsilon based on max area, with absolute floor
440+ const double RELATIVE_EPSILON = 1e-6 ;
441+ const double ABSOLUTE_FLOOR = 1e-15 ;
442+ const double epsilon = std::max (max_area * RELATIVE_EPSILON, ABSOLUTE_FLOOR);
443+
444+ // Second pass: filter triangles
426445 for (vtkIdType cellId = 0 ; cellId < mesh->GetNumberOfCells (); cellId++) {
427446 mesh->GetCellPoints (cellId, cell_point_ids);
428447
@@ -437,9 +456,7 @@ vtkSmartPointer<vtkPolyData> MeshWarper::remove_zero_area_triangles(vtkSmartPoin
437456 // Calculate the area of the triangle using VTK's built-in function
438457 double area = vtkTriangle::TriangleArea (p0, p1, p2);
439458
440- // If the area is not zero (use a small epsilon for floating point comparison)
441- const double EPSILON = 1e-10 ;
442- if (area > EPSILON) {
459+ if (area > epsilon) {
443460 // Add this triangle to the new cell array
444461 new_triangles->InsertNextCell (cell_point_ids);
445462 }
0 commit comments