概述
本教程提供了使用几何编辑的基本用法,导入 brep 格式文件,通过调用 GeomE 的 API 对模型进行几何编辑操作对模型进行修复。本教程中也会用到九韶内核 AMCAX 中的 API。另外,本教程图片中的红色边表示自由边,黄色边表示流形边。
命名空间
为了示例代码清晰,使用命名空间。
AMCAX GeomE 模块提供的所有接口所在的命名空间。
定义 misc.docu:21
AMCAX 内核提供的所有接口所在的命名空间。
定义 misc.docu:8
几何编辑示例一
CAD模型预览
导入brep格式cad模型,如下图所示:
准备工作
本教程示例首先会读入 brep 模型,接着对输入的模型进行几何编辑操作,最后将模型写入 brep 文件。
相关头文件
导入模型
导入cad文件,构建模型。
Base class of shape, containing an underlying shape with a location and an orientation
定义 TopoShape.hpp:15
输出结果
写入 brep。
如图所示,画红圈的地方,一个面的短边和另一个面的长边之间有缝隙,两条边都属于自由边。
点插入到边上
Class of Edge Editor
定义 EdgeEditor.hpp:19
AMCAX_API void TrimEdgeWithPoint(TopoShape &shape, const TopoEdge &edge, const std::vector< Point3 > &points)
Project points onto an edge
索引集的模板类
定义 IndexSet.hpp:20
static AMCAX_API const TopoEdge & Edge(const TopoShape &s)
Cast shape to edge
static AMCAX_API const TopoVertex & Vertex(const TopoShape &s)
Cast shape to vertex
Class of edge
定义 TopoEdge.hpp:12
Class of vertex
定义 TopoVertex.hpp:12
PointT< double, 3 > Point3
三维点
定义 PointT.hpp:459
结果如图所示,相应的边上已经插入点,长边被裁减成两条边。
将一条边缝合到另一条边
edgeeditor.
SewEdges(shape, edge2, edge1, 0.1);
AMCAX_API void SewEdges(AMCAX::TopoShape &shape, const AMCAX::TopoEdge &edge1, AMCAX::TopoEdge &edge2, double tol)
Sew two edges with nearby vertices, using the second edge as the resulting edge
void clear() noexcept
清除索引集合
定义 IndexSet.hpp:105
结果如图所示,两个面之间的缝隙已经消除。
如图所示,画红圈的地方,一个面的边和另一个面有缝隙。
边投影到面
static AMCAX_API void EdgesProjectFace(TopoShape &shape, const IndexSet< TopoShape > &edges, TopoFace &face, TopoShape &replaceshape)
Project edges onto a face
int insert(T &&key)
插入一个新键
定义 IndexSet.hpp:117
static AMCAX_API const TopoFace & Face(const TopoShape &s)
Cast shape to face
Class of face
定义 TopoFace.hpp:12
如图所示,指定的边已经投影到面的内部。
将一条边缝合到另一条边上
edgeeditor.
SewEdges(shape, edge2, edge1, 0.1);
如图所示,画红圈的地方,出现了很短的短边。
释放顶点
Class of Vertex Editor
定义 VertexEditor.hpp:20
AMCAX_API void ReleaseVertex(TopoShape &shape, const TopoVertex &vertex)
Release vertex onto each edge
如图所示,点被释放到各个面上。
删除点
将星形标记面的红色顶点删除。
AMCAX_API void RemoveVertex(TopoShape &shape, const TopoVertex &vertex)
Delete vertex on the edge
如图所示,星形标记面的红色顶点被删除,长边和短边连接成为一条边。
缝合顶点
如图所示,要将右边的面的顶点缝合到左边的面的顶点上。
AMCAX_API TopoVertex SewVertices(AMCAX::TopoShape &shape, const IndexSet< TopoShape > &vertexvec)
Sew a set of vertices into a single vertex
如图所示,两个顶点已经被缝合到一起。
将一条边缝合到另一条边上
edgeeditor.
SewEdges(shape, edge2, edge1, 0.1);
如图所示,将左边的面的边缝合到了右边的面的边上。
如图所示,选中两个顶点对该面进行参数切分。
参数切分
static AMCAX_API void ParameterFaceCut(AMCAX::TopoShape &shape, const AMCAX::TopoFace &face, const AMCAX::TopoVertex &vertex1, const AMCAX::TopoVertex &vertex2)
Parametrically cut the given face using the specified pair of vertices
如图所示,参数切分成功。
重建边
如图所示,可以选择一条边(黄色)进行重建
AMCAX_API TopoEdge RebuildAndUpdateEdge(TopoShape &shape, const TopoEdge &edge)
Resample the curve of an edge and update it
下图为重建边前后对比。
在边上根据比例插入点
如图所示,在选中的边(黄色)上按比例 0.3 插入一个顶点。
AMCAX_API void TrimEdgeWithRatio(TopoShape &shape, const TopoEdge &edge, const std::vector< double > &ratios)
Insert vertices on the edge based on the given ratios
如图所示,在选中边的 0.3 处插入了顶点。
释放边
如图所示,释放红圈圈起来的边。
AMCAX_API void ReleaseEdge(AMCAX::TopoShape &shape, const AMCAX::TopoEdge &edge)
Release the common edge of several faces to their respective faces
如图所示,选中的边被释放到两个面上,成为自由边。
删除面
如图所示,要删除星形标记的面。
static AMCAX_API void DeleteFace(AMCAX::TopoShape &shape, const AMCAX::TopoFace &face)
Remove a face from the shape
如图所示,选中的面已经删除。
连接两条边为一条边
如图所示,连接两条红色的边。
AMCAX_API TopoEdge JoinEdgesAndUpdate(AMCAX::TopoShape &shape, const IndexSet< TopoShape > &edges)
Join edges into one edge
如图所示,连接后两条边变为一条边,顶点消失。
反转面的定向
static AMCAX_API void ReverseOrientation(AMCAX::TopoShape &shape, const AMCAX::TopoFace &face)
Reverse the orientation of a face
点击这里example01可获得几何清理修复示例一完整源码,大家根据学习需要自行下载。
附录
下面列出了此示例的完整代码:
void GeomEdit()
{
edgeeditor.
SewEdges(shape, edge2, edge1, 0.1);
edgeeditor.
SewEdges(shape, edge2, edge1, 0.1);
edgeeditor.
SewEdges(shape, edge2, edge1, 0.1);
}
几何编辑示例二
CAD模型预览
导入step格式cad模型,如下图所示:
准备工作
本教程示例首先会读入step模型,接着对输入的模型进行几何编辑操作,最后将模型写入brep文件。
相关头文件
导入模型
导入cad文件,构建模型。
输出结果
写入brep。
检测边的类型
EdgeType
Type of edges
定义 GeomEMacros.hpp:12
如图所示,选中绿色的边进行检测,返回该边的EdgeType是FreeEdge,表明该边是自由边。
检测边所属的自由边界
如图得到包含该边的自由边界。
选中自由边界进行补洞
static AMCAX_API void FillHole(TopoShape &shape, const IndexSet< TopoShape > &freeboundaries)
Fill the holes formed by free boundaries
如图所示,以该自由边界为边界的孔洞已填补完成。
选中边界建立新的Coons曲面
如图所示,选中绿色的边作为集合构建一个新的Coons曲面。
static AMCAX_API TopoFace BuildCoons(TopoShape &shape, const IndexSet< TopoShape > &edges)
Construct a new coons face based on the given set of edges
如图所示,Coons曲面构建成功。
选中边界建立新的平面
如图所示,选中绿色的边作为集合构建一个新的平面。
static AMCAX_API TopoFace BuildPlane(TopoShape &shape, const IndexSet< TopoShape > &edges)
Construct a new plane face based on the given set of edges
如图所示,平面构建成功。
选中边界根据已有曲面建立新的面
如图所示,选中绿色的边作为集合根据黄色面的曲面建立新的面。
static AMCAX_API TopoFace BuildFaceFromSurface(TopoShape &shape, const IndexSet< TopoShape > &edges, const TopoFace &face)
Construct a new face based on the given set of edges and an existing face
如图所示,新面构建成功。
点投影到面
static AMCAX_API void VerticesProjectFace(TopoShape &shape, const IndexSet< TopoShape > &vertices, TopoFace &face, TopoShape &replaceshape)
Project vertices onto a surface
Class of making a vertex
定义 MakeVertex.hpp:16
如图所示,点成功投影到面上。
点击这里example02可获得几何清理修复示例二的完整源码,大家根据学习需要自行下载。
附录
void GeomEdit()
{
shape, "./data/skin.step");
}
几何编辑示例三
CAD 模型预览
导入 brep 格式 cad 模型,如下图所示,左图为初始模型1,右图为初始模型2。
准备工作
本教程示例首先会读入 brep 模型,接着对输入的模型进行几何编辑操作,最后将模型写入 brep 文件。
相关头文件
Class of Geometric Imprinting
Defines data structures for configuration options across various functionalities
Base class of shape, containing an underlying shape with a location and an orientation
导入模型
导入 cad 文件,构建模型。
输出结果
写入 brep。
几何编辑示例
面的定向一致
导入的初始模型 1 由两个 solid 组成,其中第一个 solid 的各个面定向并不一致。
static AMCAX_API void AlignFaceOrientations(TopoShape &shape)
Ensure consistent orientation of all faces in a shape without non-manifold edges
如下图所示,对第一个 solid 执行面的定向一致后,所有面的法向都朝外。
检测壳是否封闭
检测第一个 solid 的 shell 是否封闭,返回 true。
几何压印1
imprint1.
Imprint(shape, {solids[0], solids[1]}, {});
Class of Geometric Imprinting
定义 GeomImprint.hpp:23
AMCAX_API void Imprint(TopoShape &shape, const std::list< TopoShape > &targetlist, const std::list< TopoShape > &toollist={}, const ImprintOptions &options=ImprintOptions())
Performs mutual imprinting of multiple shapes or imprints a list of faces onto another list of faces
如下图所示,第二个 solid 被压印上一些拓扑结构。
几何压印2
如下图所示,选中绿色的面进行几何压印。
imprint2.
Imprint(shape, {faces[0]}, {faces[2]});
如下图所示,压印成功。
几何压印3
如下图所示,选中绿色的面进行几何压印。
imprint3.
Imprint(shape, {faces[1]}, {faces[2]});
如下图所示,压印成功。
点击这里example03可获得几何清理修复示例三完整源码,大家根据学习需要自行下载。
附录
void GeomEdit()
{
imprint1.
Imprint(shape, {solids[0], solids[1]}, {});
imprint2.
Imprint(shape, {faces[0]}, {faces[2]});
imprint3.
Imprint(shape, {faces[1]}, {faces[2]});
}