2023-10-02 16:30:39 -07:00
|
|
|
/********************************************************************************
|
|
|
|
|
* *
|
|
|
|
|
* This file is part of IfcOpenShell. *
|
|
|
|
|
* *
|
|
|
|
|
* IfcOpenShell is free software: you can redistribute it and/or modify *
|
|
|
|
|
* it under the terms of the Lesser GNU General Public License as published by *
|
|
|
|
|
* the Free Software Foundation, either version 3.0 of the License, or *
|
|
|
|
|
* (at your option) any later version. *
|
|
|
|
|
* *
|
|
|
|
|
* IfcOpenShell is distributed in the hope that it will be useful, *
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
|
* Lesser GNU General Public License for more details. *
|
|
|
|
|
* *
|
|
|
|
|
* You should have received a copy of the Lesser GNU General Public License *
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
|
|
|
|
* *
|
|
|
|
|
********************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "mapping.h"
|
2024-09-10 10:11:17 -07:00
|
|
|
#include "../piecewise_function_evaluator.h"
|
2023-10-02 16:30:39 -07:00
|
|
|
#define mapping POSTFIX_SCHEMA(mapping)
|
|
|
|
|
using namespace ifcopenshell::geometry;
|
|
|
|
|
|
|
|
|
|
#ifdef SCHEMA_HAS_IfcGradientCurve
|
|
|
|
|
|
|
|
|
|
taxonomy::ptr mapping::map_impl(const IfcSchema::IfcGradientCurve* inst) {
|
2023-10-25 06:47:05 -07:00
|
|
|
if (!inst->BaseCurve()->as<IfcSchema::IfcCompositeCurve>())
|
|
|
|
|
Logger::Warning("Expected IfcGradientCurve.BaseCurve to be IfcCompositeCurve", inst); // CT 4.1.7.1.1.2
|
|
|
|
|
|
2023-10-02 16:30:39 -07:00
|
|
|
auto segments = inst->Segments();
|
2024-05-07 10:24:46 -07:00
|
|
|
|
2024-07-29 09:48:15 -07:00
|
|
|
std::vector<taxonomy::piecewise_function::ptr> pwfs;
|
2023-10-02 16:30:39 -07:00
|
|
|
|
|
|
|
|
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>());
|
2024-04-29 21:02:31 +02:00
|
|
|
if (crv && crv->kind() == taxonomy::PIECEWISE_FUNCTION) {
|
2024-05-07 10:24:46 -07:00
|
|
|
pwfs.push_back(taxonomy::cast<taxonomy::piecewise_function>(crv));
|
2023-10-02 16:30:39 -07:00
|
|
|
} else {
|
|
|
|
|
Logger::Error("Unsupported");
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
Logger::Error("Unsupported");
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-29 09:48:15 -07:00
|
|
|
// 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
|
2024-09-10 10:11:17 -07:00
|
|
|
auto vertical = taxonomy::make<taxonomy::piecewise_function>(gradient_start, pwfs);
|
2024-07-29 09:48:15 -07:00
|
|
|
|
|
|
|
|
// 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
|
2024-09-10 10:11:17 -07:00
|
|
|
piecewise_function_evaluator horizontal_evaluator(horizontal, &settings_), vertical_evaluator(vertical, &settings_);
|
|
|
|
|
auto composition = [horizontal_evaluator, vertical_evaluator,start=vertical->start()](double u) -> Eigen::Matrix4d {
|
2024-07-29 09:48:15 -07:00
|
|
|
// u is distance from start of gradient curve (vertical)
|
|
|
|
|
// add vertical->start() to u to get distance from start of horizontal
|
2024-09-10 10:11:17 -07:00
|
|
|
auto xy = horizontal_evaluator.evaluate(u + start);
|
|
|
|
|
auto uz = vertical_evaluator.evaluate(u);
|
2023-12-12 15:15:41 -08:00
|
|
|
|
|
|
|
|
uz.col(3)(0) = 0.0; // x is distance along. zero it out so it doesn't add to the x from horizontal
|
|
|
|
|
uz.col(1).swap(uz.col(2)); // uz is 2D in distance along - y plane, swap y and z so elevations become z
|
|
|
|
|
uz.row(1).swap(uz.row(2));
|
|
|
|
|
|
2023-10-20 13:29:33 -07:00
|
|
|
Eigen::Matrix4d m;
|
2023-12-12 15:15:41 -08:00
|
|
|
m = xy * uz; // combine horizontal and vertical
|
2023-10-20 13:29:33 -07:00
|
|
|
return m;
|
2023-10-02 16:30:39 -07:00
|
|
|
};
|
|
|
|
|
|
2024-08-01 12:34:49 -07:00
|
|
|
taxonomy::piecewise_function::spans_t spans;
|
2024-07-29 09:48:15 -07:00
|
|
|
spans.emplace_back(length, composition);
|
2024-09-10 10:11:17 -07:00
|
|
|
auto pwf = taxonomy::make<taxonomy::piecewise_function>(start, spans, inst);
|
2024-05-07 10:24:46 -07:00
|
|
|
return pwf;
|
2023-10-02 16:30:39 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|