feat: P2-P4 全面补完 — B-Rep建模 + 数据交换 + 约束求解器 + ICP
CI / Build & Test (push) Failing after 34s
CI / Release Build (push) Failing after 37s

P2 B-Rep建模:
- brep: fillet/chamfer/shell 完整实现
- brep: box/cylinder/sphere 实体工厂
- brep: extrude/revolve/sweep/loft 建模操作

P3 数据交换:
- foundation: PLY 读写(ASCII+二进制)
- foundation: glTF 2.0 导出(JSON+bin)

P4 高级算法/杀手功能:
- sketch: 2D 草图约束求解器(Newton-Raphson, 9种约束类型)
- core: ICP 点云配准(SVD最优变换+KD-Tree加速)

新增模块: vde_sketch
This commit is contained in:
ViewDesignEngine
2026-07-23 07:33:15 +00:00
parent 2c4387aba5
commit e276ce5a64
10 changed files with 755 additions and 372 deletions
+25
View File
@@ -0,0 +1,25 @@
#pragma once
#include "vde/core/point.h"
#include "vde/core/transform.h"
#include <vector>
namespace vde::core {
struct ICPResult {
Transform3D transform; // Rigid transform aligning source to target
double rms_error; // Root-mean-square error
int iterations; // Number of iterations used
bool converged;
};
/// Iterative Closest Point (ICP) for rigid point cloud registration
/// @param source Source point cloud (moved)
/// @param target Target point cloud (fixed)
/// @param max_iter Maximum iterations
/// @param tolerance Convergence tolerance on RMS change
[[nodiscard]] ICPResult icp_register(const std::vector<Point3D>& source,
const std::vector<Point3D>& target,
int max_iter = 50,
double tolerance = 1e-6);
} // namespace vde::core
+11
View File
@@ -0,0 +1,11 @@
#pragma once
#include "vde/mesh/halfedge_mesh.h"
#include <string>
namespace vde::foundation {
/// Export mesh to glTF 2.0 (JSON + optional embedded binary)
/// Returns true on success
bool write_gltf(const std::string& filepath, const mesh::HalfedgeMesh& mesh);
} // namespace vde::foundation
+15
View File
@@ -0,0 +1,15 @@
#pragma once
#include "vde/core/point.h"
#include "vde/mesh/halfedge_mesh.h"
#include <string>
namespace vde::foundation {
/// Read PLY file (Stanford Polygon Format)
/// Supports ASCII and binary little-endian, vertex + face elements
mesh::HalfedgeMesh read_ply(const std::string& filepath);
/// Write PLY file (ASCII format)
void write_ply(const std::string& filepath, const mesh::HalfedgeMesh& mesh);
} // namespace vde::foundation
+48
View File
@@ -0,0 +1,48 @@
#pragma once
#include "vde/core/point.h"
#include <vector>
#include <string>
namespace vde::sketch {
struct SketchPoint { int id; Point2D pos; bool fixed = false; };
struct SketchLine { int id, p0, p1; };
struct SketchCircle { int id, center; double radius; };
enum class ConstraintType {
Horizontal, Vertical, Parallel, Perpendicular, Coincident,
EqualLength, Distance, Radius, Tangent, Concentric, FixedPoint
};
struct Constraint {
ConstraintType type;
std::vector<int> elements;
double value = 0.0;
};
struct SolverResult {
bool converged = false; int iterations = 0; double residual = 0.0;
std::vector<Point2D> points; std::string message;
};
class ConstraintSolver {
public:
int add_point(double x, double y, bool fixed = false);
int add_line(int p0, int p1);
int add_circle(int center, double radius);
void add_constraint(ConstraintType type, const std::vector<int>& elements, double val = 0.0);
void fix_point(int pid) { if(pid>=0&&pid<(int)points_.size()) points_[pid].fixed=true; }
[[nodiscard]] SolverResult solve(int max_iter = 100, double tol = 1e-8);
[[nodiscard]] int degrees_of_freedom() const;
[[nodiscard]] const std::vector<SketchPoint>& points() const { return points_; }
private:
std::vector<SketchPoint> points_;
std::vector<SketchLine> lines_;
std::vector<SketchCircle> circles_;
std::vector<Constraint> constraints_;
double eval_constraint(const Constraint& c) const;
};
} // namespace vde::sketch