v0.1.0: 初始工程骨架 — 7模块 40头文件 32源文件 17文档 Apache-2.0

This commit is contained in:
ViewDesignEngine
2026-07-23 05:27:51 +00:00
commit 02d0520aa5
133 changed files with 5350 additions and 0 deletions
+48
View File
@@ -0,0 +1,48 @@
#include "vde/foundation/exact_predicates.h"
#include <cmath>
namespace vde::foundation::exact {
namespace {
// Simple non-adaptive implementation; full Shewchuk predicates TBD
double orient2d_det(const Point2D& a, const Point2D& b, const Point2D& c) {
return (b.x() - a.x()) * (c.y() - a.y()) - (b.y() - a.y()) * (c.x() - a.x());
}
} // namespace
Orientation orient_2d(const Point2D& a, const Point2D& b, const Point2D& c) {
double det = orient2d_det(a, b, c);
if (det > 1e-12) return Orientation::CounterClockwise;
if (det < -1e-12) return Orientation::Clockwise;
return Orientation::Collinear;
}
Orientation orient_3d(const Point3D& a, const Point3D& b,
const Point3D& c, const Point3D& d) {
Eigen::Matrix4d m;
m << a.x(), a.y(), a.z(), 1.0,
b.x(), b.y(), b.z(), 1.0,
c.x(), c.y(), c.z(), 1.0,
d.x(), d.y(), d.z(), 1.0;
double det = m.determinant();
if (det > 1e-12) return Orientation::CounterClockwise;
if (det < -1e-12) return Orientation::Clockwise;
return Orientation::Collinear;
}
CircleTest in_circle(const Point2D& a, const Point2D& b,
const Point2D& c, const Point2D& d) {
double ax = a.x() - d.x(), ay = a.y() - d.y();
double bx = b.x() - d.x(), by = b.y() - d.y();
double cx = c.x() - d.x(), cy = c.y() - d.y();
double det = (ax*ax + ay*ay) * (bx*cy - by*cx)
- (bx*bx + by*by) * (ax*cy - ay*cx)
+ (cx*cx + cy*cy) * (ax*by - ay*bx);
if (det > 1e-12) return CircleTest::Inside;
if (det < -1e-12) return CircleTest::Outside;
return CircleTest::On;
}
} // namespace vde::foundation::exact
+54
View File
@@ -0,0 +1,54 @@
#include "vde/foundation/io_obj.h"
#include <fstream>
#include <sstream>
namespace vde::foundation {
ObjMeshData read_obj(const std::string& filepath) {
ObjMeshData data;
std::ifstream file(filepath);
if (!file) return data;
std::string line;
while (std::getline(file, line)) {
if (line.empty() || line[0] == '#') continue;
std::istringstream iss(line);
std::string token;
iss >> token;
if (token == "v") {
double x, y, z;
iss >> x >> y >> z;
data.vertices.emplace_back(x, y, z);
} else if (token == "vn") {
double nx, ny, nz;
iss >> nx >> ny >> nz;
data.normals.emplace_back(nx, ny, nz);
} else if (token == "f") {
std::vector<int> face;
std::string vertex;
while (iss >> vertex) {
std::istringstream viss(vertex);
std::string vi_str;
std::getline(viss, vi_str, '/');
face.push_back(std::stoi(vi_str) - 1);
}
data.faces.push_back(std::move(face));
}
}
return data;
}
void write_obj(const std::string& filepath, const ObjMeshData& data) {
std::ofstream file(filepath);
for (const auto& v : data.vertices)
file << "v " << v.x() << " " << v.y() << " " << v.z() << "\n";
for (const auto& n : data.normals)
file << "vn " << n.x() << " " << n.y() << " " << n.z() << "\n";
for (const auto& f : data.faces) {
file << "f";
for (int vi : f) file << " " << (vi + 1);
file << "\n";
}
}
} // namespace vde::foundation
+48
View File
@@ -0,0 +1,48 @@
#include "vde/foundation/io_stl.h"
#include <fstream>
#include <cstring>
namespace vde::foundation {
std::vector<StlTriangle> read_stl(const std::string& filepath) {
std::vector<StlTriangle> tris;
std::ifstream file(filepath, std::ios::binary);
if (!file) return tris;
// Read binary STL
char header[80];
file.read(header, 80);
uint32_t count;
file.read(reinterpret_cast<char*>(&count), 4);
tris.reserve(count);
for (uint32_t i = 0; i < count; ++i) {
StlTriangle tri{};
file.read(reinterpret_cast<char*>(&tri.normal), 12);
file.read(reinterpret_cast<char*>(&tri.v0), 12);
file.read(reinterpret_cast<char*>(&tri.v1), 12);
file.read(reinterpret_cast<char*>(&tri.v2), 12);
uint16_t attr;
file.read(reinterpret_cast<char*>(&attr), 2);
tris.push_back(tri);
}
return tris;
}
void write_stl(const std::string& filepath, const std::vector<StlTriangle>& tris) {
std::ofstream file(filepath, std::ios::binary);
char header[80] = {};
file.write(header, 80);
uint32_t count = static_cast<uint32_t>(tris.size());
file.write(reinterpret_cast<const char*>(&count), 4);
for (const auto& tri : tris) {
file.write(reinterpret_cast<const char*>(&tri.normal), 12);
file.write(reinterpret_cast<const char*>(&tri.v0), 12);
file.write(reinterpret_cast<const char*>(&tri.v1), 12);
file.write(reinterpret_cast<const char*>(&tri.v2), 12);
uint16_t attr = 0;
file.write(reinterpret_cast<const char*>(&attr), 2);
}
}
} // namespace vde::foundation
+7
View File
@@ -0,0 +1,7 @@
#include "vde/foundation/tolerance.h"
namespace vde::foundation {
Tolerance Tolerance::global_{};
} // namespace vde::foundation