AMCAX Kernel
Geometry kernel for CAD/CAE/CAM
AMCAX Kernel 1.0.0.0
Loading...
Searching...
No Matches
Geometry Edit Example

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. Additionally, in the images of this tutorial, the red edge represents free edge, while the yellow edge represents manifold edge.

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

Geometry Edit example one

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.

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");
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.
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.
TopoExplorerTool::MapShapes(shape, ShapeType::Vertex, vertices);
TopoVertex vertex = TopoCast::Vertex(vertices[799]);
Point3 point = TopoTool::Point(vertex);
//Get the inserted edge.
TopoExplorerTool::MapShapes(shape, ShapeType::Edge, edges);
TopoEdge edge = TopoCast::Edge(edges[1528]);
//Insert the point into the Edge.
EdgeEditor::TrimEdgeWithPoint(shape, edge, { point });
static AMCAX_API void TrimEdgeWithPoint(TopoShape &shape, const TopoEdge &edge, const std::vector< Point3 > &points)
Project points onto an edge.
Template class of indexed set.
Definition 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.
Definition 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.
Definition TopoVertex.hpp:12
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);
static 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
Clear the indexed set.
Definition IndexSet.hpp:90

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.
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);
static AMCAX_API void EdgesProjectFace(TopoShape &shape, const IndexSet< TopoShape > &edges, TopoFace &face, TopoShape &replaceshape)
Project edges onto a surface.
int insert(T &&key)
Insert a new key.
Definition IndexSet.hpp:102
static AMCAX_API const TopoFace & Face(const TopoShape &s)
Cast shape to face.
Class of face.
Definition TopoFace.hpp:12

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.
static AMCAX_API void ReleaseVertex(TopoShape &shape, const TopoVertex &vertex)
Release vertex onto each edge.

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.
static AMCAX_API void RemoveVertex(TopoShape &shape, const TopoVertex &vertex)
Delete vertex on the edge.

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);
static AMCAX_API TopoVertex SewVertices(AMCAX::TopoShape &shape, const IndexSet< TopoShape > &vertexvec)
Sew a set of vertices into a single vertex.

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);
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.

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.
static AMCAX_API TopoEdge RebuildAndUpdateEdge(TopoShape &shape, const TopoEdge &edge)
Resample the curve of an edge and update it.

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 });
static AMCAX_API void TrimEdgeWithRatio(TopoShape &shape, const TopoEdge &edge, const std::vector< double > &ratios)
Insert vertices on the edge based on the given ratios.

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.
static AMCAX_API void ReleaseEdge(AMCAX::TopoShape &shape, const AMCAX::TopoEdge &edge)
Release the common edge of several faces to their respective faces.

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.
static AMCAX_API void DeleteFace(AMCAX::TopoShape &shape, const AMCAX::TopoFace &face)
Remove a face from the shape.

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.
joinedges.insert(edge1);
joinedges.insert(edge2);
TopoEdge newedge = EdgeEditor::JoinEdgesAndUpdate(shape, joinedges);
static AMCAX_API TopoEdge JoinEdgesAndUpdate(AMCAX::TopoShape &shape, const IndexSet< TopoShape > &edges)
Join edges into one edge.

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.
static AMCAX_API void ReverseOrientation(AMCAX::TopoShape &shape, const AMCAX::TopoFace &face)
Reverse the orientation of a 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
TopoExplorerTool::MapShapes(shape, ShapeType::Vertex, vertices);
TopoVertex vertex = TopoCast::Vertex(vertices[799]);
Point3 point = TopoTool::Point(vertex);
// Get the inserted edge
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
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
// Get the vertex to be deleted
vertices.clear();
TopoExplorerTool::MapShapes(shape, ShapeType::Vertex, vertices);
vertex = TopoCast::Vertex(vertices[845]);
// Delete the 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
// 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
// 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
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
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
TopoExplorerTool::MapShapes(shape, ShapeType::Edge, edges);
TopoEdge edge = TopoCast::Edge(edges[15]);
// Detect the type of the edge
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.
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 =
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.

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);
static AMCAX_API void FillHole(TopoShape &shape, const IndexSet< TopoShape > &freeboundaries)
Fill the holes formed by free boundaries.

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]);
edgeset.insert(edge1);
edgeset.insert(edge2);
edgeset.insert(edge3);
// Build a coons surface using the edge set
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.

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);
static AMCAX_API TopoFace BuildPlane(TopoShape &shape, const IndexSet< TopoShape > &edges)
Construct a new plane face based on the given set of edges.

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
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);
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.

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);
vertices.insert(vertex);
// Project the point onto the face
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.
Definition MakeVertex.hpp:16

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
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 =
// 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]);
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
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);
vertices.insert(vertex);
// Project the point onto the face
TopoShape replaceshape;
FaceEditor::VerticesProjectFace(shape, vertices, existface, replaceshape);
OCCTIO::OCCTTool::Write(shape, "./shape.brep");
}

Geometry Edit example three

CAD Model Preview

Import a BREP format CAD model as shown in the following images. The left image is the initial model 1, and the right image is the initial model 2.

Preparation Work

In this tutorial, the example first reads in a BREP model, then performs geometric editing operations on the input model, and finally writes the model into a BREP file.

Relevant Header Files

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.

Importing the Model

Import the CAD file and construct the model.

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

Output Results

Write the BREP.

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

Geometry Editing Example

Consistent Face Orientation

The initial model 1 consists of two solids, with the faces of the first solid having inconsistent orientations.

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.

As shown in the image below, after performing face orientation alignment on the first solid, the normal vectors of all faces are directed outward.

Check if the Shell is Closed

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.

Check if the shell of the first solid is closed, return true.

Geometric Imprint 1

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

As shown in the image below, the second solid has been imprinted with some topological structures.

Geometric Imprint 2

As shown in the image below, select the green face for geometric imprinting.

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");

As shown in the image below, the imprint was successful.

Geometric Imprint 3

As shown in the image below, select the green face for geometric imprinting.

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");

As shown in the image below, the imprint was successful.

Click here example03 to get the full source code of the geometry edit example three. Everyone can download it as needed.

Appendix

void GeomEditor()
{
AMCAX::OCCTIO::OCCTTool::Read(shape, "./data/weidai1.brep");
// Consistent face orientation
AMCAX::TopoExplorerTool::MapShapes(shape, AMCAX::ShapeType::Solid, solids);
AMCAX::TopoShape solid = solids[0];
// Check if the shell is closed
imprint1.Imprint(shape, {solids[0], solids[1]}, {});
AMCAX::OCCTIO::OCCTTool::Write(shape, "./shape1.brep");
// Geometric Imprint 1
AMCAX::TopoShape imprintresult1 = imprint1.Imprint(shape, {solids[0], solids[1]}, {});
// Geometric Imprint 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");
// Geometric Imprint 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");
}