Files
ViewDesignEngine/include/vde/brep/brep.h
T

71 lines
2.7 KiB
C++
Raw Normal View History

2026-07-23 07:19:13 +00:00
#pragma once
#include "vde/core/point.h"
#include "vde/core/aabb.h"
#include "vde/curves/nurbs_curve.h"
#include "vde/curves/nurbs_surface.h"
#include "vde/mesh/halfedge_mesh.h"
#include <vector>
#include <memory>
#include <string>
namespace vde::brep {
using core::Point3D;
using core::Vector3D;
using core::AABB3D;
2026-07-23 07:19:13 +00:00
enum class CurveType { Line, Circle, Bezier, BSpline, Nurbs };
struct TopoVertex { int id; Point3D point; double tolerance = 1e-6; };
struct TopoEdge {
int id, v_start, v_end;
std::shared_ptr<curves::NurbsCurve> curve;
bool reversed = false;
};
struct TopoLoop { int id; std::vector<int> edges; bool is_outer = true; };
struct TopoFace { int id, surface_id; std::vector<int> loops; bool reversed = false; };
struct TopoShell { int id; std::vector<int> faces; bool closed = true; };
struct TopoBody { int id; std::vector<int> shells; std::string name; };
class BrepModel {
public:
BrepModel() = default;
int add_vertex(const Point3D& p);
int add_edge(int v0, int v1);
int add_edge(int v0, int v1, const curves::NurbsCurve& curve);
int add_loop(const std::vector<int>& edges, bool outer = true);
int add_face(int surface_id, const std::vector<int>& loops);
int add_shell(const std::vector<int>& faces, bool closed = true);
int add_body(const std::vector<int>& shells, const std::string& name = "");
int add_surface(const curves::NurbsSurface& surf);
[[nodiscard]] size_t num_vertices() const { return vertices_.size(); }
[[nodiscard]] size_t num_edges() const { return edges_.size(); }
[[nodiscard]] size_t num_faces() const { return faces_.size(); }
[[nodiscard]] size_t num_bodies() const { return bodies_.size(); }
[[nodiscard]] const TopoVertex& vertex(int id) const { return vertices_[id]; }
[[nodiscard]] const TopoEdge& edge(int id) const { return edges_[id]; }
[[nodiscard]] const TopoFace& face(int id) const { return faces_[id]; }
[[nodiscard]] const curves::NurbsSurface& surface(int id) const { return surfaces_[id]; }
[[nodiscard]] core::AABB3D bounds() const;
[[nodiscard]] bool is_valid() const;
[[nodiscard]] mesh::HalfedgeMesh to_mesh(double deflection = 0.01) const;
[[nodiscard]] std::vector<int> face_edges(int face_id) const;
[[nodiscard]] std::vector<int> edge_faces(int edge_id) const;
[[nodiscard]] std::vector<int> vertex_edges(int vertex_id) const;
private:
std::vector<TopoVertex> vertices_;
std::vector<TopoEdge> edges_;
std::vector<TopoLoop> loops_;
std::vector<TopoFace> faces_;
std::vector<TopoShell> shells_;
std::vector<TopoBody> bodies_;
std::vector<curves::NurbsSurface> surfaces_;
int next_id_ = 0;
};
} // namespace vde::brep