Manually merged in aothms revisions for gradient curves and implicit_item taxonomy

This commit is contained in:
Richard Brice
2023-10-02 16:30:39 -07:00
parent ae09a1acac
commit 7b0e2c52ac
10 changed files with 1565 additions and 1336 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::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::piecewise_function::ptr item, IfcGeom::ConversionResults& cs) { return convert(item->evaluate(), cs); }
/*
virtual void set_offset(const std::array<double, 3> &p_offset);
+27 -25
View File
@@ -23,6 +23,7 @@ using namespace ifcopenshell::geometry;
taxonomy::ptr mapping::map_impl(const IfcSchema::IfcCompositeCurve* inst) {
auto loop = taxonomy::make<taxonomy::loop>();
auto pwf = taxonomy::make<taxonomy::piecewise_function>();
#ifdef SCHEMA_HAS_IfcSegment
// 4x3
@@ -30,7 +31,7 @@ taxonomy::ptr mapping::map_impl(const IfcSchema::IfcCompositeCurve* inst) {
#else
IfcSchema::IfcCompositeCurveSegment::list::ptr segments = inst->Segments();
#endif
for (auto& segment : *segments) {
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);
@@ -47,14 +48,16 @@ taxonomy::ptr mapping::map_impl(const IfcSchema::IfcCompositeCurve* inst) {
e->orientation_2.reset(segment->as<IfcSchema::IfcCompositeCurveSegment>()->SameSense());
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());
if (crv) {
if (crv->kind() == taxonomy::EDGE) {
auto ecrv = taxonomy::cast<taxonomy::edge>(crv);
ecrv->orientation_2.reset(segment->as<IfcSchema::IfcCompositeCurveSegment>()->SameSense());
loop->children.push_back(ecrv);
} else if (crv->kind() == taxonomy::LOOP) {
}
else if (crv->kind() == taxonomy::LOOP) {
if (!segment->as<IfcSchema::IfcCompositeCurveSegment>()->SameSense()) {
crv->reverse();
}
@@ -66,31 +69,30 @@ taxonomy::ptr mapping::map_impl(const IfcSchema::IfcCompositeCurve* inst) {
}
#ifdef SCHEMA_HAS_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_as_loop = taxonomy::cast<taxonomy::loop>(crv);
// The end of the previous segment must be at the same location as the start of this segment
// @todo - need to apply some tolerancing
if (!loop->children.empty() and !crv_as_loop->children.empty()
and
boost::get<ifcopenshell::geometry::taxonomy::point3::ptr>(loop->children.back()->end)->components() != boost::get<ifcopenshell::geometry::taxonomy::point3::ptr>(crv_as_loop->children.front()->start)->components())
{
std::ostringstream os;
auto& prev = boost::get<ifcopenshell::geometry::taxonomy::point3::ptr>(loop->children.back()->end)->components();
auto& next = boost::get<ifcopenshell::geometry::taxonomy::point3::ptr>(crv_as_loop->children.front()->start)->components();
os << "Common points are not continuous: (" << prev.x() << ", " << prev.y() << ", " << prev.z() << ")" << " " << "(" << next.x() << ", " << next.y() << ", " << next.z() << ")" << std::endl;
Logger::Notice(os.str());
if (crv->kind() == taxonomy::LOOP) {
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());
}
loop->children.insert(loop->children.end(), crv_as_loop->children.begin(), crv_as_loop->children.end());
}
#endif
}
aggregate_of_instance::ptr profile = inst->data().getInverse(&IfcSchema::IfcProfileDef::Class(), -1);
const bool force_close = profile && profile->size() > 0;
loop->closed = force_close;
return loop;
if (pwf->spans.empty()) {
aggregate_of_instance::ptr profile = inst->data().getInverse(&IfcSchema::IfcProfileDef::Class(), -1);
const bool force_close = profile && profile->size() > 0;
loop->closed = force_close;
return loop;
}
else {
return pwf;
}
}
/*
@@ -110,7 +112,7 @@ taxonomy::ptr mapping::map_impl(const IfcSchema::IfcCompositeCurve* l, TopoDS_Wi
TopTools_ListOfShape converted_segments;
for (auto it = segments->begin(); it != segments->end(); ++it) {
if (!(*it)->declaration().is(IfcSchema::IfcCompositeCurveSegment::Class())) {
@@ -121,7 +123,7 @@ taxonomy::ptr mapping::map_impl(const IfcSchema::IfcCompositeCurve* l, TopoDS_Wi
IfcSchema::IfcCurve* curve = ((IfcSchema::IfcCompositeCurveSegment*)(*it))->ParentCurve();
// 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
// definitely does not make any sense.
TopoDS_Wire segment;
@@ -178,4 +180,4 @@ taxonomy::ptr mapping::map_impl(const IfcSchema::IfcCompositeCurve* l, TopoDS_Wi
return true;
}
*/
*/
+164 -124
View File
@@ -27,36 +27,11 @@ using namespace ifcopenshell::geometry;
#include <boost/mpl/vector.hpp>
#include <boost/mpl/for_each.hpp>
#include <boost/math/quadrature/trapezoidal.hpp>
// @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;
auto x1 = a;
auto f1 = fn(x1);
for (auto i = 1; i <= n; i++)
{
auto x2 = a + h * i;
auto f2 = fn(x2);
area += h * (f1 + f2) / 2.0;
x1 = x2;
f1 = f2;
}
return area;
}
}
// types of entities that can be IfcCurveSegment.ParentCurve
typedef boost::mpl::vector<
IfcSchema::IfcLine
#ifdef SCHEMA_HAS_IfcClothoid
@@ -69,40 +44,83 @@ typedef boost::mpl::vector<
, IfcSchema::IfcCircle
> curve_seg_types;
enum segment_type_t {
ST_HORIZONTAL, ST_VERTICAL, ST_CANT
};
class curve_segment_evaluator {
private:
mapping* mapping_;
double length_unit_;
double start_;
double length_;
segment_type_t segment_type_;
IfcSchema::IfcCurve* curve_;
std::optional<std::function<Eigen::Vector3d(double)>> eval_;
std::optional<std::function<Eigen::VectorXd(double)>> eval_;
public:
// First constructor, takes parameters from IfcCurveSegment
curve_segment_evaluator(mapping* mapping,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)
: mapping_(mapping)
, length_unit_(length_unit)
, segment_type_(segment_type)
, curve_(curve)
{
// @todo in IFC4X3_ADD2 this needs to be length measure
if (!st->as<IfcSchema::IfcLengthMeasure>() || !le->as<IfcSchema::IfcLengthMeasure>()) {
// @nb Parameter values are forbidden in the specification until parametrization is provided for all spirals
throw std::runtime_error("Unsupported curve measure type");
}
start_ = *st->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)
{
// 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 sign_s = binary_sign(start_);
auto sign_l = binary_sign(length_);
double L = 0;
if (sign_s == 0) L = fabs(length_); // start_ is at zero so length_ is the L
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
//const auto& transformation_matrix = taxonomy::cast<taxonomy::matrix4>(mapping_->map(s->Position()))->ccomponents();
auto transformation_matrix = taxonomy::cast<taxonomy::matrix4>(mapping_->map(s->Position()))->ccomponents();
eval_ = [L, transformation_matrix, signX, fnX, signY, fnY](double u) {
using boost::math::quadrature::trapezoidal;
// 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
auto a = 0.0;
auto b = fabs(u / L);
// @todo where to plug this in?
// auto n = 10; // use 10 steps in the numeric integration
auto x = signX(u) * trapezoidal(fnX, a, b);
auto y = signY(u) * trapezoidal(fnY, a, b);
// transform point into spiral'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;
};
}
// Clothoid using Taylor Series approximation
#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 = [](double v)->int {return v < 0 ? -1 : (0 < v ? 1 : 0); };
auto sign_s = sign(start_);
auto sign_l = sign(length_);
double L = 0;
@@ -114,81 +132,33 @@ public:
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);
}
//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 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) {
eval_ = [RL, transformation_matrix](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 x = 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(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)
{
// 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 sign_s = binary_sign(start_);
auto sign_l = binary_sign(length_);
double L = 0;
if (sign_s == 0) L = fabs(length_); // start_ is at zero so length_ is the L
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
//const auto& transformation_matrix = taxonomy::cast<taxonomy::matrix4>(mapping->map(s->Position()))->ccomponents();
auto transformation_matrix = taxonomy::cast<taxonomy::matrix4>(mapping->map(s->Position()))->ccomponents();
eval_ = [L, transformation_matrix, signX, fnX, signY, fnY](double u) {
// 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
auto a = 0.0;
auto b = fabs(u / L);
auto n = 10; // use 10 steps in the numeric integration
auto x = signX(u)*integrate(a, b, n, fnX);
auto y = signY(u)*integrate(a, b, n, fnY);
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);
return Eigen::Vector3d(result(0),result(1),result(2));
Eigen::VectorXd vec(4);
vec << result(0), result(1), 0.0, 1.0;
return vec;
};
}
#endif
// Clothoid using numerical integration
// Clothoid using numerical integration
//#ifdef SCHEMA_HAS_IfcClothoid
//// Then initialize Function(double) -> Vector3, by means of IfcCurve subtypes
// void operator()(IfcSchema::IfcClothoid* c) {
@@ -235,7 +205,7 @@ public:
auto fn_x = [theta](double t)->double {return cos(theta(t)); };
auto fn_y = [theta](double t)->double {return sin(theta(t)); };
set_spiral_functor(mapping_, 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
@@ -255,14 +225,14 @@ public:
// transform point into circle's coodinate system
auto result = transformation_matrix * Eigen::Vector4d(x, y, 0.0, 1.0);
return Eigen::Vector3d(result(0), result(1), result(2));
Eigen::VectorXd vec(4);
vec << result(0), result(1), 0.0, 1.0;
return vec;
};
}
void operator()(IfcSchema::IfcPolyline* pl)
{
auto points = taxonomy::cast<taxonomy::loop>(mapping_->map_impl(pl));
struct Range
{
double u_start;
@@ -273,23 +243,29 @@ public:
using Function = std::function<std::pair<double, double>(double u)>;
std::map<Range, Function> fns;
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 p = pl->Points();
if (p->size() < 2)
{
throw std::runtime_error("invalid polyline - must have at least 2 points"); // this should never happen, but just in case it does
}
auto iter = points->children.begin();
auto end = points->children.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 iter = p->begin();
auto end = p->end();
auto last = std::prev(end);
auto p1 = *(iter++);
auto u = 0.0;
for (; iter != end; iter++)
{
auto edge(*iter);
auto& start_point = boost::get<taxonomy::point3::ptr>(edge->start);
auto p1x = start_point->components_->x();
auto p1y = start_point->components_->y();
auto p2 = *iter;
auto& end_point = boost::get<taxonomy::point3::ptr>(edge->end);
auto p2x = end_point->components_->x();
auto p2y = end_point->components_->y();
auto p1x = p1->Coordinates()[0];
auto p1y = p1->Coordinates()[1];
auto p2x = p2->Coordinates()[0];
auto p2y = p2->Coordinates()[1];
auto dx = p2x - p1x;
auto dy = p2y - p1y;
@@ -307,6 +283,7 @@ public:
fns.insert(std::make_pair(Range{ u, u + l,iter == last ? end_compare : std_compare }, fn));
p1 = p2;
u = u + l;
}
@@ -316,12 +293,14 @@ public:
auto [u_start, u_end, compare] = fn.first;
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
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
return Eigen::Vector3d(x, y, 0);
auto [x, y] = (iter->second)(u - u_start); // (u - u_start) is distance from start of this segment of the polyline
Eigen::VectorXd vec(4);
vec << x, y, 0.0, 1.0;
return vec;
};
}
@@ -336,11 +315,27 @@ public:
auto dx = dr[0] / m;
auto dy = dr[1] / m;
eval_ = [px, py, dx, dy](double u) {
auto x = px + u * dx;
auto y = py + u * dy;
return Eigen::Vector3d(x, y, 0);
};
if (segment_type_ == ST_HORIZONTAL) {
eval_ = [px, py, dx, dy](double u) {
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;
};
}
}
// Take the boost::type value from mpl::for_each and test it against our curve instance
@@ -352,10 +347,11 @@ public:
}
// 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_) {
return (*eval_)((u + start_) * length_unit_);
} else {
}
else {
throw std::runtime_error(curve_->declaration().name() + " not implemented");
}
}
@@ -363,30 +359,73 @@ public:
double length() const {
return length_;
}
const std::optional<std::function<Eigen::VectorXd(double)>>& evaluation_function() const {
return eval_;
}
};
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
static int NUM_SEGMENTS = 64;
curve_segment_evaluator cse(this, length_unit_, inst->ParentCurve(), inst->SegmentStart(), inst->SegmentLength());
bool is_horizontal = false;
bool is_vertical = false;
bool is_cant = false;
{
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));
std::vector<taxonomy::point3::ptr> polygon;
auto fn = *cse.evaluation_function();
auto length = fabs(cse.length());
// @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();
auto transformation_matrix = taxonomy::cast<taxonomy::matrix4>(map(inst->Placement()))->ccomponents();
// @todo - is there a better way to deal with tolerance and "nearly zero" values?
auto fn_transformed = [fn, transformation_matrix](double u) {
return transformation_matrix * fn(u);
};
// @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();
if (0.001 < fabs(length))
{
for (int i = 0; i <= NUM_SEGMENTS; ++i) {
auto u = length * i / NUM_SEGMENTS;
auto p = cse(u);
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)));
@@ -394,6 +433,7 @@ taxonomy::ptr mapping::map_impl(const IfcSchema::IfcCurveSegment* inst) {
}
return polygon_from_points(polygon);
*/
}
#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) {
auto xy = horizontal->evaluate(u);
auto z = vertical->evaluate(u);
Eigen::VectorXd vec(3);
vec << xy(0), xy(1), z(0);
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.push_back({ min_length, composition });
return pwf;
}
#endif
+1 -3
View File
@@ -5,7 +5,7 @@
#define BIND(T) \
if (inst->as<IfcSchema::T>()) { \
try { \
taxonomy::ptr item = map_impl(inst->as<IfcSchema::T>()); \
item = map_impl(inst->as<IfcSchema::T>()); \
if (item != nullptr) { \
item->instance = inst; \
try { \
@@ -24,11 +24,9 @@
} else {\
Logger::Message(Logger::LOG_ERROR,"Failed to convert:", inst);\
} \
return item; \
} catch (const std::exception& e) { \
Logger::Message(Logger::LOG_ERROR, std::string(e.what()) + "\nFailed to convert:", inst); \
} \
return nullptr; \
}
#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) {
// 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"
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 {
+2
View File
@@ -22,6 +22,8 @@ namespace geometry {
double length_unit_, angle_unit_;
std::string length_unit_name_;
std::map<uint32_t, ifcopenshell::geometry::taxonomy::ptr> cache_;
const IfcParse::declaration* placement_rel_to_type_;
const IfcUtil::IfcBaseEntity* placement_rel_to_instance_;
+3
View File
@@ -113,6 +113,9 @@ BIND(IfcEdge);
BIND(IfcEdgeLoop);
BIND(IfcPolyline);
BIND(IfcPolyLoop);
#ifdef SCHEMA_HAS_IfcGradientCurve
BIND(IfcGradientCurve);
#endif
BIND(IfcCompositeCurve);
BIND(IfcTrimmedCurve);
BIND(IfcArbitraryOpenProfileDef);
+79 -41
View File
@@ -1,4 +1,5 @@
#include "taxonomy.h"
#include "profile_helper.h"
using namespace ifcopenshell::geometry::taxonomy;
@@ -23,9 +24,11 @@ namespace {
bool compare(const eigen_base<T>& t, const eigen_base<T>& u) {
if (t.components_ == nullptr && u.components_ == nullptr) {
return false;
} else if (t.components_ == nullptr && u.components_ != nullptr) {
}
else if (t.components_ == nullptr && u.components_ != nullptr) {
return true;
} else if (t.components_ != nullptr && u.components_ == nullptr) {
}
else if (t.components_ != nullptr && u.components_ == nullptr) {
return false;
}
@@ -86,11 +89,14 @@ namespace {
int less_to_order_optional(const boost::optional<T>& a, const boost::optional<T>& b) {
if (a && b) {
return less_to_order(*a, *b);
} else if (!a && !b) {
}
else if (!a && !b) {
return 0;
} else if (a) {
}
else if (a) {
return 1;
} else {
}
else {
return -1;
}
}
@@ -100,7 +106,8 @@ namespace {
if (a.which() == 0) {
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));
} else {
}
else {
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));
}
@@ -144,7 +151,11 @@ namespace {
bool compare(const surface_curve_sweep&, const surface_curve_sweep&) {
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) {
const int order[5] = {
less_to_order(a.name, b.name),
@@ -166,7 +177,8 @@ namespace {
auto A = static_cast<const type_by_kind::type<N>*>(a);
auto B = static_cast<const type_by_kind::type<N>*>(b);
return compare(*A, *B);
} else {
}
else {
return dispatch_comparison<N + 1>::dispatch(a, b);
}
}
@@ -223,23 +235,28 @@ namespace {
if (!a_has_basis) {
// Finally, equality
return false;
} else {
}
else {
return less(a.basis, b.basis);
}
} else {
}
else {
return a_has_basis < b_has_basis;
}
} else {
}
else {
return end_state == -1;
}
} else {
}
else {
return start_state == -1;
}
} else {
}
else {
return
std::tie(a.orientation, a_which_start, a_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).
return compare(*a.matrix, *b.matrix);
} else {
}
else {
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);
std::array<taxonomy::point3::ptr, 4> points{
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+dz),
taxonomy::make<taxonomy::point3>(x+0, y+0, z+dz)
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 + dz),
taxonomy::make<taxonomy::point3>(x + 0, y + 0, z + dz)
};
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);
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+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 + 0, z + 0),
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 + 0)
};
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);
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+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 + 0, y + 0, z + 0),
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 + 0)
};
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);
std::array<taxonomy::point3::ptr, 4> points{
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+dz),
taxonomy::make<taxonomy::point3>(x+ 0, y+dy, z+dz)
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 + dz),
taxonomy::make<taxonomy::point3>(x + 0, y + dy, z + dz)
};
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);
std::array<taxonomy::point3::ptr, 4> points{
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+dy, z+0),
taxonomy::make<taxonomy::point3>(x+ 0, y+dy, 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 + dy, z + 0),
taxonomy::make<taxonomy::point3>(x + 0, y + dy, z + 0)
};
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);
std::array<taxonomy::point3::ptr, 4> points{
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+dx, y+dy, z+dz),
taxonomy::make<taxonomy::point3>(x+dx, 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 + dx, y + dy, z + dz),
taxonomy::make<taxonomy::point3>(x + dx, y + 0, z + dz)
};
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;
}
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) {
auto flat = make<taxonomy::collection>();
ifcopenshell::geometry::visit<taxonomy::collection>(deep, [&flat](taxonomy::ptr i) {
flat->children.push_back(taxonomy::cast<taxonomy::geom_item>(clone(i)));
});
});
return flat;
}
@@ -446,10 +484,10 @@ const std::string& ifcopenshell::geometry::taxonomy::kind_to_string(kinds k) {
using namespace std::string_literals;
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];
}
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