AMCAX Kernel
Geometry kernel for CAD/CAE/CAM
九韶内核 1.0.0.0
载入中...
搜索中...
未找到
拓扑结构的相关属性

Orientation

OrientationType 共有 4 种类型:Forward,Reversed,Internal,External,其中最常用的是 Forward 和 Reversed。任何一级的 TopoShape 都可以用 SetOrientation() 来设置 Orientation,或者用 Orientation() 来获取 Orientation。如果想获得一个与当前 TopoShape 只有 Orientation 不同的 TopoShape,可以使用 Orientated() 。Orientation 是与几何、Location 独立的成员,改变任何一个不会影响其他任意成员。

Vertex

对于一条 Edge ,其起始 Vertex 的 Orientation 为 Forward,终止 Vertex 的 Orientation 为 Reversed。比如一个线段 Edge 有两个不同的 Vertex,则 Orientation 一个是 Forward,另一个是 Reversed。再比如圆构成的 Edge 有两个相同的 Vertex,但 Orientation 也是一个为 Forward,另一个为 Reversed。

auto c = std::make_shared<AMCAX::Geom3Circle>(AMCAX::Frame3(), 1.0);
//Make a vertex
//Set the orientation of v2 to Reversed
v2.SetOrientation(AMCAX::OrientationType::Reversed);
//Make a edge
// Add different vertices
builder.Add(edge, v1);
builder.Add(edge, v2);
std::cout << AMCAX::TopoTool::IsClosed(edge) << std::endl;//0
//Make a edge2
// Add same vertices
builder.Add(edge2, v1);
builder.Add(edge2, v1.Oriented(AMCAX::OrientationType::Reversed));
std::cout << AMCAX::TopoTool::IsClosed(edge2) << std::endl;//1
创建顶点的类
定义 MakeVertex.hpp:16
static constexpr double Confusion() noexcept
获取混淆容差
定义 Precision.hpp:122
构造 B-Rep 结构的工具类
定义 TopoBuilder.hpp:37
AMCAX_API void MakeEdge(TopoEdge &e) const
构造空边
AMCAX_API void Add(TopoShape &s, const TopoShape &c) const
向形状中添加子形状
边的类
定义 TopoEdge.hpp:12
AMCAX_API void SetOrientation(OrientationType orient)
设置形状的方向
AMCAX_API TopoShape Oriented(OrientationType orient) const
获取指定方向后的形状
static AMCAX_API bool IsClosed(const TopoShape &s)
判断形状是否封闭
顶点类
定义 TopoVertex.hpp:12
PointT< double, 3 > Point3
三维点
定义 PointT.hpp:459
FrameT< double, 3 > Frame3
三维标架
定义 FrameT.hpp:885

注:在上面这个例子中,因为圆构成的 Edge 有两个相同的 Vertex,所有只需要构造一个顶点就可以,这时 AMCAX::TopoTool::IsClosed(edge) 会返回 true。如果构造了两个顶点,那么 AMCAX::TopoTool::IsClosed(edge) 会返回 false。

Edge

Edge 的 Forward 方向是 curve3d 的方向。如果没有 curve3d 就是 pcurve 的方向。Reversed Edge 的方向与 curve 方向相反。
比如已知三条用 xoy 平面上的 3d curve 构建的 Edge,以及用自然标架构造的 Geom3Plane:

由于必须保证在参数域上,Wire 的方向是逆时针的,所以应当使用 Reversed 的 Edge0,Forward 的 Edge2,Forward 的 Edge1 构成 Wire。

如果使用了顺时针的 Wire ,即 Forward 的 Edge0,Reversed 的 Edge1,Reversed 的 Edge2,那么 Face 会定义为 Wire 不围成的部分。以下分别为逆时针和顺时针的 Wire:

如果 Geom3Plane 是用 Frame3(O, -OZ, OX) 构造的,那么 Wire 的方向应为顺时针方向,即 Forward 的 Edge0,Reversed 的 Edge1,Reversed 的 Edge2,这样就可以确保 Face 被正确定义为 Wire 围成的区域。

Wire

Wire 的 Reversed 等价于将 Forward 的 Wire 中的每个 Edge 的 Orientation 变为反向。

//Make a box
AMCAX::MakeBox box(AMCAX::Point3(-5.0, -5.0, 0.0), AMCAX::Point3(5.0, 5.0, 3.0));
//Get the wire from box
AMCAX::TopoExplorerTool::MapShapes(box, AMCAX::ShapeType::Wire, wireSet);
//Get the edge from wire1
AMCAX::TopoExplorerTool::MapShapes(wire1, AMCAX::ShapeType::Edge, edgeSet);
std::cout << int(edge1.Orientation()) << std::endl;//0
//Reverse the orientation of the wire1
//Get the edge from rewire
AMCAX::TopoExplorerTool::MapShapes(rewire, AMCAX::ShapeType::Edge, edgeSet2);
AMCAX::TopoEdge reedge = AMCAX::TopoCast::Edge(edgeSet2[0]);
std::cout << int(reedge.Orientation()) << std::endl;//1
创建立方体的类
定义 MakeBox.hpp:18
static AMCAX_API const TopoEdge & Edge(const TopoShape &s)
将形状转换为边
static AMCAX_API const TopoWire & Wire(const TopoShape &s)
将形状转换为环
static AMCAX_API void MapShapes(const TopoShape &s, ShapeType t, IndexSet< TopoShape > &shapeSet)
构造给定类型的子形状集合
AMCAX_API OrientationType Orientation() const
获取形状的方向
AMCAX_API TopoShape Reversed() const
获取反转方向后的形状
环类
定义 TopoWire.hpp:12

Face

对 Face 进行 Reversed 后, Face 所包围的方向变为曲面法向的反向。对 Face 进行 Reversed 等价于将 Forward 的 Face 中 Wire 的 Orientation 变为反向。

//Make a box
AMCAX::TopoShape box = AMCAX::MakeBox(AMCAX::Point3(-5.0, -5.0, 0.0), AMCAX::Point3(5.0, 5.0, 3.0));
//Get the face from box
AMCAX::TopoExplorerTool::MapShapes(box, AMCAX::ShapeType::Face, faceSet);
std::cout << int(face1.Orientation()) << std::endl;//1
//Get the wire from face1
AMCAX::TopoExplorerTool::MapShapes(face1, AMCAX::ShapeType::Wire, wireSet);
std::cout << int(wire1.Orientation()) << std::endl;//1
//Reverse the orientation of the face1
std::cout << int(reface1.Orientation()) << std::endl;//0
//Get the wire from reface
AMCAX::TopoExplorerTool::MapShapes(reface1, AMCAX::ShapeType::Wire, rewireSet);
AMCAX::TopoWire rewire1 = AMCAX::TopoCast::Wire(rewireSet[0]);
std::cout << int(rewire1.Orientation()) << std::endl;//0
static AMCAX_API const TopoFace & Face(const TopoShape &s)
将形状转换为面
面类
定义 TopoFace.hpp:12
形状的基类,包含具有位置和方向信息的基础形状
定义 TopoShape.hpp:15

其中获取 Face 所在曲面的法向的方法如下:

//Get the surface of face1
std::shared_ptr< AMCAX::Geom3Surface > surface = AMCAX::TopoTool::Surface(face1, location);
//Compute first derivatives at parametric coordinates (0.5, 0.5)
surface->D1(0.5, 0.5, p, du, dv);
//Calculate surface normal via cross product of derivatives
AMCAX::Vector3 normal = du.Cross(dv);
std::cout << "normal:" << normal << std::endl;//-1 0 0
virtual AMCAX_API void D1(double u, double v, Point3 &p, Vector3 &d1u, Vector3 &d1v) const =0
计算给定参数处的点和一阶偏导数
表示实体位置局部变换的类
定义 TopoLocation.hpp:14
static AMCAX_API const std::shared_ptr< Geom3Surface > & Surface(const TopoFace &f, TopoLocation &l)
获取面的曲面及曲面的位置
constexpr auto Cross(const VectorT< OtherScalar, DIM > &other) const noexcept
二维叉乘运算符
定义 VectorT.hpp:428
VectorT< double, 3 > Vector3
三维向量
定义 VectorT.hpp:707

Shell

对 Shell 进行 Reversed 后 ,Shell 所包围的方向变为反向。对 Shell 进行 Reversed 等价于将 Forward 的 Shell 中的每个 Face 的 Orientation 变为反向。

//Make a box
AMCAX::MakeBox box(AMCAX::Point3(-5.0, -5.0, 0.0), AMCAX::Point3(5.0, 5.0, 3.0));
//Get the shell from box
AMCAX::TopoShell shell = box.Shell();
//Get the face from shell
AMCAX::TopoExplorerTool::MapShapes(shell, AMCAX::ShapeType::Face, faceSet);
std::cout << int(face1.Orientation()) << std::endl;//1
//Reverse the orientation of the shell
//Get the face from reshell
AMCAX::TopoExplorerTool::MapShapes(reshell, AMCAX::ShapeType::Face, refaceSet);
AMCAX::TopoFace reface1 = AMCAX::TopoCast::Face(refaceSet[0]);
std::cout << int(reface1.Orientation()) << std::endl;//0
static AMCAX_API const TopoShell & Shell(const TopoShape &s)
将形状转换为壳体
壳体类
定义 TopoShell.hpp:12

Solid

对 Solid 进行 Reversed 后, Solid 所包围的方向变为反向。对 Solid 进行 Reversed 等价于将 Forward 的 Solid 中的每个 Face 的 Orientation 变为反向。

//Make a box
AMCAX::MakeBox box(AMCAX::Point3(-5.0, -5.0, 0.0), AMCAX::Point3(5.0, 5.0, 3.0));
//Get the solid and shell from box
AMCAX::TopoSolid solid = box.Solid();
AMCAX::TopoShell shell = box.Shell();
std::cout << int(shell.Orientation()) << std::endl;//0
//Reverse the orientation of the solid
//Get the shell from resolid
AMCAX::TopoExplorerTool::MapShapes(resolid, AMCAX::ShapeType::Shell, reshellSet);
AMCAX::TopoShell reshell1 = AMCAX::TopoCast::Shell(reshellSet[0]);
std::cout << int(reshell1.Orientation()) << std::endl;//1
static AMCAX_API const TopoSolid & Solid(const TopoShape &s)
将形状转换为实体
实体类
定义 TopoSolid.hpp:12

Tolerance

Tolerance 是表示某个 TopoShape 误差的量,比如一个 Vertex 在 Edge1 的曲线上的点是 Point3(0.0, 0.0, 0.0),在 Edge2 的曲线上的点是 Point3(1.0, 0.0, 0.0),在 tolerance=2.0 的情况下,这两个点可以视为一个点,也就是说这样的 Vertex 尽管在不同的 Edge 上的几何点不同,但作为拓扑结构,这个 Vertex 是合法的。
获取 TopoShape 的 Tolerance 的方法是:AMCAX::TopoTool::Tolerance()。只有 Vertex、Edge、Face 这种包含了几何信息的结构才有 Tolerance。而更改 Tolerance 的方法是: AMCAX::TopoBuilder::UpdateVertex()AMCAX::TopoBuilder::UpdateEdge()AMCAX::TopoBuilder::UpdateFace()

接下来我们将逐一介绍 Vertex、Edge、Face 中的 Tolerance:

Vertex

Vertex 的 Tolerance 是一个设定的值,其意义为 Point 到 Vertex 的距离(Point 到 Vertex 中 Point 的距离)不大于 Tolerance 时,认为 Point 在 Vertex 上。而 Vertex 的 Point 有很多来源:本身的 Point3,Curve 在某一参数上的值,Surface 在某一 uv 参数上的值,Vertex 的 Tolerance 要不小于这些点之间的最大距离。

AMCAX::Point3 p1(0., 0., 0.);
auto circle = std::make_shared<AMCAX::Geom3Circle>(AMCAX::Frame3(), 1.0);
//Get the first parameter
double fp = circle->FirstParameter();
//Get the first point
AMCAX::Point3 p2 = circle->Value(fp);
//Make a vertex , and the tolerance is 2.0
builder.MakeVertex(v1, p1, 2.0);
builder.MakeVertex(v2, p2, 2.0);
std::cout << AMCAX::TopoTool::Tolerance(v1);//2.0
std::cout << AMCAX::TopoTool::Tolerance(v2);//2.0
//Update the tolerance
double tol = 2.5;
builder.UpdateVertex(v1, p1, tol);
builder.UpdateVertex(v2, p2, tol);
std::cout << AMCAX::TopoTool::Tolerance(v1);//2.5
std::cout << AMCAX::TopoTool::Tolerance(v2);//2.5
AMCAX_API void MakeVertex(TopoVertex &v) const
构造空顶点
AMCAX_API void UpdateVertex(const TopoVertex &v, const Point3 &p, double tol) const
更新顶点的点
static AMCAX_API double Tolerance(const TopoFace &f)
获取面的容差

Edge

Edge 的 Tolerance 是一个设定的值,其意义为 Point 到 Edge 的距离不大于 Tolerance 时,认为 Point 在 Edge 上。此外,Edge 有 curve3d 和 pcurve,而 pcurve 可以通过 Surface 构建一个等价的 curve3d。若干条 curve3d 在采样下的最大距离不能大于 Edge 的 Tolerance,如果不满足则必须增大 Edge 的 Tolerance。另外,Vertex 的 Tolerance 必须比所在 Edge 的 Tolerance 更大或相等。

AMCAX::Point3 p1(0., 0., 0.);
auto circle = std::make_shared<AMCAX::Geom3Circle>(AMCAX::Frame3(), 1.0);
//Get the first parameter
double fp = circle->FirstParameter();
//Get the first point
AMCAX::Point3 p2 = circle->Value(fp);
//Make a vertex , and the tolerance is 2.0
builder.MakeVertex(v1, p1, 2.0);
builder.MakeVertex(v2, p2, 2.0);
//Make a edge
AMCAX::MakeEdge e(v1, v2);
AMCAX::TopoEdge edge = e.Edge();
std::cout << AMCAX::TopoTool::Tolerance(edge);//1e-7
//Update the tolerance
builder.UpdateEdge(edge, 1.0);
std::cout << AMCAX::TopoTool::Tolerance(edge);//1.0
创建边的类
定义 MakeEdge.hpp:24
AMCAX_API void UpdateEdge(const TopoEdge &e, const std::shared_ptr< Geom3Curve > &c, double tol) const
更新边的三维曲线和容差

Face

Face 的 Tolerance 是一个设定的值,其意义为 Point 到 Face 的距离不大于 Tolerance 时,认为 Point 在 Face 上,较多用于布尔操作里。除此之外,Vertex、Edge 的 Tolerance 必须比所在 Face 的 Tolerance 更大或相等。

AMCAX::Geom3Plane plane(frame);
//Make a face
AMCAX::TopoFace face = AMCAX::MakeFace(plane.GetPlane(), 0., 2., 0., 2.);
std::cout << AMCAX::TopoTool::Tolerance(face);//1e-7
//Update the tolerance
builder.UpdateFace(face, 0.5);
std::cout << AMCAX::TopoTool::Tolerance(face);//0.5
三维平面的类
定义 Geom3Plane.hpp:14
创建面的类
定义 MakeFace.hpp:22
AMCAX_API void UpdateFace(const TopoFace &f, const std::shared_ptr< Geom3Surface > &s, const TopoLocation &l, double tol) const
更新面的曲面,位置和容差

注:当存在从属关系时,Vertex 的 Tolerance ≥ Edge 的 Tolerance ≥ Face 的 Tolerance。

Closed

TopoShape 是否封闭是一个关键的 Flag。我们可以使用 AMCAX::TopoTool::IsClosed() 来判断 TopoShape 是否为封闭的。在这里需要与 AMCAX::TopoShape::Closed() 进行区分, AMCAX::TopoShape::Closed() 返回的 bool 是一个用户任意定义的 flag。比如,将一条线段构建成一个 Edge,尽管不封闭,但仍然可以用 AMCAX::TopoShape::Closed(true) 将其 flag 设为 true。

AMCAX::Point3 p1(1.0, 0.0, 0.0);
edge.Closed(true);
std::cout << edge.Closed() << std::endl;//1
std::cout << AMCAX::TopoTool::IsClosed(edge) << std::endl;//0
AMCAX_API bool Closed() const
判断形状是否封闭

AMCAX::TopoTool::IsClosed() 是对某几类 TopoShape 进行拓扑上的判断。接下来将逐一介绍输入不同 ShapeType 的 TopoShape 时, AMCAX::TopoTool::IsClosed 的用途。

Edge

AMCAX::TopoTool::IsClosed() 用于判断 Edge 的 FirstVertex 和 LastVertex 是否 IsSame。

auto c = std::make_shared<AMCAX::Geom3Circle>(AMCAX::Frame3(), 1.0);
AMCAX::TopoEdge edge1 = AMCAX::MakeEdge(c, v1, v1);
std::cout << AMCAX::TopoTool::IsClosed(edge1) << std::endl;//1

Wire

AMCAX::TopoTool::IsClosed() 用于判断 Wire 是否没有边界 Vertex,即对 Wire 遍历 Vertex,每个 Vertex 都出现偶数次。

AMCAX::MakePolygon polygon(AMCAX::Point3(-1., -1., 0.), AMCAX::Point3(1., -1., 0.), AMCAX::Point3(1., 1., 0.), AMCAX::Point3(-1., 1., 0.),true);
AMCAX::TopoWire w = polygon.Wire();
std::cout << AMCAX::TopoTool::IsClosed(w) << std::endl;//1
创建多边形的类
定义 MakePolygon.hpp:18

Shell

AMCAX::TopoTool::IsClosed() 用于判断 Shell 是否没有边界 Edge(自由Edge),即对 Shell 遍历 Edge,除退化边外每个 Edge 都出现偶数次。

AMCAX::MakeBox box(2., 2., 2.);
AMCAX::TopoShell shell = box.Shell();
std::cout << AMCAX::TopoTool::IsClosed(shell) << std::endl;//1

其他

对 edge wire shell 外的其他类型执行 AMCAX::TopoTool::IsClosed() 时,其结果就是 AMCAX::TopoShape::Closed() 的结果。

//Make a box
AMCAX::MakeBox box(2., 2., 2.);
//1. Solid
AMCAX::TopoSolid solid = box.Solid();
//Set open
solid.Closed(false);
std::cout << solid.Closed() << std::endl;//0
std::cout << AMCAX::TopoTool::IsClosed(solid) << std::endl;//0
//Set closed
solid.Closed(true);
std::cout << solid.Closed() << std::endl;//1
std::cout << AMCAX::TopoTool::IsClosed(solid) << std::endl;//1
//2. Face
AMCAX::TopoExplorerTool::MapShapes(box, AMCAX::ShapeType::Face, FaceSet);
//Set open
face1.Closed(false);
std::cout << face1.Closed() << std::endl;//0
std::cout << AMCAX::TopoTool::IsClosed(face1) << std::endl;//0
//Set closed
face1.Closed(true);
std::cout << face1.Closed() << std::endl;//1
std::cout << AMCAX::TopoTool::IsClosed(face1) << std::endl;//1