Updates taxonomy::piecewise_function so it's immutable and implements internal caching. Adds new evaluate2 method that returns loop and vector of distance along for each loop point.

This commit is contained in:
Richard Brice
2024-05-07 10:24:46 -07:00
parent e0a9f44c13
commit a0b4c24224
8 changed files with 134 additions and 98 deletions
+10 -23
View File
@@ -28,18 +28,17 @@ taxonomy::ptr mapping::map_impl(const IfcSchema::IfcGradientCurve* inst) {
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 vertical = taxonomy::make<taxonomy::piecewise_function>(&settings_);
auto segments = inst->Segments();
current_segment_count_ = segments->size();
std::vector<taxonomy::piecewise_function::ptr> pwfs;
for (auto& segment : *segments) {
if (segment->as<IfcSchema::IfcCurveSegment>()) {
// @todo check that we don't get a mixture of implicit and explicit definitions
auto crv = map(segment->as<IfcSchema::IfcCurveSegment>());
if (crv && crv->kind() == taxonomy::PIECEWISE_FUNCTION) {
auto seg = taxonomy::cast<taxonomy::piecewise_function>(crv);
vertical->spans.insert(vertical->spans.end(), seg->spans.begin(), seg->spans.end());
pwfs.push_back(taxonomy::cast<taxonomy::piecewise_function>(crv));
} else {
Logger::Error("Unsupported");
return nullptr;
@@ -49,6 +48,8 @@ taxonomy::ptr mapping::map_impl(const IfcSchema::IfcGradientCurve* inst) {
return nullptr;
}
}
auto vertical = taxonomy::make<taxonomy::piecewise_function>(pwfs,&settings_);
auto composition = [horizontal, vertical](double u)->Eigen::Matrix4d {
auto xy = horizontal->evaluate(u);
@@ -63,26 +64,12 @@ taxonomy::ptr mapping::map_impl(const IfcSchema::IfcGradientCurve* inst) {
return m;
};
std::array<taxonomy::piecewise_function::ptr, 2> both = { horizontal , vertical };
// @todo: rb - this constrains the range of u to the minimum of horizontal and vertical
// we discussed using the maximum for the range of us and then using std::numeric_limits<double>::NAN
// for values of u that horizontal or vertical cannot be computed.
// Review and decide what to do.
double min_length = std::numeric_limits<double>::infinity();
for (auto i = 0; i < 2; ++i) {
double l = 0;
for (auto& s : both[i]->spans) {
l += s.first;
}
if (l < min_length) {
min_length = l;
}
}
double min_length = std::min(horizontal->length(), vertical->length());
auto pwf = taxonomy::make<taxonomy::piecewise_function>(&settings_);
pwf->spans.emplace_back( min_length, composition );
pwf->instance = inst;
return pwf;
taxonomy::piecewise_function::spans spans;
spans.emplace_back(min_length, composition);
auto pwf = taxonomy::make<taxonomy::piecewise_function>(spans, &settings_, inst);
return pwf;
}
#endif