mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-20 15:08:51 +00:00
Merge pull request #3826 from RickBrice/v0.8.0
Some minor tweaks and implements suggestions
This commit is contained in:
@@ -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);
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -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>());
|
||||||
|
if (crv->kind() == taxonomy::LOOP) {
|
||||||
for (auto& s : taxonomy::cast<taxonomy::loop>(crv)->children) {
|
for (auto& s : taxonomy::cast<taxonomy::loop>(crv)->children) {
|
||||||
loop->children.push_back(s);
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (pwf->spans.empty()) {
|
||||||
aggregate_of_instance::ptr profile = inst->data().getInverse(&IfcSchema::IfcProfileDef::Class(), -1);
|
aggregate_of_instance::ptr profile = inst->data().getInverse(&IfcSchema::IfcProfileDef::Class(), -1);
|
||||||
const bool force_close = profile && profile->size() > 0;
|
const bool force_close = profile && profile->size() > 0;
|
||||||
loop->closed = force_close;
|
loop->closed = force_close;
|
||||||
return loop;
|
return loop;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return pwf;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -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,21 +42,30 @@ 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
|
||||||
@@ -91,67 +79,7 @@ public:
|
|||||||
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
|
|
||||||
// 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(c->as<IfcSchema::IfcSpiral>(), sign_x, fn_x, sign_y, fn_y);
|
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 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 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();
|
||||||
@@ -360,8 +298,10 @@ public:
|
|||||||
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;
|
||||||
|
|
||||||
|
if (segment_type_ == ST_HORIZONTAL) {
|
||||||
|
|
||||||
eval_ = [px, py, dx, dy](double u) {
|
eval_ = [px, py, dx, dy](double u) {
|
||||||
auto x = px + u * dx;
|
auto x = px + u * dx;
|
||||||
auto y = py + u * dy;
|
auto y = py + u * dy;
|
||||||
return Eigen::Vector3d(x, y, 0);
|
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,23 +392,75 @@ 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;
|
||||||
|
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));
|
boost::mpl::for_each<curve_seg_types, boost::type<boost::mpl::_>>(std::ref(cse));
|
||||||
|
|
||||||
std::vector<taxonomy::point3::ptr> polygon;
|
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))
|
||||||
{
|
{
|
||||||
@@ -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
|
||||||
@@ -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
|
||||||
@@ -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"
|
||||||
|
|||||||
@@ -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"
|
||||||
|
|
||||||
|
if (item) {
|
||||||
|
cache_.insert({ iden, item });
|
||||||
|
}
|
||||||
|
else {
|
||||||
Logger::Message(Logger::LOG_ERROR, "No operation defined for:", inst);
|
Logger::Message(Logger::LOG_ERROR, "No operation defined for:", inst);
|
||||||
return nullptr;
|
}
|
||||||
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|||||||
@@ -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_;
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
+76
-38
@@ -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));
|
||||||
}
|
}
|
||||||
@@ -145,6 +152,10 @@ namespace {
|
|||||||
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,6 +452,26 @@ 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) {
|
||||||
@@ -446,7 +484,7 @@ 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];
|
||||||
|
|||||||
+215
-162
@@ -27,9 +27,9 @@
|
|||||||
|
|
||||||
namespace ifcopenshell {
|
namespace ifcopenshell {
|
||||||
|
|
||||||
namespace geometry {
|
namespace geometry {
|
||||||
|
|
||||||
namespace taxonomy {
|
namespace taxonomy {
|
||||||
|
|
||||||
#ifdef TAXONOMY_USE_SHARED_PTR
|
#ifdef TAXONOMY_USE_SHARED_PTR
|
||||||
template <typename T>
|
template <typename T>
|
||||||
@@ -80,22 +80,22 @@ typedef item* ptr; \
|
|||||||
typedef item const* ptr;
|
typedef item const* ptr;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
class topology_error : public std::runtime_error {
|
class topology_error : public std::runtime_error {
|
||||||
public:
|
public:
|
||||||
topology_error() : std::runtime_error("Generic topology error") {}
|
topology_error() : std::runtime_error("Generic topology error") {}
|
||||||
topology_error(const char* const s) : std::runtime_error(s) {}
|
topology_error(const char* const s) : std::runtime_error(s) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
enum kinds { MATRIX4, POINT3, DIRECTION3, LINE, CIRCLE, ELLIPSE, BSPLINE_CURVE, OFFSET_CURVE, PLANE, CYLINDER, BSPLINE_SURFACE, EDGE, LOOP, FACE, SHELL, SOLID, LOFT, EXTRUSION, REVOLVE, SURFACE_CURVE_SWEEP, NODE, COLLECTION, BOOLEAN_RESULT, COLOUR, STYLE };
|
enum kinds { MATRIX4, POINT3, DIRECTION3, LINE, CIRCLE, ELLIPSE, BSPLINE_CURVE, OFFSET_CURVE, PLANE, CYLINDER, BSPLINE_SURFACE, EDGE, LOOP, FACE, SHELL, SOLID, LOFT, EXTRUSION, REVOLVE, SURFACE_CURVE_SWEEP, NODE, COLLECTION, BOOLEAN_RESULT, PIECEWISE_FUNCTION, COLOUR, STYLE };
|
||||||
|
|
||||||
const std::string& kind_to_string(kinds k);
|
const std::string& kind_to_string(kinds k);
|
||||||
|
|
||||||
struct item {
|
struct item {
|
||||||
private:
|
private:
|
||||||
uint32_t identity_;
|
uint32_t identity_;
|
||||||
static std::atomic_uint32_t counter_;
|
static std::atomic_uint32_t counter_;
|
||||||
mutable size_t computed_hash_;
|
mutable size_t computed_hash_;
|
||||||
public:
|
public:
|
||||||
DECLARE_PTR(item)
|
DECLARE_PTR(item)
|
||||||
|
|
||||||
const IfcUtil::IfcBaseInterface* instance;
|
const IfcUtil::IfcBaseInterface* instance;
|
||||||
@@ -104,7 +104,7 @@ public:
|
|||||||
|
|
||||||
virtual item* clone_() const = 0;
|
virtual item* clone_() const = 0;
|
||||||
virtual kinds kind() const = 0;
|
virtual kinds kind() const = 0;
|
||||||
virtual void print(std::ostream&, int indent=0) const = 0;
|
virtual void print(std::ostream&, int indent = 0) const = 0;
|
||||||
virtual void reverse() { throw taxonomy::topology_error(); }
|
virtual void reverse() { throw taxonomy::topology_error(); }
|
||||||
virtual size_t calc_hash() const = 0;
|
virtual size_t calc_hash() const = 0;
|
||||||
virtual size_t hash() const {
|
virtual size_t hash() const {
|
||||||
@@ -123,43 +123,78 @@ public:
|
|||||||
virtual ~item() {}
|
virtual ~item() {}
|
||||||
|
|
||||||
uint32_t identity() const { return identity_; }
|
uint32_t identity() const { return identity_; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct implicit_item : public item {
|
||||||
|
DECLARE_PTR(implicit_item)
|
||||||
|
|
||||||
|
virtual item::ptr evaluate() const = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct piecewise_function : public implicit_item {
|
||||||
|
DECLARE_PTR(piecewise_function)
|
||||||
|
|
||||||
|
std::vector<std::pair<double, std::function<Eigen::VectorXd(double u)>>> spans;
|
||||||
|
|
||||||
|
void print(std::ostream& o, int indent = 0) const {
|
||||||
|
o << "piecewise_function" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual piecewise_function* clone_() const { return new piecewise_function(*this); }
|
||||||
|
virtual kinds kind() const { return PIECEWISE_FUNCTION; }
|
||||||
|
|
||||||
|
virtual size_t calc_hash() const {
|
||||||
|
auto v = std::make_tuple(static_cast<size_t>(PIECEWISE_FUNCTION), 0);
|
||||||
|
return boost::hash<decltype(v)>{}(v);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual item::ptr evaluate() const;
|
||||||
|
|
||||||
|
Eigen::VectorXd evaluate(double u) const {
|
||||||
|
// @todo optimize, assume monotonic evaluation and store last evaluated segment?
|
||||||
|
for (auto& [length, fn] : spans) {
|
||||||
|
if (u < length) {
|
||||||
|
return fn(u);
|
||||||
|
}
|
||||||
|
u -= length;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
#ifdef TAXONOMY_USE_SHARED_PTR
|
#ifdef TAXONOMY_USE_SHARED_PTR
|
||||||
typedef std::shared_ptr<item> ptr;
|
typedef std::shared_ptr<item> ptr;
|
||||||
typedef std::shared_ptr<const item> const_ptr;
|
typedef std::shared_ptr<const item> const_ptr;
|
||||||
template<typename T, typename... Args>
|
template<typename T, typename... Args>
|
||||||
std::shared_ptr<T> make(Args&&... args) {
|
std::shared_ptr<T> make(Args&&... args) {
|
||||||
return std::make_shared<T>(std::forward<Args>(args)...);
|
return std::make_shared<T>(std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef TAXONOMY_USE_UNIQUE_PTR
|
#ifdef TAXONOMY_USE_UNIQUE_PTR
|
||||||
typedef std::uniqe_ptr<item> ptr;
|
typedef std::uniqe_ptr<item> ptr;
|
||||||
typedef std::uniqe_ptr<const item> ptr;
|
typedef std::uniqe_ptr<const item> ptr;
|
||||||
template<typename T, typename... Args>
|
template<typename T, typename... Args>
|
||||||
std::uniqe_ptr<T> make(Args&&... args) {
|
std::uniqe_ptr<T> make(Args&&... args) {
|
||||||
return new T(std::forward<Args>(args)...));
|
return new T(std::forward<Args>(args)...));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef TAXONOMY_USE_NAKED_PTR
|
#ifdef TAXONOMY_USE_NAKED_PTR
|
||||||
typedef item* ptr;
|
typedef item* ptr;
|
||||||
typedef item const* ptr;
|
typedef item const* ptr;
|
||||||
template<typename T, typename... Args>
|
template<typename T, typename... Args>
|
||||||
T* make(Args&&... args) {
|
T* make(Args&&... args) {
|
||||||
return new T(std::forward<Args>(args)...));
|
return new T(std::forward<Args>(args)...));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool less(item::const_ptr, item::const_ptr);
|
bool less(item::const_ptr, item::const_ptr);
|
||||||
|
|
||||||
struct less_functor {
|
struct less_functor {
|
||||||
bool operator()(item::const_ptr a, item::const_ptr b) const {
|
bool operator()(item::const_ptr a, item::const_ptr b) const {
|
||||||
return less(a, b);
|
return less(a, b);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
const T& eigen_defaults();
|
const T& eigen_defaults();
|
||||||
@@ -176,10 +211,10 @@ namespace {
|
|||||||
return identity;
|
return identity;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct eigen_base {
|
struct eigen_base {
|
||||||
T* components_;
|
T* components_;
|
||||||
|
|
||||||
eigen_base() {
|
eigen_base() {
|
||||||
@@ -219,7 +254,8 @@ struct eigen_base {
|
|||||||
const T& ccomponents() const {
|
const T& ccomponents() const {
|
||||||
if (this->components_) {
|
if (this->components_) {
|
||||||
return *this->components_;
|
return *this->components_;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
return eigen_defaults<T>();
|
return eigen_defaults<T>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -246,10 +282,10 @@ struct eigen_base {
|
|||||||
}
|
}
|
||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct matrix4 : public item, public eigen_base<Eigen::Matrix4d> {
|
struct matrix4 : public item, public eigen_base<Eigen::Matrix4d> {
|
||||||
private:
|
private:
|
||||||
void init(const Eigen::Vector3d& o, const Eigen::Vector3d& z, const Eigen::Vector3d& x) {
|
void init(const Eigen::Vector3d& o, const Eigen::Vector3d& z, const Eigen::Vector3d& x) {
|
||||||
auto X = x.normalized();
|
auto X = x.normalized();
|
||||||
auto Y = z.cross(x).normalized();
|
auto Y = z.cross(x).normalized();
|
||||||
@@ -267,7 +303,7 @@ private:
|
|||||||
tag = IDENTITY;
|
tag = IDENTITY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public:
|
public:
|
||||||
DECLARE_PTR(matrix4)
|
DECLARE_PTR(matrix4)
|
||||||
|
|
||||||
enum tag_t {
|
enum tag_t {
|
||||||
@@ -306,9 +342,9 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
Eigen::Vector3d translation_part() const { return ccomponents().col(3).head<3>(); }
|
Eigen::Vector3d translation_part() const { return ccomponents().col(3).head<3>(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
struct colour : public item, public eigen_base<Eigen::Vector3d> {
|
struct colour : public item, public eigen_base<Eigen::Vector3d> {
|
||||||
DECLARE_PTR(colour)
|
DECLARE_PTR(colour)
|
||||||
|
|
||||||
void print(std::ostream& o, int indent = 0) const {
|
void print(std::ostream& o, int indent = 0) const {
|
||||||
@@ -329,9 +365,9 @@ struct colour : public item, public eigen_base<Eigen::Vector3d> {
|
|||||||
const double& r() const { return ccomponents()[0]; }
|
const double& r() const { return ccomponents()[0]; }
|
||||||
const double& g() const { return ccomponents()[1]; }
|
const double& g() const { return ccomponents()[1]; }
|
||||||
const double& b() const { return ccomponents()[2]; }
|
const double& b() const { return ccomponents()[2]; }
|
||||||
};
|
};
|
||||||
|
|
||||||
struct style : public item {
|
struct style : public item {
|
||||||
DECLARE_PTR(style)
|
DECLARE_PTR(style)
|
||||||
|
|
||||||
std::string name;
|
std::string name;
|
||||||
@@ -374,9 +410,9 @@ struct style : public item {
|
|||||||
bool has_transparency() const {
|
bool has_transparency() const {
|
||||||
return !std::isnan(transparency);
|
return !std::isnan(transparency);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct geom_item : public item {
|
struct geom_item : public item {
|
||||||
DECLARE_PTR(geom_item)
|
DECLARE_PTR(geom_item)
|
||||||
|
|
||||||
style::ptr surface_style;
|
style::ptr surface_style;
|
||||||
@@ -385,16 +421,16 @@ struct geom_item : public item {
|
|||||||
geom_item(const IfcUtil::IfcBaseClass* instance = nullptr) : item(instance), surface_style(nullptr) {}
|
geom_item(const IfcUtil::IfcBaseClass* instance = nullptr) : item(instance), surface_style(nullptr) {}
|
||||||
geom_item(const IfcUtil::IfcBaseClass* instance, matrix4::ptr m) : item(instance), surface_style(nullptr), matrix(m) {}
|
geom_item(const IfcUtil::IfcBaseClass* instance, matrix4::ptr m) : item(instance), surface_style(nullptr), matrix(m) {}
|
||||||
geom_item(matrix4::ptr m) : surface_style(nullptr), matrix(m) {}
|
geom_item(matrix4::ptr m) : surface_style(nullptr), matrix(m) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
// @todo make 4d for easier multiplication
|
// @todo make 4d for easier multiplication
|
||||||
template <size_t N>
|
template <size_t N>
|
||||||
struct cartesian_base : public item, public eigen_base<Eigen::Vector3d> {
|
struct cartesian_base : public item, public eigen_base<Eigen::Vector3d> {
|
||||||
cartesian_base() : eigen_base() {}
|
cartesian_base() : eigen_base() {}
|
||||||
cartesian_base(double x, double y, double z = 0.) : eigen_base(Eigen::Vector3d(x, y, z)) {}
|
cartesian_base(double x, double y, double z = 0.) : eigen_base(Eigen::Vector3d(x, y, z)) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct point3 : public cartesian_base<3> {
|
struct point3 : public cartesian_base<3> {
|
||||||
DECLARE_PTR(point3)
|
DECLARE_PTR(point3)
|
||||||
|
|
||||||
virtual point3* clone_() const { return new point3(*this); }
|
virtual point3* clone_() const { return new point3(*this); }
|
||||||
@@ -411,9 +447,9 @@ struct point3 : public cartesian_base<3> {
|
|||||||
|
|
||||||
point3() : cartesian_base() {}
|
point3() : cartesian_base() {}
|
||||||
point3(double x, double y, double z = 0.) : cartesian_base(x, y, z) {}
|
point3(double x, double y, double z = 0.) : cartesian_base(x, y, z) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct direction3 : public cartesian_base<3> {
|
struct direction3 : public cartesian_base<3> {
|
||||||
DECLARE_PTR(direction3)
|
DECLARE_PTR(direction3)
|
||||||
|
|
||||||
virtual direction3* clone_() const { return new direction3(*this); }
|
virtual direction3* clone_() const { return new direction3(*this); }
|
||||||
@@ -430,16 +466,16 @@ struct direction3 : public cartesian_base<3> {
|
|||||||
|
|
||||||
direction3() : cartesian_base() {}
|
direction3() : cartesian_base() {}
|
||||||
direction3(double x, double y, double z = 0.) : cartesian_base(x, y, z) {}
|
direction3(double x, double y, double z = 0.) : cartesian_base(x, y, z) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct curve : public geom_item {
|
struct curve : public geom_item {
|
||||||
void print_impl(std::ostream& o, const std::string& classname, int indent = 0) const {
|
void print_impl(std::ostream& o, const std::string& classname, int indent = 0) const {
|
||||||
o << std::string(indent, ' ') << classname << std::endl;
|
o << std::string(indent, ' ') << classname << std::endl;
|
||||||
this->matrix->print(o, indent + 4);
|
this->matrix->print(o, indent + 4);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct line : public curve {
|
struct line : public curve {
|
||||||
DECLARE_PTR(line)
|
DECLARE_PTR(line)
|
||||||
|
|
||||||
virtual line* clone_() const { return new line(*this); }
|
virtual line* clone_() const { return new line(*this); }
|
||||||
@@ -453,9 +489,9 @@ struct line : public curve {
|
|||||||
void print(std::ostream& o, int indent = 0) const {
|
void print(std::ostream& o, int indent = 0) const {
|
||||||
print_impl(o, "line", indent);
|
print_impl(o, "line", indent);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct circle : public curve {
|
struct circle : public curve {
|
||||||
DECLARE_PTR(circle)
|
DECLARE_PTR(circle)
|
||||||
|
|
||||||
double radius;
|
double radius;
|
||||||
@@ -499,9 +535,9 @@ struct circle : public curve {
|
|||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ellipse : public circle {
|
struct ellipse : public circle {
|
||||||
DECLARE_PTR(ellipse)
|
DECLARE_PTR(ellipse)
|
||||||
|
|
||||||
double radius2;
|
double radius2;
|
||||||
@@ -517,9 +553,9 @@ struct ellipse : public circle {
|
|||||||
void print(std::ostream& o, int indent = 0) const {
|
void print(std::ostream& o, int indent = 0) const {
|
||||||
print_impl(o, "ellipse", indent);
|
print_impl(o, "ellipse", indent);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct bspline_curve : public curve {
|
struct bspline_curve : public curve {
|
||||||
DECLARE_PTR(bspline_curve)
|
DECLARE_PTR(bspline_curve)
|
||||||
|
|
||||||
virtual bspline_curve* clone_() const { return new bspline_curve(*this); }
|
virtual bspline_curve* clone_() const { return new bspline_curve(*this); }
|
||||||
@@ -554,9 +590,9 @@ struct bspline_curve : public curve {
|
|||||||
void print(std::ostream& o, int indent = 0) const {
|
void print(std::ostream& o, int indent = 0) const {
|
||||||
o << std::string(indent, ' ') << "bspline curve" << std::endl;
|
o << std::string(indent, ' ') << "bspline curve" << std::endl;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct offset_curve : public curve {
|
struct offset_curve : public curve {
|
||||||
DECLARE_PTR(offset_curve)
|
DECLARE_PTR(offset_curve)
|
||||||
|
|
||||||
direction3::ptr reference;
|
direction3::ptr reference;
|
||||||
@@ -574,9 +610,9 @@ struct offset_curve : public curve {
|
|||||||
void print(std::ostream& o, int indent = 0) const {
|
void print(std::ostream& o, int indent = 0) const {
|
||||||
o << std::string(indent, ' ') << "offset_curve" << std::endl;
|
o << std::string(indent, ' ') << "offset_curve" << std::endl;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct trimmed_curve : public item {
|
struct trimmed_curve : public item {
|
||||||
DECLARE_PTR(trimmed_curve)
|
DECLARE_PTR(trimmed_curve)
|
||||||
|
|
||||||
// @todo The copy constructor of point3 within the variant fails on the avx instruction
|
// @todo The copy constructor of point3 within the variant fails on the avx instruction
|
||||||
@@ -603,12 +639,13 @@ struct trimmed_curve : public item {
|
|||||||
basis->print(o, indent + 4);
|
basis->print(o, indent + 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
const boost::variant<point3::ptr, double> * const start_end[2] = { &start, &end };
|
const boost::variant<point3::ptr, double>* const start_end[2] = { &start, &end };
|
||||||
for (int i = 0; i < 2; ++i) {
|
for (int i = 0; i < 2; ++i) {
|
||||||
o << std::string(indent + 4, ' ') << (i == 0 ? "start" : "end") << std::endl;
|
o << std::string(indent + 4, ' ') << (i == 0 ? "start" : "end") << std::endl;
|
||||||
if (start_end[i]->which() == 0) {
|
if (start_end[i]->which() == 0) {
|
||||||
boost::get<point3::ptr>(*start_end[i])->print(o, indent + 4);
|
boost::get<point3::ptr>(*start_end[i])->print(o, indent + 4);
|
||||||
} else if (start_end[i]->which() == 1) {
|
}
|
||||||
|
else if (start_end[i]->which() == 1) {
|
||||||
o << std::string(indent + 4, ' ') << "parameter " << boost::get<double>(*start_end[i]) << std::endl;
|
o << std::string(indent + 4, ' ') << "parameter " << boost::get<double>(*start_end[i]) << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -617,9 +654,9 @@ struct trimmed_curve : public item {
|
|||||||
o << std::string(indent, ' ') << this->instance->data().toString() << std::endl;
|
o << std::string(indent, ' ') << this->instance->data().toString() << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct edge : public trimmed_curve {
|
struct edge : public trimmed_curve {
|
||||||
DECLARE_PTR(edge)
|
DECLARE_PTR(edge)
|
||||||
|
|
||||||
edge() : trimmed_curve() {}
|
edge() : trimmed_curve() {}
|
||||||
@@ -633,10 +670,10 @@ struct edge : public trimmed_curve {
|
|||||||
auto v = std::make_tuple(static_cast<size_t>(EDGE), start, end, basis ? basis->hash() : size_t(0), orientation_2 ? *orientation_2 ? 2 : 1 : 0);
|
auto v = std::make_tuple(static_cast<size_t>(EDGE), start, end, basis ? basis->hash() : size_t(0), orientation_2 ? *orientation_2 ? 2 : 1 : 0);
|
||||||
return boost::hash<decltype(v)>{}(v);
|
return boost::hash<decltype(v)>{}(v);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T=item>
|
template <typename T = item>
|
||||||
struct collection_base : public geom_item {
|
struct collection_base : public geom_item {
|
||||||
std::vector<typename T::ptr> children;
|
std::vector<typename T::ptr> children;
|
||||||
|
|
||||||
collection_base() {}
|
collection_base() {}
|
||||||
@@ -692,9 +729,9 @@ struct collection_base : public geom_item {
|
|||||||
}
|
}
|
||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct collection : public collection_base<geom_item> {
|
struct collection : public collection_base<geom_item> {
|
||||||
DECLARE_PTR(collection)
|
DECLARE_PTR(collection)
|
||||||
|
|
||||||
virtual collection* clone_() const { return new collection(*this); }
|
virtual collection* clone_() const { return new collection(*this); }
|
||||||
@@ -704,10 +741,10 @@ struct collection : public collection_base<geom_item> {
|
|||||||
auto v = std::make_tuple(static_cast<size_t>(COLLECTION), hash_elements());
|
auto v = std::make_tuple(static_cast<size_t>(COLLECTION), hash_elements());
|
||||||
return boost::hash<decltype(v)>{}(v);
|
return boost::hash<decltype(v)>{}(v);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
struct loop : public collection_base<edge> {
|
struct loop : public collection_base<edge> {
|
||||||
DECLARE_PTR(loop)
|
DECLARE_PTR(loop)
|
||||||
|
|
||||||
boost::optional<bool> external, closed;
|
boost::optional<bool> external, closed;
|
||||||
@@ -730,9 +767,9 @@ struct loop : public collection_base<edge> {
|
|||||||
auto v = std::make_tuple(static_cast<size_t>(LOOP), hash_elements(), external ? *external ? 2 : 1 : 0, closed ? *closed ? 2 : 1 : 0);
|
auto v = std::make_tuple(static_cast<size_t>(LOOP), hash_elements(), external ? *external ? 2 : 1 : 0, closed ? *closed ? 2 : 1 : 0);
|
||||||
return boost::hash<decltype(v)>{}(v);
|
return boost::hash<decltype(v)>{}(v);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct face : public collection_base<loop> {
|
struct face : public collection_base<loop> {
|
||||||
DECLARE_PTR(face)
|
DECLARE_PTR(face)
|
||||||
|
|
||||||
item::ptr basis;
|
item::ptr basis;
|
||||||
@@ -744,9 +781,9 @@ struct face : public collection_base<loop> {
|
|||||||
auto v = std::make_tuple(static_cast<size_t>(FACE), hash_elements(), basis ? basis->hash() : size_t(0));
|
auto v = std::make_tuple(static_cast<size_t>(FACE), hash_elements(), basis ? basis->hash() : size_t(0));
|
||||||
return boost::hash<decltype(v)>{}(v);
|
return boost::hash<decltype(v)>{}(v);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct shell : public collection_base<face> {
|
struct shell : public collection_base<face> {
|
||||||
DECLARE_PTR(shell)
|
DECLARE_PTR(shell)
|
||||||
|
|
||||||
boost::optional<bool> closed;
|
boost::optional<bool> closed;
|
||||||
@@ -758,9 +795,9 @@ struct shell : public collection_base<face> {
|
|||||||
auto v = std::make_tuple(static_cast<size_t>(SHELL), hash_elements(), closed ? *closed ? 2 : 1 : 0);
|
auto v = std::make_tuple(static_cast<size_t>(SHELL), hash_elements(), closed ? *closed ? 2 : 1 : 0);
|
||||||
return boost::hash<decltype(v)>{}(v);
|
return boost::hash<decltype(v)>{}(v);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct solid : public collection_base<shell> {
|
struct solid : public collection_base<shell> {
|
||||||
DECLARE_PTR(solid)
|
DECLARE_PTR(solid)
|
||||||
|
|
||||||
virtual solid* clone_() const { return new solid(*this); }
|
virtual solid* clone_() const { return new solid(*this); }
|
||||||
@@ -770,9 +807,9 @@ struct solid : public collection_base<shell> {
|
|||||||
auto v = std::make_tuple(static_cast<size_t>(SOLID), hash_elements());
|
auto v = std::make_tuple(static_cast<size_t>(SOLID), hash_elements());
|
||||||
return boost::hash<decltype(v)>{}(v);
|
return boost::hash<decltype(v)>{}(v);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct loft : public collection_base<face> {
|
struct loft : public collection_base<face> {
|
||||||
DECLARE_PTR(loft)
|
DECLARE_PTR(loft)
|
||||||
|
|
||||||
item::ptr axis;
|
item::ptr axis;
|
||||||
@@ -784,11 +821,11 @@ struct loft : public collection_base<face> {
|
|||||||
auto v = std::make_tuple(static_cast<size_t>(LOFT), hash_elements(), axis ? axis->hash() : size_t(0));
|
auto v = std::make_tuple(static_cast<size_t>(LOFT), hash_elements(), axis ? axis->hash() : size_t(0));
|
||||||
return boost::hash<decltype(v)>{}(v);
|
return boost::hash<decltype(v)>{}(v);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct surface : public geom_item {};
|
struct surface : public geom_item {};
|
||||||
|
|
||||||
struct plane : public surface {
|
struct plane : public surface {
|
||||||
DECLARE_PTR(plane)
|
DECLARE_PTR(plane)
|
||||||
|
|
||||||
virtual plane* clone_() const { return new plane(*this); }
|
virtual plane* clone_() const { return new plane(*this); }
|
||||||
@@ -802,9 +839,9 @@ struct plane : public surface {
|
|||||||
auto v = std::make_tuple(static_cast<size_t>(PLANE), matrix->hash_components());
|
auto v = std::make_tuple(static_cast<size_t>(PLANE), matrix->hash_components());
|
||||||
return boost::hash<decltype(v)>{}(v);
|
return boost::hash<decltype(v)>{}(v);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct cylinder : public surface {
|
struct cylinder : public surface {
|
||||||
DECLARE_PTR(cylinder)
|
DECLARE_PTR(cylinder)
|
||||||
|
|
||||||
double radius;
|
double radius;
|
||||||
@@ -819,9 +856,9 @@ struct cylinder : public surface {
|
|||||||
auto v = std::make_tuple(static_cast<size_t>(CYLINDER), matrix->hash_components());
|
auto v = std::make_tuple(static_cast<size_t>(CYLINDER), matrix->hash_components());
|
||||||
return boost::hash<decltype(v)>{}(v);
|
return boost::hash<decltype(v)>{}(v);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct bspline_surface : public surface {
|
struct bspline_surface : public surface {
|
||||||
DECLARE_PTR(bspline_surface)
|
DECLARE_PTR(bspline_surface)
|
||||||
|
|
||||||
virtual bspline_surface* clone_() const { return new bspline_surface(*this); }
|
virtual bspline_surface* clone_() const { return new bspline_surface(*this); }
|
||||||
@@ -866,18 +903,18 @@ struct bspline_surface : public surface {
|
|||||||
void print(std::ostream& o, int) const {
|
void print(std::ostream& o, int) const {
|
||||||
o << "not implemented";
|
o << "not implemented";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct sweep : public geom_item {
|
struct sweep : public geom_item {
|
||||||
DECLARE_PTR(sweep)
|
DECLARE_PTR(sweep)
|
||||||
|
|
||||||
face::ptr basis;
|
face::ptr basis;
|
||||||
|
|
||||||
sweep(face::ptr b) : basis(b) {}
|
sweep(face::ptr b) : basis(b) {}
|
||||||
sweep(matrix4::ptr m, face::ptr b) : geom_item(m), basis(b) {}
|
sweep(matrix4::ptr m, face::ptr b) : geom_item(m), basis(b) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct extrusion : public sweep {
|
struct extrusion : public sweep {
|
||||||
DECLARE_PTR(extrusion)
|
DECLARE_PTR(extrusion)
|
||||||
|
|
||||||
direction3::ptr direction;
|
direction3::ptr direction;
|
||||||
@@ -898,9 +935,9 @@ struct extrusion : public sweep {
|
|||||||
auto v = std::make_tuple(static_cast<size_t>(EXTRUSION), matrix->hash_components(), basis->calc_hash(), direction->hash_components(), depth);
|
auto v = std::make_tuple(static_cast<size_t>(EXTRUSION), matrix->hash_components(), basis->calc_hash(), direction->hash_components(), depth);
|
||||||
return boost::hash<decltype(v)>{}(v);
|
return boost::hash<decltype(v)>{}(v);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct revolve : public sweep {
|
struct revolve : public sweep {
|
||||||
DECLARE_PTR(revolve)
|
DECLARE_PTR(revolve)
|
||||||
|
|
||||||
point3::ptr axis_origin;
|
point3::ptr axis_origin;
|
||||||
@@ -920,9 +957,9 @@ struct revolve : public sweep {
|
|||||||
auto v = std::make_tuple(static_cast<size_t>(REVOLVE), matrix->hash_components(), basis->calc_hash(), axis_origin->hash_components(), direction->hash_components(), angle ? *angle : 1000.);
|
auto v = std::make_tuple(static_cast<size_t>(REVOLVE), matrix->hash_components(), basis->calc_hash(), axis_origin->hash_components(), direction->hash_components(), angle ? *angle : 1000.);
|
||||||
return boost::hash<decltype(v)>{}(v);
|
return boost::hash<decltype(v)>{}(v);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct surface_curve_sweep : public sweep {
|
struct surface_curve_sweep : public sweep {
|
||||||
DECLARE_PTR(surface_curve_sweep)
|
DECLARE_PTR(surface_curve_sweep)
|
||||||
|
|
||||||
item::ptr surface;
|
item::ptr surface;
|
||||||
@@ -941,9 +978,9 @@ struct surface_curve_sweep : public sweep {
|
|||||||
auto v = std::make_tuple(static_cast<size_t>(SURFACE_CURVE_SWEEP), matrix->hash_components(), basis->calc_hash(), surface->calc_hash(), curve->calc_hash());
|
auto v = std::make_tuple(static_cast<size_t>(SURFACE_CURVE_SWEEP), matrix->hash_components(), basis->calc_hash(), surface->calc_hash(), curve->calc_hash());
|
||||||
return boost::hash<decltype(v)>{}(v);
|
return boost::hash<decltype(v)>{}(v);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct node : public item {
|
struct node : public item {
|
||||||
DECLARE_PTR(node)
|
DECLARE_PTR(node)
|
||||||
|
|
||||||
// std::map<std::string, geom_item> representations;
|
// std::map<std::string, geom_item> representations;
|
||||||
@@ -957,9 +994,9 @@ struct node : public item {
|
|||||||
auto v = std::make_tuple(static_cast<size_t>(NODE));
|
auto v = std::make_tuple(static_cast<size_t>(NODE));
|
||||||
return boost::hash<decltype(v)>{}(v);
|
return boost::hash<decltype(v)>{}(v);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct boolean_result : public collection_base<geom_item> {
|
struct boolean_result : public collection_base<geom_item> {
|
||||||
DECLARE_PTR(boolean_result)
|
DECLARE_PTR(boolean_result)
|
||||||
|
|
||||||
enum operation_t {
|
enum operation_t {
|
||||||
@@ -980,39 +1017,39 @@ struct boolean_result : public collection_base<geom_item> {
|
|||||||
auto v = std::make_tuple(static_cast<size_t>(BOOLEAN_RESULT), hash_elements(), static_cast<size_t>(operation));
|
auto v = std::make_tuple(static_cast<size_t>(BOOLEAN_RESULT), hash_elements(), static_cast<size_t>(operation));
|
||||||
return boost::hash<decltype(v)>{}(v);
|
return boost::hash<decltype(v)>{}(v);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace impl {
|
namespace impl {
|
||||||
typedef std::tuple<matrix4, point3, direction3, line, circle, ellipse, bspline_curve, offset_curve, plane, cylinder, bspline_surface, edge, loop, face, shell, solid, loft, extrusion, revolve, surface_curve_sweep, node, collection, boolean_result> KindsTuple;
|
typedef std::tuple<matrix4, point3, direction3, line, circle, ellipse, bspline_curve, offset_curve, plane, cylinder, bspline_surface, edge, loop, face, shell, solid, loft, extrusion, revolve, surface_curve_sweep, node, collection, boolean_result, piecewise_function> KindsTuple;
|
||||||
typedef std::tuple<line, circle, ellipse, bspline_curve, offset_curve, loop, edge> CurvesTuple;
|
typedef std::tuple<line, circle, ellipse, bspline_curve, offset_curve, loop, edge> CurvesTuple;
|
||||||
typedef std::tuple<plane, cylinder, bspline_surface> SurfacesTuple;
|
typedef std::tuple<plane, cylinder, bspline_surface> SurfacesTuple;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct type_by_kind {
|
struct type_by_kind {
|
||||||
template <std::size_t N>
|
template <std::size_t N>
|
||||||
using type = typename std::tuple_element<N, impl::KindsTuple>::type;
|
using type = typename std::tuple_element<N, impl::KindsTuple>::type;
|
||||||
|
|
||||||
static const size_t max = std::tuple_size<impl::KindsTuple>::value;
|
static const size_t max = std::tuple_size<impl::KindsTuple>::value;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct curves {
|
struct curves {
|
||||||
template <std::size_t N>
|
template <std::size_t N>
|
||||||
using type = typename std::tuple_element<N, impl::CurvesTuple>::type;
|
using type = typename std::tuple_element<N, impl::CurvesTuple>::type;
|
||||||
|
|
||||||
static const size_t max = std::tuple_size<impl::CurvesTuple>::value;
|
static const size_t max = std::tuple_size<impl::CurvesTuple>::value;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct surfaces {
|
struct surfaces {
|
||||||
template <std::size_t N>
|
template <std::size_t N>
|
||||||
using type = typename std::tuple_element<N, impl::SurfacesTuple>::type;
|
using type = typename std::tuple_element<N, impl::SurfacesTuple>::type;
|
||||||
|
|
||||||
static const size_t max = std::tuple_size<impl::SurfacesTuple>::value;
|
static const size_t max = std::tuple_size<impl::SurfacesTuple>::value;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Hacks around not wanting to use if constexpr
|
// Hacks around not wanting to use if constexpr
|
||||||
template <typename T>
|
template <typename T>
|
||||||
class loop_to_face_upgrade {
|
class loop_to_face_upgrade {
|
||||||
public:
|
public:
|
||||||
loop_to_face_upgrade(taxonomy::ptr) {}
|
loop_to_face_upgrade(taxonomy::ptr) {}
|
||||||
|
|
||||||
operator bool() const {
|
operator bool() const {
|
||||||
@@ -1026,13 +1063,13 @@ public:
|
|||||||
operator typename T::ptr() const {
|
operator typename T::ptr() const {
|
||||||
throw taxonomy::topology_error();
|
throw taxonomy::topology_error();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
class loop_to_face_upgrade<taxonomy::face> {
|
class loop_to_face_upgrade<taxonomy::face> {
|
||||||
private:
|
private:
|
||||||
boost::optional<taxonomy::face::ptr> face_;
|
boost::optional<taxonomy::face::ptr> face_;
|
||||||
public:
|
public:
|
||||||
loop_to_face_upgrade(taxonomy::ptr item) {
|
loop_to_face_upgrade(taxonomy::ptr item) {
|
||||||
auto loop = taxonomy::dcast<taxonomy::loop>(item);
|
auto loop = taxonomy::dcast<taxonomy::loop>(item);
|
||||||
if (loop) {
|
if (loop) {
|
||||||
@@ -1052,65 +1089,65 @@ public:
|
|||||||
operator taxonomy::face::ptr() const {
|
operator taxonomy::face::ptr() const {
|
||||||
return *face_;
|
return *face_;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#ifdef TAXONOMY_USE_SHARED_PTR
|
#ifdef TAXONOMY_USE_SHARED_PTR
|
||||||
template <typename T, typename U>
|
template <typename T, typename U>
|
||||||
std::shared_ptr<T> cast(const std::shared_ptr<U>& u) {
|
std::shared_ptr<T> cast(const std::shared_ptr<U>& u) {
|
||||||
loop_to_face_upgrade<T> upg(u);
|
loop_to_face_upgrade<T> upg(u);
|
||||||
if (upg) {
|
if (upg) {
|
||||||
return upg;
|
return upg;
|
||||||
}
|
}
|
||||||
return std::static_pointer_cast<T>(u);
|
return std::static_pointer_cast<T>(u);
|
||||||
}
|
}
|
||||||
template <typename T, typename U>
|
template <typename T, typename U>
|
||||||
std::shared_ptr<T> dcast(const std::shared_ptr<U>& u) {
|
std::shared_ptr<T> dcast(const std::shared_ptr<U>& u) {
|
||||||
loop_to_face_upgrade<T> upg(u);
|
loop_to_face_upgrade<T> upg(u);
|
||||||
if (upg) {
|
if (upg) {
|
||||||
return upg;
|
return upg;
|
||||||
}
|
}
|
||||||
return std::dynamic_pointer_cast<T>(u);
|
return std::dynamic_pointer_cast<T>(u);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef TAXONOMY_USE_UNIQUE_PTR
|
#ifdef TAXONOMY_USE_UNIQUE_PTR
|
||||||
template <typename T, typename U>
|
template <typename T, typename U>
|
||||||
T* cast(const std::unique_ptr<U>& u) {
|
T* cast(const std::unique_ptr<U>& u) {
|
||||||
loop_to_face_upgrade<T> upg(u);
|
loop_to_face_upgrade<T> upg(u);
|
||||||
if (upg) {
|
if (upg) {
|
||||||
return upg;
|
return upg;
|
||||||
}
|
}
|
||||||
return static_cast<T*>(&*u);
|
return static_cast<T*>(&*u);
|
||||||
}
|
}
|
||||||
template <typename T, typename U>
|
template <typename T, typename U>
|
||||||
T* dcast(const std::unique_ptr<U>& u) {
|
T* dcast(const std::unique_ptr<U>& u) {
|
||||||
loop_to_face_upgrade<T> upg(u);
|
loop_to_face_upgrade<T> upg(u);
|
||||||
if (upg) {
|
if (upg) {
|
||||||
return upg;
|
return upg;
|
||||||
}
|
}
|
||||||
return dynamic_cast<T*>(&*u);
|
return dynamic_cast<T*>(&*u);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef TAXONOMY_USE_NAKED_PTR
|
#ifdef TAXONOMY_USE_NAKED_PTR
|
||||||
template <typename T, typename U>
|
template <typename T, typename U>
|
||||||
T* cast(const U*& u) {
|
T* cast(const U*& u) {
|
||||||
loop_to_face_upgrade<T> upg(u);
|
loop_to_face_upgrade<T> upg(u);
|
||||||
if (upg) {
|
if (upg) {
|
||||||
return upg;
|
return upg;
|
||||||
}
|
}
|
||||||
return std::static_cast<T*>(u);
|
return std::static_cast<T*>(u);
|
||||||
}
|
}
|
||||||
template <typename T, typename U>
|
template <typename T, typename U>
|
||||||
T* dcast(const U*& u) {
|
T* dcast(const U*& u) {
|
||||||
loop_to_face_upgrade<T> upg(u);
|
loop_to_face_upgrade<T> upg(u);
|
||||||
if (upg) {
|
if (upg) {
|
||||||
return upg;
|
return upg;
|
||||||
}
|
}
|
||||||
return std::dynamic_cast<T*>(u);
|
return std::dynamic_cast<T*>(u);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename U, typename Fn>
|
template <typename U, typename Fn>
|
||||||
void visit(typename U::ptr deep, Fn fn) {
|
void visit(typename U::ptr deep, Fn fn) {
|
||||||
@@ -1119,19 +1156,26 @@ T* dcast(const U*& u) {
|
|||||||
// we can't generally use collection_base anymore as a cast target.
|
// we can't generally use collection_base anymore as a cast target.
|
||||||
if (auto s = taxonomy::dcast<taxonomy::collection>(i)) {
|
if (auto s = taxonomy::dcast<taxonomy::collection>(i)) {
|
||||||
visit<taxonomy::collection>(s, fn);
|
visit<taxonomy::collection>(s, fn);
|
||||||
} else if (auto s = taxonomy::dcast<taxonomy::loop>(i)) {
|
}
|
||||||
|
else if (auto s = taxonomy::dcast<taxonomy::loop>(i)) {
|
||||||
visit<taxonomy::loop>(s, fn);
|
visit<taxonomy::loop>(s, fn);
|
||||||
} else if (auto s = taxonomy::dcast<taxonomy::face>(i)) {
|
}
|
||||||
|
else if (auto s = taxonomy::dcast<taxonomy::face>(i)) {
|
||||||
visit<taxonomy::face>(s, fn);
|
visit<taxonomy::face>(s, fn);
|
||||||
} else if (auto s = taxonomy::dcast<taxonomy::shell>(i)) {
|
}
|
||||||
|
else if (auto s = taxonomy::dcast<taxonomy::shell>(i)) {
|
||||||
visit<taxonomy::shell>(s, fn);
|
visit<taxonomy::shell>(s, fn);
|
||||||
} else if (auto s = taxonomy::dcast<taxonomy::solid>(i)) {
|
}
|
||||||
|
else if (auto s = taxonomy::dcast<taxonomy::solid>(i)) {
|
||||||
visit<taxonomy::solid>(s, fn);
|
visit<taxonomy::solid>(s, fn);
|
||||||
} else if (auto s = taxonomy::dcast<taxonomy::loft>(i)) {
|
}
|
||||||
|
else if (auto s = taxonomy::dcast<taxonomy::loft>(i)) {
|
||||||
visit<taxonomy::loft>(s, fn);
|
visit<taxonomy::loft>(s, fn);
|
||||||
} else if (auto s = taxonomy::dcast<taxonomy::boolean_result>(i)) {
|
}
|
||||||
|
else if (auto s = taxonomy::dcast<taxonomy::boolean_result>(i)) {
|
||||||
visit<taxonomy::boolean_result>(s, fn);
|
visit<taxonomy::boolean_result>(s, fn);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
fn(i);
|
fn(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1145,21 +1189,29 @@ T* dcast(const U*& u) {
|
|||||||
// we can't generally use collection_base anymore as a cast target.
|
// we can't generally use collection_base anymore as a cast target.
|
||||||
if (auto s = taxonomy::dcast<taxonomy::collection>(i)) {
|
if (auto s = taxonomy::dcast<taxonomy::collection>(i)) {
|
||||||
visit_2<T, taxonomy::collection>(s, fn);
|
visit_2<T, taxonomy::collection>(s, fn);
|
||||||
} else if (auto s = taxonomy::dcast<taxonomy::loop>(i)) {
|
}
|
||||||
|
else if (auto s = taxonomy::dcast<taxonomy::loop>(i)) {
|
||||||
visit_2<T, taxonomy::loop>(s, fn);
|
visit_2<T, taxonomy::loop>(s, fn);
|
||||||
} else if (auto s = taxonomy::dcast<taxonomy::face>(i)) {
|
}
|
||||||
|
else if (auto s = taxonomy::dcast<taxonomy::face>(i)) {
|
||||||
visit_2<T, taxonomy::face>(s, fn);
|
visit_2<T, taxonomy::face>(s, fn);
|
||||||
} else if (auto s = taxonomy::dcast<taxonomy::shell>(i)) {
|
}
|
||||||
|
else if (auto s = taxonomy::dcast<taxonomy::shell>(i)) {
|
||||||
visit_2<T, taxonomy::shell>(s, fn);
|
visit_2<T, taxonomy::shell>(s, fn);
|
||||||
} else if (auto s = taxonomy::dcast<taxonomy::solid>(i)) {
|
}
|
||||||
|
else if (auto s = taxonomy::dcast<taxonomy::solid>(i)) {
|
||||||
visit_2<T, taxonomy::solid>(s, fn);
|
visit_2<T, taxonomy::solid>(s, fn);
|
||||||
} else if (auto s = taxonomy::dcast<taxonomy::loft>(i)) {
|
}
|
||||||
|
else if (auto s = taxonomy::dcast<taxonomy::loft>(i)) {
|
||||||
visit_2<T, taxonomy::loft>(s, fn);
|
visit_2<T, taxonomy::loft>(s, fn);
|
||||||
} else if (auto s = taxonomy::dcast<taxonomy::boolean_result>(i)) {
|
}
|
||||||
|
else if (auto s = taxonomy::dcast<taxonomy::boolean_result>(i)) {
|
||||||
visit_2<T, taxonomy::boolean_result>(s, fn);
|
visit_2<T, taxonomy::boolean_result>(s, fn);
|
||||||
} else if (auto pt = taxonomy::dcast<taxonomy::point3>(i)) {
|
}
|
||||||
|
else if (auto pt = taxonomy::dcast<taxonomy::point3>(i)) {
|
||||||
fn(pt);
|
fn(pt);
|
||||||
} else if (auto l = taxonomy::dcast<taxonomy::edge>(i)) {
|
}
|
||||||
|
else if (auto l = taxonomy::dcast<taxonomy::edge>(i)) {
|
||||||
// @todo maybe make edge a collection then as well?
|
// @todo maybe make edge a collection then as well?
|
||||||
if (l->start.which() == 0) {
|
if (l->start.which() == 0) {
|
||||||
fn(boost::get<taxonomy::point3::ptr>(l->start));
|
fn(boost::get<taxonomy::point3::ptr>(l->start));
|
||||||
@@ -1182,7 +1234,8 @@ T* dcast(const U*& u) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
return fn(i);
|
return fn(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1211,7 +1264,7 @@ T* dcast(const U*& u) {
|
|||||||
for (auto it = --collection->children.end(); it >= collection->children.begin(); --it) {
|
for (auto it = --collection->children.end(); it >= collection->children.begin(); --it) {
|
||||||
if (!apply_predicate_to_collection(*it, fn)) {
|
if (!apply_predicate_to_collection(*it, fn)) {
|
||||||
#ifdef TAXONOMY_USE_NAKED_PTR
|
#ifdef TAXONOMY_USE_NAKED_PTR
|
||||||
delete *it;
|
delete* it;
|
||||||
#endif
|
#endif
|
||||||
collection->children.erase(it);
|
collection->children.erase(it);
|
||||||
}
|
}
|
||||||
@@ -1236,7 +1289,7 @@ T* dcast(const U*& u) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
typedef std::tuple<connection_type, connection_type, IfcUtil::IfcBaseEntity*> endpoint_connection;
|
typedef std::tuple<connection_type, connection_type, IfcUtil::IfcBaseEntity*> endpoint_connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user