E10: STEP 非标实体全量覆盖(HYPARC/PARABOLA/TRIM_CURVE/COMPOSITE_CURVE/POLYLINE/PCURVE/SURFACE_CURVE/B_SPLINE 变体接线 + 3 新 builder + 11 测试)

This commit is contained in:
hm
2026-08-10 20:14:02 +08:00
parent 21becf71f9
commit 07f16e2e02
3 changed files with 300 additions and 3 deletions
+1 -1
View File
@@ -306,7 +306,7 @@ Total TODO/FIXME/HACK/stub 扫描命中: 13 处
| E7 | **大规模装配空间索引**: 百万级零件平截头体裁剪 | 中 | ✅ E7 完成:Frustum 透视视锥体(6 平面,法向朝向体内心测试)+ 零件级 BVH 索引(O(n log n) 构建 / O(log n + k) 查询)+ 视锥/范围双查询 + 5 测试(含 6.4 万零件抽样暴力对照) |
| E8 | **IFC 语义双向转换**: 14 种 IFC 实体 ↔ B-Rep | 中 | ✅ E8 完成:新增 export_ifc(12 种产品类型按名称映射 + 盒体→IfcExtrudedAreaSolid/RectangleProfileDef 语义化 + 其余→IfcFacetedBrep 全链路)+ import 升级(12 构件全覆盖、矩形/圆形/任意剖面尺寸解析、FacetedBrep 顶点/边去重重建)+ 8 个双向/回读测试 |
| E9 | **STEP AP242 ED2 完整 PMI 往返** | 中 | ✅ E9 完成:AP242Writer 两阶段写入(壳/面/环/边/点全链路先子后父,修复 ISO-10303-21 内插实体损坏)+ PMI 导出链(PMI 容器/DIMENSIONAL_SIZE/度量/公差/GDT 14 子类型/DATUM 系统)+ StepPmiParser 导入重建(容器组装 + 无容器回退)+ 8 个往返测试 |
| E10 | **STEP 非标实体全量覆盖** | 中 | |
| E10 | **STEP 非标实体全量覆盖** | 中 | ✅ E10 完成:曲线派发器接线 HYPARC/PARABOLA/TRIM_CURVE/COMPOSITE_CURVE/POLYLINE/PCURVE/SURFACE_CURVE/B_SPLINE_CURVE(含 WITH_KNOTS_AND_RATIONAL 标准名修正);曲面派发器接线 B_SPLINE_SURFACE(含 AND_RATIONAL)与 RECTANGULAR_TRIMMED_SURFACE;新增 3 个 builder(无结点 B 样条均匀结点向量 + 矩形裁剪曲面委托基底);11 个非标实体测试 |
| E11 | **XT/SAT/JT 二进制格式全量实体** | 中 | |
| E12 | **性能优化**: SSI 并行、MC SIMD、STEP 解析预编译 | 中 | |
+108 -2
View File
@@ -853,6 +853,34 @@ private:
return curves::NurbsCurve(cps, knots, weights, degree);
}
// B_SPLINE_CURVE(无显式结点向量):degree, cps, form, closed, self_intersect
curves::NurbsCurve build_bspline_curve_basic(int id) {
const auto& ent = entities_.at(id);
if (ent.args.size() < 2) throw std::runtime_error("B_SPLINE_CURVE missing args");
int degree = static_cast<int>(to_double(ent.args[0]));
std::vector<Point3D> cps;
if (ent.args[1].type == StepValue::Type::List) {
for (const auto& v : ent.args[1].list) {
int ref = to_ref(v);
if (ref > 0 && points_.count(ref))
cps.push_back(points_[ref]);
}
}
if (cps.size() < 2) throw std::runtime_error("B_SPLINE_CURVE too few control points");
if (degree < 1) degree = 1;
if (degree >= static_cast<int>(cps.size())) degree = static_cast<int>(cps.size()) - 1;
// 均匀结点向量(规范化到 [0,1])
int n = static_cast<int>(cps.size());
std::vector<double> knots;
for (int i = 0; i <= n + degree; ++i)
knots.push_back(static_cast<double>(i) / (n + degree));
return curves::NurbsCurve(cps, knots, std::vector<double>(n, 1.0), degree);
}
curves::NurbsCurve build_vector_entity(int id) {
const auto& ent = entities_.at(id);
// VECTOR: name, orientation (DIRECTION ref), magnitude
@@ -1278,6 +1306,62 @@ private:
return curves::NurbsSurface(grid, ku, kv, wg, du, dv);
}
// B_SPLINE_SURFACE(无显式结点向量):udeg, vdeg, cps(二维表), form, uclosed, vclosed, selfint
curves::NurbsSurface build_bspline_surface_basic(int id) {
const auto& ent = entities_.at(id);
if (ent.args.size() < 3) throw std::runtime_error("B_SPLINE_SURFACE missing args");
int du = static_cast<int>(to_double(ent.args[0]));
int dv = static_cast<int>(to_double(ent.args[1]));
if (du < 1) du = 1;
if (dv < 1) dv = 1;
std::vector<std::vector<Point3D>> grid;
if (ent.args[2].type == StepValue::Type::List) {
for (const auto& row_val : ent.args[2].list) {
if (row_val.type == StepValue::Type::List) {
std::vector<Point3D> row;
for (const auto& pv : row_val.list) {
int ref = to_ref(pv);
row.push_back((ref > 0 && points_.count(ref)) ? points_[ref] : Point3D(0,0,0));
}
grid.push_back(std::move(row));
}
}
}
if (grid.empty()) throw std::runtime_error("B_SPLINE_SURFACE empty control grid");
size_t nu = grid.size(), nv = grid[0].size();
if (nv < 2) nv = 2;
if (du >= static_cast<int>(nu)) du = std::max(1, static_cast<int>(nu) - 1);
if (dv >= static_cast<int>(nv)) dv = std::max(1, static_cast<int>(nv) - 1);
// 均匀结点向量(规范化到 [0,1])
std::vector<double> ku, kv;
for (int i = 0; i <= static_cast<int>(nu) + du; ++i)
ku.push_back(static_cast<double>(i) / (nu + du));
for (int i = 0; i <= static_cast<int>(nv) + dv; ++i)
kv.push_back(static_cast<double>(i) / (nv + dv));
return curves::NurbsSurface(grid, ku, kv, {}, du, dv);
}
// RECTANGULAR_TRIMMED_SURFACE:委托基底曲面(裁剪参数暂不应用于 NURBS 评估)
curves::NurbsSurface build_rectangular_trimmed_surface(int id) {
const auto& ent = entities_.at(id);
if (ent.args.size() < 2) throw std::runtime_error("RECTANGULAR_TRIMMED_SURFACE missing args");
int basis_ref = to_ref(ent.args[1]);
if (basis_ref > 0 && entities_.count(basis_ref)) {
g_import_diag.approximated_surfaces++;
g_import_diag.add_warning("RECTANGULAR_TRIMMED_SURFACE #" + std::to_string(id)
+ ": 委托基底曲面 #" + std::to_string(basis_ref));
return get_or_build_surface(basis_ref);
}
throw std::runtime_error("RECTANGULAR_TRIMMED_SURFACE basis not resolvable");
}
// ── NURBS geometry constructors ──
static curves::NurbsCurve make_circle_nurbs(const Point3D& C,
@@ -1724,10 +1808,27 @@ private:
nc = build_circle_curve(ref);
else if (ent.type == "ELLIPSE")
nc = build_ellipse_curve(ref);
else if (ent.type == "B_SPLINE_CURVE_WITH_KNOTS")
else if (ent.type == "B_SPLINE_CURVE_WITH_KNOTS" ||
ent.type == "B_SPLINE_CURVE_WITH_KNOTS_AND_RATIONAL")
nc = build_bspline_curve(ref);
else if (ent.type == "B_SPLINE_CURVE")
nc = build_bspline_curve_basic(ref);
else if (ent.type == "VECTOR")
nc = build_vector_entity(ref);
else if (ent.type == "HYPARC")
nc = build_hyperbola_curve(ref);
else if (ent.type == "PARABOLA")
nc = build_parabola_curve(ref);
else if (ent.type == "TRIM_CURVE")
nc = build_trimmed_curve(ref);
else if (ent.type == "COMPOSITE_CURVE")
nc = build_composite_curve(ref);
else if (ent.type == "POLYLINE")
nc = build_polyline_curve(ref);
else if (ent.type == "PCURVE")
nc = build_pcurve(ref);
else if (ent.type == "SURFACE_CURVE")
nc = build_surface_curve(ref);
else
nc = curves::NurbsCurve({Point3D(0,0,0), Point3D(1,0,0)}, {0,0,1,1}, {1,1}, 1);
} catch (const std::exception& e) {
@@ -1769,8 +1870,13 @@ private:
ns = build_spherical_surface(ref);
else if (ent.type == "TOROIDAL_SURFACE")
ns = build_toroidal_surface(ref);
else if (ent.type == "B_SPLINE_SURFACE_WITH_KNOTS")
else if (ent.type == "B_SPLINE_SURFACE_WITH_KNOTS" ||
ent.type == "B_SPLINE_SURFACE_WITH_KNOTS_AND_RATIONAL")
ns = build_bspline_surface(ref);
else if (ent.type == "B_SPLINE_SURFACE")
ns = build_bspline_surface_basic(ref);
else if (ent.type == "RECTANGULAR_TRIMMED_SURFACE")
ns = build_rectangular_trimmed_surface(ref);
else if (ent.type == "SURFACE_OF_REVOLUTION") {
// Non-standard: approximate as B-spline
g_import_diag.approximated_surfaces++;
+191
View File
@@ -877,3 +877,194 @@ TEST(StepImport, AP203_WithManifoldSolidBrep) {
EXPECT_TRUE(bodies[0].is_valid());
EXPECT_GE(bodies[0].num_faces(), 1u);
}
// ─────────────────────────────────────────────────────────────
// E10: STEP 非标实体全量覆盖(新增派发的曲线/曲面实体)
// 场景:POLYLINE / HYPARC / PARABOLA / TRIM_CURVE / COMPOSITE_CURVE /
// B_SPLINE_CURVE(无结点) / B_SPLINE_CURVE_WITH_KNOTS_AND_RATIONAL /
// B_SPLINE_SURFACE(无结点) / B_SPLINE_SURFACE_WITH_KNOTS_AND_RATIONAL /
// RECTANGULAR_TRIMMED_SURFACE
// ─────────────────────────────────────────────────────────────
// 公共后缀:用给定曲线实体(#30 EDGE_CURVE 的几何)构建单面闭合壳
static std::string e10_shell(const std::string& curve_entity) {
return R"(
#1=CARTESIAN_POINT('',(0.0,0.0,0.0));
#2=CARTESIAN_POINT('',(2.0,1.0,0.0));
#3=CARTESIAN_POINT('',(4.0,0.0,0.0));
)" + curve_entity + R"(
#11=CARTESIAN_POINT('',(0.0,0.0,0.0));
#12=CARTESIAN_POINT('',(4.0,0.0,0.0));
#20=VERTEX_POINT('',#11);
#21=VERTEX_POINT('',#12);
#30=EDGE_CURVE('',#20,#21,#10,.T.);
#40=DIRECTION('',(1.0,0.0,0.0));
#41=VECTOR('',#40,4.0);
#42=LINE('',#11,#41);
#43=EDGE_CURVE('',#21,#20,#42,.T.);
#50=ORIENTED_EDGE('',*,*,#30,.T.);
#51=ORIENTED_EDGE('',*,*,#43,.T.);
#60=EDGE_LOOP('',(#50,#51));
#61=FACE_OUTER_BOUND('',#60,.T.);
#70=DIRECTION('',(0.0,0.0,1.0));
#71=DIRECTION('',(1.0,0.0,0.0));
#72=AXIS2_PLACEMENT_3D('',#11,#70,#71);
#73=PLANE('',#72);
#80=ADVANCED_FACE('',(#61),#73,.T.);
#90=CLOSED_SHELL('',(#80));
#100=MANIFOLD_SOLID_BREP('e10',#90);
)";
}
TEST(StepImport, PolylineCurve) {
std::string step = step_header()
+ e10_shell("#10=POLYLINE('',(#1,#2,#3));") + step_footer();
auto bodies = import_step_from_string(step);
ASSERT_GE(bodies.size(), 1u);
EXPECT_TRUE(bodies[0].is_valid());
EXPECT_GE(bodies[0].num_edges(), 1u);
}
TEST(StepImport, HyperbolaCurve) {
std::string step = step_header()
+ e10_shell("#10=HYPARC('',#72,2.0,3.0);") + step_footer();
auto bodies = import_step_from_string(step);
ASSERT_GE(bodies.size(), 1u);
EXPECT_TRUE(bodies[0].is_valid());
}
TEST(StepImport, ParabolaCurve) {
std::string step = step_header()
+ e10_shell("#10=PARABOLA('',#72,2.0);") + step_footer();
auto bodies = import_step_from_string(step);
ASSERT_GE(bodies.size(), 1u);
EXPECT_TRUE(bodies[0].is_valid());
}
TEST(StepImport, TrimmedCurve) {
std::string step = step_header()
+ e10_shell("#10=TRIM_CURVE('',#42,(0.0),(1.0),.T.,.PARAMETER.);") + step_footer();
auto bodies = import_step_from_string(step);
ASSERT_GE(bodies.size(), 1u);
EXPECT_TRUE(bodies[0].is_valid());
}
TEST(StepImport, CompositeCurve) {
std::string step = step_header()
+ R"(
#1=CARTESIAN_POINT('',(0.0,0.0,0.0));
#2=CARTESIAN_POINT('',(2.0,1.0,0.0));
#3=CARTESIAN_POINT('',(4.0,0.0,0.0));
#10=LINE('',#1,#3);
#11=CARTESIAN_POINT('',(0.0,0.0,0.0));
#12=CARTESIAN_POINT('',(4.0,0.0,0.0));
#13=DIRECTION('',(1.0,0.0,0.0));
#14=VECTOR('',#13,4.0);
#15=LINE('',#11,#14);
#16=COMPOSITE_CURVE_SEGMENT('',#15,.T.);
#17=COMPOSITE_CURVE('',(#16),.F.);
#20=VERTEX_POINT('',#11);
#21=VERTEX_POINT('',#12);
#30=EDGE_CURVE('',#20,#21,#17,.T.);
#40=DIRECTION('',(1.0,0.0,0.0));
#41=VECTOR('',#40,4.0);
#42=LINE('',#11,#41);
#43=EDGE_CURVE('',#21,#20,#42,.T.);
#50=ORIENTED_EDGE('',*,*,#30,.T.);
#51=ORIENTED_EDGE('',*,*,#43,.T.);
#60=EDGE_LOOP('',(#50,#51));
#61=FACE_OUTER_BOUND('',#60,.T.);
#70=DIRECTION('',(0.0,0.0,1.0));
#71=DIRECTION('',(1.0,0.0,0.0));
#72=AXIS2_PLACEMENT_3D('',#11,#70,#71);
#73=PLANE('',#72);
#80=ADVANCED_FACE('',(#61),#73,.T.);
#90=CLOSED_SHELL('',(#80));
#100=MANIFOLD_SOLID_BREP('composite',#90);
)" + step_footer();
auto bodies = import_step_from_string(step);
ASSERT_GE(bodies.size(), 1u);
EXPECT_TRUE(bodies[0].is_valid());
EXPECT_GE(bodies[0].num_edges(), 1u);
}
TEST(StepImport, BSplineCurveNoKnots) {
std::string step = step_header()
+ e10_shell("#10=B_SPLINE_CURVE('',3,(#1,#2,#3),.UNSPECIFIED.,.F.,.F.);")
+ step_footer();
auto bodies = import_step_from_string(step);
ASSERT_GE(bodies.size(), 1u);
EXPECT_TRUE(bodies[0].is_valid());
}
TEST(StepImport, BSplineCurveRational) {
std::string step = step_header()
+ e10_shell("#10=B_SPLINE_CURVE_WITH_KNOTS_AND_RATIONAL('',2,(#1,#2,#3),.UNSPECIFIED.,.F.,.F.,(1,1,1),(0.0,0.5,1.0),.UNSPECIFIED.,(1.0,1.0,1.0));")
+ step_footer();
auto bodies = import_step_from_string(step);
ASSERT_GE(bodies.size(), 1u);
EXPECT_TRUE(bodies[0].is_valid());
}
// 用给定曲面实体作为 ADVANCED_FACE 的几何
static std::string e10_surface_shell(const std::string& surface_entity) {
return R"(
#1=CARTESIAN_POINT('',(0.0,0.0,0.0));
#2=CARTESIAN_POINT('',(1.0,0.0,0.0));
#3=CARTESIAN_POINT('',(0.0,1.0,0.0));
#4=CARTESIAN_POINT('',(1.0,1.0,0.0));
#5=CARTESIAN_POINT('',(1.0,0.0,0.0));
#6=VERTEX_POINT('',#5);
#7=CIRCLE('',#72,1.0);
#8=EDGE_CURVE('',#6,#6,#7,.T.);
#9=ORIENTED_EDGE('',*,*,#8,.T.);
#10=EDGE_LOOP('',(#9));
#11=FACE_OUTER_BOUND('',#10,.T.);
#70=DIRECTION('',(0.0,0.0,1.0));
#71=DIRECTION('',(1.0,0.0,0.0));
#72=AXIS2_PLACEMENT_3D('',#1,#70,#71);
)" + surface_entity + R"(
#80=ADVANCED_FACE('',(#11),#73,.T.);
#90=CLOSED_SHELL('',(#80));
#100=MANIFOLD_SOLID_BREP('e10surf',#90);
)";
}
TEST(StepImport, BSplineSurfaceNoKnots) {
std::string step = step_header()
+ e10_surface_shell("#73=B_SPLINE_SURFACE('',1,1,((#1,#2),(#3,#4)),.UNSPECIFIED.,.F.,.F.,.F.);")
+ step_footer();
auto bodies = import_step_from_string(step);
ASSERT_GE(bodies.size(), 1u);
EXPECT_TRUE(bodies[0].is_valid());
EXPECT_GE(bodies[0].num_faces(), 1u);
}
TEST(StepImport, BSplineSurfaceRational) {
std::string step = step_header()
+ e10_surface_shell("#73=B_SPLINE_SURFACE_WITH_KNOTS_AND_RATIONAL('',1,1,((#1,#2),(#3,#4)),.UNSPECIFIED.,.F.,.F.,.F.,(2,2),(2,2),(0.0,1.0),(0.0,1.0),.UNSPECIFIED.,((1.0,1.0),(1.0,1.0)));")
+ step_footer();
auto bodies = import_step_from_string(step);
ASSERT_GE(bodies.size(), 1u);
EXPECT_TRUE(bodies[0].is_valid());
}
TEST(StepImport, RectangularTrimmedSurface) {
std::string step = step_header()
+ e10_surface_shell("#73=RECTANGULAR_TRIMMED_SURFACE('',#72,0.0,1.0,0.0,1.0,.T.,.T.);")
+ step_footer();
auto bodies = import_step_from_string(step);
ASSERT_GE(bodies.size(), 1u);
EXPECT_TRUE(bodies[0].is_valid());
EXPECT_GE(bodies[0].num_faces(), 1u);
}