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 文件。

相关头文件

Class of Edge Editor
Class of Face Editor
Class of read and write shapes from OCCT BRep files
Class of casting tool
Class of edge
Class of tool for explorer
Class of face
Class of tools for B-Rep structure
Class of vertex
Class of Vertex Editor

导入模型

导入cad文件,构建模型。

OCCTIO::OCCTTool::Read(shape, "./data/FEA.brep");
static AMCAX_API bool Read(TopoShape &s, std::istream &is)
Read a shape from a stream
Base class of shape, containing an underlying shape with a location and an orientation
定义 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)
Write a shape to a stream

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

点插入到边上

//获取插入点的坐标
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 });
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
static AMCAX_API void MapShapes(const TopoShape &s, ShapeType t, IndexSet< TopoShape > &shapeSet)
Construct a set of sub-shapes of given type
static AMCAX_API Point3 Point(const TopoVertex &v)
Get the point of a vertex
Class of vertex
定义 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)
Sew two edges with nearby vertices, using the second edge as the resulting edge
void clear() noexcept
清除索引集合
定义 IndexSet.hpp:105

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

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

边投影到面

// 获取要投影的边
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::EdgesProjectFace(shape, projectedges, face, replaceshape);
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

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

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

// 获取两条要缝合的边
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);
Class of Vertex Editor
定义 VertexEditor.hpp:20
AMCAX_API void ReleaseVertex(TopoShape &shape, const TopoVertex &vertex)
Release vertex onto each edge

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

删除点

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

// 获取删除的顶点
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)
Delete vertex on the edge

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

缝合顶点

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

// 获取缝合的顶点
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)
Sew a set of vertices into a single vertex

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

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

// 获取两条要缝合的边
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);
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

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

重建边

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

// 获取重建的边
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)
Resample the curve of an edge and update it

下图为重建边前后对比。

在边上根据比例插入点

如图所示,在选中的边(黄色)上按比例 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)
Insert vertices on the edge based on the given 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)
Release the common edge of several faces to their respective faces

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

删除面

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

// 获取要删除的面
faces.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Face, faces);
face = TopoCast::Face(faces[832]);
// 删除面
static AMCAX_API void DeleteFace(AMCAX::TopoShape &shape, const AMCAX::TopoFace &face)
Remove a face from the shape

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

连接两条边为一条边

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

// 获取两条要连接的边
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)
Join edges into one edge

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

反转面的定向

// 获取要反转定向的面
faces.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Face, faces);
face = TopoCast::Face(faces[139]);
// 反转面的定向
static AMCAX_API void ReverseOrientation(AMCAX::TopoShape &shape, const AMCAX::TopoFace &face)
Reverse the orientation of a 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::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]);
// 反转面的定向
AMCAX::OCCTIO::OCCTTool::Write(shape, "./shape.brep");
}

几何编辑示例二

CAD模型预览

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

准备工作

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

相关头文件

Class of Detect Tool
Enumerations in GeomE
Class of making a vertex
Class of tools for StepData.

导入模型

导入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)
Detect the type of a given edge within the specified shape
EdgeType
Type of edges
定义 GeomEMacros.hpp:12

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

检测边所属的自由边界

//检测该边所属的自由边界
IndexSet<TopoShape> freeboundaries =
static AMCAX_API IndexSet< TopoShape > DetectFreeBoundaries(const TopoShape &shape, const TopoEdge &edge)
Find a set of free boundaries within the given shape that includes the specified free edge

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

选中自由边界进行补洞

//选中自由边界进行补洞
FaceEditor::FillHole(shape, freeboundaries);
static AMCAX_API void FillHole(TopoShape &shape, const IndexSet< TopoShape > &freeboundaries)
Fill the holes formed by free boundaries

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

选中边界建立新的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);
static AMCAX_API TopoFace BuildCoons(TopoShape &shape, const IndexSet< TopoShape > &edges)
Construct a new coons face based on the given set of edges

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

选中边界建立新的平面

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

// 获取边集
edges.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Edge, edges);
edge = TopoCast::Edge(edges[8]);
edgeset.clear();
edgeset.insert(edge);
// 用边集构建平面
face = FaceEditor::BuildPlane(shape, edgeset);
static AMCAX_API TopoFace BuildPlane(TopoShape &shape, const IndexSet< TopoShape > &edges)
Construct a new plane face based on the given set of 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);
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

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

点投影到面

// 造一个顶点
Point3 p(350., -7., 380.);
TopoVertex vertex = MakeVertex(p);
vertices.insert(vertex);
// 点投影到面
TopoShape replaceshape;
FaceEditor::VerticesProjectFace(shape, vertices, existface, replaceshape);
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()
{
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::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 文件。

相关头文件

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 文件,构建模型。

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];
static AMCAX_API void AlignFaceOrientations(TopoShape &shape)
Ensure consistent orientation of all faces in a shape without non-manifold edges

如下图所示,对第一个 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)
Check whether the shell, wire, or edge is closed

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

几何压印1

imprint1.Imprint(shape, {solids[0], solids[1]}, {});
AMCAX::OCCTIO::OCCTTool::Write(shape, "./shape1.brep");
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

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

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];
// 检测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");
}