// discover.hpp — automatic feature discovery from a scan mesh. #pragma once #include #include #include #include "geom.hpp" #include "mesh.hpp" namespace discover { struct DPlane { geom::Vec3 origin, normal, u, v; double umin = 0, umax = 0, vmin = 0, vmax = 0; // extent in (u,v) int npts = 0; double rms = 0; }; struct DCyl { geom::Vec3 center, axis, p1, p2; double diameter = 0, depth = 0; int npts = 0; double rms = 0; double coverage = 0; // fraction of the circle the supporting points span bool isHole = true; // false => boss/shaft (convex) }; struct Params { double angTolDeg = 20.0; // normal-agreement for planar growth double distTolRel = 0.004; // planar distance tolerance, fraction of bbox diag double curvSeed = 0.05; // max surface-variation to start a planar region int minPlanePts = 40; // minimum vertices for a plane int minCylPts = 24; // minimum vertices for a cylinder cluster double minRadiusMM = 0.4; // accepted hole radius range double maxRadiusRel = 0.25;// max radius as fraction of bbox diag double minDiameterMM = 0.0; // explicit Ø lower bound (0 = use minRadiusMM only) double maxDiameterMM = 0.0; // explicit Ø upper bound (0 = use maxRadiusRel only) bool holesOnly = false; // keep only concave (isHole) cylinders double cylRmsRatio = 0.12; // accept cylinder if rms/radius below this int maxPlanes = 40; int maxCyls = 200; int smoothPasses = 0; // normal-denoising iterations (raise for noisy scans) double curvCap = 0.20; // skip seeding where surface variation exceeds this (edges) double minCoverage = 0.10; // reject cylinders spanning less than this of the circle int maxSeedFits = 25000; // cap model-selection fits so noisy scans never hang // optional region restriction: a screen-drag box becomes a set of half-space // clip planes; a vertex is kept only if nx*x+ny*y+nz*z+d <= 0 for ALL planes. std::vector> region; }; struct Result { std::vector planes; std::vector cyls; int datumIndex = -1; // index into planes of the suggested datum (largest) int nverts = 0, ntris = 0; double ms = 0; // wall-clock of discovery std::string note; // diagnostics int dbgPlanesRejected = 0, dbgLeftover = 0, dbgComponents = 0; int dbgCylRejFit = 0, dbgCylRejRadius = 0, dbgCylRejRms = 0, dbgCylRejSmall = 0; int dbgCylRejCoverage = 0; int dbgMaxRegion = 0; }; Result discover(mesh::Mesh& m, const Params& p); } // namespace discover