mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-19 11:43:53 +00:00
Major update: taxonomy shared pointers, collection type safety, work towards hashing
This commit is contained in:
@@ -2,13 +2,13 @@
|
||||
|
||||
using namespace ifcopenshell::geometry;
|
||||
|
||||
taxonomy::loop* ifcopenshell::geometry::fillet_loop(taxonomy::loop* loop, double radius) {
|
||||
taxonomy::loop::ptr ifcopenshell::geometry::fillet_loop(taxonomy::loop::ptr loop, double radius) {
|
||||
std::vector<profile_point_with_edges_3d> pps(loop->children.size());
|
||||
for (int b = 0; b < loop->children.size(); ++b) {
|
||||
int c = (b - 1) % loop->children.size();
|
||||
pps[b] = {
|
||||
boost::get<taxonomy::point3>(((taxonomy::edge*)loop->children[c])->start).ccomponents(),
|
||||
radius, (taxonomy::edge*) loop->children[c], (taxonomy::edge*) loop->children[b]
|
||||
boost::get<taxonomy::point3::ptr>(loop->children[c]->start)->ccomponents(),
|
||||
radius, loop->children[c], loop->children[b]
|
||||
};
|
||||
}
|
||||
size_t i = pps.size();
|
||||
@@ -16,10 +16,10 @@ taxonomy::loop* ifcopenshell::geometry::fillet_loop(taxonomy::loop* loop, double
|
||||
const auto& p = pps[i];
|
||||
if (p.radius && *p.radius > 0.) {
|
||||
|
||||
auto p0 = boost::get<taxonomy::point3>(p.previous->start).ccomponents();
|
||||
auto p1a = boost::get<taxonomy::point3>(p.previous->end).ccomponents();
|
||||
auto p2 = boost::get<taxonomy::point3>(p.next->end).ccomponents();
|
||||
auto p1b = boost::get<taxonomy::point3>(p.next->start).ccomponents();
|
||||
auto p0 = boost::get<taxonomy::point3::ptr>(p.previous->start)->ccomponents();
|
||||
auto p1a = boost::get<taxonomy::point3::ptr>(p.previous->end)->ccomponents();
|
||||
auto p2 = boost::get<taxonomy::point3::ptr>(p.next->end)->ccomponents();
|
||||
auto p1b = boost::get<taxonomy::point3::ptr>(p.next->start)->ccomponents();
|
||||
|
||||
auto ba_ = p0 - p1a;
|
||||
auto bc_ = p2 - p1b;
|
||||
@@ -30,10 +30,10 @@ taxonomy::loop* ifcopenshell::geometry::fillet_loop(taxonomy::loop* loop, double
|
||||
const double angle = std::acos(ba.dot(bc));
|
||||
const double inset = *p.radius / std::tan(angle / 2.);
|
||||
|
||||
boost::get<taxonomy::point3>(p.previous->end).components() += ba * inset;
|
||||
boost::get<taxonomy::point3>(p.next->start).components() += bc * inset;
|
||||
boost::get<taxonomy::point3::ptr>(p.previous->end)->components() += ba * inset;
|
||||
boost::get<taxonomy::point3::ptr>(p.next->start)->components() += bc * inset;
|
||||
|
||||
auto e = new taxonomy::edge;
|
||||
auto e = taxonomy::make<taxonomy::edge>();
|
||||
e->start = p.previous->end;
|
||||
e->end = p.next->start;
|
||||
|
||||
@@ -41,10 +41,10 @@ taxonomy::loop* ifcopenshell::geometry::fillet_loop(taxonomy::loop* loop, double
|
||||
|
||||
auto ab = ba.cross(bc);
|
||||
|
||||
auto O = boost::get<taxonomy::point3>(p.previous->end).ccomponents().head<3>() + ab * *p.radius;
|
||||
auto O = boost::get<taxonomy::point3::ptr>(p.previous->end)->ccomponents().head<3>() + ab * *p.radius;
|
||||
|
||||
auto c = new taxonomy::circle;
|
||||
c->matrix = taxonomy::matrix4(O, ab);
|
||||
auto c = taxonomy::make<taxonomy::circle>();
|
||||
c->matrix = taxonomy::make<taxonomy::matrix4>(O, ab);
|
||||
c->radius = *p.radius;
|
||||
e->basis = c;
|
||||
|
||||
@@ -54,14 +54,14 @@ taxonomy::loop* ifcopenshell::geometry::fillet_loop(taxonomy::loop* loop, double
|
||||
return loop;
|
||||
}
|
||||
|
||||
taxonomy::loop* ifcopenshell::geometry::polygon_from_points(const std::vector<taxonomy::point3>& ps, bool external) {
|
||||
auto loop = new taxonomy::loop();
|
||||
taxonomy::loop::ptr ifcopenshell::geometry::polygon_from_points(const std::vector<taxonomy::point3::ptr>& ps, bool external) {
|
||||
auto loop = taxonomy::make<taxonomy::loop>();
|
||||
loop->external = external;
|
||||
boost::optional<taxonomy::point3> previous;
|
||||
taxonomy::point3::ptr previous;
|
||||
for (auto& p : ps) {
|
||||
if (previous) {
|
||||
auto e = new taxonomy::edge;
|
||||
e->start = *previous;
|
||||
auto e = taxonomy::make<taxonomy::edge>();
|
||||
e->start = previous;
|
||||
e->end = p;
|
||||
loop->children.push_back(e);
|
||||
}
|
||||
@@ -70,7 +70,7 @@ taxonomy::loop* ifcopenshell::geometry::polygon_from_points(const std::vector<ta
|
||||
return loop;
|
||||
}
|
||||
|
||||
taxonomy::loop* ifcopenshell::geometry::profile_helper(const taxonomy::matrix4& m4, const std::vector<profile_point>& points) {
|
||||
taxonomy::loop::ptr ifcopenshell::geometry::profile_helper(const taxonomy::matrix4::ptr& m4, const std::vector<profile_point>& points) {
|
||||
|
||||
/* TopoDS_Vertex* vertices = new TopoDS_Vertex[numVerts];
|
||||
for (int i = 0; i < numVerts; i++) {
|
||||
@@ -99,19 +99,19 @@ taxonomy::loop* ifcopenshell::geometry::profile_helper(const taxonomy::matrix4&
|
||||
}
|
||||
*/
|
||||
|
||||
const bool has_position = !m4.is_identity();
|
||||
const bool has_position = !m4->is_identity();
|
||||
|
||||
// @todo precision
|
||||
|
||||
std::vector<taxonomy::point3> ps;
|
||||
std::vector<taxonomy::point3::ptr> ps;
|
||||
ps.reserve(points.size() + 1);
|
||||
std::transform(points.begin(), points.end(), std::back_inserter(ps), [&has_position, &m4](const profile_point& p) {
|
||||
if (has_position) {
|
||||
Eigen::Vector4d v(p.xy[0], p.xy[1], 0., 1.);
|
||||
v = m4.ccomponents() * v;
|
||||
return taxonomy::point3(v(0), v(1), 0.);
|
||||
v = m4->ccomponents() * v;
|
||||
return taxonomy::make<taxonomy::point3>(v(0), v(1), 0.);
|
||||
} else {
|
||||
return taxonomy::point3(p.xy[0], p.xy[1], 0.);
|
||||
return taxonomy::make<taxonomy::point3>(p.xy[0], p.xy[1], 0.);
|
||||
}
|
||||
});
|
||||
ps.push_back(ps.front());
|
||||
@@ -121,7 +121,7 @@ taxonomy::loop* ifcopenshell::geometry::profile_helper(const taxonomy::matrix4&
|
||||
std::vector<profile_point_with_edges> pps(points.size());
|
||||
for (int b = 0; b < points.size(); ++b) {
|
||||
int c = (b - 1) % points.size();
|
||||
pps[b] = { Eigen::Vector2d(points[b].xy[0], points[b].xy[1]), points[b].radius, (taxonomy::edge*) loop->children[c], (taxonomy::edge*) loop->children[b] };
|
||||
pps[b] = { Eigen::Vector2d(points[b].xy[0], points[b].xy[1]), points[b].radius, loop->children[c], loop->children[b] };
|
||||
}
|
||||
|
||||
size_t i = pps.size();
|
||||
@@ -129,10 +129,10 @@ taxonomy::loop* ifcopenshell::geometry::profile_helper(const taxonomy::matrix4&
|
||||
const auto& p = pps[i];
|
||||
if (p.radius && *p.radius > 0.) {
|
||||
// Position is a IfcAxis2Placement2D, so should remain 2d points
|
||||
auto p0 = boost::get<taxonomy::point3>(p.previous->start).components_->head<2>();
|
||||
auto p1a = boost::get<taxonomy::point3>(p.previous->end).components_->head<2>();
|
||||
auto p2 = boost::get<taxonomy::point3>(p.next->end).components_->head<2>();
|
||||
auto p1b = boost::get<taxonomy::point3>(p.next->start).components_->head<2>();
|
||||
auto p0 = boost::get<taxonomy::point3::ptr>(p.previous->start)->components_->head<2>();
|
||||
auto p1a = boost::get<taxonomy::point3::ptr>(p.previous->end)->components_->head<2>();
|
||||
auto p2 = boost::get<taxonomy::point3::ptr>(p.next->end)->components_->head<2>();
|
||||
auto p1b = boost::get<taxonomy::point3::ptr>(p.next->start)->components_->head<2>();
|
||||
|
||||
auto ba_ = p0 - p1a;
|
||||
auto bc_ = p2 - p1b;
|
||||
@@ -143,10 +143,10 @@ taxonomy::loop* ifcopenshell::geometry::profile_helper(const taxonomy::matrix4&
|
||||
const double angle = std::acos(ba.dot(bc));
|
||||
const double inset = *p.radius / std::tan(angle / 2.);
|
||||
|
||||
boost::get<taxonomy::point3>(p.previous->end).components_->head<2>() += ba * inset;
|
||||
boost::get<taxonomy::point3>(p.next->start).components_->head<2>() += bc * inset;
|
||||
boost::get<taxonomy::point3::ptr>(p.previous->end)->components_->head<2>() += ba * inset;
|
||||
boost::get<taxonomy::point3::ptr>(p.next->start)->components_->head<2>() += bc * inset;
|
||||
|
||||
auto e = new taxonomy::edge;
|
||||
auto e = taxonomy::make<taxonomy::edge>();
|
||||
e->start = p.previous->end;
|
||||
e->end = p.next->start;
|
||||
|
||||
@@ -154,10 +154,10 @@ taxonomy::loop* ifcopenshell::geometry::profile_helper(const taxonomy::matrix4&
|
||||
|
||||
double sign = ab.head<2>().dot(bc) > 0 ? 1. : -1.;
|
||||
|
||||
auto O = boost::get<taxonomy::point3>(p.previous->end).ccomponents().head<3>() + ab * *p.radius * sign;
|
||||
auto O = boost::get<taxonomy::point3::ptr>(p.previous->end)->ccomponents().head<3>() + ab * *p.radius * sign;
|
||||
|
||||
auto c = new taxonomy::circle;
|
||||
c->matrix = Eigen::Matrix4d(Eigen::Affine3d(Eigen::Translation3d(O)).matrix());
|
||||
auto c = taxonomy::make<taxonomy::circle>();
|
||||
c->matrix = taxonomy::make<taxonomy::matrix4>(Eigen::Matrix4d(Eigen::Affine3d(Eigen::Translation3d(O)).matrix()));
|
||||
c->radius = *p.radius;
|
||||
e->basis = c;
|
||||
c->orientation.reset(sign == -1.);
|
||||
|
||||
Reference in New Issue
Block a user