Fixes domain of vertical and cant pwf (Issue #5072)

This commit is contained in:
Richard Brice
2024-07-29 09:48:15 -07:00
parent 52130a3eb6
commit 60b007d28a
7 changed files with 144 additions and 81 deletions
+28 -10
View File
@@ -27,11 +27,9 @@ taxonomy::ptr mapping::map_impl(const IfcSchema::IfcGradientCurve* inst) {
if (!inst->BaseCurve()->as<IfcSchema::IfcCompositeCurve>())
Logger::Warning("Expected IfcGradientCurve.BaseCurve to be IfcCompositeCurve", inst); // CT 4.1.7.1.1.2
auto horizontal = taxonomy::cast<taxonomy::piecewise_function>(map(inst->BaseCurve()));
auto segments = inst->Segments();
std::vector<taxonomy::piecewise_function::ptr> pwfs;
std::vector<taxonomy::piecewise_function::ptr> pwfs;
for (auto& segment : *segments) {
if (segment->as<IfcSchema::IfcCurveSegment>()) {
@@ -48,11 +46,33 @@ taxonomy::ptr mapping::map_impl(const IfcSchema::IfcGradientCurve* inst) {
return nullptr;
}
}
auto vertical = taxonomy::make<taxonomy::piecewise_function>(pwfs,&settings_);
// Get starting position of gradient curve, which is relative to the base curve
// The gradient curve can start before or after the start of the base curve
auto first_segment = *(segments->begin());
auto p = taxonomy::cast<taxonomy::matrix4>(map(first_segment->as<IfcSchema::IfcCurveSegment>()->Placement()));
const Eigen::Matrix4d& m = p->ccomponents();
double gradient_start = m(0, 3); // start of vertical (row 0, col 3) - "Distance Along" horizontal curve
// create the vertical pwf
auto vertical = taxonomy::make<taxonomy::piecewise_function>(gradient_start, pwfs, &settings_);
// Determine the valid domain of the PWF... the valid domain is where both
// the base curve and gradient curves are defined
auto horizontal = taxonomy::cast<taxonomy::piecewise_function>(map(inst->BaseCurve()));
double start = std::max(horizontal->start(),vertical->start());
double end = std::min(horizontal->end(), vertical->end());
double length = end - start;
if (!(0 < length)) {
Logger::Error("IfcGradientCurve does not have a common domain with BaseCurve");
}
// define the callback function for the gradient curve
auto composition = [horizontal, vertical](double u)->Eigen::Matrix4d {
auto xy = horizontal->evaluate(u);
// u is distance from start of gradient curve (vertical)
// add vertical->start() to u to get distance from start of horizontal
auto xy = horizontal->evaluate(u + vertical->start());
auto uz = vertical->evaluate(u);
uz.col(3)(0) = 0.0; // x is distance along. zero it out so it doesn't add to the x from horizontal
@@ -64,11 +84,9 @@ taxonomy::ptr mapping::map_impl(const IfcSchema::IfcGradientCurve* inst) {
return m;
};
double min_length = std::min(horizontal->length(), vertical->length());
taxonomy::piecewise_function::spans spans;
spans.emplace_back(min_length, composition);
auto pwf = taxonomy::make<taxonomy::piecewise_function>(spans, &settings_, inst);
spans.emplace_back(length, composition);
auto pwf = taxonomy::make<taxonomy::piecewise_function>(start, spans, &settings_, inst);
return pwf;
}