mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-19 11:43:53 +00:00
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:
@@ -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
|
||||
Reference in New Issue
Block a user