AMCAX Kernel
Geometry kernel for CAD/CAE/CAM
九韶内核 1.0.0.0
载入中...
搜索中...
未找到
几何清理修复示例

概述

本教程提供了使用几何编辑的基本用法,导入 brep 格式文件,通过调用 GeomE 的 API 对模型进行几何编辑操作对模型进行修复。本教程中也会用到九韶内核 AMCAX 中的 API。另外,本教程图片中的红色边表示自由边,黄色边表示流形边。

命名空间

为了示例代码清晰,使用命名空间。

using namespace AMCAX;
using namespace AMCAX::GeomE;
AMCAX GeomE 模块提供的所有接口所在的命名空间。
定义 misc.docu:21
AMCAX 内核提供的所有接口所在的命名空间。
定义 misc.docu:8

几何编辑示例一

CAD模型预览

导入brep格式cad模型,如下图所示:

准备工作

本教程示例首先会读入 brep 模型,接着对输入的模型进行几何编辑操作,最后将模型写入 brep 文件。

相关头文件

编辑边的类
编辑面的类
用于读写 OCCT BRep 文件中形状的类
类型转换的工具类
边的类
拓扑遍历的工具类
面的类
B-Rep 结构的工具类
编辑顶点的类

导入模型

导入cad文件,构建模型。

OCCTIO::OCCTTool::Read(shape, "./data/FEA.brep");
static AMCAX_API bool Read(TopoShape &s, std::istream &is)
读取输入流中的形状
形状的基类,包含具有位置和方向信息的基础形状
定义 TopoShape.hpp:15

输出结果

写入 brep。

success = AMCAX::OCCTIO::OCCTTool::Write(shape, "./result/shape.brep");
static AMCAX_API bool Write(const TopoShape &s, std::ostream &os, int format=3)
将形状写入输出流

如图所示,画红圈的地方,一个面的短边和另一个面的长边之间有缝隙,两条边都属于自由边。

点插入到边上

//获取插入点的坐标
TopoExplorerTool::MapShapes(shape, ShapeType::Vertex, vertices);
TopoVertex vertex = TopoCast::Vertex(vertices[799]);
Point3 point = TopoTool::Point(vertex);
//获取插入的边
TopoExplorerTool::MapShapes(shape, ShapeType::Edge, edges);
TopoEdge edge = TopoCast::Edge(edges[1528]);
EdgeEditor edgeeditor;
//将点插入到边上
edgeeditor.TrimEdgeWithPoint(shape, edge, { point });
编辑边的类
定义 EdgeEditor.hpp:19
AMCAX_API void TrimEdgeWithPoint(TopoShape &shape, const TopoEdge &edge, const std::vector< Point3 > &points)
将点投影到边上
索引集的模板类
定义 IndexSet.hpp:20
static AMCAX_API const TopoEdge & Edge(const TopoShape &s)
将形状转换为边
static AMCAX_API const TopoVertex & Vertex(const TopoShape &s)
将形状转换为顶点
边的类
定义 TopoEdge.hpp:12
static AMCAX_API void MapShapes(const TopoShape &s, ShapeType t, IndexSet< TopoShape > &shapeSet)
构造给定类型的子形状集合
static AMCAX_API Point3 Point(const TopoVertex &v)
获取顶点的几何点
顶点类
定义 TopoVertex.hpp:12
PointT< double, 3 > Point3
三维点
定义 PointT.hpp:459

结果如图所示,相应的边上已经插入点,长边被裁减成两条边。

将一条边缝合到另一条边

// 获取两条要缝合的边
edges.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Edge, edges);
TopoEdge edge1 = TopoCast::Edge(edges[1528]);
TopoEdge edge2 = TopoCast::Edge(edges[1759]);
// 将edge2缝合到edge1上
edgeeditor.SewEdges(shape, edge2, edge1, 0.1);
AMCAX_API void SewEdges(AMCAX::TopoShape &shape, const AMCAX::TopoEdge &edge1, AMCAX::TopoEdge &edge2, double tol)
缝合两条具有相近顶点的边,并将第二条边作为结果边
void clear() noexcept
清除索引集合
定义 IndexSet.hpp:90

结果如图所示,两个面之间的缝隙已经消除。

如图所示,画红圈的地方,一个面的边和另一个面有缝隙。

边投影到面

// 获取要投影的边
edges.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Edge, edges);
edge = TopoCast::Edge(edges[1736]);
// 获取要投影的面
TopoExplorerTool::MapShapes(shape, ShapeType::Face, faces);
TopoFace face = TopoCast::Face(faces[30]);
// 边投影到面上
TopoShape replaceshape;
IndexSet<TopoShape> projectedges;
projectedges.insert(edge);
FaceEditor faceeditor;
faceeditor.EdgesProjectFace(shape, projectedges, face, replaceshape);
编辑面的类
定义 FaceEditor.hpp:25
AMCAX_API void EdgesProjectFace(TopoShape &shape, const IndexSet< TopoShape > &edges, TopoFace &face, TopoShape &replaceshape)
将边投影到面上
int insert(T &&key)
插入一个新键
定义 IndexSet.hpp:102
static AMCAX_API const TopoFace & Face(const TopoShape &s)
将形状转换为面
面类
定义 TopoFace.hpp:12

如图所示,指定的边已经投影到面的内部。

将一条边缝合到另一条边上

// 获取两条要缝合的边
edges.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Edge, edges);
edge1 = TopoCast::Edge(edges[1737]);
edge2 = TopoCast::Edge(edges[102]);
// 将edge2缝合到edge1上
edgeeditor.SewEdges(shape, edge2, edge1, 0.1);

如图所示,画红圈的地方,出现了很短的短边。

释放顶点

// 获取要释放的顶点
vertices.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Vertex, vertices);
vertex = TopoCast::Vertex(vertices[845]);
VertexEditor vertexeditor;
// 释放顶点
vertexeditor.ReleaseVertex(shape, vertex);
编辑顶点的类
定义 VertexEditor.hpp:19
AMCAX_API void ReleaseVertex(TopoShape &shape, const TopoVertex &vertex)
将指定顶点释放到各边上

如图所示,点被释放到各个面上。

删除点

将星形标记面的红色顶点删除。

// 获取删除的顶点
vertices.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Vertex, vertices);
vertex = TopoCast::Vertex(vertices[845]);
// 删除顶点
vertexeditor.RemoveVertex(shape, vertex);
AMCAX_API void RemoveVertex(TopoShape &shape, const TopoVertex &vertex)
在指定形状中删除边上的顶点

如图所示,星形标记面的红色顶点被删除,长边和短边连接成为一条边。

缝合顶点

如图所示,要将右边的面的顶点缝合到左边的面的顶点上。

// 获取缝合的顶点
vertices.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Vertex, vertices);
TopoVertex vertex1 = TopoCast::Vertex(vertices[417]);
TopoVertex vertex2 = TopoCast::Vertex(vertices[847]);
// 将vertex2缝合到vertex1上
vertexeditor.SewVertices(shape, vertex2, vertex1);
AMCAX_API TopoVertex SewVertices(AMCAX::TopoShape &shape, const IndexSet< TopoShape > &vertexvec)
将一组顶点缝合为一个顶点

如图所示,两个顶点已经被缝合到一起。

将一条边缝合到另一条边上

// 获取两条要缝合的边
edges.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Edge, edges);
edge1 = TopoCast::Edge(edges[1887]);
edge2 = TopoCast::Edge(edges[1880]);
// 将edge2缝合到edge1上
edgeeditor.SewEdges(shape, edge2, edge1, 0.1);

如图所示,将左边的面的边缝合到了右边的面的边上。

如图所示,选中两个顶点对该面进行参数切分。

参数切分

// 获取切分的顶点
vertices.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Vertex, vertices);
vertex1 = TopoCast::Vertex(vertices[578]);
vertex2 = TopoCast::Vertex(vertices[821]);
// 获取切分的面
faces.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Face, faces);
face = TopoCast::Face(faces[903]);
// 进行参数切分
faceeditor.ParameterFaceCut(shape, face, vertex1, vertex2);
AMCAX_API void ParameterFaceCut(AMCAX::TopoShape &shape, const AMCAX::TopoFace &face, const AMCAX::TopoVertex &vertex1, const AMCAX::TopoVertex &vertex2)
根据指定的起始顶点和结束顶点对给定的面进行参数化切割

如图所示,参数切分成功。

重建边

如图所示,可以选择一条边(黄色)进行重建

// 获取重建的边
edges.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Edge, edges);
edge = TopoCast::Edge(edges[452]);
// 重建并更新边
edgeeditor.RebuildAndUpdateEdge(shape, edge);
AMCAX_API TopoEdge RebuildAndUpdateEdge(TopoShape &shape, const TopoEdge &edge)
对某条边的曲线进行重采样并更新边

下图为重建边前后对比。

在边上根据比例插入点

如图所示,在选中的边(黄色)上按比例 0.3 插入一个顶点。

// 获取插入的边
edges.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Edge, edges);
edge = TopoCast::Edge(edges[446]);
// 根据比例在边上插入顶点
edgeeditor.TrimEdgeWithRatio(shape, edge, { 0.3 });
AMCAX_API void TrimEdgeWithRatio(TopoShape &shape, const TopoEdge &edge, const std::vector< double > &ratios)
根据给定比例在边上插入顶点

如图所示,在选中边的 0.3 处插入了顶点。

释放边

如图所示,释放红圈圈起来的边。

// 获取释放的边
edges.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Edge, edges);
edge = TopoCast::Edge(edges[447]);
// 释放边
edgeeditor.ReleaseEdge(shape, edge);
AMCAX_API void ReleaseEdge(AMCAX::TopoShape &shape, const AMCAX::TopoEdge &edge)
将多个面之间的公共边释放回各自所属的面

如图所示,选中的边被释放到两个面上,成为自由边。

删除面

如图所示,要删除星形标记的面。

// 获取要删除的面
faces.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Face, faces);
face = TopoCast::Face(faces[832]);
// 删除面
faceeditor.DeleteFace(shape, face);
AMCAX_API void DeleteFace(AMCAX::TopoShape &shape, const AMCAX::TopoFace &face)
移除形状中的面

如图所示,选中的面已经删除。

连接两条边为一条边

如图所示,连接两条红色的边。

// 获取两条要连接的边
edges.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Edge, edges);
edge1 = TopoCast::Edge(edges[446]);
edge2 = TopoCast::Edge(edges[447]);
// 连接两条边为一条边
joinedges.insert(edge1);
joinedges.insert(edge2);
TopoEdge newedge = edgeeditor.JoinEdgesAndUpdate(shape, joinedges);
AMCAX_API TopoEdge JoinEdgesAndUpdate(AMCAX::TopoShape &shape, const IndexSet< TopoShape > &edges)
将多条边合并为一条边,并更新形状

如图所示,连接后两条边变为一条边,顶点消失。

反转面的定向

// 获取要反转定向的面
faces.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Face, faces);
face = TopoCast::Face(faces[139]);
// 反转面的定向
faceeditor.ReverseOrientation(shape, face);
AMCAX_API void ReverseOrientation(AMCAX::TopoShape &shape, const AMCAX::TopoFace &face)
反转指定面的方向

点击这里example01可获得几何清理修复示例一完整源码,大家根据学习需要自行下载。

附录

下面列出了此示例的完整代码:

void GeomEdit()
{
using namespace AMCAX;
using namespace AMCAX::GeomE;
OCCTIO::OCCTTool::Read(shape, "./data/FEA.brep");
// 获取插入点的坐标
TopoExplorerTool::MapShapes(shape, ShapeType::Vertex, vertices);
TopoVertex vertex = TopoCast::Vertex(vertices[799]);
Point3 point = TopoTool::Point(vertex);
// 获取插入的边
TopoExplorerTool::MapShapes(shape, ShapeType::Edge, edges);
TopoEdge edge = TopoCast::Edge(edges[1528]);
EdgeEditor edgeeditor;
// 将点插入到边上
edgeeditor.TrimEdgeWithPoint(shape, edge, { point });
// 获取两条要缝合的边
edges.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Edge, edges);
TopoEdge edge1 = TopoCast::Edge(edges[1528]);
TopoEdge edge2 = TopoCast::Edge(edges[1759]);
// 将edge2缝合到edge1上
edgeeditor.SewEdges(shape, edge2, edge1, 0.1);
// 获取要投影的边
edges.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Edge, edges);
edge = TopoCast::Edge(edges[1736]);
// 获取要投影的面
TopoExplorerTool::MapShapes(shape, ShapeType::Face, faces);
TopoFace face = TopoCast::Face(faces[30]);
// 边投影到面上
TopoShape replaceshape;
IndexSet<TopoShape> projectedges;
projectedges.insert(edge);
FaceEditor faceeditor;
faceeditor.EdgesProjectFace(shape, projectedges, face, replaceshape);
// 获取两条要缝合的边
edges.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Edge, edges);
edge1 = TopoCast::Edge(edges[1737]);
edge2 = TopoCast::Edge(edges[102]);
// 将edge2缝合到edge1上
edgeeditor.SewEdges(shape, edge2, edge1, 0.1);
// 获取要释放的顶点
vertices.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Vertex, vertices);
vertex = TopoCast::Vertex(vertices[845]);
VertexEditor vertexeditor;
// 释放顶点
vertexeditor.ReleaseVertex(shape, vertex);
// 获取删除的顶点
vertices.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Vertex, vertices);
vertex = TopoCast::Vertex(vertices[845]);
// 删除顶点
vertexeditor.RemoveVertex(shape, vertex);
// 获取缝合的顶点
vertices.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Vertex, vertices);
TopoVertex vertex1 = TopoCast::Vertex(vertices[417]);
TopoVertex vertex2 = TopoCast::Vertex(vertices[847]);
// 将vertex2缝合到vertex1上
vertexeditor.SewVertices(shape, vertex2, vertex1);
// 获取两条要缝合的边
edges.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Edge, edges);
edge1 = TopoCast::Edge(edges[1887]);
edge2 = TopoCast::Edge(edges[1880]);
// 将edge2缝合到edge1上
edgeeditor.SewEdges(shape, edge2, edge1, 0.1);
// 获取切分的顶点
vertices.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Vertex, vertices);
vertex1 = TopoCast::Vertex(vertices[578]);
vertex2 = TopoCast::Vertex(vertices[821]);
// 获取切分的面
faces.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Face, faces);
face = TopoCast::Face(faces[903]);
// 进行参数切分
faceeditor.ParameterFaceCut(shape, face, vertex1, vertex2);
// 获取重建的边
edges.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Edge, edges);
edge = TopoCast::Edge(edges[452]);
// 重建并更新边
edgeeditor.RebuildAndUpdateEdge(shape, edge);
// 获取插入的边
edges.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Edge, edges);
edge = TopoCast::Edge(edges[446]);
// 根据比例在边上插入顶点
edgeeditor.TrimEdgeWithRatio(shape, edge, { 0.3 });
// 获取释放的边
edges.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Edge, edges);
edge = TopoCast::Edge(edges[447]);
// 释放边
edgeeditor.ReleaseEdge(shape, edge);
// 获取要删除的面
faces.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Face, faces);
face = TopoCast::Face(faces[832]);
// 删除面
faceeditor.DeleteFace(shape, face);
// 获取两条要连接的边
edges.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Edge, edges);
edge1 = TopoCast::Edge(edges[446]);
edge2 = TopoCast::Edge(edges[447]);
// 连接两条边为一条边
joinedges.insert(edge1);
joinedges.insert(edge2);
TopoEdge newedge = edgeeditor.JoinEdgesAndUpdate(shape, joinedges);
// 获取要反转定向的面
faces.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Face, faces);
face = TopoCast::Face(faces[139]);
// 反转面的定向
faceeditor.ReverseOrientation(shape, face);
AMCAX::OCCTIO::OCCTTool::Write(shape, "./shape.brep");
}

几何编辑示例二

CAD模型预览

导入step格式cad模型,如下图所示:

准备工作

本教程示例首先会读入step模型,接着对输入的模型进行几何编辑操作,最后将模型写入brep文件。

相关头文件

检测工具类
GeomE 模块中的枚举类型
创建顶点的类
Utility class for operations on STEP shape data structures.

导入模型

导入cad文件,构建模型。

bool success = AMCAX::STEP::StepDataTool::Read(shape, "./data/skin.step");
static AMCAX_API bool Read(AMCAX::TopoShape &s, std::istream &is)
Read a TopoShape from a stream in STEP format.

输出结果

写入brep。

success = AMCAX::OCCTIO::OCCTTool::Write(shape, "./result/shape.brep");

检测边的类型

//获取检测的边
TopoExplorerTool::MapShapes(shape, ShapeType::Edge, edges);
TopoEdge edge = TopoCast::Edge(edges[15]);
//检测该边的类型
EdgeType edgetype = DetectTool::GetEdgeType(shape,edge);
static AMCAX_API EdgeType GetEdgeType(const TopoShape &shape, const TopoEdge &edge)
获取指定形状中给定边的类型
EdgeType
边的类型
定义 GeomEMacros.hpp:11

如图所示,选中绿色的边进行检测,返回该边的EdgeType是FreeEdge,表明该边是自由边。

检测边所属的自由边界

//检测该边所属的自由边界
IndexSet<TopoShape> freeboundaries =
static AMCAX_API IndexSet< TopoShape > DetectFreeBoundaries(const TopoShape &shape, const TopoEdge &edge)
在给定形状中查找包含指定自由边的自由边界集合

如图得到包含该边的自由边界。

选中自由边界进行补洞

//选中自由边界进行补洞
FaceEditor faceeditor;
faceeditor.FillHole(shape, freeboundaries);
AMCAX_API void FillHole(TopoShape &shape, const IndexSet< TopoShape > &freeboundaries)
填补给定模型中孔的自由边界

如图所示,以该自由边界为边界的孔洞已填补完成。

选中边界建立新的Coons曲面

如图所示,选中绿色的边作为集合构建一个新的Coons曲面。

// 获取边集
edges.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Edge, edges);
TopoEdge edge1 = TopoCast::Edge(edges[9]);
TopoEdge edge2 = TopoCast::Edge(edges[10]);
TopoEdge edge3 = TopoCast::Edge(edges[11]);
edgeset.insert(edge1);
edgeset.insert(edge2);
edgeset.insert(edge3);
// 用边集构建Coons曲面
TopoFace face = faceeditor.BuildCoons(shape, edgeset);
AMCAX_API TopoFace BuildCoons(TopoShape &shape, const IndexSet< TopoShape > &edges)
根据给定边集构造新的新的 coons 面

如图所示,Coons曲面构建成功。

选中边界建立新的平面

如图所示,选中绿色的边作为集合构建一个新的平面。

// 获取边集
edges.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Edge, edges);
edge = TopoCast::Edge(edges[8]);
edgeset.clear();
edgeset.insert(edge);
// 用边集构建平面
face = faceeditor.BuildPlane(shape, edgeset);
AMCAX_API TopoFace BuildPlane(TopoShape &shape, const IndexSet< TopoShape > &edges)
根据给定边集构造一个新的平面

如图所示,平面构建成功。

选中边界根据已有曲面建立新的面

如图所示,选中绿色的边作为集合根据黄色面的曲面建立新的面。

// 获取边集
edges.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Edge, edges);
edge = TopoCast::Edge(edges[3]);
edge1 = TopoCast::Edge(edges[4]);
edge2 = TopoCast::Edge(edges[13]);
edge3 = TopoCast::Edge(edges[14]);
edgeset.clear();
edgeset.insert(edge);
edgeset.insert(edge1);
edgeset.insert(edge2);
edgeset.insert(edge3);
// 获取已有的面
TopoExplorerTool::MapShapes(shape, ShapeType::Face, faces);
TopoFace existface = TopoCast::Face(faces[0]);
// 用边集根据已有曲面建立新的面
face = faceeditor.BuildFaceFromSurface(shape, edgeset, existface);
AMCAX_API TopoFace BuildFaceFromSurface(TopoShape &shape, const IndexSet< TopoShape > &edges, const TopoFace &face)
根据给定边集和已有面构造一个新的面

如图所示,新面构建成功。

点投影到面

// 造一个顶点
Point3 p(350., -7., 380.);
TopoVertex vertex = MakeVertex(p);
vertices.insert(vertex);
// 点投影到面
TopoShape replaceshape;
faceeditor.VerticesProjectFace(shape, vertices, existface, replaceshape);
AMCAX_API void VerticesProjectFace(TopoShape &shape, const IndexSet< TopoShape > &vertices, TopoFace &face, TopoShape &replaceshape)
将顶点投影到面上
创建顶点的类
定义 MakeVertex.hpp:16

如图所示,点成功投影到面上。

点击这里example02可获得几何清理修复示例二的完整源码,大家根据学习需要自行下载。

附录

void GeomEdit()
{
using namespace AMCAX;
using namespace AMCAX::GeomE;
TopoShape shape;
bool success = STEP::StepDataTool::Read(
shape, "./data/skin.step");
// 获取检测的边
TopoExplorerTool::MapShapes(shape, ShapeType::Edge, edges);
TopoEdge edge = TopoCast::Edge(edges[15]);
// 检测该边的类型
EdgeType edgetype = DetectTool::GetEdgeType(shape, edge);
// 检测该边所属的自由边界
IndexSet<TopoShape> freeboundaries =
// 选中自由边界进行补洞
FaceEditor faceeditor;
FaceEditor::FillHole(shape, freeboundaries);
// 获取边集
edges.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Edge, edges);
TopoEdge edge1 = TopoCast::Edge(edges[9]);
TopoEdge edge2 = TopoCast::Edge(edges[10]);
TopoEdge edge3 = TopoCast::Edge(edges[11]);
edgeset.insert(edge1);
edgeset.insert(edge2);
edgeset.insert(edge3);
// 用边集构建Coons曲面
TopoFace face = faceeditor.BuildCoons(shape, edgeset);
// 获取边集
edges.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Edge, edges);
edge = TopoCast::Edge(edges[8]);
edgeset.clear();
edgeset.insert(edge);
// 用边集构建平面
face = faceeditor.BuildPlane(shape, edgeset);
// 获取边集
edges.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Edge, edges);
edge = TopoCast::Edge(edges[3]);
edge1 = TopoCast::Edge(edges[4]);
edge2 = TopoCast::Edge(edges[13]);
edge3 = TopoCast::Edge(edges[14]);
edgeset.clear();
edgeset.insert(edge);
edgeset.insert(edge1);
edgeset.insert(edge2);
edgeset.insert(edge3);
// 获取已有的面
TopoExplorerTool::MapShapes(shape, ShapeType::Face, faces);
TopoFace existface = TopoCast::Face(faces[0]);
// 用边集根据已有曲面建立新的面
face = faceeditor.BuildFaceFromSurface(shape, edgeset, existface);
// 造一个顶点
Point3 p(350., -7., 380.);
TopoVertex vertex = MakeVertex(p);
vertices.insert(vertex);
// 点投影到面
TopoShape replaceshape;
faceeditor.VerticesProjectFace(shape, vertices, existface, replaceshape);
OCCTIO::OCCTTool::Write(shape, "./shape.brep");
}

几何编辑示例三

CAD 模型预览

导入 brep 格式 cad 模型,如下图所示,左图为初始模型1,右图为初始模型2。

准备工作

本教程示例首先会读入 brep 模型,接着对输入的模型进行几何编辑操作,最后将模型写入 brep 文件。

相关头文件

几何压印的类
定义跨各种功能的配置选项的数据结构
形状的基类,包含具有位置和方向信息的基础形状

导入模型

导入 cad 文件,构建模型。

AMCAX::OCCTIO::OCCTTool::Read(shape, "./data/weidai1.brep");

输出结果

写入 brep。

success = AMCAX::OCCTIO::OCCTTool::Write(shape, "./result/shape.brep");

几何编辑示例

面的定向一致

导入的初始模型 1 由两个 solid 组成,其中第一个 solid 的各个面定向并不一致。

AMCAX::TopoExplorerTool::MapShapes(shape, AMCAX::ShapeType::Solid, solids);
AMCAX::TopoShape solid = solids[0];
AMCAX::GeomE::faceeditor.AlignFaceOrientations(solid);
AMCAX_API void AlignFaceOrientations(TopoShape &shape)
确保形状中的所有面具有一致朝向(无非流形边),与形状中的第一个面的朝向一致

如下图所示,对第一个 solid 执行面的定向一致后,所有面的法向都朝外。

检测壳是否封闭

AMCAX::TopoExplorerTool::MapShapes(solid, AMCAX::ShapeType::Shell, shells);
bool isclosed = AMCAX::GeomE::DetectTool::IsClosed(shells[0]);
static AMCAX_API bool IsClosed(const TopoShape &s)
检查实体、壳体、环或边是否封闭

检测第一个 solid 的 shell 是否封闭,返回 true。

几何压印1

imprint1.Imprint(shape, {solids[0], solids[1]}, {});
AMCAX::OCCTIO::OCCTTool::Write(shape, "./shape1.brep");
几何压印的类
定义 GeomImprint.hpp:22
AMCAX_API void Imprint(TopoShape &shape, const std::list< TopoShape > &targetlist, const std::list< TopoShape > &toollist={}, const ImprintOptions &options=ImprintOptions())
对多个形状执行相互压印,或将一组面压印到另一组面上

如下图所示,第二个 solid 被压印上一些拓扑结构。

几何压印2

如下图所示,选中绿色的面进行几何压印。

AMCAX::OCCTIO::OCCTTool::Read(shape, "./data/faces.brep");
AMCAX::TopoExplorerTool::MapShapes(shape, AMCAX::ShapeType::Face, faces);
imprint2.Imprint(shape, {faces[0]}, {faces[2]});
AMCAX::OCCTIO::OCCTTool::Write(shape, "./shape2.brep");

如下图所示,压印成功。

几何压印3

如下图所示,选中绿色的面进行几何压印。

AMCAX::OCCTIO::OCCTTool::Read(shape, "./data/faces.brep");
faces.clear();
AMCAX::TopoExplorerTool::MapShapes(shape, AMCAX::ShapeType::Face, faces);
imprint3.Imprint(shape, {faces[1]}, {faces[2]});
AMCAX::OCCTIO::OCCTTool::Write(shape, "./shape3.brep");

如下图所示,压印成功。

点击这里example03可获得几何清理修复示例三完整源码,大家根据学习需要自行下载。

附录

void GeomEdit()
{
AMCAX::OCCTIO::OCCTTool::Read(shape, "./data/weidai1.brep");
// 面的定向一致
AMCAX::TopoExplorerTool::MapShapes(shape, AMCAX::ShapeType::Solid, solids);
AMCAX::TopoShape solid = solids[0];
AMCAX::GeomE::faceeditor.AlignFaceOrientations(solid);
// 检测shell是否closed
AMCAX::TopoExplorerTool::MapShapes(solid, AMCAX::ShapeType::Shell, shells);
bool isclosed = AMCAX::GeomE::DetectTool::IsClosed(shells[0]);
// 几何压印1
imprint1.Imprint(shape, {solids[0], solids[1]}, {});
AMCAX::OCCTIO::OCCTTool::Write(shape, "./shape1.brep");
// 几何压印2
AMCAX::OCCTIO::OCCTTool::Read(shape, "./data/faces.brep");
AMCAX::TopoExplorerTool::MapShapes(shape, AMCAX::ShapeType::Face, faces);
imprint2.Imprint(shape, {faces[0]}, {faces[2]});
AMCAX::OCCTIO::OCCTTool::Write(shape, "./shape2.brep");
// 几何压印3
AMCAX::OCCTIO::OCCTTool::Read(shape, "./data/faces.brep");
faces.clear();
AMCAX::TopoExplorerTool::MapShapes(shape, AMCAX::ShapeType::Face, faces);
imprint3.Imprint(shape, {faces[1]}, {faces[2]});
AMCAX::OCCTIO::OCCTTool::Write(shape, "./shape3.brep");
}