Honour IfcAxis2PlacementLinear Axis/RefDirection in the loft builder (#9408)

* Honour IfcAxis2PlacementLinear Axis/RefDirection in the loft builder

make_loft() (src/ifcgeom/infra_sweep_helper.cpp), shared by
IfcSectionedSolidHorizontal and IfcSectionedSurface, mishandled a cross
section's IfcAxis2PlacementLinear in two ways:

1. A placement carrying Axis but no RefDirection was placed with a fixed
   [e_y | e_z | e_x] world-axis permutation that ignored the directrix.
   On any directrix not running along +X (e.g. a north-south road
   pavement, or anywhere along a curve) the profile came out mis-oriented
   or collapsed to a sliver.

2. When two adjacent CrossSectionPositions used direction vectors
   inconsistently (a raked RefDirection at one, a plain Axis at the
   other) make_loft() logged GEO 42, dropped the rotation for the whole
   segment and squared every cap -- and in one configuration left the
   sweep frame flipped, so OpenCASCADE failed to build the solid at all.

Now a small profile_basis() helper builds every cross section's frame the
same way: profile Y = Axis, profile normal = RefDirection, and -- when
RefDirection is absent -- profile normal = the directrix tangent, so the
section stays perpendicular to the path (buildingSMART IFC4.x-IF #147).

When the two bracketing placements ask for the same orientation the sweep
frame carries it, built against the curve. When they disagree the sweep
frame stays on the shared Axis (continuous with the neighbouring
consistent segments, so nothing flips) and each end's own authored
orientation is folded into its profile points via a change of basis, so
each end cap still lands exactly as authored while the body in between
keeps following the directrix. The all-equal and no-direction-vector
paths are unchanged.

The two mappings now also carry the raw RefDirection through on
cross_section, alongside the existing rotation matrix.

Adds C++ tests (a raked end logs no GEO 42; a directrix that does not run
along +X still lofts a full-size solid) and Python tests (uniform prism
raked at one end and square at the other; a north-south directrix keeps
its width; OffsetLateral/OffsetVertical are scaled by the model length
unit).

* Renames profile_rotations to profile_axis for consistency with profile_ref_directions
This commit is contained in:
Richard Brice
2026-09-01 10:35:11 -07:00
committed by GitHub
parent e4190a1636
commit 4374c81981
6 changed files with 558 additions and 42 deletions
@@ -1,7 +1,9 @@
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <catch2/catch_approx.hpp>
#include <catch2/catch_test_macros.hpp>
#include "ifcgeom/converter.h"
@@ -148,8 +150,152 @@ const ifcopenshell::geom::geometry_conversion_task* task_for_product(
return nullptr;
}
// A minimal IfcSectionedSolidHorizontal (IFC4X3_ADD2) whose two
// IfcAxis2PlacementLinear cross section positions use direction vectors
// inconsistently: the near position carries a raked RefDirection and a
// 1/cos(theta) wider profile, the far position carries neither. Before the
// make_loft() fix this logged GEO 42 and dropped the rotation, lofting a wedge.
constexpr const char* RAKED_SECTIONED_SOLID_SPF = R"IFC(ISO-10303-21;
HEADER;
FILE_DESCRIPTION((''),'2;1');
FILE_NAME('','',(''),(''),'','','');
FILE_SCHEMA(('IFC4X3_ADD2'));
ENDSEC;
DATA;
#1=IFCPROJECT('0RYK8PV8D0ee9DDm77xcTZ',$,'T',$,$,$,$,(#6),$);
#2=IFCCARTESIANPOINT((0.,0.,0.));
#3=IFCDIRECTION((0.,0.,1.));
#4=IFCDIRECTION((1.,0.,0.));
#5=IFCAXIS2PLACEMENT3D(#2,#3,#4);
#6=IFCGEOMETRICREPRESENTATIONCONTEXT($,'Model',3,1.E-05,#5,$);
#7=IFCGEOMETRICREPRESENTATIONSUBCONTEXT('Body','Model',*,*,*,*,#6,$,.MODEL_VIEW.,$);
#8=IFCCARTESIANPOINT((0.,0.,0.));
#9=IFCCARTESIANPOINT((40.,0.,0.));
#10=IFCPOLYLINE((#8,#9));
#11=IFCDIRECTION((0.,0.,1.));
#12=IFCDIRECTION((0.9034641832977311,-0.42866358545853134,0.));
#13=IFCPOINTBYDISTANCEEXPRESSION(IFCLENGTHMEASURE(0.),$,$,$,#10);
#14=IFCAXIS2PLACEMENTLINEAR(#13,#11,#12);
#15=IFCPOINTBYDISTANCEEXPRESSION(IFCLENGTHMEASURE(40.),$,$,$,#10);
#16=IFCAXIS2PLACEMENTLINEAR(#15,#11,$);
#17=IFCCARTESIANPOINTLIST2D(((-0.9223756168081689,0.),(0.9223756168081689,0.),(0.9223756168081689,6.),(-0.9223756168081689,6.),(-0.9223756168081689,0.)),$);
#18=IFCINDEXEDPOLYCURVE(#17,$,.F.);
#19=IFCARBITRARYCLOSEDPROFILEDEF(.AREA.,$,#18);
#20=IFCCARTESIANPOINTLIST2D(((-0.8333333333333334,0.),(0.8333333333333334,0.),(0.8333333333333334,6.),(-0.8333333333333334,6.),(-0.8333333333333334,0.)),$);
#21=IFCINDEXEDPOLYCURVE(#20,$,.F.);
#22=IFCARBITRARYCLOSEDPROFILEDEF(.AREA.,$,#21);
#23=IFCSECTIONEDSOLIDHORIZONTAL(#10,(#19,#22),(#14,#16));
#24=IFCBUILDINGELEMENTPROXY('3cWcr4$892GAeKwryhDILR',$,'wingwall',$,$,$,#26,$,$);
#25=IFCSHAPEREPRESENTATION(#7,'Body','AdvancedSweptSolid',(#23));
#26=IFCPRODUCTDEFINITIONSHAPE($,$,(#25));
ENDSEC;
END-ISO-10303-21;
)IFC";
struct sectioned_solid_result {
std::size_t geo42_count = 0;
bool produced_brep = false;
double projected_area_x = 0.0;
double projected_area_y = 0.0;
double projected_area_z = 0.0;
};
sectioned_solid_result convert_sectioned_solid(const std::string& spf) {
std::istringstream stream(spf);
ifcopenshell::logger log;
log.output_format(ifcopenshell::logger::FMT_INMEMORY);
ifcopenshell::file file(stream, static_cast<int>(spf.size()), log);
REQUIRE(file.good());
ifcopenshell::geom::settings settings;
ifcopenshell::geom::converter converter(
ifcopenshell::geom::kernels::construct(&file, "opencascade", settings, log), &file, settings, log);
std::vector<ifcopenshell::geom::geometry_conversion_task> tasks;
std::vector<ifcopenshell::geom::filter_function> filters;
converter.mapping()->get_representations(tasks, filters);
REQUIRE(!tasks.empty());
sectioned_solid_result result;
for (const auto& task : tasks) {
REQUIRE(!task.products.empty());
auto* elem = converter.create_brep_for_representation_and_product(task.representation, task.products.front());
if (elem) {
result.produced_brep = true;
elem->calculate_projected_surface_area(
result.projected_area_x, result.projected_area_y, result.projected_area_z);
}
delete elem;
}
result.geo42_count = log.count("GEO42");
return result;
}
std::size_t count_geo42_converting(const std::string& spf) {
return convert_sectioned_solid(spf).geo42_count;
}
// A minimal IfcSectionedSolidHorizontal (IFC4X3_ADD2) whose cross section
// placements carry an explicit Axis = (0,0,1) but no RefDirection, on a
// directrix that runs along +Y (not the global +X). Per buildingSMART
// IFC4.x-IF #147 the profile normal follows the directrix tangent, so the
// 12 x 0.5 rectangle sweeps 60 along +Y: a plan (Z) projected area of ~720.
// Before the fix the profile was placed with a fixed axis permutation that
// ignored the directrix and the solid collapsed.
constexpr const char* AXIS_ALIGNED_SECTIONED_SOLID_SPF = R"IFC(ISO-10303-21;
HEADER;
FILE_DESCRIPTION((''),'2;1');
FILE_NAME('','',(''),(''),'','','');
FILE_SCHEMA(('IFC4X3_ADD2'));
ENDSEC;
DATA;
#1=IFCPROJECT('0RYK8PV8D0ee9DDm77xcTZ',$,'T',$,$,$,$,(#6),$);
#2=IFCCARTESIANPOINT((0.,0.,0.));
#3=IFCDIRECTION((0.,0.,1.));
#4=IFCDIRECTION((1.,0.,0.));
#5=IFCAXIS2PLACEMENT3D(#2,#3,#4);
#6=IFCGEOMETRICREPRESENTATIONCONTEXT($,'Model',3,1.E-05,#5,$);
#7=IFCGEOMETRICREPRESENTATIONSUBCONTEXT('Body','Model',*,*,*,*,#6,$,.MODEL_VIEW.,$);
#8=IFCCARTESIANPOINT((0.,0.,0.));
#9=IFCCARTESIANPOINT((0.,60.,0.));
#10=IFCPOLYLINE((#8,#9));
#11=IFCDIRECTION((0.,0.,1.));
#13=IFCPOINTBYDISTANCEEXPRESSION(IFCLENGTHMEASURE(0.),$,$,$,#10);
#14=IFCAXIS2PLACEMENTLINEAR(#13,#11,$);
#15=IFCPOINTBYDISTANCEEXPRESSION(IFCLENGTHMEASURE(60.),$,$,$,#10);
#16=IFCAXIS2PLACEMENTLINEAR(#15,#11,$);
#17=IFCCARTESIANPOINTLIST2D(((-6.,0.),(6.,0.),(6.,0.5),(-6.,0.5),(-6.,0.)),$);
#18=IFCINDEXEDPOLYCURVE(#17,$,.F.);
#19=IFCARBITRARYCLOSEDPROFILEDEF(.AREA.,$,#18);
#23=IFCSECTIONEDSOLIDHORIZONTAL(#10,(#19,#19),(#14,#16));
#24=IFCBUILDINGELEMENTPROXY('3cWcr4$892GAeKwryhDILR',$,'pavement',$,$,$,#26,$,$);
#25=IFCSHAPEREPRESENTATION(#7,'Body','AdvancedSweptSolid',(#23));
#26=IFCPRODUCTDEFINITIONSHAPE($,$,(#25));
ENDSEC;
END-ISO-10303-21;
)IFC";
} // namespace
TEST_CASE("IfcSectionedSolidHorizontal raked end cut does not log GEO 42", "[ifcgeom][infra-sweep]") {
if (std::string(STRINGIFY(IfcSchema)) != "Ifc4x3_add2") {
SKIP("fixture is authored for IFC4X3_ADD2");
}
CHECK(count_geo42_converting(RAKED_SECTIONED_SOLID_SPF) == 0);
}
TEST_CASE("IfcSectionedSolidHorizontal follows a non-axis-aligned directrix", "[ifcgeom][infra-sweep]") {
if (std::string(STRINGIFY(IfcSchema)) != "Ifc4x3_add2") {
SKIP("fixture is authored for IFC4X3_ADD2");
}
const auto result = convert_sectioned_solid(AXIS_ALIGNED_SECTIONED_SOLID_SPF);
CHECK(result.geo42_count == 0);
REQUIRE(result.produced_brep);
// Plan projection is the top plus the bottom of the slab, 2 x width x length;
// a collapsed sweep (the pre-fix behaviour) is nowhere near this.
CHECK(result.projected_area_z == Catch::Approx(2.0 * 12.0 * 60.0).margin(2.0));
}
TEST_CASE("IfcGeom C++ fixture creates walls below and above the void limit", "[ifcgeom][voids]") {
hierarchy_helper<IfcSchema> below_limit_file;
const auto below_limit_wall = create_wall_with_voids(below_limit_file, MAX_VOIDS - 1);