From 599ca5649630478af9b536a2d359decf2ed4e310 Mon Sep 17 00:00:00 2001 From: Thomas Krijnen Date: Thu, 27 Jun 2024 09:33:04 +0200 Subject: [PATCH] Mark piecewise_function as geom_item #4727 --- src/ifcgeom/taxonomy.h | 229 ++++++++++++++++++++--------------------- 1 file changed, 114 insertions(+), 115 deletions(-) diff --git a/src/ifcgeom/taxonomy.h b/src/ifcgeom/taxonomy.h index 2275555bf3..c3fbbf9008 100644 --- a/src/ifcgeom/taxonomy.h +++ b/src/ifcgeom/taxonomy.h @@ -130,115 +130,6 @@ typedef item const* ptr; uint32_t identity() const { return identity_; } }; - struct implicit_item : public item { - DECLARE_PTR(implicit_item) - using item::item; - - virtual item::ptr evaluate() const = 0; - }; - - struct piecewise_function : public implicit_item { - DECLARE_PTR(piecewise_function) - - using spans = std::vector>>; - - piecewise_function(const spans& s, ifcopenshell::geometry::Settings* settings = nullptr, const IfcUtil::IfcBaseInterface* instance = nullptr) : - implicit_item(instance), settings_(settings), spans_(s){}; - piecewise_function(const std::vector& pwfs, ifcopenshell::geometry::Settings* settings = nullptr, const IfcUtil::IfcBaseInterface* instance = nullptr) : - implicit_item(instance), settings_(settings) - { - for (auto& pwf : pwfs) { - spans_.insert(spans_.end(), pwf->spans_.begin(), pwf->spans_.end()); - } - }; - piecewise_function(piecewise_function&&) = default; - piecewise_function(const piecewise_function&) = default; - - const ifcopenshell::geometry::Settings* settings_ = nullptr; - - bool is_empty() const { return spans_.empty(); } - - double length() const { - if (!length_.has_value()) { - length_ = std::accumulate(spans_.begin(), spans_.end(), 0.0, [](const auto& v, const auto& s) { return v + s.first; }); - } - return *length_; - } - - void print(std::ostream& o, int = 0) const; - - 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(PIECEWISE_FUNCTION), 0); - return boost::hash{}(v); - } - - item::ptr evaluate() const override; - std::pair> evaluate2() const; - - /// @brief evaluates the piecewise function between ustart and uend - /// @param ustart starting location - taken as 0.0 if before start - /// @param uend ending location - taken as length if beyond end - /// @param nsteps number of steps to evaluate - /// @return taxonomy::loop::ptr - item::ptr evaluate(double ustart, double uend, unsigned nsteps) const; - - /// @brief evaluates the piecewise function between ustart and uend - /// @param ustart starting location - taken as 0.0 if before start - /// @param uend ending location - taken as length if beyond end - /// @param nsteps number of steps to evaluate - /// @return taxonomy::loop::ptr and vector of u values - std::pair> evaluate2(double ustart, double uend, unsigned nsteps) const; - - /// @brief evaluates the piecewise function at u - /// @param u u is constrained to be between 0 and length - /// @return 4x4 placement matrix - Eigen::Matrix4d evaluate(double u) const; - - private: - std::tuple*> get_span(double u) const; - spans spans_; - mutable double current_span_start_ = 0; - mutable double current_span_end_ = 0; - mutable const std::function* current_span_fn_ = nullptr; - mutable boost::optional length_; - }; - -#ifdef TAXONOMY_USE_SHARED_PTR - typedef std::shared_ptr ptr; - typedef std::shared_ptr const_ptr; - template - std::shared_ptr make(Args&&... args) { - return std::make_shared(std::forward(args)...); - } -#endif -#ifdef TAXONOMY_USE_UNIQUE_PTR - typedef std::uniqe_ptr ptr; - typedef std::uniqe_ptr ptr; - template - std::uniqe_ptr make(Args&&... args) { - return new T(std::forward(args)...)); - } -#endif -#ifdef TAXONOMY_USE_NAKED_PTR - typedef item* ptr; - typedef item const* ptr; - template - T* make(Args&&... args) { - return new T(std::forward(args)...)); - } -#endif - - bool less(item::const_ptr, item::const_ptr); - - struct less_functor { - bool operator()(item::const_ptr a, item::const_ptr b) const { - return less(a, b); - } - }; - namespace { template @@ -299,8 +190,7 @@ typedef item const* ptr; const T& ccomponents() const { if (this->components_) { return *this->components_; - } - else { + } else { return eigen_defaults(); } } @@ -321,11 +211,11 @@ typedef item const* ptr; boost::hash_combine(h, std::hash{}(T::ColsAtCompileTime)); if (components_) { for (int i = 0; i < components_->size(); ++i) { - auto elem = *(components_->data() + (size_t) i); + auto elem = *(components_->data() + (size_t)i); boost::hash_combine(h, std::hash()(elem)); } } - return (uint32_t) h; + return (uint32_t)h; } }; @@ -447,11 +337,120 @@ typedef item const* ptr; style::ptr surface_style; matrix4::ptr matrix; - 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::IfcBaseInterface* instance = nullptr) : item(instance), surface_style(nullptr) {} + geom_item(const IfcUtil::IfcBaseInterface* instance, matrix4::ptr m) : item(instance), surface_style(nullptr), matrix(m) {} geom_item(matrix4::ptr m) : surface_style(nullptr), matrix(m) {} }; + struct implicit_item : public geom_item { + DECLARE_PTR(implicit_item) + using geom_item::geom_item; + + virtual item::ptr evaluate() const = 0; + }; + + struct piecewise_function : public implicit_item { + DECLARE_PTR(piecewise_function) + + using spans = std::vector>>; + + piecewise_function(const spans& s, ifcopenshell::geometry::Settings* settings = nullptr, const IfcUtil::IfcBaseInterface* instance = nullptr) : + implicit_item(instance), settings_(settings), spans_(s){}; + piecewise_function(const std::vector& pwfs, ifcopenshell::geometry::Settings* settings = nullptr, const IfcUtil::IfcBaseInterface* instance = nullptr) : + implicit_item(instance), settings_(settings) + { + for (auto& pwf : pwfs) { + spans_.insert(spans_.end(), pwf->spans_.begin(), pwf->spans_.end()); + } + }; + piecewise_function(piecewise_function&&) = default; + piecewise_function(const piecewise_function&) = default; + + const ifcopenshell::geometry::Settings* settings_ = nullptr; + + bool is_empty() const { return spans_.empty(); } + + double length() const { + if (!length_.has_value()) { + length_ = std::accumulate(spans_.begin(), spans_.end(), 0.0, [](const auto& v, const auto& s) { return v + s.first; }); + } + return *length_; + } + + void print(std::ostream& o, int = 0) const; + + 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(PIECEWISE_FUNCTION), 0); + return boost::hash{}(v); + } + + item::ptr evaluate() const override; + std::pair> evaluate2() const; + + /// @brief evaluates the piecewise function between ustart and uend + /// @param ustart starting location - taken as 0.0 if before start + /// @param uend ending location - taken as length if beyond end + /// @param nsteps number of steps to evaluate + /// @return taxonomy::loop::ptr + item::ptr evaluate(double ustart, double uend, unsigned nsteps) const; + + /// @brief evaluates the piecewise function between ustart and uend + /// @param ustart starting location - taken as 0.0 if before start + /// @param uend ending location - taken as length if beyond end + /// @param nsteps number of steps to evaluate + /// @return taxonomy::loop::ptr and vector of u values + std::pair> evaluate2(double ustart, double uend, unsigned nsteps) const; + + /// @brief evaluates the piecewise function at u + /// @param u u is constrained to be between 0 and length + /// @return 4x4 placement matrix + Eigen::Matrix4d evaluate(double u) const; + + private: + std::tuple*> get_span(double u) const; + spans spans_; + mutable double current_span_start_ = 0; + mutable double current_span_end_ = 0; + mutable const std::function* current_span_fn_ = nullptr; + mutable boost::optional length_; + }; + +#ifdef TAXONOMY_USE_SHARED_PTR + typedef std::shared_ptr ptr; + typedef std::shared_ptr const_ptr; + template + std::shared_ptr make(Args&&... args) { + return std::make_shared(std::forward(args)...); + } +#endif +#ifdef TAXONOMY_USE_UNIQUE_PTR + typedef std::uniqe_ptr ptr; + typedef std::uniqe_ptr ptr; + template + std::uniqe_ptr make(Args&&... args) { + return new T(std::forward(args)...)); + } +#endif +#ifdef TAXONOMY_USE_NAKED_PTR + typedef item* ptr; + typedef item const* ptr; + template + T* make(Args&&... args) { + return new T(std::forward(args)...)); + } +#endif + + bool less(item::const_ptr, item::const_ptr); + + struct less_functor { + bool operator()(item::const_ptr a, item::const_ptr b) const { + return less(a, b); + } + }; + // @todo make 4d for easier multiplication template struct cartesian_base : public item, public eigen_base {