MakeShape
快捷创建拓扑结构是一项基础需求,而 AMCAX::MakeVertex、AMCAX::MakeEdge、AMCAX::MakeWire、AMCAX::MakeFace 等提供了不同拓扑结构的快捷创建方式,这是极为常用且重要的功能。
MakeVertex
创建 Vertex 可通过一个 Point3 实现:
创建顶点的类
定义 MakeVertex.hpp:18
PointT< double, 3 > Point3
三维点
定义 PointT.hpp:459
MakeEdge
AMCAX::MakeEdge 可通过 Curve 快捷创建 Edge。若 MakeEdge 的输入中未包含 Vertex,它会自动生成两个 Vertex。这意味着,若想通过 MakeEdge 构建两条相连的 Edge,需特别注意 Vertex 的共用问题 —— 简单创建会得到 2 个 Edge 和 4 个 Vertex。此外,退化边也可通过 MakeEdge 构建。MakeEdge 功能丰富,下文将分类介绍:
简单构建
可通过两个 Point3 构建线段 Edge,也可通过两个 TopoVertex 构建。需要注意的是,两个 Point3/TopoVertex 之间的距离需大于 AMCAX::Precision::Confusion (),否则会被判定为同一个 Point3/TopoVertex。
基于数学表达构建
例如,可基于 Circle3、Line3 等数学表达式构建,以下以 Line3 为例:
double fp = 0.0;
double lp = 1.0;
LineS< 3 > Line3
三维直线
定义 LineT.hpp:457
DirectionT< double, 3 > Direction3
三维方向
定义 DirectionT.hpp:566
此外,MakeEdge 会根据数学表达自动调整参数、Point3、Vertex 的顺序,以及 Vertex 的 Orientation:
基于 curve 3d 构建
这是基于 curve 构建 Edge 的重要功能。在此,MakeEdge 仍会自动调整参数、Point3、Vertex 的顺序,以及 Vertex 的 Orientation。具体构建方法如下:
std::shared_ptr<AMCAX::Geom3Curve> curve = std::make_shared<AMCAX::Geom3Line>(line);
double fp = 0.0;
double lp = 1.0;
基于 pcurve 构建
需要注意的是,基于 pcurve 与 Surface 构建的 Edge 不包含 curve3d。在此,MakeEdge 仍会自动调整参数、Point3、Vertex 的顺序,以及 Vertex 的 Orientation。具体构建方法如下:
std::shared_ptr<AMCAX::Geom2Curve> pcurve = std::make_shared<AMCAX::Geom2Line>(point, dir);
std::shared_ptr<AMCAX::Geom3Surface> surf = std::make_shared<AMCAX::Geom3Plane>(frame);
double fp = 0.0;
double lp = 1.0;
DirectionT< double, 2 > Direction2
二维方向
定义 DirectionT.hpp:563
FrameT< double, 3 > Frame3
三维标架
定义 FrameT.hpp:887
PointT< double, 2 > Point2
二维点
定义 PointT.hpp:456
MakeWire
构建一个 Wire 可以通过以下三种方式:
单独添加 Edge
std::cout << makewire2.
IsDone() << std::endl;
std::cout <<
"error type:" << int(makewire2.
Error());
AMCAX_API const TopoWire & Wire()
获取构造的环
AMCAX_API WireError Error() const noexcept
获取构造过程中的错误状态
AMCAX_API void Add(const TopoEdge &e)
向环中添加边
AMCAX_API bool IsDone() const noexcept override
判断构造算法是否完成
注:每次添加的边必须与已添加的边在几何上相连。在上述示例中,若按 e1—e3—e2—e4 的顺序添加,在添加 e3 时会因与 e1 不相连而失败,此时调用 IsDone () 将返回 false,调用 Error () 将返回 WireError::DisconnectedWire。若能确定待连成 wire 的 edge 彼此相连但不清楚具体连接关系,则必须采用下文一次性添加 edge 列表的方式。
添加 Edge 的 list
列表中 edge 的顺序不影响构造结果。
std::list<AMCAX::TopoShape> elist = { e1, e3, e2, e4 };
添加 wire
在添加 wire 时,要求待添加 wire 的第一条 edge 需与已有的 wire 相连,Add 操作才能成功。
mw3.Add(wire45);
mw5.Add(wire54);
std::cout << mw5.IsDone() << std::endl;
std::cout << "error type:" << int(mw5.Error());
在该示例中,若向现有 wire123 中添加 wire54,由于 wire54 中的第一条 edge (edge5)与 wire123 不相连,所以此时调用 IsDone () 将返回 false,调用 Error () 将返回 WireError::DisconnectedWire。
MakeFace
MakeFace 功能丰富,下文将分类介绍:
基于数学表达
可基于 Plane、Cylinder 等数学表达式构建,以下以 Plane 为例:
double uMin = 0.0;
double uMax = 1.0;
double vMin = 0.0;
double vMax = 1.0;
基于 Surface
基于 Geom3Surface 构建 Face 是 MakeFace 最常用的功能。
std::shared_ptr<AMCAX::Geom3Surface> surface = std::make_shared<AMCAX::Geom3Plane>(frame);
double uMin = 0.0;
double uMax = 1.0;
double vMin = 0.0;
double vMax = 1.0;
static constexpr double Confusion() noexcept
获取混淆容差
定义 Precision.hpp:122
MakeFace 要求在提供 Surface 的同时提供 Tolerance。需要注意的是,当输入的曲面为无穷大且没有约束参数范围时,将不会自动生成 Wire。其余情况都会自动生成 Wire。
基于 Wire
单独 Wire
当 Wire 为平面上的 Wire 时,输入单独 Wire 即可成功构建 Face。
double r = 1.0;
CircleS< 3 > Circle3
三维圆
定义 CircleT.hpp:187
注:单独输入不在平面上的 Wire 可能会构建 Face 失败。
Wire + 数学表达
double r = 1.0;
bool inside = true;
注:需指定 Face 所表示的区域位于 Wire 的内部还是外部(最后的 bool 参数中,true 表示位于内部)。
Wire + Surface
double r = 1.0;
std::shared_ptr<AMCAX::Geom3Surface> surface = std::make_shared<AMCAX::Geom3Plane>(frame);
bool inside = true;
Wire + Face
double r1 = 1.0;
std::shared_ptr<AMCAX::Geom3Surface> surface1 = std::make_shared<AMCAX::Geom3Plane>(frame1);
bool inside = true;
double r2 = 0.5;
结果如下图所示:左边为 face1,右图为 face2。
但需注意 Wire 的 Orientation,即若按如下写法,会得到错误结果。
double r1 = 1.0;
std::shared_ptr<AMCAX::Geom3Surface> surface1 = std::make_shared<AMCAX::Geom3Plane>(frame1);
bool inside = true;
double r2 = 0.5;
而修正方法是在 Edge 或 Wire 层级将其 Orientation 设为 Reversed,以下以 Wire 为例:
static AMCAX_API const TopoWire & Wire(const TopoShape &s)
将形状转换为环
形状的基类,包含具有位置和方向信息的基础形状
定义 TopoShape.hpp:15
AMCAX_API TopoShape Oriented(OrientationType orient) const noexcept
获取指定方向后的形状
TopoBuilder
尽管 Make*.hpp 提供了若干便于构建 TopoShape 的 API,但部分建模问题仍需依赖 TopoBuilder 解决。下文将介绍使用 TopoBuilder 构建不同拓扑结构的方法。
Vertex
MakeVertex 提供构建顶点的功能。
构造 B-Rep 结构的工具类
定义 TopoBuilder.hpp:39
AMCAX_API void MakeVertex(TopoVertex &v) const
构造空顶点
AMCAX_API void UpdateVertex(const TopoVertex &v, const Point3 &p, double tol) const
更新顶点的点
Edge
针对不同类型的 Edge,其构建方法各不相同,以下将逐一介绍:
普通 Edge
规范的建模思路为:先通过几何计算获取所有所需的 Point、Curve3d 及 Pcurve,再据此构建拓扑结构。
第一步:准备所需的 Curve3d ,基于该 Curve3d 构建 Edge 。
std::shared_ptr<AMCAX::Geom3Curve >curve = line.Value();
double fp = 0.0;
double lp = 2.0;
builder.
Range(edge, fp, lp);
构造三维几何直线的类
定义 MakeGeom3Line.hpp:15
AMCAX_API void MakeEdge(TopoEdge &e) const
构造空边
AMCAX_API void Range(const TopoEdge &e, double first, double last, bool only3d=false) const
设置边的参数边界
Range 用于设置 TopoEdge 的参数范围。若 Curve3d 的参数范围与 TopoEdge 所需的参数范围一致,此步骤可省略。
第二步:准备 Edge 对应的起始 Vertex 与终止 Vertex,并将这两个 Vertex 关联至该 Edge。
builder.
Add(edge, v2.
Oriented(AMCAX::OrientationType::Reversed));
AMCAX_API void Add(TopoShape &s, const TopoShape &c) const
向形状中添加子形状
AMCAX_API void SetOrientation(OrientationType orient) noexcept
设置形状的方向
AMCAX_API void Reverse() noexcept
反转形状的方向
注:此处需注意起始 Vertex 与终止 Vertex 的 Orientation。TopoEdge 的起始 Vertex 方向为 Forward,终止 Vertex 方向为 Reversed。
由于 Orientation 的默认值为 Forward,因此需调整终止 Vertex 的方向属性。调整方式分为两类:一是对自身进行改变,对应的接口为 SetOrientation 和 Reverse;二是不对自身进行改变,生成一个方向为 Reversed 的新 Vertex,对应的接口为 Oriented,生成的新对象需传入 builder 中使用。
第三步:在完成 Face 的构建后,为其添加 Pcurve。
double uMin = 0.0;
double uMax = 2.0;
double vMin = 0.0;
double vMax = 2.0;
std::shared_ptr< Geom3Surface > surf1 = mp1.Value();
std::shared_ptr< Geom3Surface > surf2 = mp2.Value();
std::shared_ptr< AMCAX::Geom2Curve > pcurve1;
std::shared_ptr< AMCAX::Geom2Curve > pcurve2;
构造三维几何平面的类
定义 MakeGeom3Plane.hpp:13
static constexpr double PConfusion(double t) noexcept
获取二维参数空间中的混淆容差
定义 Precision.hpp:127
AMCAX_API void UpdateEdge(const TopoEdge &e, const std::shared_ptr< Geom3Curve > &c, double tol) const
更新边的三维曲线和容差
需注意 Pcurve 的方向应与 Curve3d 保持一致,且 Edge 的 Orientation 对 Pcurve 的方向无任何影响,需牢记 “几何是几何,拓扑是拓扑” 的核心逻辑。
此外,添加 Vertex 的操作仅需在 MakeEdge 之后执行即可:一方面,第二步(添加 Vertex)与第三步(添加 Pcurve)的顺序可互换;另一方面,在设置 Range 之前添加 Vertex,同样不影响建模流程。
Seam Edge
其他的步骤都相同,仅第三步有所不同:
builder.
UpdateEdge(edge, pcurve1, pcurve2, face, Precision::PConfusion());
需注意 pcurve1 与 pcurve2 的方向仍需与 curve3d 保持一致。二者的区别在于:pcurve1 对应正向(Forward)Edge 在 Surface 参数域上的参数曲线,pcurve2 对应反向(Reversed)Edge 在 Surface 参数域上的参数曲线。
Degenerated Edge
其他的步骤都相同,仅第一步不同,没有 curve3d:
AMCAX_API void Degenerated(const TopoEdge &e, bool d) const
设置边的退化标志
constexpr double pi
数学常数 Pi,圆的周长与直径之比
定义 Constants.hpp:42
此处需注意将退化标志(Flag)设为 True。不同于常规情况,此处 Pcurve 的方向无需与 Curve3d 保持一致,只需与 Edge 的 Orientation 保持一致即可。
自由 Edge
其他的步骤都相同,仅第三步不同,只有 1 条 pcurve。
Wire
正常的思路是:
第一步:先依据参数域上的 Wire 确定其方向,再明确需选用的 Edge 以及这些 Edge 各自的 Orientation。
std::vector<std::pair<int, bool>> wireEdges1 =
{
{1, true},
{2, true},
{3, true},
{4, true}
};
第二步:构建 Edge 并将其添加至 Wire 中。
for (const auto& edgeInfo : wireEdges1)
{
int edgeID = edgeInfo.first;
bool isForward = edgeInfo.second;
if (isForward)
{
}
else
{
}
builder.
Add(wire1, edge);
}
AMCAX_API void MakeWire(TopoWire &w) const
构造一个空环
static AMCAX_API const TopoEdge & Edge(const TopoShape &s)
将形状转换为边
注:这里 Edge 的添加顺序可以是任意的。
第三步:将 Wire 的 Closed Flag 设置为对应状态。
AMCAX_API bool Closed() const noexcept
判断形状是否封闭
Face
构建 Face 的方法如下:
builder.
Add(face1, wire1);
static AMCAX_API const Direction3 & DZ() noexcept
获取三维中的 z 方向
AMCAX_API void MakeFace(TopoFace &f) const
构造一个空面
Shell
构建 Shell 时需要注意 Closed Flag,方法如下:
std::vector<AMCAX::TopoFace> allFaces = { face1 };
for (const auto& face : allFaces)
{
builder.
Add(shell, face);
}
AMCAX_API void MakeShell(TopoShell &s) const
构造一个空壳
Solid
构建 Solid 的方式如下:
builder.
Add(solid, shell);
AMCAX_API void MakeSolid(TopoSolid &s) const
构造一个空实体
Compound
构建 Compound 的方式如下:
builder.
Add(comp, anyShape);
AMCAX_API void MakeCompound(TopoCompound &c) const
构造一个空复合体
复合体的类
定义 TopoCompound.hpp:12