97 lines
3.5 KiB
C++
97 lines
3.5 KiB
C++
#pragma once
|
||
#include "vde/mesh/halfedge_mesh.h"
|
||
#include <cmath>
|
||
#include <vector>
|
||
#include <string>
|
||
|
||
namespace vde::mesh {
|
||
using core::Point2D;
|
||
using core::Point3D;
|
||
using core::Vector3D;
|
||
|
||
// ── Triangle quality ────────────────────────────────
|
||
|
||
struct MeshQuality {
|
||
double min_angle_deg = 0;
|
||
double max_angle_deg = 0;
|
||
double avg_aspect_ratio = 0;
|
||
double max_aspect_ratio = 0;
|
||
size_t degenerate_faces = 0;
|
||
};
|
||
|
||
MeshQuality evaluate_mesh_quality(const HalfedgeMesh& mesh);
|
||
|
||
// ── Tetrahedron quality ─────────────────────────────
|
||
|
||
struct TetQuality {
|
||
double min_jacobian = 0.0; // scaled Jacobian (normalised, 0=b−ad … 1=regular)
|
||
double max_jacobian = 0.0;
|
||
double avg_jacobian = 0.0;
|
||
double min_dihedral_deg = 0.0; // minimum dihedral angle (degrees)
|
||
double max_dihedral_deg = 0.0; // maximum dihedral angle
|
||
double max_aspect_ratio = 0.0; // circumsphere-radius / shortest-edge
|
||
size_t degenerate_tets = 0;
|
||
size_t total_tets = 0;
|
||
};
|
||
|
||
/// Evaluate tetrahedron quality from a triangle mesh.
|
||
/// This function interprets the mesh as a tetrahedral mesh where
|
||
/// each face belongs to a tet defined by the face vertices + face centroid
|
||
/// (suitable for closed triangle surfaces interpreted as volume boundaries).
|
||
TetQuality evaluate_tet_quality(const HalfedgeMesh& mesh);
|
||
|
||
// ── Generic element quality ─────────────────────────
|
||
|
||
enum class ElementType { Tri, Quad, Tet, Hex };
|
||
|
||
struct ElemQuality {
|
||
double min_jacobian = 0.0;
|
||
double max_jacobian = 0.0;
|
||
double avg_jacobian = 0.0;
|
||
size_t total_elements = 0;
|
||
size_t degenerate = 0;
|
||
};
|
||
|
||
/// Dispatch by element type; implemented for Tri and Tet (Quad/Hex return stub).
|
||
ElemQuality evaluate_element_quality(const HalfedgeMesh& mesh, ElementType type);
|
||
|
||
// ── Quality report ──────────────────────────────────
|
||
|
||
struct QualityReport {
|
||
std::string element_type; // "triangle" / "tetrahedron"
|
||
size_t total = 0;
|
||
size_t degenerate = 0;
|
||
|
||
// Binned histogram (quality ∈ [0,1])
|
||
static constexpr int kBins = 10;
|
||
std::array<size_t, kBins> histogram{};
|
||
|
||
// Grade counts (A=excellent B=good C=acceptable D=poor F=fail)
|
||
size_t grade_A = 0, grade_B = 0, grade_C = 0, grade_D = 0, grade_F = 0;
|
||
|
||
double min_quality = 0.0;
|
||
double max_quality = 0.0;
|
||
double avg_quality = 0.0;
|
||
double stddev_quality = 0.0;
|
||
};
|
||
|
||
/// Generate a full quality report from a triangle surface mesh.
|
||
QualityReport mesh_quality_report(const HalfedgeMesh& mesh);
|
||
|
||
/// Generate a full quality report from a tetrahedral mesh.
|
||
/// The mesh is treated as having 4-vertex faces (tets) in the
|
||
/// same index order as the surface-mesh face loop.
|
||
QualityReport mesh_quality_report_tet(const HalfedgeMesh& mesh);
|
||
|
||
// ── Utility ─────────────────────────────────────────
|
||
|
||
/// Compute the scaled Jacobian (determinant / (product of edge-lengths))
|
||
/// for a triangle; returns [−1,1], 1 = equilateral.
|
||
double tri_scaled_jacobian(const Point3D& a, const Point3D& b, const Point3D& c);
|
||
|
||
/// Compute the scaled Jacobian for a tetrahedron; returns [0,1].
|
||
double tet_scaled_jacobian(const Point3D& a, const Point3D& b,
|
||
const Point3D& c, const Point3D& d);
|
||
|
||
} // namespace vde::mesh
|