Something went wrong. Try again.
Builds CAD models from 3d scan data
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889// meshedit.hpp — topology-aware repair, reduction, and surface deviation.#pragma once
#include <cstddef>#include <cstdint>#include <string>#include <vector>
#include "mesh.hpp"
namespace meshedit {
struct Hole { std::vector<int> vertices; // ordered so patch faces oppose the old boundary faces int nedges = 0; geom::Vec3 center; double radius = 0;};
struct Component { int ntris = 0; double area = 0;};
struct Analysis { int boundaryEdges = 0; int nonManifoldEdges = 0; bool watertight = false; std::vector<Component> components; // sorted by ntris descending std::vector<Hole> holes; // sorted by nedges descending std::vector<int> triangleComponent; // component id for each input triangle};
Analysis analyze(const mesh::Mesh& m);
// Returns the surviving triangle count. Targets below four triangles are clamped.std::size_t decimate(mesh::Mesh& m, std::size_t targetTriangles);
struct DeviationStats { double max = 0; double rms = 0; double pctWithin = 0; std::vector<double> distances;};
// Compact uniform-grid index. Triangles are assigned to every cell touched by// their AABB; the CSR layout avoids millions of small allocations on scan meshes.struct TriangleGrid { geom::Vec3 origin; double cellSize = 1; int nx = 1, ny = 1, nz = 1; const mesh::Mesh* source = nullptr; std::vector<std::uint64_t> offsets; std::vector<int> triangleIds;
TriangleGrid() = default; explicit TriangleGrid(const mesh::Mesh& m) { build(m); } void build(const mesh::Mesh& m); bool closestPoint(const geom::Vec3& p, geom::Vec3& point, geom::Vec3& normal, double& distance) const; double closestDistance(const geom::Vec3& p) const;};
DeviationStats deviationStats(const mesh::Mesh& edited, const mesh::Mesh& original, double tolerance);DeviationStats deviationStats(const mesh::Mesh& edited, const TriangleGrid& original, double tolerance);
// Returns one when a loop was filled and zero when it could not be triangulated.int fillHole(mesh::Mesh& m, const Hole& hole, const std::string& method = "auto");int fillHoles(mesh::Mesh& m, const std::vector<Hole>& holes, const std::string& method = "auto");int fillAllHoles(mesh::Mesh& m, const std::string& method = "auto", int maxEdges = 0);
struct RemoveOptions { std::vector<int> ids; int minTris = -1; double minArea = -1; bool keepLargest = false;};
// Returns the number of connected components removed.int removeComponents(mesh::Mesh& m, const Analysis& analysis, const RemoveOptions& options);int removeComponents(mesh::Mesh& m, const RemoveOptions& options);
} // namespace meshedit