Something went wrong. Try again.
Builds CAD models from 3d scan data
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102// prim.hpp — selected-region primitive fitting and reference constructions.#pragma once
#include <array>#include <string>#include <vector>
#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<geom::Vec3, 4> 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<int>& out);void paintSelect(const mesh::Mesh& m, const std::vector<geom::Vec3>& centers, double radius, std::vector<int>& out);
// Selected point-cloud fits. Normals may be empty for plane/cylinder; cone needs// one usable normal per point.PlaneFit fitPlane(const std::vector<geom::Vec3>& points, const std::vector<geom::Vec3>& normals = {});CylinderFit fitCylinder(const std::vector<geom::Vec3>& points, const std::vector<geom::Vec3>& normals);ConeFit fitCone(const std::vector<geom::Vec3>& points, const std::vector<geom::Vec3>& normals);SphereFit fitSphere(const std::vector<geom::Vec3>& 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<Line>& 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<geom::Vec3, 3>& origins, const std::array<geom::Vec3, 3>& 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<geom::Vec3>& points);
} // namespace prim