mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-19 22:50:21 +00:00
Merge branch 'v0.8.0' into v0.8.0
This commit is contained in:
+31
-159
@@ -356,8 +356,6 @@ typedef item const* ptr;
|
||||
struct implicit_item : public geom_item {
|
||||
DECLARE_PTR(implicit_item)
|
||||
using geom_item::geom_item;
|
||||
|
||||
virtual item::ptr evaluate() const = 0;
|
||||
};
|
||||
|
||||
struct piecewise_function_impl; // forward declaration
|
||||
@@ -366,14 +364,12 @@ typedef item const* ptr;
|
||||
|
||||
using spans_t = std::vector<std::pair<double, std::function<Eigen::Matrix4d(double u)>>>;
|
||||
|
||||
piecewise_function(double start, const spans_t& s, ifcopenshell::geometry::Settings* settings = nullptr, const IfcUtil::IfcBaseInterface* instance = nullptr);
|
||||
piecewise_function(double start, const std::vector<piecewise_function::ptr>& pwfs, ifcopenshell::geometry::Settings* settings = nullptr, const IfcUtil::IfcBaseInterface* instance = nullptr);
|
||||
piecewise_function(double start, const spans_t& s, const IfcUtil::IfcBaseInterface* instance = nullptr);
|
||||
piecewise_function(double start, const std::vector<piecewise_function::ptr>& pwfs, const IfcUtil::IfcBaseInterface* instance = nullptr);
|
||||
piecewise_function(piecewise_function&&) = default;
|
||||
piecewise_function(const piecewise_function&);
|
||||
virtual ~piecewise_function();
|
||||
|
||||
const ifcopenshell::geometry::Settings* settings_ = nullptr;
|
||||
|
||||
const spans_t& spans() const;
|
||||
bool is_empty() const;
|
||||
double start() const;
|
||||
@@ -388,33 +384,6 @@ typedef item const* ptr;
|
||||
return boost::hash<decltype(v)>{}(v);
|
||||
}
|
||||
|
||||
/// @brief returns a vector of "distance along" points where the evaluate function computes loop points
|
||||
std::vector<double> evaluation_points() const;
|
||||
|
||||
/// @brief returns a vector of "distance along" points between ustart and uend
|
||||
/// @param ustart starting location
|
||||
/// @param uend ending location
|
||||
/// @param nsteps number of steps to evaluate
|
||||
std::vector<double> evaluation_points(double ustart, double uend, unsigned nsteps) const;
|
||||
|
||||
/// @brief evaluates the piecewise function between start and end
|
||||
/// evaluation point step size is taken from the settings object
|
||||
item::ptr evaluate() const override;
|
||||
|
||||
/// @brief evaluates the piecewise function between ustart and uend
|
||||
/// if ustart and uend are out of range, the range of values evaluated
|
||||
/// are constrained to start_ and start_+length_
|
||||
/// @param ustart starting location
|
||||
/// @param uend ending location
|
||||
/// @param nsteps number of steps to evaluate
|
||||
/// @return taxonomy::loop::ptr
|
||||
item::ptr evaluate(double ustart, double uend, unsigned nsteps) const;
|
||||
|
||||
/// @brief evaluates the piecewise function at u
|
||||
/// @param u u is constrained to be between start_ and start_+length
|
||||
/// @return 4x4 placement matrix
|
||||
Eigen::Matrix4d evaluate(double u) const;
|
||||
|
||||
private:
|
||||
// note: it would be better if this were a std::unique_ptr, but that requires having the full definition
|
||||
// of piecewise_function_impl in this header file, which defeats the purpose of the PIMPL idiom.
|
||||
@@ -850,7 +819,7 @@ typedef item const* ptr;
|
||||
}
|
||||
};
|
||||
|
||||
struct loft : public collection_base<face> {
|
||||
struct loft : public collection_base<geom_item> {
|
||||
DECLARE_PTR(loft)
|
||||
|
||||
item::ptr axis;
|
||||
@@ -1075,6 +1044,7 @@ typedef item const* ptr;
|
||||
typedef std::tuple<matrix4, point3, direction3, line, circle, ellipse, bspline_curve, offset_curve, plane, cylinder, sphere, torus, bspline_surface, edge, loop, face, shell, solid, loft, extrusion, revolve, sweep_along_curve, node, collection, boolean_result, piecewise_function> KindsTuple;
|
||||
typedef std::tuple<line, circle, ellipse, bspline_curve, offset_curve, loop, edge> CurvesTuple;
|
||||
typedef std::tuple<plane, cylinder, sphere, torus, bspline_surface, extrusion, revolve> SurfacesTuple;
|
||||
typedef std::tuple<edge, loop, face, piecewise_function> UpgradesTuple;
|
||||
}
|
||||
|
||||
struct type_by_kind {
|
||||
@@ -1098,6 +1068,14 @@ typedef item const* ptr;
|
||||
static const size_t max = std::tuple_size<impl::SurfacesTuple>::value;
|
||||
};
|
||||
|
||||
struct upgrades {
|
||||
template <std::size_t N>
|
||||
using type = typename std::tuple_element<N, impl::UpgradesTuple>::type;
|
||||
|
||||
static const size_t max = std::tuple_size<impl::UpgradesTuple>::value;
|
||||
};
|
||||
|
||||
boost::optional<face::ptr> loop_to_face_upgrade_impl(ptr item);
|
||||
template <typename T>
|
||||
class loop_to_face_upgrade {
|
||||
private:
|
||||
@@ -1105,15 +1083,7 @@ typedef item const* ptr;
|
||||
public:
|
||||
loop_to_face_upgrade(taxonomy::ptr item) {
|
||||
if constexpr (std::is_same_v<T, face>) {
|
||||
auto loop = taxonomy::dcast<taxonomy::loop>(item);
|
||||
if (loop) {
|
||||
loop->external = true;
|
||||
|
||||
face_ = taxonomy::make<taxonomy::face>();
|
||||
(*face_)->instance = loop->instance;
|
||||
(*face_)->matrix = loop->matrix;
|
||||
(*face_)->children = { taxonomy::clone(loop) };
|
||||
}
|
||||
face_ = loop_to_face_upgrade_impl(item);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1131,6 +1101,7 @@ typedef item const* ptr;
|
||||
}
|
||||
};
|
||||
|
||||
boost::optional<edge::ptr> curve_to_edge_upgrade_impl(ptr item);
|
||||
template <typename T>
|
||||
class curve_to_edge_upgrade {
|
||||
private:
|
||||
@@ -1138,28 +1109,7 @@ typedef item const* ptr;
|
||||
public:
|
||||
curve_to_edge_upgrade(taxonomy::ptr item) {
|
||||
if constexpr (std::is_same_v<T, edge>) {
|
||||
auto circle = taxonomy::dcast<taxonomy::circle>(item);
|
||||
auto ellipse = taxonomy::dcast<taxonomy::ellipse>(item);
|
||||
auto line = taxonomy::dcast<taxonomy::line>(item);
|
||||
auto bspline_curve = taxonomy::dcast<taxonomy::bspline_curve>(item);
|
||||
if (circle || ellipse || line || bspline_curve) {
|
||||
edge_ = taxonomy::make<taxonomy::edge>();
|
||||
if (circle) {
|
||||
(*edge_)->basis = circle;
|
||||
} else if (ellipse) {
|
||||
(*edge_)->basis = ellipse;
|
||||
} else if (line) {
|
||||
(*edge_)->basis = line;
|
||||
} else if (bspline_curve) {
|
||||
(*edge_)->basis = bspline_curve;
|
||||
}
|
||||
|
||||
if (circle || ellipse) {
|
||||
// @todo
|
||||
(*edge_)->start = 0.;
|
||||
(*edge_)->end = 2 * boost::math::constants::pi<double>();
|
||||
}
|
||||
}
|
||||
edge_ = taxonomy::curve_to_edge_upgrade_impl(item);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1177,7 +1127,7 @@ typedef item const* ptr;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
boost::optional<loop::ptr> curve_to_loop_upgrade_impl(ptr item);
|
||||
template <typename T>
|
||||
class curve_to_loop_upgrade {
|
||||
private:
|
||||
@@ -1185,31 +1135,7 @@ typedef item const* ptr;
|
||||
public:
|
||||
curve_to_loop_upgrade(taxonomy::ptr item) {
|
||||
if constexpr (std::is_same_v<T, loop>) {
|
||||
auto circle = taxonomy::dcast<taxonomy::circle>(item);
|
||||
auto ellipse = taxonomy::dcast<taxonomy::ellipse>(item);
|
||||
auto line = taxonomy::dcast<taxonomy::line>(item);
|
||||
auto bspline_curve = taxonomy::dcast<taxonomy::bspline_curve>(item);
|
||||
if (circle || ellipse || line || bspline_curve) {
|
||||
auto edge = taxonomy::make<taxonomy::edge>();
|
||||
if (circle) {
|
||||
edge->basis = circle;
|
||||
} else if (ellipse) {
|
||||
edge->basis = ellipse;
|
||||
} else if (line) {
|
||||
edge->basis = line;
|
||||
} else if (bspline_curve) {
|
||||
edge->basis = bspline_curve;
|
||||
}
|
||||
|
||||
if (circle || ellipse) {
|
||||
// @todo
|
||||
edge->start = 0.;
|
||||
edge->end = 2 * boost::math::constants::pi<double>();
|
||||
}
|
||||
|
||||
loop_ = taxonomy::make<taxonomy::loop>();
|
||||
(*loop_)->children.push_back(edge);
|
||||
}
|
||||
loop_ = curve_to_loop_upgrade_impl(item);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1227,6 +1153,7 @@ typedef item const* ptr;
|
||||
}
|
||||
};
|
||||
|
||||
boost::optional<loop::ptr> edge_to_loop_upgrade_impl(ptr item);
|
||||
template <typename T>
|
||||
class edge_to_loop_upgrade {
|
||||
private:
|
||||
@@ -1234,11 +1161,7 @@ typedef item const* ptr;
|
||||
public:
|
||||
edge_to_loop_upgrade(taxonomy::ptr item) {
|
||||
if constexpr (std::is_same_v<T, loop>) {
|
||||
auto edge = taxonomy::dcast<taxonomy::edge>(item);
|
||||
if (edge) {
|
||||
loop_ = taxonomy::make<taxonomy::loop>();
|
||||
(*loop_)->children.push_back(edge);
|
||||
}
|
||||
loop_ = edge_to_loop_upgrade_impl(item);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1256,7 +1179,7 @@ typedef item const* ptr;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
boost::optional<face::ptr> curve_to_face_upgrade_impl(ptr item);
|
||||
template <typename T>
|
||||
class curve_to_face_upgrade {
|
||||
private:
|
||||
@@ -1264,36 +1187,7 @@ typedef item const* ptr;
|
||||
public:
|
||||
curve_to_face_upgrade(taxonomy::ptr item) {
|
||||
if constexpr (std::is_same_v<T, edge>) {
|
||||
auto circle = taxonomy::dcast<taxonomy::circle>(item);
|
||||
auto ellipse = taxonomy::dcast<taxonomy::ellipse>(item);
|
||||
auto line = taxonomy::dcast<taxonomy::line>(item);
|
||||
auto bspline_curve = taxonomy::dcast<taxonomy::bspline_curve>(item);
|
||||
if (circle || ellipse || line || bspline_curve) {
|
||||
auto edge = taxonomy::make<taxonomy::edge>();
|
||||
if (circle) {
|
||||
edge->basis = circle;
|
||||
} else if (ellipse) {
|
||||
edge->basis = ellipse;
|
||||
} else if (line) {
|
||||
edge->basis = line;
|
||||
} else if (bspline_curve) {
|
||||
edge->basis = bspline_curve;
|
||||
}
|
||||
|
||||
if (circle || ellipse) {
|
||||
// @todo
|
||||
edge->start = 0.;
|
||||
edge->end = 2 * boost::math::constants::pi<double>();
|
||||
}
|
||||
|
||||
auto loop = taxonomy::make<taxonomy::loop>();
|
||||
loop->children.push_back(edge);
|
||||
|
||||
face_ = taxonomy::make<taxonomy::face>();
|
||||
(*face_)->instance = loop->instance;
|
||||
(*face_)->matrix = loop->matrix;
|
||||
(*face_)->children = { taxonomy::clone(loop) };
|
||||
}
|
||||
face_ = curve_to_face_upgrade_impl(item);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1311,6 +1205,7 @@ typedef item const* ptr;
|
||||
}
|
||||
};
|
||||
|
||||
boost::optional<piecewise_function::ptr> loop_to_piecewise_function_upgrade_impl(ptr item);
|
||||
template <typename T>
|
||||
class loop_to_piecewise_function_upgrade {
|
||||
private:
|
||||
@@ -1319,36 +1214,7 @@ typedef item const* ptr;
|
||||
public:
|
||||
loop_to_piecewise_function_upgrade(taxonomy::ptr item) {
|
||||
if constexpr (std::is_same_v<T, piecewise_function>) {
|
||||
auto loop = taxonomy::dcast<taxonomy::loop>(item);
|
||||
if (loop) {
|
||||
if (loop->pwf.is_initialized()) {
|
||||
pwf_ = loop->pwf;
|
||||
} else {
|
||||
taxonomy::piecewise_function::spans_t spans;
|
||||
spans.reserve(loop->children.size());
|
||||
for (auto& edge : loop->children) {
|
||||
// the edge could be an arc or trimmed circle in the case of IfcIndexPolyCurve - support for this isn't implemented yet
|
||||
if (edge->basis) {
|
||||
Logger::Message(Logger::Severity::LOG_NOTICE, "Shape of basis curve ignored - edge is treated as a straight line edge");
|
||||
}
|
||||
|
||||
const auto& s = boost::get<taxonomy::point3::ptr>(edge->start)->ccomponents();
|
||||
const auto& e = boost::get<taxonomy::point3::ptr>(edge->end)->ccomponents();
|
||||
Eigen::Vector3d v = e - s;
|
||||
auto l = v.norm(); // the norm of a vector is a measure of its length
|
||||
v.normalize(); // normalize the vector so that it is a unit direction vector
|
||||
std::function<Eigen::Matrix4d(double)> fn = [s, v](double u) {
|
||||
Eigen::Vector3d o(s + u * v), axis(0, 0, 1), refDirection(v);
|
||||
auto Y = axis.cross(refDirection).normalized();
|
||||
axis = refDirection.cross(Y).normalized();
|
||||
return taxonomy::make<taxonomy::matrix4>(o, axis, refDirection)->components();
|
||||
};
|
||||
spans.emplace_back(l, fn);
|
||||
}
|
||||
pwf_ = taxonomy::make<taxonomy::piecewise_function>(0.0,spans);
|
||||
loop->pwf = pwf_;
|
||||
}
|
||||
}
|
||||
pwf_ = loop_to_piecewise_function_upgrade_impl(item);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1382,13 +1248,13 @@ typedef item const* ptr;
|
||||
}
|
||||
}
|
||||
{
|
||||
edge_to_loop_upgrade<T> upg(u);
|
||||
curve_to_face_upgrade<T> upg(u);
|
||||
if (upg) {
|
||||
return upg;
|
||||
}
|
||||
}
|
||||
{
|
||||
curve_to_face_upgrade<T> upg(u);
|
||||
edge_to_loop_upgrade<T> upg(u);
|
||||
if (upg) {
|
||||
return upg;
|
||||
}
|
||||
@@ -1419,6 +1285,12 @@ typedef item const* ptr;
|
||||
return upg;
|
||||
}
|
||||
}
|
||||
{
|
||||
curve_to_loop_upgrade<T> upg(u);
|
||||
if (upg) {
|
||||
return upg;
|
||||
}
|
||||
}
|
||||
{
|
||||
curve_to_face_upgrade<T> upg(u);
|
||||
if (upg) {
|
||||
|
||||
Reference in New Issue
Block a user