Files
IfcOpenShell/src/ifcgeom/function_item_evaluator.h
T

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

81 lines
3.2 KiB
C++
Raw 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-02-22 16:16:59 -08:00
/// @brief Computes the curve length of a polynomial of the form y = A + Bx + Cx^2
/// This function is needed on the python side. To do this computation, a large library like scipy
/// is needed. That is too much overhead. For this reason, a simple function is here on the C++ side
/// that the python side can call
/// @param A constant term
/// @param B linear term
/// @param C quadradic term
/// @param horizontal_length length of the polynomal projected onto the horizontal axis
/// @return curve length
double polynomial_length(double A, double B, double C,double horizontal_length);
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.
struct fn_evaluator {
fn_evaluator(const ifcopenshell::geometry::Settings& settings) : settings_(settings) {
}
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_;
};
/// @brief utility class to evaluate function_item objects.
class function_item_evaluator {
public:
2025-01-02 11:10:56 -08:00
function_item_evaluator(const ifcopenshell::geometry::Settings& settings, taxonomy::function_item::const_ptr fn);
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
/// @return 4x4 placement matrix
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
};
}}
#endif