Geometry edit example one
Overview
This tutorial provides the basic usage of geometry editing, including importing brep format files and performing geometric editing operations on the model using the GeomE API for model repair. The tutorial also utilizes the API from the AMCAX kernel.
Namespace
To keep the example code clear, namespaces are used.
Namespace of all interface in the AMCAX GeomE module.
Definition: misc.docu:21
Namespace of all interface in the AMCAX kernel.
Definition: misc.docu:8
CAD Model Preview
Import a brep format CAD model, as shown in the figure below:
Preparation
This tutorial example will first read in a brep model, then perform geometric editing operations on the input model, and finally write the model into a BREP file. Red edges represent free edges,yellow edges represent manifold edges, and blue edges represent non-manifold edges.
Header Files
Import Model
Import the CAD file and construct the model.
OCCTIO::OCCTTool::Read(shape, "./data/FEA.brep");
Base class of shape, containing an underlying shape with a location and an orientation.
Definition: TopoShape.hpp:15
Output Result
Write to brep file.
As shown in the figure, the area marked with a red circle has a gap between the short edge of one face and the long edge of another face. Both edges are free edges.
Point insertion into edge
IndexSet<TopoShape> vertices;
TopoExplorerTool::MapShapes(shape, ShapeType::Vertex, vertices);
TopoVertex vertex = TopoCast::Vertex(vertices[799]);
Point3 point = TopoTool::Point(vertex);
IndexSet<TopoShape> edges;
TopoExplorerTool::MapShapes(shape, ShapeType::Edge, edges);
TopoEdge edge = TopoCast::Edge(edges[1528]);
EdgeEditor::TrimEdgeWithPoint(shape, edge, { point });
PointT< double, 3 > Point3
3D point
Definition: PointT.hpp:459
As shown in the figure, the point has been inserted into the corresponding edge, and the long edge has been split into two edges.
Sew one edge onto another edge
edges.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Edge, edges);
TopoEdge edge1 = TopoCast::Edge(edges[1528]);
TopoEdge edge2 = TopoCast::Edge(edges[1759]);
EdgeEditor::SewEdges(shape, edge2, edge1, 0.1);
As shown in the figure, the gap between the two faces has been eliminated.
As shown in the figure, the area marked with a red circle has a gap between the edge of one face and another face.
Project the edge onto the face
edges.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Edge, edges);
edge = TopoCast::Edge(edges[1736]);
IndexSet<TopoShape> faces;
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);
As shown in the figure, the specified edge has been projected onto the interior of the face.
Sew one edge to another edge
edges.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Edge, edges);
edge1 = TopoCast::Edge(edges[1737]);
edge2 = TopoCast::Edge(edges[102]);
EdgeEditor::SewEdges(shape, edge2, edge1, 0.1);
As shown in the figure, in the area marked with a red circle, a very short edge has appeared.
Release the Vertex
vertices.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Vertex, vertices);
vertex = TopoCast::Vertex(vertices[845]);
VertexEditor::ReleaseVertex(shape, vertex);
As shown in the figure, the vertex has been released onto the respective faces.
Delete the Vertex
Delete the red vertex of the star-shaped marked face.
vertices.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Vertex, vertices);
vertex = TopoCast::Vertex(vertices[845]);
VertexEditor::RemoveVertex(shape, vertex);
As shown in the figure, the red vertex of the star-shaped marked face has been deleted, and the long edge and short edge are now connected as a single edge.
Sew the Vertex
As shown in the figure, the vertex of the face on the right needs to be sewn to the vertex of the face on the left.
vertices.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Vertex, vertices);
TopoVertex vertex1 = TopoCast::Vertex(vertices[417]);
TopoVertex vertex2 = TopoCast::Vertex(vertices[847]);
VertexEditor::SewVertices(shape, vertex2, vertex1);
As shown in the figure, the two vertices have been sewn together.
Sew one edge to another edge.
edges.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Edge, edges);
edge1 = TopoCast::Edge(edges[1887]);
edge2 = TopoCast::Edge(edges[1880]);
EdgeEditor::SewEdges(shape, edge2, edge1, 0.1);
As shown in the figure, the edge of the left face is stitched to the edge of the right face.
As shown in the figure, select the two vertices to perform parameter cut on the face.
Parameter Cut
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);
As shown in the figure, the parameter cut was successful.
Rebuild the edge
As shown in the figure, you can select an edge (yellow) for rebuilding.
edges.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Edge, edges);
edge = TopoCast::Edge(edges[452]);
EdgeEditor::RebuildAndUpdateEdge(shape, edge);
The following are the edge before rebuilding and the edge after rebuilding.
Insert a vertex on the edge based on the ratio.
As shown in the figure, insert a vertex at a ratio of 0.3 on the selected edge (yellow).
edges.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Edge, edges);
edge = TopoCast::Edge(edges[446]);
EdgeEditor::TrimEdgeWithRatio(shape, edge, { 0.3 });
As shown in the figure, a vertex has been inserted at 0.3 of the selected edge.
Release the edge
As shown in the figure, release the edge circled in red.
edges.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Edge, edges);
edge = TopoCast::Edge(edges[447]);
EdgeEditor::ReleaseEdge(shape, edge);
As shown in the figure, the selected edge has been released onto two faces, becoming free edges.
Delete the face
As shown in the figure, the star-marked face needs to be deleted.
faces.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Face, faces);
face = TopoCast::Face(faces[832]);
FaceEditor::DeleteFace(shape, face);
As shown in the figure, the selected face has been deleted.
Join two edges into one edge
As shown in the figure, join the two red edges.
edges.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Edge, edges);
edge1 = TopoCast::Edge(edges[446]);
edge2 = TopoCast::Edge(edges[447]);
IndexSet<TopoShape> joinedges;
joinedges.insert(edge1);
joinedges.insert(edge2);
TopoEdge newedge = EdgeEditor::JoinEdgesAndUpdate(shape, joinedges);
As shown in the figure, after the joint, the two edges become one edge, and the vertex disappears.
Reverse the orientation of the face
faces.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Face, faces);
face = TopoCast::Face(faces[139]);
FaceEditor::ReverseOrientation(shape, face);
Click here example01 to get the full source code of the geometry edit example one. Everyone can download it as needed.
Appendix
The complete code for this example is listed below:
void GeomEdit()
{
OCCTIO::OCCTTool::Read(shape, "./data/FEA.brep");
IndexSet<TopoShape> vertices;
TopoExplorerTool::MapShapes(shape, ShapeType::Vertex, vertices);
TopoVertex vertex = TopoCast::Vertex(vertices[799]);
Point3 point = TopoTool::Point(vertex);
IndexSet<TopoShape> edges;
TopoExplorerTool::MapShapes(shape, ShapeType::Edge, edges);
TopoEdge edge = TopoCast::Edge(edges[1528]);
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]);
EdgeEditor::SewEdges(shape, edge2, edge1, 0.1);
edges.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Edge, edges);
edge = TopoCast::Edge(edges[1736]);
IndexSet<TopoShape> faces;
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]);
EdgeEditor::SewEdges(shape, edge2, edge1, 0.1);
vertices.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Vertex, vertices);
vertex = TopoCast::Vertex(vertices[845]);
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]);
VertexEditor::SewVertices(shape, vertex2, vertex1);
edges.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Edge, edges);
edge1 = TopoCast::Edge(edges[1887]);
edge2 = TopoCast::Edge(edges[1880]);
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]);
IndexSet<TopoShape> joinedges;
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);
}
Geometry Edit example two
CAD Model Preview
Import a STEP format CAD model, as shown in the figure below:
Preparation
In this tutorial example, the STEP model will first be read in, followed by geometric editing operations on the input model, and finally, the model will be written to a BREP file.
Relevant Header Files
Class of making a vertex.
Import Model
Import the CAD file and build the model.
Output Result
Write the model to a BREP file.
Detect Edge Type
IndexSet<TopoShape> edges;
TopoExplorerTool::MapShapes(shape, ShapeType::Edge, edges);
TopoEdge edge = TopoCast::Edge(edges[15]);
EdgeType edgetype = DetectTool::GetEdgeType(shape, edge);
EdgeType
Type of edges.
Definition: GeomEMacros.hpp:12
As shown in the figure, the green edge is selected for detection. The returned EdgeType for this edge is FreeEdge, indicating that this edge is a free edge.
Detect Free Boundaries of the Edge
IndexSet<TopoShape> freeboundaries =
DetectTool::DetectFreeBoundaries(shape, edge);
As shown in the figure, the free boundary containing the edge is detected.
Fill Holes in the Free Boundary
FaceEditor::FillHole(shape, freeboundaries);
As shown in the figure, the hole bounded by the free boundary has been filled.
Create a New Coons Surface from the Selected Boundary
As shown in the figure, the green edges are selected as a set to construct a new plane.
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]);
IndexSet<TopoShape> edgeset;
edgeset.insert(edge1);
edgeset.insert(edge2);
edgeset.insert(edge3);
TopoFace face = FaceEditor::BuildCoons(shape, edgeset);
As shown in the figure, the Coons Surface has been successfully constructed.
Create a New Plane from the Selected Boundary
As shown in the figure, the green edges are selected as a set to construct a new plane.
edges.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Edge, edges);
edge = TopoCast::Edge(edges[8]);
edgeset.clear();
edgeset.insert(edge);
face = FaceEditor::BuildPlane(shape, edgeset);
As shown in the figure, the plane has been successfully constructed.
Create a New Face Based on an Existing Surface
As shown in the figure, the green edges are selected as a set to create a new face based on the surface of the yellow face.
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);
IndexSet<TopoShape> faces;
TopoExplorerTool::MapShapes(shape, ShapeType::Face, faces);
TopoFace existface = TopoCast::Face(faces[0]);
face = FaceEditor::BuildFaceFromSurface(shape, edgeset, existface);
As shown in the figure, the new face has been successfully created.
Project a Point onto a Face
TopoVertex vertex = MakeVertex(p);
IndexSet<TopoShape> vertices;
vertices.insert(vertex);
TopoShape replaceshape;
FaceEditor::VerticesProjectFace(shape, vertices, existface, replaceshape);
As shown in the figure, the point has been successfully projected onto the face.
Click here example02 to get the full source code of the geometry edit example two. Everyone can download it as needed.
Appendix
void GeomEdit()
{
TopoShape shape;
bool success = STEP::StepDataTool::Read(
shape, "./data/skin.step");
IndexSet<TopoShape> edges;
TopoExplorerTool::MapShapes(shape, ShapeType::Edge, edges);
TopoEdge edge = TopoCast::Edge(edges[15]);
EdgeType edgetype = DetectTool::GetEdgeType(shape, edge);
IndexSet<TopoShape> freeboundaries =
DetectTool::DetectFreeBoundaries(shape, edge);
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]);
IndexSet<TopoShape> edgeset;
edgeset.insert(edge1);
edgeset.insert(edge2);
edgeset.insert(edge3);
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);
IndexSet<TopoShape> faces;
TopoExplorerTool::MapShapes(shape, ShapeType::Face, faces);
TopoFace existface = TopoCast::Face(faces[0]);
face = FaceEditor::BuildFaceFromSurface(shape, edgeset, existface);
TopoVertex vertex = MakeVertex(p);
IndexSet<TopoShape> vertices;
vertices.insert(vertex);
TopoShape replaceshape;
FaceEditor::VerticesProjectFace(shape, vertices, existface, replaceshape);
OCCTIO::OCCTTool::Write(shape, "./shape.brep");
}