ViewDesignEngine  3.1.0
高性能 CAD 计算几何引擎
brep.h
浏览该文件的文档.
1 #pragma once
45 #include "vde/core/point.h"
46 #include "vde/core/aabb.h"
47 #include "vde/curves/nurbs_curve.h"
49 #include "vde/mesh/halfedge_mesh.h"
50 #include <vector>
51 #include <memory>
52 #include <string>
53 
54 namespace vde::brep {
55 using core::Point3D;
56 using core::Vector3D;
57 using core::AABB3D;
58 
65 enum class CurveType { Line, Circle, Bezier, BSpline, Nurbs };
66 
67 // ═══════════════════════════════════════════════
68 // 拓扑实体定义
69 // ═══════════════════════════════════════════════
70 
77 struct TopoVertex {
78  int id;
80  double tolerance = 1e-6;
81 };
82 
91 struct TopoEdge {
92  int id;
93  int v_start, v_end;
94  std::shared_ptr<curves::NurbsCurve> curve;
95  bool reversed = false;
96 };
97 
105 struct TopoLoop {
106  int id;
107  std::vector<int> edges;
108  bool is_outer = true;
109 };
110 
118 struct TopoFace {
119  int id;
121  std::vector<int> loops;
122  bool reversed = false;
123 };
124 
131 struct TopoShell {
132  int id;
133  std::vector<int> faces;
134  bool closed = true;
135 };
136 
143 struct TopoBody {
144  int id;
145  std::vector<int> shells;
146  std::string name;
147 };
148 
149 // ═══════════════════════════════════════════════
150 // B-Rep 模型类
151 // ═══════════════════════════════════════════════
152 
177 class BrepModel {
178 public:
179  BrepModel() = default;
180 
186  int add_vertex(const Point3D& p);
187 
194  int add_edge(int v0, int v1);
195 
203  int add_edge(int v0, int v1, const curves::NurbsCurve& curve);
204 
211  int add_loop(const std::vector<int>& edges, bool outer = true);
212 
219  int add_face(int surface_id, const std::vector<int>& loops);
220 
227  int add_shell(const std::vector<int>& faces, bool closed = true);
228 
235  int add_body(const std::vector<int>& shells, const std::string& name = "");
236 
243 
244  // ── 计数查询 ──
245 
247  [[nodiscard]] size_t num_vertices() const { return vertices_.size(); }
248 
250  [[nodiscard]] size_t num_edges() const { return edges_.size(); }
251 
253  [[nodiscard]] size_t num_faces() const { return faces_.size(); }
254 
256  [[nodiscard]] size_t num_bodies() const { return bodies_.size(); }
257 
259  [[nodiscard]] size_t num_surfaces() const { return surfaces_.size(); }
260 
261  // ── 元素访问(按数组索引 — 更快,适合顺序遍历) ──
262 
264  [[nodiscard]] const TopoVertex& vertex(int id) const { return vertices_[id]; }
265 
267  [[nodiscard]] const TopoVertex& vertex_by_id(int id) const;
268 
270  [[nodiscard]] const TopoEdge& edge(int id) const { return edges_[id]; }
271 
273  [[nodiscard]] const TopoFace& face(int id) const { return faces_[id]; }
274 
276  [[nodiscard]] const curves::NurbsSurface& surface(int id) const { return surfaces_[id]; }
277 
279  [[nodiscard]] const TopoLoop& loop_by_id(int id) const;
280 
282  [[nodiscard]] const std::vector<TopoLoop>& all_loops() const { return loops_; }
283 
284  // ── 几何/拓扑查询 ──
285 
293  [[nodiscard]] core::AABB3D bounds() const;
294 
305  [[nodiscard]] bool is_valid() const;
306 
317  [[nodiscard]] mesh::HalfedgeMesh to_mesh(double deflection = 0.01) const;
318 
319  // ── 邻接关系查询 ──
320 
329  [[nodiscard]] std::vector<int> face_edges(int face_id) const;
330 
340  [[nodiscard]] std::vector<int> edge_faces(int edge_id) const;
341 
348  [[nodiscard]] std::vector<int> vertex_edges(int vertex_id) const;
349 
350 private:
351  std::vector<TopoVertex> vertices_;
352  std::vector<TopoEdge> edges_;
353  std::vector<TopoLoop> loops_;
354  std::vector<TopoFace> faces_;
355  std::vector<TopoShell> shells_;
356  std::vector<TopoBody> bodies_;
357  std::vector<curves::NurbsSurface> surfaces_;
358  int next_id_ = 0;
359 };
360 
361 } // namespace vde::brep
B-Rep 模型
Definition: brep.h:177
const TopoEdge & edge(int id) const
按数组索引访问边
Definition: brep.h:270
const std::vector< TopoLoop > & all_loops() const
获取所有环的只读引用
Definition: brep.h:282
int add_shell(const std::vector< int > &faces, bool closed=true)
添加壳
bool is_valid() const
检查模型有效性(快速版本)
std::vector< int > vertex_edges(int vertex_id) const
获取顶点的所有相邻边
mesh::HalfedgeMesh to_mesh(double deflection=0.01) const
将 B-Rep 模型 tessellate 为三角网格
int add_face(int surface_id, const std::vector< int > &loops)
添加面
size_t num_bodies() const
体数量
Definition: brep.h:256
const TopoLoop & loop_by_id(int id) const
按唯一 ID 访问环
size_t num_vertices() const
顶点数量
Definition: brep.h:247
int add_body(const std::vector< int > &shells, const std::string &name="")
添加体
const TopoVertex & vertex_by_id(int id) const
按唯一 ID 访问顶点(适用于边数据中的 ID 引用)
core::AABB3D bounds() const
计算模型的轴对齐包围盒
int add_edge(int v0, int v1, const curves::NurbsCurve &curve)
添加曲线边
int add_edge(int v0, int v1)
添加直线边
int add_vertex(const Point3D &p)
添加顶点
size_t num_edges() const
边数量
Definition: brep.h:250
size_t num_faces() const
面数量
Definition: brep.h:253
std::vector< int > face_edges(int face_id) const
获取面的所有边
const TopoVertex & vertex(int id) const
按数组索引访问顶点
Definition: brep.h:264
const TopoFace & face(int id) const
按数组索引访问面
Definition: brep.h:273
int add_loop(const std::vector< int > &edges, bool outer=true)
添加环
const curves::NurbsSurface & surface(int id) const
按数组索引访问曲面
Definition: brep.h:276
size_t num_surfaces() const
曲面数量
Definition: brep.h:259
int add_surface(const curves::NurbsSurface &surf)
添加 NURBS 曲面
std::vector< int > edge_faces(int edge_id) const
获取边的所有相邻面
轴对齐包围盒(AABB)
Definition: aabb.h:21
NURBS 曲线(Non-Uniform Rational B-Spline)
Definition: nurbs_curve.h:26
NURBS 张量积曲面
Definition: nurbs_surface.h:24
半边数据结构三角网格
Definition: halfedge_mesh.h:54
Definition: brep.h:54
CurveType
边曲线类型枚举
Definition: brep.h:65
AABB< double > AABB3D
双精度三维包围盒
Definition: aabb.h:131
foundation::Vector3D Vector3D
双精度三维向量(重新导出)
Definition: point.h:49
foundation::Point3D Point3D
双精度三维点(重新导出)
Definition: point.h:31
拓扑体
Definition: brep.h:143
std::string name
体名称(对应 STEP 中的 PRODUCT)
Definition: brep.h:146
int id
唯一体 ID
Definition: brep.h:144
std::vector< int > shells
壳 ID 列表
Definition: brep.h:145
拓扑边
Definition: brep.h:91
int v_end
起点和终点顶点 ID
Definition: brep.h:93
bool reversed
是否相对于曲线参数方向反转
Definition: brep.h:95
int id
唯一边 ID
Definition: brep.h:92
std::shared_ptr< curves::NurbsCurve > curve
边的几何曲线(可为空,表示直线)
Definition: brep.h:94
拓扑面
Definition: brep.h:118
std::vector< int > loops
环 ID 列表(第一个为外环,后续为内环)
Definition: brep.h:121
int id
唯一面 ID
Definition: brep.h:119
bool reversed
面法向量是否反转
Definition: brep.h:122
int surface_id
关联的曲面 ID
Definition: brep.h:120
拓扑环(Loop)
Definition: brep.h:105
bool is_outer
true = 外环, false = 内环(孔)
Definition: brep.h:108
int id
唯一环 ID
Definition: brep.h:106
std::vector< int > edges
边 ID 序列(按环的遍历顺序)
Definition: brep.h:107
拓扑壳
Definition: brep.h:131
int id
唯一壳 ID
Definition: brep.h:132
std::vector< int > faces
面 ID 列表
Definition: brep.h:133
bool closed
是否为封闭壳
Definition: brep.h:134
拓扑顶点
Definition: brep.h:77
double tolerance
几何容差
Definition: brep.h:80
Point3D point
三维坐标
Definition: brep.h:79
int id
唯一定点 ID
Definition: brep.h:78