ViewDesignEngine  3.1.0
高性能 CAD 计算几何引擎
vde::brep 命名空间参考

struct  TopoVertex
 拓扑顶点 更多...
 
struct  TopoEdge
 拓扑边 更多...
 
struct  TopoLoop
 拓扑环(Loop) 更多...
 
struct  TopoFace
 拓扑面 更多...
 
struct  TopoShell
 拓扑壳 更多...
 
struct  TopoBody
 拓扑体 更多...
 
class  BrepModel
 B-Rep 模型 更多...
 
struct  ValidationResult
 B-Rep 模型的综合验证结果 更多...
 

枚举

enum class  CurveType {
  Line , Circle , Bezier , BSpline ,
  Nurbs
}
 边曲线类型枚举 更多...
 
enum class  IgesError {
  Ok = 0 , FileNotFound , ParseError , InvalidSection ,
  UnsupportedEntity , MissingEntity , EntityTypeError
}
 IGES 导入错误码 更多...
 
enum class  StepError {
  Ok = 0 , FileNotFound , ParseError , InvalidHeader ,
  UnsupportedSchema , MissingEntity , EntityTypeError
}
 STEP 导入错误码 更多...
 

函数

BrepModel brep_union (const BrepModel &a, const BrepModel &b)
 B-Rep 布尔并集: A ∪ B 更多...
 
BrepModel brep_intersection (const BrepModel &a, const BrepModel &b)
 B-Rep 布尔交集: A ∩ B 更多...
 
BrepModel brep_difference (const BrepModel &a, const BrepModel &b)
 B-Rep 布尔差集: A \ B 更多...
 
ValidationResult validate (const BrepModel &body)
 BrepModel 执行综合验证 更多...
 
std::string export_iges (const std::vector< BrepModel > &bodies)
 将 B-Rep 体导出为 IGES 格式字符串(版本 5.3) 更多...
 
void export_iges_file (const std::string &filepath, const std::vector< BrepModel > &bodies)
 将 B-Rep 体导出为 IGES 文件 更多...
 
std::vector< BrepModelimport_iges (const std::string &filepath)
 从文件导入 IGES 更多...
 
std::vector< BrepModelimport_iges_from_string (const std::string &data)
 从字符串导入 IGES(用于测试) 更多...
 
IgesError iges_last_error ()
 获取最近一次 IGES 导入的错误码 更多...
 
const std::string & iges_last_error_message ()
 获取最近一次 IGES 导入的可读错误描述 更多...
 
BrepModel extrude (const curves::NurbsCurve &profile, const Vector3D &dir)
 沿方向挤出平面轮廓 更多...
 
BrepModel revolve (const curves::NurbsCurve &profile, const Point3D &axis_origin, const Vector3D &axis_dir, double angle_rad=2.0 *M_PI)
 绕轴旋转平面轮廓 更多...
 
BrepModel sweep (const curves::NurbsCurve &profile, const curves::NurbsCurve &path)
 沿任意路径扫掠轮廓 更多...
 
BrepModel loft (const std::vector< curves::NurbsCurve > &profiles)
 在两个或多个轮廓曲线之间放样 更多...
 
BrepModel make_box (double w, double h, double d)
 创建立方体 更多...
 
BrepModel make_cylinder (double radius, double height, int segments=32)
 创建圆柱体 更多...
 
BrepModel make_sphere (double radius, int segments_u=32, int segments_v=16)
 创建球体 更多...
 
BrepModel fillet (const BrepModel &body, int edge_id, double radius)
 对边做圆角处理 更多...
 
BrepModel chamfer (const BrepModel &body, int edge_id, double distance)
 对边做倒角 更多...
 
BrepModel shell (const BrepModel &body, int face_id, double thickness)
 抽壳(挖空实体) 更多...
 
std::string export_step (const std::vector< BrepModel > &bodies)
 将 B-Rep 体导出为 STEP AP214 字符串 更多...
 
void export_step_file (const std::string &filepath, const std::vector< BrepModel > &bodies)
 将 B-Rep 体导出为 STEP 文件 更多...
 
std::vector< BrepModelimport_step (const std::string &filepath)
 从文件导入 STEP(AP203/AP214) 更多...
 
std::vector< BrepModelimport_step_from_string (const std::string &step_data)
 从字符串导入 STEP(用于测试和嵌入式场景) 更多...
 
StepError step_last_error ()
 获取最近一次 STEP 导入的错误码 更多...
 
const std::string & step_last_error_message ()
 获取最近一次 STEP 导入的可读错误描述 更多...
 

枚举类型说明

◆ CurveType

enum vde::brep::CurveType
strong

边曲线类型枚举

指定边所使用的曲线表示类别, 影响 tessellation、布尔运算和文件交换时的处理方式。

枚举值
Line 
Circle 
Bezier 
BSpline 
Nurbs 

在文件 brep.h65 行定义.

◆ IgesError

enum vde::brep::IgesError
strong

IGES 导入错误码

枚举值
Ok 

导入成功

FileNotFound 

文件不存在或无法读取

ParseError 

IGES 语法错误(固定宽度格式异常)

InvalidSection 

段标记无效或缺失

UnsupportedEntity 

遇到了不支持但合法的实体类型

MissingEntity 

引用了未定义的实体

EntityTypeError 

实体类型解析失败

在文件 iges_import.h42 行定义.

◆ StepError

enum vde::brep::StepError
strong

STEP 导入错误码

枚举 import_step()import_step_from_string() 可能返回的所有错误类型。

枚举值
Ok 

导入成功

FileNotFound 

文件不存在或无法读取

ParseError 

STEP 语法错误(令牌/格式异常)

InvalidHeader 

HEADER 段格式无效

UnsupportedSchema 

不支持的 SCHEMA(非 AP203/AP214)

MissingEntity 

引用了未定义的实体

EntityTypeError 

实体类型未识别或类型不匹配

在文件 step_import.h39 行定义.

函数说明

◆ brep_difference()

BrepModel vde::brep::brep_difference ( const BrepModel a,
const BrepModel b 
)

B-Rep 布尔差集: A \ B

从 A 中减去 B 所占据的区域。

参数
a被减实体 A
b减去实体 B
返回
新的 B-Rep 实体(a \ b)
前置条件
a 和 b 必须是有效的封闭实体
// 从盒子中减去球体 = 带球形凹陷的盒子
auto box = make_box(2, 2, 2);
auto sphere = make_sphere(0.5);
auto result = brep_difference(box, sphere);
BrepModel make_sphere(double radius, int segments_u=32, int segments_v=16)
创建球体
BrepModel brep_difference(const BrepModel &a, const BrepModel &b)
B-Rep 布尔差集: A \ B
BrepModel make_box(double w, double h, double d)
创建立方体
double box(const Point3D &p, const Point3D &half_extents)
轴对齐立方体的 SDF
double sphere(const Point3D &p, double radius)
球体的 SDF
参见
brep_union 并集
brep_intersection 交集

◆ brep_intersection()

BrepModel vde::brep::brep_intersection ( const BrepModel a,
const BrepModel b 
)

B-Rep 布尔交集: A ∩ B

保留两个实体共有的区域。

参数
a第一个 B-Rep 实体
b第二个 B-Rep 实体
返回
新的 B-Rep 实体(a ∩ b)
前置条件
a 和 b 必须是有效的封闭实体
// 长方体与球体的交集 = 八分之一球(角部)
auto box = make_box(2, 2, 2);
auto sphere = make_sphere(1.8);
auto result = brep_intersection(box, sphere);
BrepModel brep_intersection(const BrepModel &a, const BrepModel &b)
B-Rep 布尔交集: A ∩ B
参见
brep_union 并集
brep_difference 差集

◆ brep_union()

BrepModel vde::brep::brep_union ( const BrepModel a,
const BrepModel b 
)

B-Rep 布尔并集: A ∪ B

合并两个 B-Rep 实体为一个,自动处理相交曲面的分割和重新连接。

算法概要:

  1. 计算两个模型之间的所有曲面交线
  2. 沿交线分割曲面
  3. 根据布尔操作类型保留或丢弃分割后的面片
  4. 重新连接拓扑结构(边、环、壳)
参数
a第一个 B-Rep 实体
b第二个 B-Rep 实体
返回
新的 B-Rep 实体(a ∪ b)
警告
两个输入实体必须都是水密(watertight)且非自交(non-self-intersecting)。 如果任一输入未通过验证,结果未定义。
auto box = make_box(2, 2, 2);
auto sphere = make_sphere(1.5);
auto result = brep_union(box, sphere);
BrepModel brep_union(const BrepModel &a, const BrepModel &b)
B-Rep 布尔并集: A ∪ B
参见
brep_intersection 交集
brep_difference 差集

◆ chamfer()

BrepModel vde::brep::chamfer ( const BrepModel body,
int  edge_id,
double  distance 
)

对边做倒角

将尖锐边替换为 45° 斜面。

参数
body输入实体
edge_id要倒角的边 ID
distance倒角距离(从原边沿两个面各偏移的距离)
返回
倒角后的新实体
前置条件
distance > 0
参见
fillet 圆角

◆ export_iges()

std::string vde::brep::export_iges ( const std::vector< BrepModel > &  bodies)

将 B-Rep 体导出为 IGES 格式字符串(版本 5.3)

序列化所有传入的体及其几何/拓扑数据为 IGES 固定宽度格式。

输出结构:

S 1H,,1H;, ... S0000001
G ... G0000003
D 116,1,2,... (Point entity) D0000001
D 110,3,4,... (Line entity) D0000002
... ...
P 116,0.,0.,0.; 1P0000001
P 110,0.,0.,0.,1.,0.,0.; 3P0000002
T 1 T0000001
foundation::Point< T, Dim > Point
通用 N 维点类型(重新导出,便于 core 模块使用)
Definition: point.h:26

实体输出策略

  1. **几何实体**(点/线/弧/曲线/面/曲面)先输出并使 Directory 条目索引递增
  2. **拓扑实体**(顶点/边/环/面/壳/B-Rep Object)随后输出,通过索引引用于几何实体
  3. 如果体有 name,作为 B-Rep Object 的属性输出
参数
bodiesB-Rep 体列表
返回
IGES 5.3 格式字符串
auto body = make_box(10, 5, 3);
std::string iges_str = export_iges({body});
std::string export_iges(const std::vector< BrepModel > &bodies)
将 B-Rep 体导出为 IGES 格式字符串(版本 5.3)
参见
export_iges_file 直接写入文件
export_step STEP 格式导出

◆ export_iges_file()

void vde::brep::export_iges_file ( const std::string &  filepath,
const std::vector< BrepModel > &  bodies 
)

将 B-Rep 体导出为 IGES 文件

调用 export_iges() 后写入文件。

参数
filepath输出文件路径(建议扩展名 .igs 或 .iges)
bodiesB-Rep 体列表
参见
export_iges 获取字符串输出

◆ export_step()

std::string vde::brep::export_step ( const std::vector< BrepModel > &  bodies)

将 B-Rep 体导出为 STEP AP214 字符串

序列化所有传入的体及其几何数据为 STEP 文本格式。

输出结构:

ISO-10303-21;
HEADER;
FILE_DESCRIPTION(...)
FILE_NAME(...)
FILE_SCHEMA(('AUTOMOTIVE_DESIGN'))
ENDSEC;
DATA;
#1 = PRODUCT(...)
#2 = CARTESIAN_POINT(...)
...
ENDSEC;
END-ISO-10303-21;
参数
bodiesB-Rep 体列表(每个体对应一个 PRODUCT)
返回
STEP AP214 格式字符串
注解
输出包含所有必要的 ISO 10303-21 头部信息。
auto body = make_box(10, 5, 3);
std::string step_str = export_step({body});
// 写入文件或通过网络发送
std::string export_step(const std::vector< BrepModel > &bodies)
将 B-Rep 体导出为 STEP AP214 字符串
参见
export_step_file 直接写入文件
export_iges IGES 格式导出

◆ export_step_file()

void vde::brep::export_step_file ( const std::string &  filepath,
const std::vector< BrepModel > &  bodies 
)

将 B-Rep 体导出为 STEP 文件

便捷函数:调用 export_step() 后写入文件。

参数
filepath输出文件路径(建议扩展名 .step 或 .stp)
bodiesB-Rep 体列表
参见
export_step 获取字符串输出

◆ extrude()

BrepModel vde::brep::extrude ( const curves::NurbsCurve profile,
const Vector3D &  dir 
)

沿方向挤出平面轮廓

将平面曲线沿给定方向扫掠,生成柱状实体。

算法: 曲线的每个点沿方向向量平移,两端加盖平面形成封闭实体。

参数
profile轮廓曲线(必须位于一个平面内)
dir挤出方向向量(其长度决定挤出距离)
返回
挤出后的 B-Rep 实体
前置条件
profile 必须是平面曲线(存在于某个平面内)且闭合
// 沿 Z 轴挤出 5 个单位
auto circle = NurbsCurve::create_circle(Point3D(0,0,0), 2.0);
auto cylinder = extrude(circle, Vector3D(0, 0, 5));
BrepModel extrude(const curves::NurbsCurve &profile, const Vector3D &dir)
沿方向挤出平面轮廓
foundation::Vector3D Vector3D
双精度三维向量(重新导出)
Definition: point.h:49
foundation::Point3D Point3D
双精度三维点(重新导出)
Definition: point.h:31
double cylinder(const Point3D &p, double radius, double height)
带平端盖的圆柱体 SDF
参见
revolve 旋转扫掠
sweep 沿任意路径扫掠

◆ fillet()

BrepModel vde::brep::fillet ( const BrepModel body,
int  edge_id,
double  radius 
)

对边做圆角处理

在指定的边上施加恒定半径的圆角(倒圆)。 适用于凹边和凸边。

参数
body输入实体
edge_id要倒圆的边 ID
radius圆角半径,必须 > 0
返回
圆角后的新实体
注解
圆角半径不能超过相邻面的最小宽度,否则会产生自交。
只支持恒定半径圆角。变半径圆角尚未实现。
auto box = make_box(10, 5, 3);
auto rounded = fillet(box, 0, 2.0); // 对边 0 做半径 2 的圆角
BrepModel fillet(const BrepModel &body, int edge_id, double radius)
对边做圆角处理
参见
chamfer 倒角
shell 抽壳

◆ iges_last_error()

IgesError vde::brep::iges_last_error ( )

获取最近一次 IGES 导入的错误码

返回
IgesError 枚举值
参见
iges_last_error_message 获取可读描述

◆ iges_last_error_message()

const std::string& vde::brep::iges_last_error_message ( )

获取最近一次 IGES 导入的可读错误描述

返回
错误描述字符串
参见
iges_last_error 获取枚举错误码

◆ import_iges()

std::vector<BrepModel> vde::brep::import_iges ( const std::string &  filepath)

从文件导入 IGES

解析 .igs 或 .iges 文件并返回其中的 B-Rep 体。

算法概要:

  1. 读取文件并按 80 字符行分割
  2. 解析 Start, Global, Directory, Parameter 各段
  3. 根据 Directory Entry 识别实体类型和参数位置
  4. 构建 B-Rep 拓扑结构(B-Rep Object 或独立几何实体)
参数
filepath.igs 或 .iges 文件路径
返回
B-Rep 体列表
注解
IGES 格式较为宽松,不同 CAD 系统的实现差异很大。 对于非常规实体或自定义类型,可能会返回 IgesError::UnsupportedEntity。
auto bodies = import_iges("part.igs");
for (auto& body : bodies) {
auto mesh = body.to_mesh(0.01);
// 处理 mesh
}
std::vector< BrepModel > import_iges(const std::string &filepath)
从文件导入 IGES
参见
import_iges_from_string 从字符串导入
iges_last_error 获取错误码

◆ import_iges_from_string()

std::vector<BrepModel> vde::brep::import_iges_from_string ( const std::string &  data)

从字符串导入 IGES(用于测试)

参数
dataIGES 文件完整内容(字符串形式)
返回
B-Rep 体列表
参见
import_iges 从文件导入

◆ import_step()

std::vector<BrepModel> vde::brep::import_step ( const std::string &  filepath)

从文件导入 STEP(AP203/AP214)

解析 .step / .stp 文件并提取所有 PRODUCT 对应的 B-Rep 体。 每个 PRODUCT 定义对应返回向量的一个元素。

算法概要:

  1. 读取文件并分割为 HEADER, DATA 段
  2. 解析 DATA 段中的实体定义(::ID = TYPE(params);)
  3. 构建实体依赖图并按拓扑层次重建模型
  4. 将每个 CLOSED_SHELL 转换为 BrepModel
参数
filepath.step 或 .stp 文件路径
返回
B-Rep 体列表(每个文件中的 PRODUCT 一个)
注解
大型 STEP 文件(> 100 MB)可能需要数秒到数十秒进行解析。
{.cpp"}
auto bodies = import_step("assembly.step");
for (auto& body : bodies) {
auto mesh = body.to_mesh();
// 渲染或处理 mesh
}
参见
import_step_from_string 从内存字符串导入(测试用)
step_last_error 获取错误码

◆ import_step_from_string()

std::vector<BrepModel> vde::brep::import_step_from_string ( const std::string &  step_data)

从字符串导入 STEP(用于测试和嵌入式场景)

import_step() 功能完全相同,但从内存中的 STEP 数据字符串解析。

参数
step_data完整的 STEP 文件内容(字符串形式)
返回
B-Rep 体列表
std::string step_str = R"(
ISO-10303-21;
HEADER; ... ENDSEC;
DATA; ... ENDSEC;
END-ISO-10303-21;
)";
auto bodies = import_step_from_string(step_str);
std::vector< BrepModel > import_step_from_string(const std::string &step_data)
从字符串导入 STEP(用于测试和嵌入式场景)
参见
import_step 从文件导入

◆ loft()

BrepModel vde::brep::loft ( const std::vector< curves::NurbsCurve > &  profiles)

在两个或多个轮廓曲线之间放样

通过线性或平滑插值连接多个平行或非平行轮廓, 生成过渡实体。

参数
profiles轮廓曲线列表(至少 2 条)
返回
放样后的 B-Rep 实体
前置条件
profiles.size() ≥ 2
所有轮廓应是平面曲线(逐一)
auto profile_a = NurbsCurve::create_circle(Point3D(0,0,0), 5.0);
auto profile_b = NurbsCurve::create_circle(Point3D(0,0,10), 2.0);
auto cone = loft({profile_a, profile_b});
BrepModel loft(const std::vector< curves::NurbsCurve > &profiles)
在两个或多个轮廓曲线之间放样
double cone(const Point3D &p, double angle_rad, double height)
圆锥台的 SDF(非内联实现)
参见
extrude 单轮廓挤出

◆ make_box()

BrepModel vde::brep::make_box ( double  w,
double  h,
double  d 
)

创建立方体

以原点为中心、轴对齐的立方体。

参数
w宽度(X 方向),必须 > 0
h高度(Y 方向),必须 > 0
d深度(Z 方向),必须 > 0
返回
实心立方体 B-Rep
auto box = make_box(10, 5, 3); // 10×5×3 的盒子
参见
make_cylinder 圆柱体
make_sphere 球体

◆ make_cylinder()

BrepModel vde::brep::make_cylinder ( double  radius,
double  height,
int  segments = 32 
)

创建圆柱体

沿 Y 轴、以原点为中心的圆柱体。

参数
radius截面半径,必须 > 0
height总高度,沿 Y 轴从 -h/2 到 +h/2
segments截面分段数(边数,默认 32)
返回
实心圆柱体 B-Rep
注解
segments 越大圆柱越光滑,但面和边数增加。
auto cyl = make_cylinder(2.0, 10.0, 64); // 高精度圆柱
BrepModel make_cylinder(double radius, double height, int segments=32)
创建圆柱体
参见
make_box 立方体
make_sphere 球体

◆ make_sphere()

BrepModel vde::brep::make_sphere ( double  radius,
int  segments_u = 32,
int  segments_v = 16 
)

创建球体

以原点为中心的球体。

参数
radius球半径,必须 > 0
segments_u经度方向分段数(默认 32)
segments_v纬度方向分段数(默认 16)
返回
实心球体 B-Rep
auto sphere = make_sphere(5.0, 32, 32);
参见
make_cylinder 圆柱体

◆ revolve()

BrepModel vde::brep::revolve ( const curves::NurbsCurve profile,
const Point3D &  axis_origin,
const Vector3D &  axis_dir,
double  angle_rad = 2.0 *M_PI 
)

绕轴旋转平面轮廓

将轮廓绕给定轴旋转,生成旋转体(如轮子、瓶子等)。

参数
profile轮廓曲线(通常位于轴的半平面中)
axis_origin旋转轴上的一个点
axis_dir旋转轴方向(单位向量)
angle_rad旋转角度(弧度,默认 2π = 完整的旋转体)
返回
旋转后的 B-Rep 实体
前置条件
profile 必须在轴的同一侧(不应跨越轴线)
// 绕 Y 轴旋转半圆,生成球体的一半
NurbsCurve semicircle = 在 XZ 平面中的半圆弧;
auto half_sphere = revolve(semicircle, Point3D(0,0,0),
Vector3D(0,1,0), M_PI);
BrepModel revolve(const curves::NurbsCurve &profile, const Point3D &axis_origin, const Vector3D &axis_dir, double angle_rad=2.0 *M_PI)
绕轴旋转平面轮廓
参见
extrude 线性挤出
make_sphere 直接创建球体

◆ shell()

BrepModel vde::brep::shell ( const BrepModel body,
int  face_id,
double  thickness 
)

抽壳(挖空实体)

将实体变为等厚度的壳,去除指定面形成开口。

参数
body输入实心实体
face_id要移除的面 ID(形成开口),-1 表示封闭壳(不开口)
thickness壁厚(正值 = 向外偏移,负值 = 向内偏移)
返回
抽壳后的新实体
注解
壁厚不应超过实体最小尺寸的一半。
当 face_id = -1 时,结果是一个封闭的壳(中空但没有开口)。
{.cpp"}
auto box = make_box(10, 5, 3);
auto shelled = shell(box, 0, 0.5); // 移除面 0,壁厚 0.5
参见
fillet 圆角

◆ step_last_error()

StepError vde::brep::step_last_error ( )

获取最近一次 STEP 导入的错误码

线程安全的:返回当前线程最近一次导入的错误。

返回
StepError 枚举值
参见
step_last_error_message 获取可读的错误描述

◆ step_last_error_message()

const std::string& vde::brep::step_last_error_message ( )

获取最近一次 STEP 导入的可读错误描述

返回
错误描述字符串(如 "Missing entity reference #42")
auto bodies = import_step("nonexistent.step");
if (bodies.empty()) {
std::cerr << "Import failed: " << step_last_error_message() << std::endl;
}
const std::string & step_last_error_message()
获取最近一次 STEP 导入的可读错误描述
std::vector< BrepModel > import_step(const std::string &filepath)
从文件导入 STEP(AP203/AP214)
参见
step_last_error 获取枚举错误码

◆ sweep()

BrepModel vde::brep::sweep ( const curves::NurbsCurve profile,
const curves::NurbsCurve path 
)

沿任意路径扫掠轮廓

轮廓沿一条空间路径曲线运动,生成管道或异形截面杆。

参数
profile截面轮廓(需位于路径起点的垂直平面内)
path扫掠路径曲线
返回
扫掠后的 B-Rep 实体
注解
路径曲率过大处可能出现自交,需要控制路径的光滑性。
{.cpp"}
auto circle = NurbsCurve::create_circle(Point3D(0,0,0), 0.5);
auto helix = NurbsCurve::create_helix(// ...);
auto pipe = sweep(circle, helix);
参见
extrude 直线挤出
revolve 旋转扫掠

◆ validate()

ValidationResult vde::brep::validate ( const BrepModel body)

BrepModel 执行综合验证

检查以下项:

  1. 基本完整性: 顶点/边/面计数 > 0,ID 引用有效
  2. 水密性: 每条边恰好有 2 个相邻面,构成封闭流形
  3. 方向一致性: 相邻面的法向量方向一致(没有翻转的面)
  4. 自交检测: 面片内部不相交(共享边除外)
  5. 边尺寸: 无退化边(太短)或异常长边
  6. 壳闭合性: 每个标记为 closed 的壳在几何上确实封闭
参数
body待验证的 B-Rep 模型
返回
ValidationResult 包含所有检查结果的详细报告
注解
自交检测是最昂贵的检查项(O(n²) 面对数), 对于大模型(> 1000 面)可能需要较长时间。
auto result = validate(my_model);
if (!result.valid) {
for (auto& err : result.errors) {
std::cerr << "Error: " << err << std::endl;
}
}
if (result.watertightness < 0.99) {
std::cerr << "Model is not watertight!" << std::endl;
}
ValidationResult validate(const BrepModel &body)
对 BrepModel 执行综合验证
参见
BrepModel::is_valid() 快速有效性检查(无详细报告)