AMCAX Kernel
Geometry kernel for CAD/CAE/CAM
AMCAX Kernel 1.0.0.0
Geometry Edit Example

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.

using namespace AMCAX;
using namespace AMCAX::GeomE;
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

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.

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.

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.

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

//Get the point of the inserted vertex.
IndexSet<TopoShape> vertices;
TopoExplorerTool::MapShapes(shape, ShapeType::Vertex, vertices);
TopoVertex vertex = TopoCast::Vertex(vertices[799]);
Point3 point = TopoTool::Point(vertex);
//Get the inserted edge.
IndexSet<TopoShape> edges;
TopoExplorerTool::MapShapes(shape, ShapeType::Edge, edges);
TopoEdge edge = TopoCast::Edge(edges[1528]);
//Insert the point into the Edge.
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

//Get the two edges to be sewn
edges.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Edge, edges);
TopoEdge edge1 = TopoCast::Edge(edges[1528]);
TopoEdge edge2 = TopoCast::Edge(edges[1759]);
//Sew edge2 onto edge1.
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

//Get the edge to be projected.
edges.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Edge, edges);
edge = TopoCast::Edge(edges[1736]);
//Get the face to which the edge will be projected.
IndexSet<TopoShape> faces;
TopoExplorerTool::MapShapes(shape, ShapeType::Face, faces);
TopoFace face = TopoCast::Face(faces[30]);
//Project the edge onto the face.
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

// Get the two edges to be sewn.
edges.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Edge, edges);
edge1 = TopoCast::Edge(edges[1737]);
edge2 = TopoCast::Edge(edges[102]);
// Sew edge2 onto edge1.
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

// Get the vertex to be released.
vertices.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Vertex, vertices);
vertex = TopoCast::Vertex(vertices[845]);
// Release the vertex.
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.

// Get the vertex to be deleted.
vertices.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Vertex, vertices);
vertex = TopoCast::Vertex(vertices[845]);
// Delete the vertex.
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.

// Get the vertices to be sewn.
vertices.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Vertex, vertices);
TopoVertex vertex1 = TopoCast::Vertex(vertices[417]);
TopoVertex vertex2 = TopoCast::Vertex(vertices[847]);
// Sew vertex2 to vertex1.
VertexEditor::SewVertices(shape, vertex2, vertex1);

As shown in the figure, the two vertices have been sewn together.

Sew one edge to another edge.

// Get the two edges to be sewn.
edges.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Edge, edges);
edge1 = TopoCast::Edge(edges[1887]);
edge2 = TopoCast::Edge(edges[1880]);
// Sew edge2 onto edge1.
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

// Get the cutting vertices.
vertices.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Vertex, vertices);
vertex1 = TopoCast::Vertex(vertices[578]);
vertex2 = TopoCast::Vertex(vertices[821]);
// Get the cut face.
faces.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Face, faces);
face = TopoCast::Face(faces[903]);
// Perform parameter cut.
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.

//Get the edge to be rebuilt.
edges.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Edge, edges);
edge = TopoCast::Edge(edges[452]);
//Rebuild and update the edge.
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).

// Get the inserted edge
edges.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Edge, edges);
edge = TopoCast::Edge(edges[446]);
// Insert a vertex on the edge based on the ratio.
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.

// Get the released edge.
edges.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Edge, edges);
edge = TopoCast::Edge(edges[447]);
// Release the edge.
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.

// Get the face to be deleted.
faces.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Face, faces);
face = TopoCast::Face(faces[832]);
// Delete the face.
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.

// Get the two edges to be joined.
edges.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Edge, edges);
edge1 = TopoCast::Edge(edges[446]);
edge2 = TopoCast::Edge(edges[447]);
// Join two edges into a single edge.
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

// Get the face whose orientation is to be reversed.
faces.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Face, faces);
face = TopoCast::Face(faces[139]);
// Reverse the orientation of the face.
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()
{
using namespace AMCAX;
using namespace AMCAX::GeomE;
OCCTIO::OCCTTool::Read(shape, "./data/FEA.brep");
// Get the coordinates of the insertion point
IndexSet<TopoShape> vertices;
TopoExplorerTool::MapShapes(shape, ShapeType::Vertex, vertices);
TopoVertex vertex = TopoCast::Vertex(vertices[799]);
Point3 point = TopoTool::Point(vertex);
// Get the inserted edge
IndexSet<TopoShape> edges;
TopoExplorerTool::MapShapes(shape, ShapeType::Edge, edges);
TopoEdge edge = TopoCast::Edge(edges[1528]);
// Insert the point onto the edge
EdgeEditor::TrimEdgeWithPoint(shape, edge, { point });
// Get two edges to be sewn together
edges.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Edge, edges);
TopoEdge edge1 = TopoCast::Edge(edges[1528]);
TopoEdge edge2 = TopoCast::Edge(edges[1759]);
// Sew edge2 to edge1
EdgeEditor::SewEdges(shape, edge2, edge1, 0.1);
// Get the edge to be projected
edges.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Edge, edges);
edge = TopoCast::Edge(edges[1736]);
// Get the face to which the edge will be projected
IndexSet<TopoShape> faces;
TopoExplorerTool::MapShapes(shape, ShapeType::Face, faces);
TopoFace face = TopoCast::Face(faces[30]);
// Project the edge onto the face
TopoShape replaceshape;
IndexSet<TopoShape> projectedges;
projectedges.insert(edge);
FaceEditor::EdgesProjectFace(shape, projectedges, face, replaceshape);
// Get two edges to be sewn together
edges.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Edge, edges);
edge1 = TopoCast::Edge(edges[1737]);
edge2 = TopoCast::Edge(edges[102]);
// Sew edge2 to edge1
EdgeEditor::SewEdges(shape, edge2, edge1, 0.1);
// Get the vertex to be released
vertices.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Vertex, vertices);
vertex = TopoCast::Vertex(vertices[845]);
// Release the vertex
VertexEditor::ReleaseVertex(shape, vertex);
// Get the vertex to be deleted
vertices.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Vertex, vertices);
vertex = TopoCast::Vertex(vertices[845]);
// Delete the vertex
VertexEditor::RemoveVertex(shape, vertex);
// Get the vertices to be sewn together
vertices.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Vertex, vertices);
TopoVertex vertex1 = TopoCast::Vertex(vertices[417]);
TopoVertex vertex2 = TopoCast::Vertex(vertices[847]);
// Sew vertex2 to vertex1
VertexEditor::SewVertices(shape, vertex2, vertex1);
// Get two edges to be sewn together
edges.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Edge, edges);
edge1 = TopoCast::Edge(edges[1887]);
edge2 = TopoCast::Edge(edges[1880]);
// Sew edge2 to edge1
EdgeEditor::SewEdges(shape, edge2, edge1, 0.1);
// Get the split vertices
vertices.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Vertex, vertices);
vertex1 = TopoCast::Vertex(vertices[578]);
vertex2 = TopoCast::Vertex(vertices[821]);
// Get the face to be split
faces.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Face, faces);
face = TopoCast::Face(faces[903]);
// Perform parametric split
FaceEditor::ParameterFaceCut(shape, face, vertex1, vertex2);
// Get the rebuilt edge
edges.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Edge, edges);
edge = TopoCast::Edge(edges[452]);
// Rebuild and update the edge
EdgeEditor::RebuildAndUpdateEdge(shape, edge);
// Get the inserted edge
edges.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Edge, edges);
edge = TopoCast::Edge(edges[446]);
// Insert a vertex on the edge based on ratio
EdgeEditor::TrimEdgeWithRatio(shape, edge, { 0.3 });
// Get the edge to be released
edges.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Edge, edges);
edge = TopoCast::Edge(edges[447]);
// Release the edge
EdgeEditor::ReleaseEdge(shape, edge);
// Get the face to be deleted
faces.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Face, faces);
face = TopoCast::Face(faces[832]);
// Delete the face
FaceEditor::DeleteFace(shape, face);
// Get two edges to be connected
edges.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Edge, edges);
edge1 = TopoCast::Edge(edges[446]);
edge2 = TopoCast::Edge(edges[447]);
// Connect the two edges into one edge
IndexSet<TopoShape> joinedges;
joinedges.insert(edge1);
joinedges.insert(edge2);
TopoEdge newedge = EdgeEditor::JoinEdgesAndUpdate(shape, joinedges);
// Get the face to reverse orientation
faces.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Face, faces);
face = TopoCast::Face(faces[139]);
// Reverse the orientation of the face
FaceEditor::ReverseOrientation(shape, face);
AMCAX::OCCTIO::OCCTTool::Write(shape, "./shape.brep");
}

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 Detect Tool.
Enumerations in GeomE.
Class of making a vertex.
Class of tools for StepData.

Import Model

Import the CAD file and build the model.

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.

Output Result

Write the model to a BREP file.

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

Detect Edge Type

// Get the edge to be checked
IndexSet<TopoShape> edges;
TopoExplorerTool::MapShapes(shape, ShapeType::Edge, edges);
TopoEdge edge = TopoCast::Edge(edges[15]);
// Detect the type of the edge
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

// Detect the 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

// Fill holes using 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.

// Get edge set
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);
// Build a coons surface using the edge set
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.

// Get edge set
edges.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Edge, edges);
edge = TopoCast::Edge(edges[8]);
edgeset.clear();
edgeset.insert(edge);
// Build a Plane using the edge set
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.

// Get edge set
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);
// Get the existing face
IndexSet<TopoShape> faces;
TopoExplorerTool::MapShapes(shape, ShapeType::Face, faces);
TopoFace existface = TopoCast::Face(faces[0]);
// Create a new face based on the existing surface
face = FaceEditor::BuildFaceFromSurface(shape, edgeset, existface);

As shown in the figure, the new face has been successfully created.

Project a Point onto a Face

// Create a vertex
Point3 p(350., -7., 380.);
TopoVertex vertex = MakeVertex(p);
IndexSet<TopoShape> vertices;
vertices.insert(vertex);
// Project the point onto the face
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()
{
using namespace AMCAX;
using namespace AMCAX::GeomE;
TopoShape shape;
bool success = STEP::StepDataTool::Read(
shape, "./data/skin.step");
// Get the detected edges
IndexSet<TopoShape> edges;
TopoExplorerTool::MapShapes(shape, ShapeType::Edge, edges);
TopoEdge edge = TopoCast::Edge(edges[15]);
// Detect the type of this edge
EdgeType edgetype = DetectTool::GetEdgeType(shape, edge);
// Detect the free boundary to which this edge belongs
IndexSet<TopoShape> freeboundaries =
DetectTool::DetectFreeBoundaries(shape, edge);
// Select the free boundary for hole filling
FaceEditor::FillHole(shape, freeboundaries);
// Get the edge set
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);
// Build a Coons surface from the edge set
TopoFace face = FaceEditor::BuildCoons(shape, edgeset);
// Get the edge set
edges.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Edge, edges);
edge = TopoCast::Edge(edges[8]);
edgeset.clear();
edgeset.insert(edge);
// Build a plane from the edge set
face = FaceEditor::BuildPlane(shape, edgeset);
// Get the edge set
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);
// Get the existing face
IndexSet<TopoShape> faces;
TopoExplorerTool::MapShapes(shape, ShapeType::Face, faces);
TopoFace existface = TopoCast::Face(faces[0]);
// Build a new face based on the existing surface using the edge set
face = FaceEditor::BuildFaceFromSurface(shape, edgeset, existface);
// Create a vertex
Point3 p(350., -7., 380.);
TopoVertex vertex = MakeVertex(p);
IndexSet<TopoShape> vertices;
vertices.insert(vertex);
// Project the point onto the face
TopoShape replaceshape;
FaceEditor::VerticesProjectFace(shape, vertices, existface, replaceshape);
OCCTIO::OCCTTool::Write(shape, "./shape.brep");
}