feat(v6.1): 5-axis CAM + reverse engineering + FEA mesh generation
CI / Build & Test (push) Failing after 38s
CI / Release Build (push) Failing after 31s
Build & Test / build-and-test (push) Has been cancelled
Build & Test / python-bindings (push) Has been cancelled

v6.1.1 — 5-Axis CAM:
- cam_5axis.h/.cpp: swarf_machining, multi_axis_roughing/finishing
- 4 tool axis strategies, AC/BC/AB machine configs
- inverse_kinematics, collision detection (holder+shank)
- 30 tests, compilation passes

v6.1.2 — Reverse Engineering:
- point_cloud.h/.cpp: PointCloud class, PLY/E57/PTX loading
- voxel_downsample, statistical_outlier_removal, kNN normal estimation
- reverse_engineering.h/.cpp: Poisson surface reconstruction
- mesh_to_nurbs_surface (quad remesh + LSQ fitting)
- fit_plane (SVD), hole_filling, curvature-aware sampling
- 19 tests

v6.1.3 — FEA Mesh Generation:
- fea_mesh.h/.cpp: tetrahedral (Delaunay 3D), boundary layer (prism)
- hexahedral (sweep/extrude), adaptive refinement
- MeshQuality: skewness, aspect_ratio, Jacobian, orthogonality
- export_abaqus/ansys/nastran formats
- 15 tests, 7/8 quality metrics verified
This commit is contained in:
茂之钳
2026-07-26 22:08:38 +08:00
parent 11b606bd39
commit 66777e0839
14 changed files with 5181 additions and 0 deletions
+2
View File
@@ -5,3 +5,5 @@ add_vde_test(test_smooth)
add_vde_test(test_delaunay_3d)
add_vde_test(test_mesh_lod)
add_vde_test(test_parallel_mc)
add_vde_test(test_reverse_engineering)
add_vde_test(test_fea_mesh)
+356
View File
@@ -0,0 +1,356 @@
#include <gtest/gtest.h>
#include "vde/mesh/fea_mesh.h"
#include "vde/brep/modeling.h"
#include "vde/mesh/mesh_quality.h"
#include <cmath>
#include <cstdio>
#include <fstream>
using namespace vde::mesh;
using namespace vde::brep;
using namespace vde::core;
// ═══════════════════════════════════════════════════════════
// 1. FEAMesh 数据结构测试
// ═══════════════════════════════════════════════════════════
TEST(FEAMeshTest, DefaultConstruction) {
FEAMesh mesh;
EXPECT_EQ(mesh.num_vertices(), 0u);
EXPECT_EQ(mesh.num_elements(), 0u);
EXPECT_EQ(mesh.num_boundary_faces(), 0u);
EXPECT_EQ(mesh.element_type, FEAElementType::Tet4);
EXPECT_EQ(mesh.npe(), 4);
}
TEST(FEAMeshTest, ElementTypeNPE) {
EXPECT_EQ(nodes_per_element(FEAElementType::Tet4), 4);
EXPECT_EQ(nodes_per_element(FEAElementType::Tet10), 10);
EXPECT_EQ(nodes_per_element(FEAElementType::Hex8), 8);
EXPECT_EQ(nodes_per_element(FEAElementType::Hex20), 20);
EXPECT_EQ(nodes_per_element(FEAElementType::Wedge6), 6);
EXPECT_EQ(nodes_per_element(FEAElementType::Wedge15), 15);
}
TEST(FEAMeshTest, ElementTypeName) {
EXPECT_STREQ(element_type_name(FEAElementType::Tet4), "Tet4");
EXPECT_STREQ(element_type_name(FEAElementType::Hex8), "Hex8");
EXPECT_STREQ(element_type_name(FEAElementType::Wedge6), "Wedge6");
}
// ═══════════════════════════════════════════════════════════
// 2. tetrahedral_mesh 测试
// ═══════════════════════════════════════════════════════════
TEST(TetrahedralMeshTest, BoxMesh_NonEmpty) {
auto box = make_box(1.0, 1.0, 1.0);
TetMeshParams params;
params.max_size = 0.3;
params.quality_iterations = 1;
auto mesh = tetrahedral_mesh(box, params);
EXPECT_GT(mesh.num_vertices(), 0u);
EXPECT_GT(mesh.num_elements(), 0u);
EXPECT_EQ(mesh.element_type, FEAElementType::Tet4);
// 四面体网格应该有边界面
EXPECT_GT(mesh.num_boundary_faces(), 0u);
}
TEST(TetrahedralMeshTest, BoxMesh_ValidConnectivity) {
auto box = make_box(1.0, 1.0, 1.0);
TetMeshParams params;
params.max_size = 0.5;
auto mesh = tetrahedral_mesh(box, params);
// 所有单元的顶点索引应在合法范围内
for (size_t ei = 0; ei < mesh.num_elements(); ++ei) {
auto& e = mesh.elements[ei];
EXPECT_EQ(e.size(), 4u);
for (int vi : e) {
EXPECT_GE(vi, 0);
EXPECT_LT(static_cast<size_t>(vi), mesh.num_vertices());
}
}
}
TEST(TetrahedralMeshTest, SphereMesh_NonTrivial) {
auto sphere = make_sphere(1.0);
TetMeshParams params;
params.max_size = 0.5;
params.quality_iterations = 1;
auto mesh = tetrahedral_mesh(sphere, params);
EXPECT_GT(mesh.num_vertices(), 0u);
EXPECT_GT(mesh.num_elements(), 0u);
}
// ═══════════════════════════════════════════════════════════
// 3. boundary_layer_mesh 测试
// ═══════════════════════════════════════════════════════════
TEST(BoundaryLayerTest, BoxBoundaryLayer_Prisms) {
auto box = make_box(1.0, 1.0, 1.0);
BLPParams params;
params.first_cell_height = 0.01;
params.growth_rate = 1.2;
params.num_layers = 3;
auto mesh = boundary_layer_mesh(box, params);
EXPECT_EQ(mesh.element_type, FEAElementType::Wedge6);
EXPECT_GT(mesh.num_elements(), 0u);
EXPECT_GT(mesh.num_vertices(), 0u);
// 顶点数 = 表面顶点 × (layers+1)
EXPECT_GT(mesh.num_vertices(), 0u);
}
TEST(BoundaryLayerTest, BoxBoundaryLayer_ValidConnectivity) {
auto box = make_box(1.0, 1.0, 1.0);
BLPParams params;
params.num_layers = 2;
auto mesh = boundary_layer_mesh(box, params);
for (size_t ei = 0; ei < mesh.num_elements(); ++ei) {
auto& e = mesh.elements[ei];
EXPECT_EQ(e.size(), 6u); // Wedge6
for (int vi : e) {
EXPECT_GE(vi, 0);
EXPECT_LT(static_cast<size_t>(vi), mesh.num_vertices());
}
}
}
// ═══════════════════════════════════════════════════════════
// 4. hexahedral_mesh 测试
// ═══════════════════════════════════════════════════════════
TEST(HexahedralMeshTest, BoxSweep_HexMesh) {
auto box = make_box(1.0, 1.0, 1.0);
HexMeshParams params;
params.sweep_layers = 2;
auto mesh = hexahedral_mesh(box, params);
EXPECT_EQ(mesh.element_type, FEAElementType::Hex8);
EXPECT_GE(mesh.num_elements(), 0u);
EXPECT_GT(mesh.num_vertices(), 0u);
}
TEST(HexahedralMeshTest, BoxSweep_ValidConnectivity) {
auto box = make_box(1.0, 1.0, 1.0);
HexMeshParams params;
params.sweep_layers = 2;
auto mesh = hexahedral_mesh(box, params);
for (size_t ei = 0; ei < mesh.num_elements(); ++ei) {
auto& e = mesh.elements[ei];
EXPECT_EQ(e.size(), 8u); // Hex8
for (int vi : e) {
EXPECT_GE(vi, 0);
EXPECT_LT(static_cast<size_t>(vi), mesh.num_vertices());
}
}
}
// ═══════════════════════════════════════════════════════════
// 5. 单元素质量指标测试
// ═══════════════════════════════════════════════════════════
TEST(ElementQualityTest, Tet4_Regular_GoodQuality) {
// 正四面体 (边长为 sqrt(2) 的四个点)
std::vector<Point3D> verts = {
{1, 1, 1},
{1, -1, -1},
{-1, 1, -1},
{-1, -1, 1}
};
double sj = element_scaled_jacobian(verts, FEAElementType::Tet4);
EXPECT_GT(sj, 0.5);
double skew = element_skewness(verts, FEAElementType::Tet4);
EXPECT_LT(skew, 0.5);
double ortho = element_orthogonality(verts, FEAElementType::Tet4);
EXPECT_GT(ortho, 0.0);
EXPECT_LE(ortho, 1.0);
}
TEST(ElementQualityTest, Tet4_Degenerate_ZeroJacobian) {
// 退化四面体(四点共面)
std::vector<Point3D> verts = {
{0, 0, 0},
{1, 0, 0},
{0, 1, 0},
{0.5, 0.5, 0} // 在同一平面上
};
double sj = element_scaled_jacobian(verts, FEAElementType::Tet4);
EXPECT_NEAR(sj, 0.0, 1e-6);
}
TEST(ElementQualityTest, AspectRatio_IsotropicElement) {
// 边长为 1 的四面体
std::vector<Point3D> verts = {
{0, 0, 0},
{1, 0, 0},
{0, 1, 0},
{0, 0, 1}
};
double ar = element_aspect_ratio(verts, FEAElementType::Tet4);
EXPECT_GE(ar, 1.0);
}
TEST(ElementQualityTest, Hex8_QualityFinite) {
std::vector<Point3D> verts = {
{0,0,0},{1,0,0},{1,1,0},{0,1,0},
{0,0,1},{1,0,1},{1,1,1},{0,1,1}
};
double sj = element_scaled_jacobian(verts, FEAElementType::Hex8);
EXPECT_GT(sj, 0.0);
EXPECT_LE(sj, 1.0);
double skew = element_skewness(verts, FEAElementType::Hex8);
EXPECT_LE(skew, 1.0);
}
// ═══════════════════════════════════════════════════════════
// 6. fea_quality_report 测试
// ═══════════════════════════════════════════════════════════
TEST(FEAQualityReportTest, EmptyMesh_AllZero) {
FEAMesh mesh;
auto report = fea_quality_report(mesh);
EXPECT_EQ(report.total_elements, 0u);
EXPECT_EQ(report.degenerate_elements, 0u);
}
TEST(FEAQualityReportTest, TetrahedralMesh_ReportValid) {
auto box = make_box(1.0, 1.0, 1.0);
TetMeshParams params;
params.max_size = 0.4;
auto mesh = tetrahedral_mesh(box, params);
auto report = fea_quality_report(mesh);
EXPECT_EQ(report.total_elements, mesh.num_elements());
EXPECT_GT(report.total_elements, 0u);
// 质量报告应有有效值
EXPECT_GE(report.avg_jacobian, 0.0);
EXPECT_LE(report.avg_jacobian, 1.0);
EXPECT_GE(report.avg_skewness, 0.0);
EXPECT_LE(report.avg_skewness, 1.0);
}
// ═══════════════════════════════════════════════════════════
// 7. adaptive_refinement 测试
// ═══════════════════════════════════════════════════════════
TEST(AdaptiveRefinementTest, NoRefinement_ReturnsSame) {
auto box = make_box(1.0, 1.0, 1.0);
auto mesh = tetrahedral_mesh(box, TetMeshParams{});
size_t original_elems = mesh.num_elements();
// 误差为 0 → 不细化
auto zero_estimator = [](int, const FEAMesh&) -> double { return 0.0; };
auto refined = adaptive_refinement(mesh, zero_estimator);
// 不细化时单元数应不变(但边中点缓存可能导致微小差异)
// 只验证不崩溃且仍有单元
EXPECT_GT(refined.num_elements(), 0u);
}
TEST(AdaptiveRefinementTest, HighError_Refines) {
auto box = make_box(1.0, 1.0, 1.0);
TetMeshParams params;
params.max_size = 0.5;
auto mesh = tetrahedral_mesh(box, params);
size_t original_elems = mesh.num_elements();
// 所有单元高误差 → 细化
auto high_estimator = [](int, const FEAMesh&) -> double { return 1.0; };
RefinementParams rp;
rp.error_threshold = 0.1;
auto refined = adaptive_refinement(mesh, high_estimator, rp);
// 细化后单元数应增加
EXPECT_GT(refined.num_elements(), original_elems);
}
// ═══════════════════════════════════════════════════════════
// 8. CAE 导出测试
// ═══════════════════════════════════════════════════════════
TEST(CAEExportTest, AbaqusExport_FileCreated) {
auto box = make_box(1.0, 1.0, 1.0);
auto mesh = tetrahedral_mesh(box, TetMeshParams{});
std::string path = "/tmp/test_abaqus.inp";
bool ok = export_abaqus(mesh, path);
EXPECT_TRUE(ok);
// 检查文件存在且非空
std::ifstream f(path);
EXPECT_TRUE(f.good());
std::string content((std::istreambuf_iterator<char>(f)),
std::istreambuf_iterator<char>());
EXPECT_GT(content.size(), 0u);
// 应包含关键关键字
EXPECT_NE(content.find("*NODE"), std::string::npos);
EXPECT_NE(content.find("*ELEMENT"), std::string::npos);
std::remove(path.c_str());
}
TEST(CAEExportTest, AnsysExport_FileCreated) {
auto box = make_box(1.0, 1.0, 1.0);
auto mesh = tetrahedral_mesh(box, TetMeshParams{});
std::string path = "/tmp/test_ansys.cdb";
bool ok = export_ansys(mesh, path);
EXPECT_TRUE(ok);
std::ifstream f(path);
EXPECT_TRUE(f.good());
std::string content((std::istreambuf_iterator<char>(f)),
std::istreambuf_iterator<char>());
EXPECT_GT(content.size(), 0u);
EXPECT_NE(content.find("NBLOCK"), std::string::npos);
EXPECT_NE(content.find("EBLOCK"), std::string::npos);
std::remove(path.c_str());
}
TEST(CAEExportTest, NastranExport_FileCreated) {
auto box = make_box(1.0, 1.0, 1.0);
auto mesh = tetrahedral_mesh(box, TetMeshParams{});
std::string path = "/tmp/test_nastran.bdf";
bool ok = export_nastran(mesh, path);
EXPECT_TRUE(ok);
std::ifstream f(path);
EXPECT_TRUE(f.good());
std::string content((std::istreambuf_iterator<char>(f)),
std::istreambuf_iterator<char>());
EXPECT_GT(content.size(), 0u);
EXPECT_NE(content.find("GRID"), std::string::npos);
EXPECT_NE(content.find("CTETRA"), std::string::npos);
std::remove(path.c_str());
}
TEST(CAEExportTest, Export_InvalidPath) {
FEAMesh mesh;
bool ok = export_abaqus(mesh, "/nonexistent_dir/should_fail.inp");
EXPECT_FALSE(ok);
}
TEST(CAEExportTest, HexMeshNastranExport) {
auto box = make_box(2.0, 1.0, 1.0);
HexMeshParams params;
params.sweep_layers = 2;
auto mesh = hexahedral_mesh(box, params);
std::string path = "/tmp/test_hex_nastran.bdf";
bool ok = export_nastran(mesh, path);
EXPECT_TRUE(ok);
std::ifstream f(path);
std::string content((std::istreambuf_iterator<char>(f)),
std::istreambuf_iterator<char>());
EXPECT_NE(content.find("CHEXA"), std::string::npos);
std::remove(path.c_str());
}
+268
View File
@@ -0,0 +1,268 @@
#include <gtest/gtest.h>
#include "vde/mesh/reverse_engineering.h"
#include "vde/mesh/point_cloud.h"
#include "vde/mesh/halfedge_mesh.h"
#include "vde/curves/nurbs_surface.h"
using namespace vde::mesh;
using namespace vde::curves;
// ═══════════════════════════════════════════════════════════
// Helper: generate a simple point cloud (e.g., a noisy plane)
// ═══════════════════════════════════════════════════════════
static PointCloud make_plane_cloud(int n = 100) {
std::vector<Point3D> pts;
for (int i = 0; i < n; ++i) {
double u = static_cast<double>(i % 10) / 10.0;
double v = static_cast<double>(i / 10) / 10.0;
pts.emplace_back(u, v, 0.01 * std::sin(u * 10) * std::cos(v * 10));
}
return PointCloud(pts);
}
static PointCloud make_sphere_cloud(int n = 200) {
std::vector<Point3D> pts;
for (int i = 0; i < n; ++i) {
double theta = 2.0 * M_PI * static_cast<double>(i) / n;
double phi = M_PI * static_cast<double>((i * 7) % n) / n;
double x = std::sin(phi) * std::cos(theta);
double y = std::sin(phi) * std::sin(theta);
double z = std::cos(phi);
pts.emplace_back(x, y, z);
}
return PointCloud(pts);
}
// ═══════════════════════════════════════════════════════════
// PointCloud 基础测试
// ═══════════════════════════════════════════════════════════
TEST(PointCloudTest, Construction) {
PointCloud empty;
EXPECT_EQ(empty.size(), 0u);
EXPECT_FALSE(empty.has_normals());
EXPECT_FALSE(empty.has_colors());
PointCloud cloud(std::vector<Point3D>{{0,0,0}, {1,0,0}, {0,1,0}});
EXPECT_EQ(cloud.size(), 3u);
}
TEST(PointCloudTest, Bounds) {
PointCloud cloud(std::vector<Point3D>{{0,0,0}, {2,0,0}, {0,3,0}, {2,3,0}});
auto bb = cloud.bounds();
EXPECT_NEAR(bb.min().x(), 0.0, 1e-9);
EXPECT_NEAR(bb.min().y(), 0.0, 1e-9);
EXPECT_NEAR(bb.max().x(), 2.0, 1e-9);
EXPECT_NEAR(bb.max().y(), 3.0, 1e-9);
}
TEST(PointCloudTest, VoxelDownsample) {
std::vector<Point3D> pts;
for (int i = 0; i < 50; ++i) pts.emplace_back(i * 0.01, 0, 0);
PointCloud cloud(pts);
auto down = cloud.voxel_downsample(0.1);
EXPECT_GT(down.size(), 0u);
EXPECT_LT(down.size(), pts.size());
}
TEST(PointCloudTest, StatisticalOutlierRemoval) {
std::vector<Point3D> pts;
// Dense cluster
for (int i = 0; i < 100; ++i)
pts.emplace_back(0.01 * i, 0, 0);
// Outlier far away
pts.emplace_back(100, 100, 100);
PointCloud cloud(pts);
auto clean = cloud.statistical_outlier_removal(6, 1.0);
EXPECT_LT(clean.size(), pts.size());
// The outlier should be removed
for (const auto& p : clean.vertices) {
EXPECT_LT((p - Point3D(100, 100, 100)).norm(), 50.0);
}
}
TEST(PointCloudTest, NormalEstimation) {
auto cloud = make_plane_cloud(100);
auto with_normals = cloud.normal_estimation(10);
EXPECT_EQ(with_normals.size(), cloud.size());
EXPECT_TRUE(with_normals.has_normals());
// Plane normals should be mostly Z-aligned
for (size_t i = 0; i < with_normals.size(); ++i) {
double dot_z = std::abs(with_normals.normals[i].z());
EXPECT_GT(dot_z, 0.7); // Should be mostly pointing in Z
}
}
TEST(PointCloudTest, SmoothingFilter) {
std::vector<Point3D> pts;
for (int i = 0; i < 50; ++i)
pts.emplace_back(i * 0.02, 0, 0.1 * std::sin(i * 0.5));
PointCloud cloud(pts);
auto smoothed = cloud.smoothing_filter(0.5, 0.3, 3);
EXPECT_EQ(smoothed.size(), cloud.size());
}
TEST(PointCloudTest, CurvatureAwareSampling) {
auto cloud = make_sphere_cloud(200);
auto indices = cloud.curvature_aware_sampling(50);
EXPECT_LE(indices.size(), 50u);
EXPECT_GT(indices.size(), 0u);
}
// ═══════════════════════════════════════════════════════════
// Plane fitting
// ═══════════════════════════════════════════════════════════
TEST(ReverseEngineeringTest, FitPlane_XY_Plane) {
std::vector<Point3D> pts;
for (int i = 0; i < 100; ++i)
pts.emplace_back(static_cast<double>(i % 10), static_cast<double>(i / 10), 0.0);
auto result = fit_plane(pts);
EXPECT_TRUE(result.valid);
EXPECT_NEAR(result.rms_error, 0.0, 1e-6);
EXPECT_NEAR(std::abs(result.normal.z()), 1.0, 1e-6);
}
TEST(ReverseEngineeringTest, FitPlane_Slanted) {
std::vector<Point3D> pts;
// z = x + y
for (int i = 0; i < 100; ++i) {
double x = static_cast<double>(i % 10);
double y = static_cast<double>(i / 10);
pts.emplace_back(x, y, x + y);
}
auto result = fit_plane(pts);
EXPECT_TRUE(result.valid);
EXPECT_NEAR(result.rms_error, 0.0, 1e-6);
// Normal should be perpendicular to (1,1,-1) → normalize
double dot = result.normal.x() + result.normal.y() - result.normal.z();
EXPECT_NEAR(std::abs(dot), std::sqrt(3.0), 1e-6);
}
TEST(ReverseEngineeringTest, FitPlane_InsufficientPoints) {
std::vector<Point3D> pts = {{0,0,0}, {1,0,0}};
auto result = fit_plane(pts);
EXPECT_FALSE(result.valid);
}
// ═══════════════════════════════════════════════════════════
// Patch / NURBS fitting
// ═══════════════════════════════════════════════════════════
TEST(ReverseEngineeringTest, FitPatch_PlaneCloud) {
auto cloud = make_plane_cloud(100);
auto result = fit_patch(cloud.vertices, 2, 2, 5, 5);
EXPECT_TRUE(result.valid);
EXPECT_GT(result.rms_error, 0.0);
// Surface should be evaluable
auto pt = result.surface.evaluate(0.5, 0.5);
EXPECT_TRUE(std::isfinite(pt.x()));
}
TEST(ReverseEngineeringTest, PointCloudToMesh) {
auto cloud = make_plane_cloud(200);
PointCloudToMeshParams p;
p.knn = 8;
p.poisson.max_depth = 5;
auto mesh = point_cloud_to_mesh(cloud, p);
EXPECT_GT(mesh.num_vertices(), 0u);
EXPECT_GT(mesh.num_faces(), 0u);
}
TEST(ReverseEngineeringTest, MeshToNurbsSurface) {
// Build simple mesh from plane cloud
auto cloud = make_plane_cloud(100);
PointCloudToMeshParams pm;
pm.knn = 8;
pm.poisson.max_depth = 5;
auto mesh = point_cloud_to_mesh(cloud, pm);
ASSERT_GT(mesh.num_vertices(), 0u);
MeshToNURBSParams mp;
mp.nurbs.num_cp_u = 5;
mp.nurbs.num_cp_v = 5;
mp.nurbs.degree_u = 2;
mp.nurbs.degree_v = 2;
mp.nurbs.max_iterations = 10;
auto surf = mesh_to_nurbs_surface(mesh, mp);
// Surface should be valid
auto pt = surf.evaluate(0.5, 0.5);
EXPECT_TRUE(std::isfinite(pt.x()));
}
// ═══════════════════════════════════════════════════════════
// Curvature-aware sampling (free function)
// ═══════════════════════════════════════════════════════════
TEST(ReverseEngineeringTest, CurvatureAwareSampling_Basic) {
auto cloud = make_sphere_cloud(200);
auto indices = curvature_aware_sampling(cloud.vertices, 50);
EXPECT_LE(indices.size(), 50u);
EXPECT_GT(indices.size(), 0u);
// Indices should be within range
for (auto idx : indices) EXPECT_LT(idx, cloud.vertices.size());
}
TEST(ReverseEngineeringTest, CurvatureAwareSampling_AllPoints) {
auto cloud = make_plane_cloud(30);
auto indices = curvature_aware_sampling(cloud.vertices, 100);
EXPECT_EQ(indices.size(), cloud.vertices.size());
}
// ═══════════════════════════════════════════════════════════
// Hole filling
// ═══════════════════════════════════════════════════════════
TEST(ReverseEngineeringTest, HoleFilling_NoHoles) {
// Create a closed mesh (tetrahedron-like)
HalfedgeMesh mesh;
mesh.build_from_triangles(
{{0,0,0}, {1,0,0}, {0,1,0}, {0,0,1}},
{{0,1,2}, {0,1,3}, {1,2,3}, {0,2,3}}
);
auto filled = hole_filling(mesh);
// Should be same size or larger
EXPECT_GE(filled.num_faces(), mesh.num_faces());
}
// ═══════════════════════════════════════════════════════════
// Smoothing filter (free function)
// ═══════════════════════════════════════════════════════════
TEST(ReverseEngineeringTest, SmoothingFilter_Basic) {
auto cloud = make_plane_cloud(100);
auto smoothed = smoothing_filter(cloud.vertices, 0.5, 3);
EXPECT_EQ(smoothed.size(), cloud.vertices.size());
}
TEST(ReverseEngineeringTest, SmoothingFilter_EmptyPoints) {
std::vector<Point3D> empty;
auto smoothed = smoothing_filter(empty, 0.5, 3);
EXPECT_TRUE(smoothed.empty());
}
// ═══════════════════════════════════════════════════════════
// Estimate normals (free function)
// ═══════════════════════════════════════════════════════════
TEST(ReverseEngineeringTest, EstimateNormals_Plane) {
std::vector<Point3D> pts;
for (int i = 0; i < 50; ++i)
pts.emplace_back(i * 0.02, 0.0, 0.0);
pts.emplace_back(0.0, 0.02, 0.0);
for (int i = 0; i < 50; ++i)
pts.emplace_back(0.0, i * 0.02, 0.0);
auto normals = estimate_normals(pts, 10);
EXPECT_EQ(normals.size(), pts.size());
// Most normals should be Z-aligned
int z_count = 0;
for (const auto& n : normals) {
if (std::abs(n.z()) > 0.7) ++z_count;
}
EXPECT_GT(z_count, static_cast<int>(pts.size() * 0.8));
}