// surface.hpp — selected-region tensor-product cubic B-spline fitting. #pragma once #include #include #include #include "geom.hpp" #include "mesh.hpp" namespace surface { struct Params { int nu = 10; int nv = 10; double smooth = 0.3; double extend = 0.08; bool automatic = false; double tol = 0.05; }; struct Preview { int nu = 0, nv = 0; std::vector positions; // NaN means the extended skirt has no nearby scan support. std::vector deviations; }; struct Fit { bool ok = false; std::string error; int nu = 0, nv = 0; int degree = 3; int npts = 0; double rms = 0; double max = 0; double pctWithin = 0; double extend = 0; double lambda = 0; // Poles are row-major in u: poles[iv * nu + iu]. std::vector poles; // Full clamped knot vectors, including repeated end knots. std::vector knotsU, knotsV; // The unexpanded minimum-area data rectangle. The natural surface domain // [0,1]^2 extends it by `extend` of each side length on every side. geom::Vec3 rectOrigin; geom::Vec3 axisU, axisV, planeNormal; double dataWidth = 0, dataHeight = 0; Preview preview; }; // Fits the active vertex selection. Preview-to-scan deviations use triangles // having at least one selected vertex. Fit fit(const mesh::Mesh& scan, const std::vector& selected, const Params& params = {}); // Point-only fitting is useful for callers without topology. Its preview // deviations are NaN because no scan triangles are available. Fit fitPoints(const std::vector& points, const std::vector& normals, const Params& params = {}); geom::Vec3 evaluate(const Fit& fit, double u, double v); bool writeSTEP(const Fit& fit, const std::string& path, std::string* error = nullptr); } // namespace surface