#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 #include #include namespace vde::brep { using core::Point3D; using core::Vector3D; using core::AABB3D; 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 curve; bool reversed = false; }; struct TopoLoop { int id; std::vector edges; bool is_outer = true; }; struct TopoFace { int id, surface_id; std::vector loops; bool reversed = false; }; struct TopoShell { int id; std::vector faces; bool closed = true; }; struct TopoBody { int id; std::vector 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& edges, bool outer = true); int add_face(int surface_id, const std::vector& loops); int add_shell(const std::vector& faces, bool closed = true); int add_body(const std::vector& 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(); } // Look up vertex by array index (faster, for sequential access) [[nodiscard]] const TopoVertex& vertex(int id) const { return vertices_[id]; } // Look up vertex by unique ID (correct for ID-based references from edge data) [[nodiscard]] const TopoVertex& vertex_by_id(int id) const; [[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 face_edges(int face_id) const; [[nodiscard]] std::vector edge_faces(int edge_id) const; [[nodiscard]] std::vector vertex_edges(int vertex_id) const; [[nodiscard]] size_t num_surfaces() const { return surfaces_.size(); } [[nodiscard]] const TopoLoop& loop_by_id(int id) const; [[nodiscard]] const std::vector& all_loops() const { return loops_; } private: std::vector vertices_; std::vector edges_; std::vector loops_; std::vector faces_; std::vector shells_; std::vector bodies_; std::vector surfaces_; int next_id_ = 0; }; } // namespace vde::brep