Something went wrong. Try again.
Builds CAD models from 3d scan data
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103// builder.hpp — reconstruct a parametric-style B-rep solid and export STEP (OpenCASCADE).#pragma once#include <string>#include <vector>
#include "geom.hpp"
namespace builder {
struct Datum { geom::Vec3 origin; geom::Vec3 normal; geom::Vec3 u, v;};
struct Hole { geom::Vec3 center; // a point on the hole axis (world) geom::Vec3 axis; // unit axis direction double diameter = 0; // mm bool through = true; double depth = 0; // mm, used when !through std::string thread; // e.g. "M5x0.8" (metadata / for macro) std::string label;};
struct BuildParams { Datum datum; std::vector<Hole> holes; double thickness = 6.0; // plate thickness, mm double margin = 8.0; // plate border beyond outermost holes, mm};
struct BuildResult { bool ok = false; std::string error; std::string stepPath; int holesCut = 0;};
// Build the solid and write STEP to `stepPath`.BuildResult buildAndExport(const BuildParams& p, const std::string& stepPath);
// A coordinate frame derived from a bolt pattern: origin + orthonormal x/y/z.struct RefFrame { geom::Vec3 origin; geom::Vec3 x, y, z; // z is the bolt-up direction, x an in-plane reference};
// Derive a reference frame from the picked holes. originIdx names the origin hole// (<0 => pattern centroid); xIdx names the hole the +x axis points toward (<0 => the// hole farthest from the origin); zIdx names the hole whose axis defines z (<0 => the// average of all hole axes). x is (origin->xHole) projected perpendicular to z; y = z X x.RefFrame frameFromHoles(const std::vector<Hole>& holes, int originIdx, int xIdx, int zIdx, std::string& err);
// Export the mounting-hole INTERFACE (not a plate) as STEP reference geometry: a// vertex + axis segment + diameter circle per hole, plus the coordinate triad.BuildResult exportInterface(const std::vector<Hole>& holes, const RefFrame& fr, const std::string& stepPath);
// One mounting point modeled as a clean solid: a boss (short cylinder) seated on the// fitted mount-face plane, with a coaxial hole down its axis.struct Mount { geom::Vec3 seat; // point on the mount-face plane, on the hole axis (world) geom::Vec3 axis; // unit, oriented OUTWARD (boss grows this way) double holeDiameter; // mm double bossDiameter; // mm (>= holeDiameter) double bossHeight; // mm double faceHalfSize; // mm, half-extent of the square mount-face reference patch int group = -1; // coplanar group id (>= 0): members share ONE exported // reference plane face instead of per-mount squares std::string label;};
// User-extracted reference geometry (the Prims-step registry), carried into the// STEP so CAD sees every datum the user built, not just the per-mount seats:// planes as their minimal bounding-rectangle faces, lines/axes as edges, points// as vertices.struct RefGeometry { std::vector<std::array<geom::Vec3, 4>> planeRects; std::vector<std::array<geom::Vec3, 2>> lines; // segment endpoints std::vector<geom::Vec3> points;};
// Export the mount assembly as a STEP: one boss+coaxial-hole SOLID per mount at its// true position/axis, a planar reference face at each mount seat (mounts in the same// coplanar `group` share a single merged face), plus the coordinate triad + origin// vertex, plus any user reference geometry. Multi-body — SolidWorks imports each// boss as its own body.BuildResult exportMounts(const std::vector<Mount>& mounts, const RefFrame& fr, const std::string& stepPath, const RefGeometry* refs = nullptr);
// Planes-only export: the three world datum planes (XY, YZ, XZ) through the// origin, each a rectangle covering the part's [bbMin, bbMax] extent (padded,// and always including the origin), plus the axis triad and origin vertex,// plus any user reference geometry.BuildResult exportDatums(const geom::Vec3& bbMin, const geom::Vec3& bbMax, const std::string& stepPath, const RefGeometry* refs = nullptr);
} // namespace builder