Files

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

88 lines
3.6 KiB
C++
Raw Permalink Normal View History

#ifndef ITERATOR_PWF_EVALUATOR_H
#define ITERATOR_PWF_EVALUATOR_H
#include "../ifcgeom/taxonomy.h"
#include <boost/function.hpp>
namespace ifcopenshell { namespace geometry {
2025-03-14 07:31:50 -07:00
/// @brief Computes a point on a helmert curve at s.
/// Returns (x,y,theta) at L/2. The results are in a vector so they can be returned to python
2025-09-26 14:24:49 +02:00
IFC_GEOM_API std::vector<double> helmert_curve_point(double A0, double A1, double A2, double s);
2025-02-22 16:16:59 -08:00
2025-07-17 10:47:13 -07:00
/// @brief Converts a loop to a function item.
/// This is intended to be used from python side. Polylines are mapped to a loop, but when
/// representing an alignment they need to be a function_item so the can be evaluated by function_item_evaluator.
/// On the C++ side, the dcast operator take care of this, but dcast is not accessible on the python side.
/// @param loop
/// @return
static taxonomy::function_item::ptr convert_loop_to_function_item(taxonomy::loop::ptr loop) {
return ifcopenshell::geometry::taxonomy::dcast<taxonomy::function_item>(loop);
}
2025-01-02 11:10:56 -08:00
/// @brief Abstract class for evaluating a function_item. This class is specialized for each of the function_item types.
2025-09-26 14:24:49 +02:00
struct IFC_GEOM_API fn_evaluator {
fn_evaluator(const ifcopenshell::geometry::Settings& settings, Logger& logger = Logger::Root()) : settings_(settings), logger_(logger) {
2025-01-02 11:10:56 -08:00
}
fn_evaluator(const fn_evaluator& other) = default;
virtual ~fn_evaluator() = default;
virtual fn_evaluator* clone() const = 0;
virtual Eigen::Matrix4d evaluate(double u) const = 0;
virtual double start() const = 0;
virtual double end() const = 0;
double length() const { return end() - start(); }
ifcopenshell::geometry::Settings settings_;
protected:
Logger& logger_;
2025-01-02 11:10:56 -08:00
};
/// @brief utility class to evaluate function_item objects.
2025-09-26 14:24:49 +02:00
class IFC_GEOM_API function_item_evaluator {
public:
function_item_evaluator(const ifcopenshell::geometry::Settings& settings, taxonomy::function_item::const_ptr fn, Logger& logger = Logger::Root());
2025-01-02 11:10:56 -08:00
function_item_evaluator(const function_item_evaluator& other);
~function_item_evaluator();
/// @brief returns a vector of "distance along" points where the evaluate function computes loop points
std::vector<double> evaluation_points() const;
/// @brief returns a vector of "distance along" points between ustart and uend
/// @param ustart starting location
/// @param uend ending location
/// @param nsteps number of steps to evaluate
std::vector<double> evaluation_points(double ustart, double uend, unsigned nsteps) const;
2025-01-02 11:10:56 -08:00
/// @brief evaluates the function between start and end
/// evaluation point step size is taken from the settings object
taxonomy::item::ptr evaluate() const;
2025-01-02 11:10:56 -08:00
/// @brief evaluates the function between ustart and uend
/// if ustart and uend are out of range, the range of values evaluated
/// are constrained to start_ and start_+length_
/// @param ustart starting location
/// @param uend ending location
/// @param nsteps number of steps to evaluate
/// @return taxonomy::loop::ptr
taxonomy::item::ptr evaluate(double ustart, double uend, unsigned nsteps) const;
2025-01-02 11:10:56 -08:00
/// @brief evaluates the function at u
/// @param u u is constrained to be between start_ and start_+length
2025-03-14 07:31:50 -07:00
/// @return 4x4 placement matrix. Curvature values for horizontal, vertical, and vertical + cant are stored in the last row.
Eigen::Matrix4d evaluate(double u) const;
private:
taxonomy::item::ptr evaluate(const std::vector<double>& dist) const;
2025-01-02 11:10:56 -08:00
fn_evaluator* fn_evaluator_ = nullptr;
2025-01-02 11:10:56 -08:00
mutable boost::optional<std::vector<double>> eval_points_; // cache evaluation points
Logger& logger_;
};
}}
#endif