// align.hpp — sequential datum (3-2-1) frame construction. #pragma once #include #include #include #include "geom.hpp" #include "mesh.hpp" namespace align { using Mat3 = std::array; enum class FeatureKind { Plane, LineLike, PointLike, }; struct Feature { int id = -1; FeatureKind kind = FeatureKind::PointLike; geom::Vec3 anchor; geom::Vec3 direction; }; struct Slot { int primId = -1; std::string target; bool flip = false; }; struct Result { bool ok = false; std::string error; Mat3 R{1, 0, 0, 0, 1, 0, 0, 0, 1}; geom::Vec3 t; std::array rotLocked{false, false, false}; std::array transLocked{false, false, false}; bool fullyDefined = false; std::vector overconstrained; geom::Vec3 origin; std::array axes{}; }; // Features form the registry; slots select them by id and impose target roles. // `translate` is applied last, in the newly constructed frame. Result buildFrame(const std::vector& features, const std::vector& slots, geom::Vec3 translate = {0, 0, 0}); // Point-based 3-2-1 (ZEISS INSPECT style). `rule` "AAA-BB-C" names the axis // each group sets a coordinate on: three plane points get A = values[0..2] // (so the plane is perpendicular to A when those are equal), two line points // get B = values[3..4] (the line then runs along C), one point gets // C = values[5]. Solved exactly, unequal values included. Accepts 3, 5, or 6 // points for a partially constrained frame. // "Plane positive" (flipPlane = false): +A points to the `planeHint` side // (out of the picked face), or follows right-hand pick order without a hint. // "Line positive" (flipLine = false): +C runs from the 1st to the 2nd line point. struct PointsSpec { std::vector points; std::string rule = "ZZZ-YY-X"; std::array values{}; bool flipPlane = false; bool flipLine = false; geom::Vec3 planeHint; }; Result buildFrameFromPoints(const PointsSpec& spec, geom::Vec3 translate = {0, 0, 0}); // A given rigid move (proper rotation R, then translation t) packaged as a // fully defined Result, for direct edits like "move the planes 5 mm". Result fromRigid(const Mat3& R, const geom::Vec3& t); // 90-degree rotation about world X, Y, or Z ("X"/"Y"/"Z"; anything else = I). Mat3 rot90(const std::string& axis); geom::Vec3 transformPoint(const Mat3& R, const geom::Vec3& t, const geom::Vec3& p); geom::Vec3 transformDirection(const Mat3& R, const geom::Vec3& d); void applyTo(mesh::Mesh& mesh, const Mat3& R, const geom::Vec3& t); } // namespace align