// prim.hpp — selected-region primitive fitting and reference constructions. #pragma once #include #include #include #include "fit.hpp" #include "geom.hpp" #include "mesh.hpp" namespace prim { struct PlaneFit { bool ok = false; std::string err; geom::Vec3 origin; geom::Vec3 normal; geom::Vec3 u, v; std::array rect{}; double rms = 0; int npts = 0; }; struct CylinderFit { bool ok = false; std::string err; geom::Vec3 center; geom::Vec3 axis; double radius = 0; geom::Vec3 p1, p2; double rms = 0; int npts = 0; }; struct ConeFit { bool ok = false; std::string err; geom::Vec3 apex; geom::Vec3 axis; double halfAngleDeg = 0; double h1 = 0, h2 = 0; double rms = 0; int npts = 0; }; struct SphereFit { bool ok = false; std::string err; geom::Vec3 center; double radius = 0; double rms = 0; int npts = 0; }; // Region selection. Both functions replace `out`. void wandSelect(const mesh::Mesh& m, geom::Vec3 seedPoint, double angleDeg, std::vector& out); void paintSelect(const mesh::Mesh& m, const std::vector& centers, double radius, std::vector& out); // Selected point-cloud fits. Normals may be empty for plane/cylinder; cone needs // one usable normal per point. PlaneFit fitPlane(const std::vector& points, const std::vector& normals = {}); CylinderFit fitCylinder(const std::vector& points, const std::vector& normals); ConeFit fitCone(const std::vector& points, const std::vector& normals); SphereFit fitSphere(const std::vector& points); struct Line { bool ok = false; geom::Vec3 p; geom::Vec3 d; std::string err; }; struct Point { bool ok = false; geom::Vec3 p; std::string err; }; Line lineFromPlanes(const geom::Vec3& origin1, const geom::Vec3& normal1, const geom::Vec3& origin2, const geom::Vec3& normal2); Line axisLine(const geom::Vec3& p, const geom::Vec3& d); Line averageLines(const std::vector& lines); Line projectLine(const Line& line, const geom::Vec3& planeOrigin, const geom::Vec3& planeNormal); Point linePlanePoint(const Line& line, const geom::Vec3& planeOrigin, const geom::Vec3& planeNormal); Point threePlanesPoint(const std::array& origins, const std::array& normals); Point midpointPoints(const geom::Vec3& a, const geom::Vec3& b); Point midpointLine(const Line& line); Point sphereCenter(const geom::Vec3& center); Point centroidPoint(const std::vector& points); } // namespace prim