Merge pull request #3826 from RickBrice/v0.8.0

Some minor tweaks and implements suggestions
This commit is contained in:
Thomas Krijnen
2023-10-12 20:59:31 +02:00
committed by GitHub
10 changed files with 1624 additions and 1380 deletions
+1
View File
@@ -54,6 +54,7 @@ namespace ifcopenshell { namespace geometry { namespace kernels {
virtual bool convert_impl(const taxonomy::surface_curve_sweep::ptr, IfcGeom::ConversionResults&) { throw std::runtime_error("Not implemented"); } virtual bool convert_impl(const taxonomy::surface_curve_sweep::ptr, IfcGeom::ConversionResults&) { throw std::runtime_error("Not implemented"); }
virtual bool convert_impl(const taxonomy::loft::ptr, IfcGeom::ConversionResults&) { throw std::runtime_error("Not implemented"); } virtual bool convert_impl(const taxonomy::loft::ptr, IfcGeom::ConversionResults&) { throw std::runtime_error("Not implemented"); }
virtual bool convert_impl(const taxonomy::collection::ptr, IfcGeom::ConversionResults&); virtual bool convert_impl(const taxonomy::collection::ptr, IfcGeom::ConversionResults&);
virtual bool convert_impl(const taxonomy::piecewise_function::ptr item, IfcGeom::ConversionResults& cs) { return convert(item->evaluate(), cs); }
/* /*
virtual void set_offset(const std::array<double, 3> &p_offset); virtual void set_offset(const std::array<double, 3> &p_offset);
+27 -12
View File
@@ -23,6 +23,7 @@ using namespace ifcopenshell::geometry;
taxonomy::ptr mapping::map_impl(const IfcSchema::IfcCompositeCurve* inst) { taxonomy::ptr mapping::map_impl(const IfcSchema::IfcCompositeCurve* inst) {
auto loop = taxonomy::make<taxonomy::loop>(); auto loop = taxonomy::make<taxonomy::loop>();
auto pwf = taxonomy::make<taxonomy::piecewise_function>();
#ifdef SCHEMA_HAS_IfcSegment #ifdef SCHEMA_HAS_IfcSegment
// 4x3 // 4x3
@@ -30,7 +31,7 @@ taxonomy::ptr mapping::map_impl(const IfcSchema::IfcCompositeCurve* inst) {
#else #else
IfcSchema::IfcCompositeCurveSegment::list::ptr segments = inst->Segments(); IfcSchema::IfcCompositeCurveSegment::list::ptr segments = inst->Segments();
#endif #endif
for (auto& segment : *segments) { for (auto& segment : *segments) {
if (segment->as<IfcSchema::IfcCompositeCurveSegment>() && segment->as<IfcSchema::IfcCompositeCurveSegment>()->ParentCurve()->as<IfcSchema::IfcLine>()) { if (segment->as<IfcSchema::IfcCompositeCurveSegment>() && segment->as<IfcSchema::IfcCompositeCurveSegment>()->ParentCurve()->as<IfcSchema::IfcLine>()) {
Logger::Notice("Infinite IfcLine used as ParentCurve of segment, treating as a segment", segment); Logger::Notice("Infinite IfcLine used as ParentCurve of segment, treating as a segment", segment);
@@ -47,14 +48,16 @@ taxonomy::ptr mapping::map_impl(const IfcSchema::IfcCompositeCurve* inst) {
e->orientation_2.reset(segment->as<IfcSchema::IfcCompositeCurveSegment>()->SameSense()); e->orientation_2.reset(segment->as<IfcSchema::IfcCompositeCurveSegment>()->SameSense());
loop->children.push_back(e); loop->children.push_back(e);
} else if (segment->as<IfcSchema::IfcCompositeCurveSegment>()) { }
else if (segment->as<IfcSchema::IfcCompositeCurveSegment>()) {
auto crv = map(segment->as<IfcSchema::IfcCompositeCurveSegment>()->ParentCurve()); auto crv = map(segment->as<IfcSchema::IfcCompositeCurveSegment>()->ParentCurve());
if (crv) { if (crv) {
if (crv->kind() == taxonomy::EDGE) { if (crv->kind() == taxonomy::EDGE) {
auto ecrv = taxonomy::cast<taxonomy::edge>(crv); auto ecrv = taxonomy::cast<taxonomy::edge>(crv);
ecrv->orientation_2.reset(segment->as<IfcSchema::IfcCompositeCurveSegment>()->SameSense()); ecrv->orientation_2.reset(segment->as<IfcSchema::IfcCompositeCurveSegment>()->SameSense());
loop->children.push_back(ecrv); loop->children.push_back(ecrv);
} else if (crv->kind() == taxonomy::LOOP) { }
else if (crv->kind() == taxonomy::LOOP) {
if (!segment->as<IfcSchema::IfcCompositeCurveSegment>()->SameSense()) { if (!segment->as<IfcSchema::IfcCompositeCurveSegment>()->SameSense()) {
crv->reverse(); crv->reverse();
} }
@@ -66,18 +69,30 @@ taxonomy::ptr mapping::map_impl(const IfcSchema::IfcCompositeCurve* inst) {
} }
#ifdef SCHEMA_HAS_IfcCurveSegment #ifdef SCHEMA_HAS_IfcCurveSegment
else if (segment->as<IfcSchema::IfcCurveSegment>()) { else 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>()); auto crv = map(segment->as<IfcSchema::IfcCurveSegment>());
for (auto& s : taxonomy::cast<taxonomy::loop>(crv)->children) { if (crv->kind() == taxonomy::LOOP) {
loop->children.push_back(s); for (auto& s : taxonomy::cast<taxonomy::loop>(crv)->children) {
loop->children.push_back(s);
}
}
else if (crv->kind() == taxonomy::PIECEWISE_FUNCTION) {
auto seg = taxonomy::cast<taxonomy::piecewise_function>(crv);
pwf->spans.insert(pwf->spans.end(), seg->spans.begin(), seg->spans.end());
} }
} }
#endif #endif
} }
aggregate_of_instance::ptr profile = inst->data().getInverse(&IfcSchema::IfcProfileDef::Class(), -1); if (pwf->spans.empty()) {
const bool force_close = profile && profile->size() > 0; aggregate_of_instance::ptr profile = inst->data().getInverse(&IfcSchema::IfcProfileDef::Class(), -1);
loop->closed = force_close; const bool force_close = profile && profile->size() > 0;
return loop; loop->closed = force_close;
return loop;
}
else {
return pwf;
}
} }
/* /*
@@ -97,7 +112,7 @@ taxonomy::ptr mapping::map_impl(const IfcSchema::IfcCompositeCurve* l, TopoDS_Wi
TopTools_ListOfShape converted_segments; TopTools_ListOfShape converted_segments;
for (auto it = segments->begin(); it != segments->end(); ++it) { for (auto it = segments->begin(); it != segments->end(); ++it) {
if (!(*it)->declaration().is(IfcSchema::IfcCompositeCurveSegment::Class())) { if (!(*it)->declaration().is(IfcSchema::IfcCompositeCurveSegment::Class())) {
@@ -108,7 +123,7 @@ taxonomy::ptr mapping::map_impl(const IfcSchema::IfcCompositeCurve* l, TopoDS_Wi
IfcSchema::IfcCurve* curve = ((IfcSchema::IfcCompositeCurveSegment*)(*it))->ParentCurve(); IfcSchema::IfcCurve* curve = ((IfcSchema::IfcCompositeCurveSegment*)(*it))->ParentCurve();
// The type of ParentCurve is IfcCurve, but the documentation says: // The type of ParentCurve is IfcCurve, but the documentation says:
// ParentCurve: The *bounded curve* which defines the geometry of the segment. // ParentCurve: The *bounded curve* which defines the geometry of the segment.
// At least let's exclude IfcLine as an infinite linear segment // At least let's exclude IfcLine as an infinite linear segment
// definitely does not make any sense. // definitely does not make any sense.
TopoDS_Wire segment; TopoDS_Wire segment;
@@ -165,4 +180,4 @@ taxonomy::ptr mapping::map_impl(const IfcSchema::IfcCompositeCurve* l, TopoDS_Wi
return true; return true;
} }
*/ */
+223 -181
View File
@@ -27,31 +27,10 @@ using namespace ifcopenshell::geometry;
#include <boost/mpl/vector.hpp> #include <boost/mpl/vector.hpp>
#include <boost/mpl/for_each.hpp> #include <boost/mpl/for_each.hpp>
#include <boost/math/quadrature/trapezoidal.hpp>
// @todo use std::numbers::pi when upgrading to C++ 20 // @todo use std::numbers::pi when upgrading to C++ 20
#define PI 3.1415926535897932384626433832795 static const double PI = boost::math::constants::pi<double>();
namespace
{
// trapezoid rule integration
// @todo is there a well established math library we can use instead of
// creating our own integrator?
double integrate(double a, double b, unsigned n, std::function<double(double)> fn)
{
double area = 0;
double h = (b - a) / n;
for (auto i = 1; i <= n; i++)
{
auto x1 = a + h * (i - 1);
auto x2 = a + h * i;
auto f1 = fn(x1);
auto f2 = fn(x2);
area += h * (f1 + f2) / 2.0;
}
return area;
}
}
typedef boost::mpl::vector< typedef boost::mpl::vector<
IfcSchema::IfcLine IfcSchema::IfcLine
@@ -63,95 +42,44 @@ typedef boost::mpl::vector<
#endif #endif
, IfcSchema::IfcPolyline , IfcSchema::IfcPolyline
, IfcSchema::IfcCircle , IfcSchema::IfcCircle
, IfcSchema::IfcPolynomialCurve
> curve_seg_types; > curve_seg_types;
enum segment_type_t {
ST_HORIZONTAL, ST_VERTICAL, ST_CANT
};
class curve_segment_evaluator { class curve_segment_evaluator {
private: private:
mapping* mapping_;
double length_unit_; double length_unit_;
double start_; double start_;
double length_; double length_;
segment_type_t segment_type_;
IfcSchema::IfcCurve* curve_; IfcSchema::IfcCurve* curve_;
std::optional<std::function<Eigen::Vector3d(double)>> eval_; std::optional<std::function<Eigen::VectorXd(double)>> eval_;
public: public:
// First constructor, takes parameters from IfcCurveSegment // First constructor, takes parameters from IfcCurveSegment
curve_segment_evaluator(double length_unit, IfcSchema::IfcCurve* curve, IfcSchema::IfcCurveMeasureSelect* st, IfcSchema::IfcCurveMeasureSelect* le) curve_segment_evaluator(mapping* mapping,double length_unit, segment_type_t segment_type, IfcSchema::IfcCurve* curve, IfcSchema::IfcCurveMeasureSelect* st, IfcSchema::IfcCurveMeasureSelect* le)
: length_unit_(length_unit) : mapping_(mapping)
, length_unit_(length_unit)
, segment_type_(segment_type)
, curve_(curve) , curve_(curve)
{ {
// @todo in IFC4X3_ADD2 this needs to be length measure // @todo in IFC4X3_ADD2 this needs to be length measure
if (!st->as<IfcSchema::IfcLengthMeasure>() || !le->as<IfcSchema::IfcLengthMeasure>()) { if (!st->as<IfcSchema::IfcLengthMeasure>() || !le->as<IfcSchema::IfcLengthMeasure>()) {
// @nb Parameter values are forbidden in the specification until parametrization is provided for all spirals // @nb Parameter values are forbidden in the specification until parametrization is provided for all spirals
throw std::runtime_error("Unsupported curve measure type"); throw std::runtime_error("Unsupported curve measure type");
} }
start_ = *st->as<IfcSchema::IfcLengthMeasure>() * length_unit; start_ = *st->as<IfcSchema::IfcLengthMeasure>() * length_unit;
length_ = *le->as<IfcSchema::IfcLengthMeasure>() * length_unit; length_ = *le->as<IfcSchema::IfcLengthMeasure>() * length_unit;
} }
// Clothoid using Taylor Series approximation void set_spiral_functor(mapping* mapping_,IfcSchema::IfcSpiral* s, std::function<double(double)> signX, std::function<double(double)> fnX, std::function<double(double)> signY, std::function<double(double)> fnY)
//#ifdef SCHEMA_HAS_IfcClothoid
// // Then initialize Function(double) -> Vector3, by means of IfcCurve subtypes
// void operator()(IfcSchema::IfcClothoid* c) {
// // @todo verify
// auto sign = [](double v)->int{return v < 0 ? -1 : (0 < v ? 1 : 0); };
// auto sign_s = sign(start_);
// auto sign_l = sign(length_);
// double L = 0;
// if (sign_s == 0) L = fabs(length_);
// else if (sign_s == sign_l) L = fabs(start_ + length_);
// else L = fabs(start_);
//
// auto A = c->ClothoidConstant();
// auto R = A * A / L;
// auto RL = (A < 0 ? -1.0 : 1.0) * R * L;
//
// auto position = c->Position();
// auto placement = position->as<IfcSchema::IfcAxis2Placement2D>();
// auto ref_direction = placement->RefDirection();
// double theta = 0.0; // angle the circle's placement X-axis makes with respect to global X axis
// if (ref_direction)
// {
// auto dr = ref_direction->DirectionRatios();
// auto dx = dr[0];
// auto dy = dr[1];
// theta = atan2(dy, dx);
// }
//
// auto C = placement->Location();
// if (!C->as<IfcSchema::IfcCartesianPoint>())
// {
// throw std::runtime_error("Only IfcCartesianPoint is supported for center of IfcCircle");
// // @todo add support for other IfcPoint subtypes
// }
// auto Cx = C->as<IfcSchema::IfcCartesianPoint>()->Coordinates()[0];
// auto Cy = C->as<IfcSchema::IfcCartesianPoint>()->Coordinates()[1];
//
// eval_ = [RL,Cx,Cy,theta](double u) {
// // coordinate along clothoid is local coordinates
// auto xterm_1 = u;
// auto xterm_2 = std::pow(u, 5) / (40 * std::pow(RL, 2));
// auto xterm_3 = std::pow(u, 9) / (3456 * std::pow(RL, 4));
// auto xterm_4 = std::pow(u, 13) / (599040 * std::pow(RL, 6));
// auto xl = xterm_1 - xterm_2 + xterm_3 - xterm_4;
//
// auto yterm_1 = std::pow(u, 3) / (6 * RL);
// auto yterm_2 = std::pow(u, 7) / (336 * std::pow(RL, 3));
// auto yterm_3 = std::pow(u, 11) / (42240 * std::pow(RL, 5));
// auto yterm_4 = std::pow(u, 15) / (9676800 * std::pow(RL, 7));
// auto yl = yterm_1 - yterm_2 + yterm_3 - yterm_4;
//
// // transform point into clothoid's coodinate system
// auto x = xl * cos(theta) - yl * sin(theta) + Cx;
// auto y = xl * sin(theta) + yl * cos(theta) + Cy;
// return Eigen::Vector3d(x, y, 0.0);
// };
// }
//#endif
void set_spiral_functor(IfcSchema::IfcSpiral* s, std::function<double(double)> signX,std::function<double(double)> fnX, std::function<double(double)> signY, std::function<double(double)> fnY)
{ {
// determine the length of the spiral from the local origin to the end point // determine the length of the spiral from the local origin to the end point
auto binary_sign = [](double v)->int {return v < 0 ? -1 : (0 < v ? 1 : 0); }; // returns -1, 0, or 1 auto binary_sign = [](double v)->int {return v < 0 ? -1 : (0 < v ? 1 : 0); }; // returns -1, 0, or 1
@@ -162,70 +90,99 @@ public:
else if (sign_s == sign_l) L = fabs(start_ + length_); // start_ and length_ are additive else if (sign_s == sign_l) L = fabs(start_ + length_); // start_ and length_ are additive
else L = fabs(start_); // start_ and length_ are in opposite directions so start_ is furthest from the origin else L = fabs(start_); // start_ and length_ are in opposite directions so start_ is furthest from the origin
auto position = s->Position(); //const auto& transformation_matrix = taxonomy::cast<taxonomy::matrix4>(mapping_->map(s->Position()))->ccomponents();
auto placement = position->as<IfcSchema::IfcAxis2Placement2D>(); // @todo Update, this could be IfcAxis2Placement2D or IfcAxisPlacement3D auto transformation_matrix = taxonomy::cast<taxonomy::matrix4>(mapping_->map(s->Position()))->ccomponents();
if (!placement) { throw std::runtime_error("Only IfcAxis2Placement2D is supported right now"); }
auto ref_direction = placement->RefDirection();
double theta = 0.0; // angle the circle's placement X-axis makes with respect to global X axis
if (ref_direction)
{
auto dr = ref_direction->DirectionRatios();
auto dx = dr[0];
auto dy = dr[1];
theta = atan2(dy, dx);
}
auto C = placement->Location(); eval_ = [L, transformation_matrix, signX, fnX, signY, fnY](double u) {
if (!C->as<IfcSchema::IfcCartesianPoint>()) using boost::math::quadrature::trapezoidal;
{
throw std::runtime_error("Only IfcCartesianPoint is supported right now");
// @todo add support for other IfcPoint subtypes
}
auto Cx = C->as<IfcSchema::IfcCartesianPoint>()->Coordinates()[0];
auto Cy = C->as<IfcSchema::IfcCartesianPoint>()->Coordinates()[1];
eval_ = [L, Cx, Cy, theta, signX, fnX, signY, fnY](double u) {
// integration limits, integrate from a to b // integration limits, integrate from a to b
// from 8.9.3.19.1, integration limits are 0.0 to u where u is a normalized parameter // from 8.9.3.19.1, integration limits are 0.0 to u where u is a normalized parameter
auto a = 0.0; auto a = 0.0;
auto b = fabs(u / L); auto b = fabs(u / L);
auto n = 10; // use 10 steps in the numeric integration // @todo where to plug this in?
// auto n = 10; // use 10 steps in the numeric integration
auto xl = signX(u)*integrate(a, b, n, fnX); auto x = signX(u) * trapezoidal(fnX, a, b);
auto yl = signY(u)*integrate(a, b, n, fnY); auto y = signY(u) * trapezoidal(fnY, a, b);
// transform point into clothoid's coodinate system // transform point into spiral's coodinate system
auto x = xl * cos(theta) - yl * sin(theta) + Cx; auto result = transformation_matrix * Eigen::Vector4d(x, y, 0.0, 1.0);
auto y = xl * sin(theta) + yl * cos(theta) + Cy; Eigen::VectorXd vec(4);
return Eigen::Vector3d(x, y, 0.0); vec << result(0), result(1), 0.0, 1.0;
return vec;
}; };
} }
// Clothoid using numerical integration
// Clothoid using Taylor Series approximation
#ifdef SCHEMA_HAS_IfcClothoid #ifdef SCHEMA_HAS_IfcClothoid
// Then initialize Function(double) -> Vector3, by means of IfcCurve subtypes // Then initialize Function(double) -> Vector3, by means of IfcCurve subtypes
void operator()(IfcSchema::IfcClothoid* c) { void operator()(IfcSchema::IfcClothoid* c) {
// @todo verify
auto sign = [](double v)->int {return v < 0 ? -1 : (0 < v ? 1 : 0); };
auto sign_s = sign(start_);
auto sign_l = sign(length_);
double L = 0;
if (sign_s == 0) L = fabs(length_);
else if (sign_s == sign_l) L = fabs(start_ + length_);
else L = fabs(start_);
auto A = c->ClothoidConstant(); auto A = c->ClothoidConstant();
auto R = A * A / L;
auto RL = (A < 0 ? -1.0 : 1.0) * R * L;
// the integration is for the +X, +Y quadrant - need to adjust the signs of the resulting X and Y values //const auto& transformation_matrix = taxonomy::cast<taxonomy::matrix4>(mapping_->map(c->Position()))->ccomponents();
// so that the results are in the correct quadrant. auto transformation_matrix = taxonomy::cast<taxonomy::matrix4>(mapping_->map(c->Position()))->ccomponents();
// A > 0 and u > 0 -> +X, +Y
// A < 0 and u > 0 -> +X, -Y eval_ = [RL, transformation_matrix](double u) {
// A > 0 and u < 0 -> -X, -Y // coordinate along clothoid is local coordinates
// A < 0 and u < 0 -> -X, +Y auto xterm_1 = u;
// X depends only on u, Y depends on u and A. auto xterm_2 = std::pow(u, 5) / (40 * std::pow(RL, 2));
auto sign = [](double v)->int {return v < 0 ? -1 : 1; }; // returns -1 or 1 auto xterm_3 = std::pow(u, 9) / (3456 * std::pow(RL, 4));
auto sign_x = [sign](double t) {return sign(t); }; auto xterm_4 = std::pow(u, 13) / (599040 * std::pow(RL, 6));
auto sign_y = [sign, A](double t) {return sign(t) == sign(A) ? 1.0 : -1.0; }; auto x = xterm_1 - xterm_2 + xterm_3 - xterm_4;
auto fn_x = [A](double t)->double {return A * sqrt(PI) * cos(PI * A * t * t / (2 * fabs(A))); };
auto fn_y = [A](double t)->double {return A * sqrt(PI) * sin(PI * A * t * t / (2 * fabs(A))); }; auto yterm_1 = std::pow(u, 3) / (6 * RL);
auto yterm_2 = std::pow(u, 7) / (336 * std::pow(RL, 3));
set_spiral_functor(c->as<IfcSchema::IfcSpiral>(), sign_x, fn_x, sign_y, fn_y); auto yterm_3 = std::pow(u, 11) / (42240 * std::pow(RL, 5));
auto yterm_4 = std::pow(u, 15) / (9676800 * std::pow(RL, 7));
auto y = yterm_1 - yterm_2 + yterm_3 - yterm_4;
// transform point into clothoid's coodinate system
auto result = transformation_matrix * Eigen::Vector4d(x, y, 0.0, 1.0);
Eigen::VectorXd vec(4);
vec << result(0), result(1), 0.0, 1.0;
return vec;
};
} }
#endif #endif
// Clothoid using numerical integration
//#ifdef SCHEMA_HAS_IfcClothoid
//// Then initialize Function(double) -> Vector3, by means of IfcCurve subtypes
// void operator()(IfcSchema::IfcClothoid* c) {
//
// auto A = c->ClothoidConstant();
//
// // the integration is for the +X, +Y quadrant - need to adjust the signs of the resulting X and Y values
// // so that the results are in the correct quadrant.
// // A > 0 and u > 0 -> +X, +Y
// // A < 0 and u > 0 -> +X, -Y
// // A > 0 and u < 0 -> -X, -Y
// // A < 0 and u < 0 -> -X, +Y
// // X depends only on u, Y depends on u and A.
// auto sign = [](double v)->int {return v < 0 ? -1 : 1; }; // returns -1 or 1
// auto sign_x = [sign](double t) {return sign(t); };
// auto sign_y = [sign, A](double t) {return sign(t) == sign(A) ? 1.0 : -1.0; };
// auto fn_x = [A](double t)->double {return A * sqrt(PI) * cos(PI * A * t * t / (2 * fabs(A))); };
// auto fn_y = [A](double t)->double {return A * sqrt(PI) * sin(PI * A * t * t / (2 * fabs(A))); };
//
// set_spiral_functor(mapping_,c->as<IfcSchema::IfcSpiral>(), sign_x, fn_x, sign_y, fn_y);
// }
//#endif
#ifdef SCHEMA_HAS_IfcSecondOrderPolynomialSpiral #ifdef SCHEMA_HAS_IfcSecondOrderPolynomialSpiral
void operator()(IfcSchema::IfcSecondOrderPolynomialSpiral* s) void operator()(IfcSchema::IfcSecondOrderPolynomialSpiral* s)
{ {
@@ -249,48 +206,29 @@ public:
auto fn_x = [theta](double t)->double {return cos(theta(t)); }; auto fn_x = [theta](double t)->double {return cos(theta(t)); };
auto fn_y = [theta](double t)->double {return sin(theta(t)); }; auto fn_y = [theta](double t)->double {return sin(theta(t)); };
set_spiral_functor(s->as<IfcSchema::IfcSpiral>(), sign_x, fn_x, sign_y, fn_y); set_spiral_functor(mapping_,s->as<IfcSchema::IfcSpiral>(), sign_x, fn_x, sign_y, fn_y);
} }
#endif #endif
void operator()(IfcSchema::IfcCircle* c) void operator()(IfcSchema::IfcCircle* c)
{ {
auto R = c->Radius(); auto R = c->Radius();
//const auto& transformation_matrix = taxonomy::cast<taxonomy::matrix4>(mapping_->map(c->Position()))->ccomponents();
auto transformation_matrix = taxonomy::cast<taxonomy::matrix4>(mapping_->map(c->Position()))->ccomponents();
auto position = c->Position(); eval_ = [R, transformation_matrix](double u)
auto placement = position->as<IfcSchema::IfcAxis2Placement2D>();
auto ref_direction = placement->RefDirection();
double theta = 0.0; // angle the circle's placement X-axis makes with respect to global X axis
if (ref_direction)
{
auto dr = ref_direction->DirectionRatios();
auto dx = dr[0];
auto dy = dr[1];
theta = atan2(dy, dx);
}
// center of circle location
auto C = placement->Location();
if (!C->as<IfcSchema::IfcCartesianPoint>())
{
throw std::runtime_error("Only IfcCartesianPoint is supported for center of IfcCircle");
// @todo add support for other IfcPoint subtypes
}
auto Cx = C->as<IfcSchema::IfcCartesianPoint>()->Coordinates()[0];
auto Cy = C->as<IfcSchema::IfcCartesianPoint>()->Coordinates()[1];
eval_ = [R, Cx, Cy, theta](double u)
{ {
auto angle = u / R; // angle subtended by arc length u auto angle = u / R; // angle subtended by arc length u
// compute point on circle centered at (0,0) with x-axis horizontal and y-axis vertical // compute point on circle centered at (0,0) with x-axis horizontal and y-axis vertical
auto xl = R * cos(angle); auto x = R * cos(angle);
auto yl = R * sin(angle); auto y = R * sin(angle);
// transform point into circle's coodinate system // transform point into circle's coodinate system
auto x = xl * cos(theta) - yl * sin(theta) + Cx; auto result = transformation_matrix * Eigen::Vector4d(x, y, 0.0, 1.0);
auto y = xl * sin(theta) + yl * cos(theta) + Cy; Eigen::VectorXd vec(4);
return Eigen::Vector3d(x, y, 0.0); vec << result(0), result(1), 0.0, 1.0;
return vec;
}; };
} }
@@ -313,7 +251,7 @@ public:
} }
auto std_compare = [](double u_start, double u, double u_end) {return u_start <= u && u < u_end; }; auto std_compare = [](double u_start, double u, double u_end) {return u_start <= u && u < u_end; };
auto end_compare = [](double u_start, double u, double u_end) {return u_start <= u && u <= (u_end+0.001); }; auto end_compare = [](double u_start, double u, double u_end) {return u_start <= u && u <= (u_end + 0.001); };
auto iter = p->begin(); auto iter = p->begin();
auto end = p->end(); auto end = p->end();
@@ -356,12 +294,14 @@ public:
auto [u_start, u_end, compare] = fn.first; auto [u_start, u_end, compare] = fn.first;
return compare(u_start, u, u_end); return compare(u_start, u, u_end);
}); });
if (iter == fns.end()) throw std::runtime_error("invalid distance from start"); // this should never happen, but just in case it does if (iter == fns.end()) throw std::runtime_error("invalid distance from start"); // this should never happen, but just in case it does
auto [u_start, u_end, compare] = iter->first; auto [u_start, u_end, compare] = iter->first;
auto [x,y] = (iter->second)(u - u_start); // (u - u_start) is distance from start of this segment of the polyline auto [x, y] = (iter->second)(u - u_start); // (u - u_start) is distance from start of this segment of the polyline
return Eigen::Vector3d(x, y, 0); Eigen::VectorXd vec(4);
vec << x, y, 0.0, 1.0;
return vec;
}; };
} }
@@ -376,11 +316,59 @@ public:
auto dx = dr[0] / m; auto dx = dr[0] / m;
auto dy = dr[1] / m; auto dy = dr[1] / m;
eval_ = [px, py, dx, dy](double u) { if (segment_type_ == ST_HORIZONTAL) {
auto x = px + u * dx;
auto y = py + u * dy; eval_ = [px, py, dx, dy](double u) {
return Eigen::Vector3d(x, y, 0); auto x = px + u * dx;
}; auto y = py + u * dy;
Eigen::VectorXd vec(4);
vec << x, y, 0.0, 1.0;
return vec;
};
}
else if (segment_type_ == ST_VERTICAL) {
eval_ = [py, dy](double u) {
auto z = py + u * dy;
Eigen::VectorXd vec(4);
vec << 0.0, 0.0, z, 1.0;
return vec;
};
}
}
void operator()(IfcSchema::IfcPolynomialCurve* p) {
if (segment_type_ == ST_HORIZONTAL) {
auto coeffX = p->CoefficientsX();
auto coeffY = p->CoefficientsY();
eval_ = [coeffX,coeffY](double u) {
Eigen::VectorXd vec(4);
vec << 0.0, 0.0, 0.0, 1.0;
return vec;
};
}
else if (segment_type_ == ST_VERTICAL) {
auto coeffY = p->CoefficientsY();
eval_ = [coeffY](double u) {
const auto& coeffs = coeffY.get();
auto exp = coeffs.size() - 1;
auto z = 0.0;
for (auto c : coeffs)
{
z += c * pow(u, exp--);
}
Eigen::VectorXd vec(4);
vec << 0.0, 0.0, z, 1.0;
return vec;
};
}
} }
// Take the boost::type value from mpl::for_each and test it against our curve instance // Take the boost::type value from mpl::for_each and test it against our curve instance
@@ -392,10 +380,11 @@ public:
} }
// Then, with function populated based on IfcCurve subtype, we can evaluate to points // Then, with function populated based on IfcCurve subtype, we can evaluate to points
Eigen::Vector3d operator()(double u) { Eigen::VectorXd operator()(double u) {
if (eval_) { if (eval_) {
return (*eval_)((u + start_) * length_unit_); return (*eval_)((u + start_) * length_unit_);
} else { }
else {
throw std::runtime_error(curve_->declaration().name() + " not implemented"); throw std::runtime_error(curve_->declaration().name() + " not implemented");
} }
} }
@@ -403,29 +392,81 @@ public:
double length() const { double length() const {
return length_; return length_;
} }
const std::optional<std::function<Eigen::VectorXd(double)>>& evaluation_function() const {
return eval_;
}
}; };
taxonomy::ptr mapping::map_impl(const IfcSchema::IfcCurveSegment* inst) { taxonomy::ptr mapping::map_impl(const IfcSchema::IfcCurveSegment* inst) {
// @todo fixed number of segments or fixed interval?
// @todo placement
// @todo figure out what to do with the zero length segments at the end of compound curves // @todo figure out what to do with the zero length segments at the end of compound curves
static int NUM_SEGMENTS = 64; bool is_horizontal = false;
curve_segment_evaluator cse(length_unit_, inst->ParentCurve(), inst->SegmentStart(), inst->SegmentLength()); bool is_vertical = false;
boost::mpl::for_each<curve_seg_types, boost::type<boost::mpl::_>>(std::ref(cse)); bool is_cant = false;
std::vector<taxonomy::point3::ptr> polygon; {
aggregate_of_instance::ptr segment_owners = inst->data().getInverse(&IfcSchema::IfcCompositeCurve::Class(), 0);
if (segment_owners) {
for (auto& cc : *segment_owners) {
if (cc->as<IfcSchema::IfcSegmentedReferenceCurve>()) {
is_cant = true;
}
else if (cc->as<IfcSchema::IfcGradientCurve>()) {
is_vertical = true;
}
else {
is_horizontal = true;
}
}
}
}
if ((is_horizontal + is_vertical + is_cant) != 1) {
// We have to choose the correct functor based on usage. We can't
// support multiple, because we don't know the caller at this point.
return nullptr;
}
auto segment_type = is_horizontal ? ST_HORIZONTAL : is_vertical ? ST_VERTICAL : ST_CANT;
curve_segment_evaluator cse(this,length_unit_, segment_type, inst->ParentCurve(), inst->SegmentStart(), inst->SegmentLength());
boost::mpl::for_each<curve_seg_types, boost::type<boost::mpl::_>>(std::ref(cse));
auto eval_fn = cse.evaluation_function();
if(!eval_fn) throw std::runtime_error(inst->ParentCurve()->declaration().name() + " not implemented");
auto fn = *eval_fn;
auto length = fabs(cse.length());
// @todo - for some reason this isn't working, the matrix gets all messed up // @todo - for some reason this isn't working, the matrix gets all messed up
//const auto& transformation_matrix = taxonomy::cast<taxonomy::matrix4>(map(inst->Placement()))->ccomponents(); //const auto& transformation_matrix = taxonomy::cast<taxonomy::matrix4>(map(inst->Placement()))->ccomponents();
auto transformation_matrix = taxonomy::cast<taxonomy::matrix4>(map(inst->Placement()))->ccomponents(); auto transformation_matrix = taxonomy::cast<taxonomy::matrix4>(map(inst->Placement()))->ccomponents();
auto fn_transformed = [fn, transformation_matrix](double u)->Eigen::VectorXd {
auto result = fn(u);
Eigen::Vector4d v(result.x(), result.y(), result.z(), 1.0);
// return transformation_matrix * fn(u);
auto r = transformation_matrix * v;
Eigen::VectorXd d(4);
d << r(0), r(1), r(2), r(3);
return d;
};
// @todo it might be suboptimal that we no longer have the spans now
auto pwf = taxonomy::make<taxonomy::piecewise_function>();
pwf->spans.push_back({ length, fn_transformed });
return pwf;
/*
static int NUM_SEGMENTS = 64;
std::vector<taxonomy::point3::ptr> polygon;
auto length = cse.length(); auto length = cse.length();
if (0.001 < fabs(length)) if (0.001 < fabs(length))
{ {
for (int i = 0; i <= NUM_SEGMENTS; ++i) { for (int i = 0; i <= NUM_SEGMENTS; ++i) {
auto u = length * i / NUM_SEGMENTS; auto u = length * i / NUM_SEGMENTS;
auto p = cse(u); auto p = cse(u);
auto result = transformation_matrix * Eigen::Vector4d(p(0),p(1),p(2), 1.); auto result = transformation_matrix * Eigen::Vector4d(p(0),p(1),p(2), 1.);
polygon.push_back(taxonomy::make<taxonomy::point3>(result(0),result(1),result(2))); polygon.push_back(taxonomy::make<taxonomy::point3>(result(0),result(1),result(2)));
@@ -433,6 +474,7 @@ taxonomy::ptr mapping::map_impl(const IfcSchema::IfcCurveSegment* inst) {
} }
return polygon_from_points(polygon); return polygon_from_points(polygon);
*/
} }
#endif #endif
+76
View File
@@ -0,0 +1,76 @@
/********************************************************************************
* *
* 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"
#define mapping POSTFIX_SCHEMA(mapping)
using namespace ifcopenshell::geometry;
#ifdef SCHEMA_HAS_IfcGradientCurve
taxonomy::ptr mapping::map_impl(const IfcSchema::IfcGradientCurve* inst) {
auto horizontal = taxonomy::cast<taxonomy::piecewise_function>(map(inst->BaseCurve()));
auto vertical = taxonomy::make<taxonomy::piecewise_function>();
auto segments = inst->Segments();
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->kind() == taxonomy::PIECEWISE_FUNCTION) {
auto seg = taxonomy::cast<taxonomy::piecewise_function>(crv);
vertical->spans.insert(vertical->spans.end(), seg->spans.begin(), seg->spans.end());
} else {
Logger::Error("Unsupported");
return nullptr;
}
} else {
Logger::Error("Unsupported");
return nullptr;
}
}
// @todo does this really make sense?
auto composition = [horizontal, vertical](double u)->Eigen::VectorXd {
auto xy = horizontal->evaluate(u);
auto z = vertical->evaluate(u);
Eigen::VectorXd vec(3);
vec << xy(0), xy(1), z(2);
return vec;
};
// @todo where do we get the startdistalong from @civilx64's code?
std::array<taxonomy::piecewise_function::ptr, 2> both = { horizontal , vertical };
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;
}
}
auto pwf = taxonomy::make<taxonomy::piecewise_function>();
pwf->spans.emplace_back( min_length, composition );
return pwf;
}
#endif
+1 -3
View File
@@ -5,7 +5,7 @@
#define BIND(T) \ #define BIND(T) \
if (inst->as<IfcSchema::T>()) { \ if (inst->as<IfcSchema::T>()) { \
try { \ try { \
taxonomy::ptr item = map_impl(inst->as<IfcSchema::T>()); \ item = map_impl(inst->as<IfcSchema::T>()); \
if (item != nullptr) { \ if (item != nullptr) { \
item->instance = inst; \ item->instance = inst; \
try { \ try { \
@@ -24,11 +24,9 @@
} else {\ } else {\
Logger::Message(Logger::LOG_ERROR,"Failed to convert:", inst);\ Logger::Message(Logger::LOG_ERROR,"Failed to convert:", inst);\
} \ } \
return item; \
} catch (const std::exception& e) { \ } catch (const std::exception& e) { \
Logger::Message(Logger::LOG_ERROR, std::string(e.what()) + "\nFailed to convert:", inst); \ Logger::Message(Logger::LOG_ERROR, std::string(e.what()) + "\nFailed to convert:", inst); \
} \ } \
return nullptr; \
} }
#include "mapping.i" #include "mapping.i"
+19 -3
View File
@@ -490,10 +490,26 @@ taxonomy::ptr mapping::map_impl(const IfcSchema::IfcStyledItem* inst) {
taxonomy::ptr mapping::map(const IfcBaseInterface* inst) { taxonomy::ptr mapping::map(const IfcBaseInterface* inst) {
// std::wcout << inst->data().toString().c_str() << std::endl; auto iden = inst->as<IfcUtil::IfcBaseClass>()->identity();
auto it = cache_.find(iden);
if (it != cache_.end()) {
return it->second;
}
taxonomy::ptr item = nullptr;
// @todo we should check whether there is a notice performance impact on the large sequence
// of if-statements and whether a switch on e.g inst->declaration()->index_in_schema()
// isn't more efficient (which would disable inheritance though).
#include "bind_convert_impl.i" #include "bind_convert_impl.i"
Logger::Message(Logger::LOG_ERROR, "No operation defined for:", inst);
return nullptr; if (item) {
cache_.insert({ iden, item });
}
else {
Logger::Message(Logger::LOG_ERROR, "No operation defined for:", inst);
}
return item;
} }
namespace { namespace {
+2
View File
@@ -22,6 +22,8 @@ namespace geometry {
double length_unit_, angle_unit_; double length_unit_, angle_unit_;
std::string length_unit_name_; std::string length_unit_name_;
std::map<uint32_t, ifcopenshell::geometry::taxonomy::ptr> cache_;
const IfcParse::declaration* placement_rel_to_type_; const IfcParse::declaration* placement_rel_to_type_;
const IfcUtil::IfcBaseEntity* placement_rel_to_instance_; const IfcUtil::IfcBaseEntity* placement_rel_to_instance_;
+3
View File
@@ -114,6 +114,9 @@ BIND(IfcEdgeLoop);
BIND(IfcPolyline); BIND(IfcPolyline);
BIND(IfcPolyLoop); BIND(IfcPolyLoop);
BIND(IfcCompositeCurve); BIND(IfcCompositeCurve);
#ifdef SCHEMA_HAS_IfcGradientCurve
BIND(IfcGradientCurve);
#endif
BIND(IfcTrimmedCurve); BIND(IfcTrimmedCurve);
BIND(IfcArbitraryOpenProfileDef); BIND(IfcArbitraryOpenProfileDef);
#ifdef SCHEMA_HAS_IfcIndexedPolyCurve #ifdef SCHEMA_HAS_IfcIndexedPolyCurve
+79 -41
View File
@@ -1,4 +1,5 @@
#include "taxonomy.h" #include "taxonomy.h"
#include "profile_helper.h"
using namespace ifcopenshell::geometry::taxonomy; using namespace ifcopenshell::geometry::taxonomy;
@@ -23,9 +24,11 @@ namespace {
bool compare(const eigen_base<T>& t, const eigen_base<T>& u) { bool compare(const eigen_base<T>& t, const eigen_base<T>& u) {
if (t.components_ == nullptr && u.components_ == nullptr) { if (t.components_ == nullptr && u.components_ == nullptr) {
return false; return false;
} else if (t.components_ == nullptr && u.components_ != nullptr) { }
else if (t.components_ == nullptr && u.components_ != nullptr) {
return true; return true;
} else if (t.components_ != nullptr && u.components_ == nullptr) { }
else if (t.components_ != nullptr && u.components_ == nullptr) {
return false; return false;
} }
@@ -86,11 +89,14 @@ namespace {
int less_to_order_optional(const boost::optional<T>& a, const boost::optional<T>& b) { int less_to_order_optional(const boost::optional<T>& a, const boost::optional<T>& b) {
if (a && b) { if (a && b) {
return less_to_order(*a, *b); return less_to_order(*a, *b);
} else if (!a && !b) { }
else if (!a && !b) {
return 0; return 0;
} else if (a) { }
else if (a) {
return 1; return 1;
} else { }
else {
return -1; return -1;
} }
} }
@@ -100,7 +106,8 @@ namespace {
if (a.which() == 0) { if (a.which() == 0) {
a_lt_b = compare(*boost::get<point3::ptr>(a), *boost::get<point3::ptr>(b)); a_lt_b = compare(*boost::get<point3::ptr>(a), *boost::get<point3::ptr>(b));
b_lt_a = compare(*boost::get<point3::ptr>(b), *boost::get<point3::ptr>(a)); b_lt_a = compare(*boost::get<point3::ptr>(b), *boost::get<point3::ptr>(a));
} else { }
else {
a_lt_b = std::less<double>()(boost::get<double>(a), boost::get<double>(b)); a_lt_b = std::less<double>()(boost::get<double>(a), boost::get<double>(b));
b_lt_a = std::less<double>()(boost::get<double>(b), boost::get<double>(a)); b_lt_a = std::less<double>()(boost::get<double>(b), boost::get<double>(a));
} }
@@ -144,7 +151,11 @@ namespace {
bool compare(const surface_curve_sweep&, const surface_curve_sweep&) { bool compare(const surface_curve_sweep&, const surface_curve_sweep&) {
throw std::runtime_error("not implemented"); throw std::runtime_error("not implemented");
} }
bool compare(const piecewise_function&, const piecewise_function&) {
throw std::runtime_error("not implemented");
}
bool compare(const style& a, const style& b) { bool compare(const style& a, const style& b) {
const int order[5] = { const int order[5] = {
less_to_order(a.name, b.name), less_to_order(a.name, b.name),
@@ -166,7 +177,8 @@ namespace {
auto A = static_cast<const type_by_kind::type<N>*>(a); auto A = static_cast<const type_by_kind::type<N>*>(a);
auto B = static_cast<const type_by_kind::type<N>*>(b); auto B = static_cast<const type_by_kind::type<N>*>(b);
return compare(*A, *B); return compare(*A, *B);
} else { }
else {
return dispatch_comparison<N + 1>::dispatch(a, b); return dispatch_comparison<N + 1>::dispatch(a, b);
} }
} }
@@ -223,23 +235,28 @@ namespace {
if (!a_has_basis) { if (!a_has_basis) {
// Finally, equality // Finally, equality
return false; return false;
} else { }
else {
return less(a.basis, b.basis); return less(a.basis, b.basis);
} }
} else { }
else {
return a_has_basis < b_has_basis; return a_has_basis < b_has_basis;
} }
} else { }
else {
return end_state == -1; return end_state == -1;
} }
} else { }
else {
return start_state == -1; return start_state == -1;
} }
} else { }
else {
return return
std::tie(a.orientation, a_which_start, a_which_end) < std::tie(a.orientation, a_which_start, a_which_end) <
std::tie(b.orientation, b_which_start, b_which_end); std::tie(b.orientation, b_which_start, b_which_end);
@@ -262,7 +279,8 @@ namespace {
} }
// Vectors equal, compare matrix (in case of mapped items). // Vectors equal, compare matrix (in case of mapped items).
return compare(*a.matrix, *b.matrix); return compare(*a.matrix, *b.matrix);
} else { }
else {
return a.children.size() < b.children.size(); return a.children.size() < b.children.size();
} }
} }
@@ -314,10 +332,10 @@ ifcopenshell::geometry::taxonomy::solid::ptr ifcopenshell::geometry::create_box(
shell->children.push_back(face); shell->children.push_back(face);
std::array<taxonomy::point3::ptr, 4> points{ std::array<taxonomy::point3::ptr, 4> points{
taxonomy::make<taxonomy::point3>(x+0, y+0, z+ 0), taxonomy::make<taxonomy::point3>(x + 0, y + 0, z + 0),
taxonomy::make<taxonomy::point3>(x+0, y+dy, z+ 0), taxonomy::make<taxonomy::point3>(x + 0, y + dy, z + 0),
taxonomy::make<taxonomy::point3>(x+0, y+dy, z+dz), taxonomy::make<taxonomy::point3>(x + 0, y + dy, z + dz),
taxonomy::make<taxonomy::point3>(x+0, y+0, z+dz) taxonomy::make<taxonomy::point3>(x + 0, y + 0, z + dz)
}; };
loop->children.push_back(make<taxonomy::edge>(points[0], points[1])); loop->children.push_back(make<taxonomy::edge>(points[0], points[1]));
@@ -335,10 +353,10 @@ ifcopenshell::geometry::taxonomy::solid::ptr ifcopenshell::geometry::create_box(
shell->children.push_back(face); shell->children.push_back(face);
std::array<taxonomy::point3::ptr, 4> points{ std::array<taxonomy::point3::ptr, 4> points{
taxonomy::make<taxonomy::point3>(x+dx, y+0, z+ 0), taxonomy::make<taxonomy::point3>(x + dx, y + 0, z + 0),
taxonomy::make<taxonomy::point3>(x+dx, y+0, z+dz), taxonomy::make<taxonomy::point3>(x + dx, y + 0, z + dz),
taxonomy::make<taxonomy::point3>(x+dx, y+dy, z+dz), taxonomy::make<taxonomy::point3>(x + dx, y + dy, z + dz),
taxonomy::make<taxonomy::point3>(x+dx, y+dy, z+ 0) taxonomy::make<taxonomy::point3>(x + dx, y + dy, z + 0)
}; };
loop->children.push_back(make<taxonomy::edge>(points[0], points[1])); loop->children.push_back(make<taxonomy::edge>(points[0], points[1]));
@@ -356,10 +374,10 @@ ifcopenshell::geometry::taxonomy::solid::ptr ifcopenshell::geometry::create_box(
shell->children.push_back(face); shell->children.push_back(face);
std::array<taxonomy::point3::ptr, 4> points{ std::array<taxonomy::point3::ptr, 4> points{
taxonomy::make<taxonomy::point3>(x+0, y+0, z+ 0), taxonomy::make<taxonomy::point3>(x + 0, y + 0, z + 0),
taxonomy::make<taxonomy::point3>(x+0, y+0, z+dz), taxonomy::make<taxonomy::point3>(x + 0, y + 0, z + dz),
taxonomy::make<taxonomy::point3>(x+dx, y+0, z+dz), taxonomy::make<taxonomy::point3>(x + dx, y + 0, z + dz),
taxonomy::make<taxonomy::point3>(x+dx, y+0, z+ 0) taxonomy::make<taxonomy::point3>(x + dx, y + 0, z + 0)
}; };
loop->children.push_back(make<taxonomy::edge>(points[0], points[1])); loop->children.push_back(make<taxonomy::edge>(points[0], points[1]));
@@ -377,10 +395,10 @@ ifcopenshell::geometry::taxonomy::solid::ptr ifcopenshell::geometry::create_box(
shell->children.push_back(face); shell->children.push_back(face);
std::array<taxonomy::point3::ptr, 4> points{ std::array<taxonomy::point3::ptr, 4> points{
taxonomy::make<taxonomy::point3>(x+ 0, y+dy, z+ 0), taxonomy::make<taxonomy::point3>(x + 0, y + dy, z + 0),
taxonomy::make<taxonomy::point3>(x+dx, y+dy, z+ 0), taxonomy::make<taxonomy::point3>(x + dx, y + dy, z + 0),
taxonomy::make<taxonomy::point3>(x+dx, y+dy, z+dz), taxonomy::make<taxonomy::point3>(x + dx, y + dy, z + dz),
taxonomy::make<taxonomy::point3>(x+ 0, y+dy, z+dz) taxonomy::make<taxonomy::point3>(x + 0, y + dy, z + dz)
}; };
loop->children.push_back(make<taxonomy::edge>(points[0], points[1])); loop->children.push_back(make<taxonomy::edge>(points[0], points[1]));
@@ -398,10 +416,10 @@ ifcopenshell::geometry::taxonomy::solid::ptr ifcopenshell::geometry::create_box(
shell->children.push_back(face); shell->children.push_back(face);
std::array<taxonomy::point3::ptr, 4> points{ std::array<taxonomy::point3::ptr, 4> points{
taxonomy::make<taxonomy::point3>(x+ 0, y+ 0, z+0), taxonomy::make<taxonomy::point3>(x + 0, y + 0, z + 0),
taxonomy::make<taxonomy::point3>(x+dx, y+ 0, z+0), taxonomy::make<taxonomy::point3>(x + dx, y + 0, z + 0),
taxonomy::make<taxonomy::point3>(x+dx, y+dy, z+0), taxonomy::make<taxonomy::point3>(x + dx, y + dy, z + 0),
taxonomy::make<taxonomy::point3>(x+ 0, y+dy, z+0) taxonomy::make<taxonomy::point3>(x + 0, y + dy, z + 0)
}; };
loop->children.push_back(make<taxonomy::edge>(points[0], points[1])); loop->children.push_back(make<taxonomy::edge>(points[0], points[1]));
@@ -419,10 +437,10 @@ ifcopenshell::geometry::taxonomy::solid::ptr ifcopenshell::geometry::create_box(
shell->children.push_back(face); shell->children.push_back(face);
std::array<taxonomy::point3::ptr, 4> points{ std::array<taxonomy::point3::ptr, 4> points{
taxonomy::make<taxonomy::point3>(x+ 0, y+ 0, z+dz), taxonomy::make<taxonomy::point3>(x + 0, y + 0, z + dz),
taxonomy::make<taxonomy::point3>(x+ 0, y+dy, z+dz), taxonomy::make<taxonomy::point3>(x + 0, y + dy, z + dz),
taxonomy::make<taxonomy::point3>(x+dx, y+dy, z+dz), taxonomy::make<taxonomy::point3>(x + dx, y + dy, z + dz),
taxonomy::make<taxonomy::point3>(x+dx, y+ 0, z+dz) taxonomy::make<taxonomy::point3>(x + dx, y + 0, z + dz)
}; };
loop->children.push_back(make<taxonomy::edge>(points[0], points[1])); loop->children.push_back(make<taxonomy::edge>(points[0], points[1]));
@@ -434,11 +452,31 @@ ifcopenshell::geometry::taxonomy::solid::ptr ifcopenshell::geometry::create_box(
return solid; return solid;
} }
ifcopenshell::geometry::taxonomy::item::ptr ifcopenshell::geometry::taxonomy::piecewise_function::evaluate() const {
// @todo configure resolution
//double length = std::accumulate(spans.begin(), spans.end(), 0.0); // don't know why this doesn't compile
double length = 0.0;
for (auto& s : spans)
length += s.first;
static const double resolution = 0.5;
std::vector<taxonomy::point3::ptr> polygon;
int num_steps = std::ceil(length / resolution);
for (int i = 0; i < num_steps; ++i) {
auto u = resolution * i;
auto p = evaluate(u);
polygon.push_back(taxonomy::make<taxonomy::point3>(p(0), p(1), p(2)));
}
return polygon_from_points(polygon);
}
ifcopenshell::geometry::taxonomy::collection::ptr ifcopenshell::geometry::flatten(taxonomy::collection::ptr deep) { ifcopenshell::geometry::taxonomy::collection::ptr ifcopenshell::geometry::flatten(taxonomy::collection::ptr deep) {
auto flat = make<taxonomy::collection>(); auto flat = make<taxonomy::collection>();
ifcopenshell::geometry::visit<taxonomy::collection>(deep, [&flat](taxonomy::ptr i) { ifcopenshell::geometry::visit<taxonomy::collection>(deep, [&flat](taxonomy::ptr i) {
flat->children.push_back(taxonomy::cast<taxonomy::geom_item>(clone(i))); flat->children.push_back(taxonomy::cast<taxonomy::geom_item>(clone(i)));
}); });
return flat; return flat;
} }
@@ -446,10 +484,10 @@ const std::string& ifcopenshell::geometry::taxonomy::kind_to_string(kinds k) {
using namespace std::string_literals; using namespace std::string_literals;
static std::string values[] = { static std::string values[] = {
"matrix4"s, "point3"s, "direction3"s, "line"s, "circle"s, "ellipse"s, "bspline_curve"s, "offset_curve"s, "plane"s, "cylinder"s, "bspline_surface"s, "edge"s, "loop"s, "face"s, "shell"s, "solid"s, "loft"s, "extrusion"s, "revolve"s, "surface_curve_sweep"s, "node"s, "collection"s, "boolean_result"s "matrix4"s, "point3"s, "direction3"s, "line"s, "circle"s, "ellipse"s, "bspline_curve"s, "offset_curve"s, "plane"s, "cylinder"s, "bspline_surface"s, "edge"s, "loop"s, "face"s, "shell"s, "solid"s, "loft"s, "extrusion"s, "revolve"s, "surface_curve_sweep"s, "node"s, "collection"s, "boolean_result"s, "piecewise_function"s, "colour"s, "style"s,
}; };
return values[k]; return values[k];
} }
std::atomic_uint32_t item::counter_(0); std::atomic_uint32_t item::counter_(0);
+1193 -1140
View File
File diff suppressed because it is too large Load Diff