Topology¶
The afem.topology package provides tools for the creation and use of
OpenCASCADE topology (i.e., shapes). While geometry defines curves and
surfaces, topology describes their connectivity and boundary representation.
OpenCASCADE shapes are the core building blocks for building more complex parts
and assemblies. The topology entities and tools can be imported by:
from afem.topology import *
The user should review the OpenCASCADE topology documentation to become with the underlying types and data structures:
The types in afem.topology.entities are essentially wrappers of their
underlying TopoDS_Shape object. This is an attempt to provide a more
“Pythonic” interface for the OpenCASCADE TopoDS_Shape types. Many tools are
provided for the user to easily create, modify, and operate on shapes. If a
tool is not available, the user can still use the pyOCCT package and access
the wrapped TopoDS_Shape instance using the object property of
Shape.
A subset of afem.topology entities and tools are featured in the following
example:
from afem.geometry import *
from afem.graphics import *
from afem.topology import *
gui = Viewer()
# Create a box by size
builder = BoxBySize(10, 10, 10)
box = builder.solid
box.set_transparency(0.5)
# Create a cylinder partially inside the box
circle = CircleByNormal((5, 5, 5), (0, 0, 1), 2).circle
face = FaceByPlanarWire(circle).face
cyl = SolidByDrag(face, (0, 0, 15)).solid
# View the two shapes
gui.add(box, cyl)
gui.start()
gui.clear()
# Fuse the shapes
fuse = FuseShapes(box, cyl)
fused_shape = fuse.shape
fused_shape.set_transparency(0.5)
gui.add(fused_shape)
gui.start()
gui.clear()
# Cut the cylinder from the box
cut = CutShapes(box, cyl)
cut_shape = cut.shape
gui.add(cut_shape)
gui.start()
gui.clear()
# Common material between the two shapes
common = CommonShapes(box, cyl)
common_shape = common.shape
# Show original box for reference
gui.add(common_shape, box)
gui.start()
gui.clear()
# Intersect the shapes
sec = IntersectShapes(box, cyl)
sec_shape = sec.shape
# Original shapes shown for reference
gui.add(sec_shape, box, cyl)
gui.start()
gui.clear()
# Split the box with the cylinder. The resulting shape is a compound with
# two solids.
split = SplitShapes(box, cyl)
split_shape = split.shape
split_shape.set_transparency(0.5)
gui.add(split_shape)
gui.start()
gui.clear()
# Locally split one face of the box with a plane
pln = PlaneByAxes((5, 5, 5), 'xz').plane
local = LocalSplit(builder.front_face, pln, box)
local_shape = local.shape
local_shape.set_transparency(0.5)
gui.add(local_shape)
gui.start()
gui.clear()
# Offset the box
offset = OffsetShape(box, 2)
offset_shape = offset.shape
offset_shape.set_transparency(0.5)
gui.add(box, offset_shape)
gui.start()
gui.clear()
# Rebuild the box with the results of the cut tool.
rebuild = RebuildShapeByTool(box, cut)
new_shape = rebuild.new_shape
gui.add(new_shape)
gui.start()
# Check the new shape for errors
check = CheckShape(new_shape)
print('Shape is valid:', check.is_valid)
print('Shape type:', new_shape.shape_type)
# Since a face is removed it is no longer a valid solid but a shell. Try to
# fix the shape.
fix = FixShape(new_shape)
fixed_shape = fix.shape
check = CheckShape(fixed_shape)
print('Shape is valid:', check.is_valid)
print('Shape type:', fixed_shape.shape_type)
gui.add(fixed_shape)
gui.start()
# Find free edges of a shape
tool = ExploreFreeEdges(fixed_shape)
gui.add(*tool.free_edges)
gui.start()
The needed entities and tools are imported by:
from afem.geometry import *
from afem.graphics import *
from afem.topology import *
A number of tools exist to create shapes but these examples the primary shapes are a solid box and a solid cylinder. The box is created by a length, width, and height:
builder = BoxBySize(10, 10, 10)
box = builder.solid
box.set_transparency(0.5)
The cylinder is created by extruding a circular face along a vector:
circle = CircleByNormal((5, 5, 5), (0, 0, 1), 2).circle
face = FaceByPlanarWire(circle).face
cyl = SolidByDrag(face, (0, 0, 15)).solid
The two shapes are shown below:
Boolean operations are some of the most commonly used and most powerful
modeling tools. The two shapes are fused together to form, in this case, a
single solid using the FuseShapes tool:
fuse = FuseShapes(box, cyl)
fused_shape = fuse.shape
In the resulting shape, the portion of the cylinder that was inside the solid box has been removed and the union of the box and cylinder is shown below:
The cylinder is cut from the box using the CutShapes tool:
cut = CutShapes(box, cyl)
cut_shape = cut.shape
In this tool, material from shape2 is cut away from shape1 and the
result is shown below:
Finding common material between two shapes is done by the
CommonShapes tool:
common = CommonShapes(box, cyl)
common_shape = common.shape
This tool will find the material that is shared by both the box and the cylinder, which in this case in the segment of the cylinder inside the box. The result is shown below where the original box is shown for reference:
The intersection of shapes is done by IntersectShapes and in this
case the resulting shape is a compound of edges:
sec = IntersectShapes(box, cyl)
sec_shape = sec.shape
Sometimes it’s possible for the result to only contain vertices if, for example, to edges are used in the intersection. The intersecting shape is shown in red in the image below:
The SplitShapes tool splits arbitrary shapes with each other and in
this example is used to split the box with the cylinder:
split = SplitShapes(box, cyl)
split_shape = split.shape
The resulting shape in this case in a compound consisting of two different solids as shown below:
The SplitShapes tool is very general and can be used for splitting
faces with edges, among other applications.
In some cases it may be desirable to only split a sub-shape of a basis shape.
This example uses the LocalSplit tool to split one of the front face
of the original solid box with a plane:
pln = PlaneByAxes((5, 5, 5), 'xz').plane
local = LocalSplit(builder.front_face, pln, box)
local_shape = local.shape
The front face of the box is provided as the shape to split and the box is provided as the “basis shape”, where the shape to fit must be a sub-shape of the basis shape. The result is still a solid but with one of the faces now split:
The OffsetShape tool is used to offset the solid box:
offset = OffsetShape(box, 2)
offset_shape = offset.shape
The resulting offset shape is shown below:
The rest of the example script demonstrates rebuilding (or substituting) shapes
using specified substitutions or, in this example, the results of a Boolean
operation. The rebuilding tools may not be used that often in practice, but
set up an example of using the CheckShape and FixShape
tools. Since a face was removed from the solid, it is not longer a valid,
closed solid. This is detected by the CheckShape tool and fixed with
the generic FixShape tool. In this example the only fix was just
switching the type from a Solid to a Shell, but they can be
used to detect and fix more complicated errors like self-intersecting shapes or
improperly defined geometry.
Entities¶
Shape¶
-
class
afem.topology.entities.Shape(shape)¶ Shape.
- Parameters
shape (OCCT.TopoDS.TopoDS_Shape) – The underlying shape.
- Variables
SHAPE (OCCT.TopAbs.TopAbs_ShapeEnum.TopAbs_SHAPE) – Shape type.
VERTEX (OCCT.TopAbs.TopAbs_ShapeEnum.TopAbs_VERTEX) – Vertex type.
EDGE (OCCT.TopAbs.TopAbs_ShapeEnum.TopAbs_EDGE) – Edge type.
WIRE (OCCT.TopAbs.TopAbs_ShapeEnum.TopAbs_WIRE) – Wire type.
FACE (OCCT.TopAbs.TopAbs_ShapeEnum.TopAbs_FACE) – Face type.
SHELL (OCCT.TopAbs.TopAbs_ShapeEnum.TopAbs_SHELL) – Shell type.
SOLID (OCCT.TopAbs.TopAbs_ShapeEnum.TopAbs_SOLID) – Solid type.
COMPSOLID (OCCT.TopAbs.TopAbs_ShapeEnum.TopAbs_COMPSOLID) – CompSolid type.
COMPOUND (OCCT.TopAbs.TopAbs_ShapeEnum.TopAbs_COMPOUND) – Compound type.
- Raises
TypeError – If
shapeis not aTopoDS_Shape.
Vertex¶
-
class
afem.topology.entities.Vertex(shape)¶ Vertex.
- Parameters
shape (OCCT.TopoDS.TopoDS_Vertex) – The vertex.
- Raises
TypeError – If
shapeis not aTopoDS_Vertex.
Edge¶
-
class
afem.topology.entities.Edge(shape)¶ Edge.
- Parameters
shape (OCCT.TopoDS.TopoDS_Edge) – The edge.
- Raises
TypeError – If
shapeis not aTopoDS_Edge.
Wire¶
-
class
afem.topology.entities.Wire(shape)¶ Wire.
- Parameters
shape (OCCT.TopoDS.TopoDS_Wire) – The wire.
- Raises
TypeError – If
shapeis not aTopoDS_Wire.
Face¶
-
class
afem.topology.entities.Face(shape)¶ Face.
- Parameters
shape (OCCT.TopoDS.TopoDS_Face) – The face.
- Raises
TypeError – If
shapeis not aTopoDS_Face.
Shell¶
-
class
afem.topology.entities.Shell(shape)¶ Shell.
- Parameters
shape (OCCT.TopoDS.TopoDS_Shell) – The shell.
- Raises
TypeError – If
shapeis not aTopoDS_Shell.
Solid¶
-
class
afem.topology.entities.Solid(shape)¶ Solid.
- Parameters
shape (OCCT.TopoDS.TopoDS_Solid) – The solid.
- Raises
TypeError – If
shapeis not aTopoDS_Solid.
CompSolid¶
-
class
afem.topology.entities.CompSolid(shape)¶ CompSolid.
- Parameters
shape (OCCT.TopoDS.TopoDS_CompSolid) – The compsolid.
- Raises
TypeError – If
shapeis not aTopoDS_CompSolid.
Create¶
VertexByPoint¶
-
class
afem.topology.create.VertexByPoint(pnt)¶ Create a vertex using a point.
- Parameters
pnt (point_like) – The point.
EdgeByPoints¶
-
class
afem.topology.create.EdgeByPoints(p1, p2)¶ Create an edge between two points.
- Parameters
p1 (point_like) – The first point.
p2 (point_like) – The second point.
EdgeByVertices¶
-
class
afem.topology.create.EdgeByVertices(v1, v2)¶ Create an edge between two vertices.
- Parameters
v1 (afem.topology.entities.Vertex) – The first vertex.
v2 (afem.topology.entities.Vertex) – The second vertex.
EdgeByCurve¶
-
class
afem.topology.create.EdgeByCurve(crv)¶ Create an edge using a curve.
- Parameters
crv (afem.geometry.entities.Curve) – The curve.
EdgeByDrag¶
-
class
afem.topology.create.EdgeByDrag(vertex, v)¶ Create an edge by dragging a vertex along a vector.
- Parameters
vertex (afem.topology.entities.Vertex) – The vertex.
v (vector_like) – The vector to drag the shape.
EdgeByWireConcat¶
-
class
afem.topology.create.EdgeByWireConcat(wire)¶ Create an edge by concatenating all the edges of a wire. The edge may have C0 continuity.
- Parameters
wire (afem.topology.entities.Wire) – The wire.
WireByEdges¶
-
class
afem.topology.create.WireByEdges(*edges)¶ Create a wire using topologically connected edges.
- Parameters
edges (collections.Sequence(afem.topology.entities.Edge)) – The edges. They must share a common vertex to be connected.
WiresByConnectedEdges¶
-
class
afem.topology.create.WiresByConnectedEdges(edges, tol=None, shared=False)¶ Create wires from a list of unsorted edges.
- Parameters
edges (collections.Sequence(afem.topology.entities.Edge)) – The edges.
tol (float) – Connection tolerance. If None if provided then the maximum tolerance of all edge will be used.
shared (bool) – Option to use only shared vertices to connect edges. If False then geometric coincidence will be also checked.
WireByPlanarOffset¶
-
class
afem.topology.create.WireByPlanarOffset(spine, distance, altitude=0.0, join=GeomAbs_JoinType.GeomAbs_Arc, is_open=False)¶ Create a wire by offsetting a planar wire or face.
- Parameters
spine (afem.topology.entities.Wire or afem.topology.entities.Face) – The wire to offset. If a face is provided the outer wire will be used.
distance (float) – Offset distance in the plane.
altitude (float) – Offset altitude normal to the plane.
join (OCCT.GeomAbs.GeomAbs_JoinType) – Join type.
WiresByShape¶
-
class
afem.topology.create.WiresByShape(shape)¶ Create wires by connecting all the edges of a shape. This method gathers all the unique edges of a shape and then uses
WiresByConnectedEdges.- Parameters
shape (afem.topology.entities.Shape) – The shape.
- Raises
ValueError – If no edges are found in the shape.
WireByPoints¶
-
class
afem.topology.create.WireByPoints(pnts, close=False)¶ Create a polygonal wire by connecting points.
- Parameters
pnts (collections.Sequence(point_like)) – The ordered points.
close (bool) – Option to close the wire.
WireByConcat¶
-
class
afem.topology.create.WireByConcat(wire)¶ Create a wire by concatenating all the edges of the wire. The wire may have C0 continuity.
- Parameters
wire (afem.topology.entities.Wire) – The wire.
FaceBySurface¶
-
class
afem.topology.create.FaceBySurface(srf, tol=1e-07)¶ Create a face from a surface.
- Parameters
srf (afem.geometry.entities.Surface) – The surface.
tol (float) – Tolerance for resolution of degenerate edges.
FaceByPlane¶
-
class
afem.topology.create.FaceByPlane(pln, umin, umax, vmin, vmax)¶ Create a finite face from a plane.
- Parameters
pln (afem.geometry.entities.Plane) – The plane.
umin (float) – Minimum u-parameter.
umax (float) – Maximum u-parameter.
vmin (float) – Minimum v-parameter.
vmax (float) – Maximum v-parameter.
FaceByPlanarWire¶
-
class
afem.topology.create.FaceByPlanarWire(wire)¶ Create a face from a planar wire.
- Parameters
wire (afem.topology.entities.Wire or afem.topology.entities.Edge or afem.geometry.entities.Curve) – The wire.
FaceByDrag¶
-
class
afem.topology.create.FaceByDrag(edge, v)¶ Create a face by dragging an edge along a vector.
- Parameters
edge (afem.topology.entities.Edge) – The edge.
v (vector_like) – The vector to drag the shape.
ShellBySurface¶
-
class
afem.topology.create.ShellBySurface(srf)¶ Create a shell from a surface.
- Parameters
srf (afem.geometry.entities.Surface) – The surface.
ShellByFaces¶
-
class
afem.topology.create.ShellByFaces(faces)¶ Create a shell from connected faces. This method initializes a shell an then simply adds the faces to it. The faces should already have shared edges. This is not checked.
- Parameters
faces (collections.Sequence(afem.topology.entities.Face)) – The faces.
ShellByDrag¶
-
class
afem.topology.create.ShellByDrag(wire, v)¶ Create a shell by dragging a wire along a vector.
- Parameters
wire (afem.topology.entities.Wire) – The wire.
v (vector_like) – The vector to drag the shape.
ShellBySewing¶
-
class
afem.topology.create.ShellBySewing(faces, tol=None, cut_free_edges=False, non_manifold=False)¶ Create a shell by sewing faces.
- Parameters
faces (collections.Sequence(afem.topology.entities.Face)) – The faces.
tol (float) – Sewing tolerance. If None the maximum tolerance of all the faces is used.
cut_free_edges (bool) – Option for cutting of free edges.
non_manifold (bool) – Option for non-manifold processing.
- Raises
RuntimeError – If an invalid shape type results.
SolidByShell¶
-
class
afem.topology.create.SolidByShell(shell)¶ Create a solid using a shell. The shell can either be closed (finite solid) or open (infinite solid).
- Parameters
shell (afem.topology.entities.Shell) – The shell.
SolidByPlane¶
-
class
afem.topology.create.SolidByPlane(pln, width, height, depth)¶ Create a solid box using a plane. The plane will be extruded in the direction of the plane’s normal. The solid’s width and height will be centered at the plane’s origin.
- Parameters
pln (afem.geometry.entities.Plane) – The plane.
width (float) – Width of the box.
height (float) – Height of the box.
depth (float) – Depth of the box.
SolidByDrag¶
-
class
afem.topology.create.SolidByDrag(face, v)¶ Create a solid by dragging a face along a vector.
- Parameters
face (afem.topology.entities.Face) – The face.
v (vector_like) – The vector to drag the shape.
CompoundByShapes¶
-
class
afem.topology.create.CompoundByShapes(shapes)¶ Create a compound from a list of shapes.
- Parameters
shapes – List of shapes.
- Type
collections.Sequence(afem.topology.entities.Shape)
HalfspaceByShape¶
-
class
afem.topology.create.HalfspaceByShape(shape, pnt)¶ Create a half-space by a face or shell and a reference point.A half-space is an infinite solid, limited by a surface. It is built from a face or a shell, which bounds it, and with a reference point, which specifies the side of the surface where the matter of the half-space is located. A half-space is a tool commonly used in topological operations to cut another shape.
- Parameters
shape (afem.topology.entities.Face or afem.topology.entities.Shell) – The face or shell.
pnt (point_like) – The reference point where the matter is located.
- Raises
RuntimeError – If shape is not a face or shell.
HalfspaceBySurface¶
-
class
afem.topology.create.HalfspaceBySurface(srf, pnt)¶ Create a half-space using a surface.
- Parameters
afem.geometry.entities.Surface – The surface.
pnt (point_like) – The reference point where the matter is located.
ShapeByFaces¶
-
class
afem.topology.create.ShapeByFaces(faces, sew=False, tol=None, cut_free_edges=False, non_manifold=False)¶ Create either a face or a shell from faces.
- Parameters
faces (collections.Sequence(afem.topology.entities.Face)) – The faces.
sew (bool) – Option to sew the faces if more than one face is provided.
tol (float) – Sewing tolerance. If None the maximum tolerance of all the faces is used.
cut_free_edges (bool) – Option for cutting of free edges.
non_manifold (bool) – Option for non-manifold processing.
ShapeByDrag¶
-
class
afem.topology.create.ShapeByDrag(shape, v)¶ Create a shape by dragging another shape along a vector.
- Parameters
shape (afem.topology.entities.Shape) – The shape.
v (vector_like) – The vector to drag the shape.
BoxBySize¶
-
class
afem.topology.create.BoxBySize(dx=1.0, dy=1.0, dz=1.0)¶ Build a box with the corner at (0, 0, 0) and the other at (dx, dy, dz).
- Parameters
dx (float) – The corner x-location.
dy (float) – The corner y-location.
dz (float) – The corner z-location.
BoxBy2Points¶
-
class
afem.topology.create.BoxBy2Points(p1, p2)¶ Build a box between two points.
- Parameters
p1 (point_like) – The first corner point.
p2 (point_like) – The other corner point.
CylinderByAxis¶
-
class
afem.topology.create.CylinderByAxis(radius, height, axis2=None)¶ Create a cylinder.
- Parameters
radius (float) – The radius.
height (float) – The height.
axis2 – Not yet implemented. Solid will be constructed in xy-plane.
- Raises
NotImplementedError – If an axis is provided.
SphereByRadius¶
-
class
afem.topology.create.SphereByRadius(origin=0.0, 0.0, 0.0, radius=1.0)¶ Create a sphere by a center and radius.
- Parameters
origin (point_like) – The origin.
radius (float) – The radius.
SphereBy3Points¶
-
class
afem.topology.create.SphereBy3Points(p1, p2, p3)¶ Create a sphere using three points.
- Parameters
p1 (point_like) – The first point.
p2 (point_like) – The second point.
p3 (point_like) – The third point.
PointAlongShape¶
-
class
afem.topology.create.PointAlongShape(shape, ds, tol=1e-07)¶ Create a point along an edge or wire at a specified distance from the first parameter.
- Parameters
shape (afem.topology.entities.Edge or afem.topology.entities.Wire) – The shape.
ds (float) – The distance along the curve from the given parameter.
tol (float) – Tolerance.
- Raises
TypeError – If shape if not a curve or wire.
RuntimeError – If OCC method fails.
PointsAlongShapeByNumber¶
-
class
afem.topology.create.PointsAlongShapeByNumber(shape, n, d1=None, d2=None, shape1=None, shape2=None)¶ Create a specified number of points along an edge or wire.
- Parameters
shape (afem.topology.entities.Edge or afem.topology.entities.Wire) – The shape.
n (int) – Number of points to create (n > 0).
d1 (float) – An offset distance for the first point. This is typically a positive number indicating a distance from u1 towards u2.
d2 (float) – An offset distance for the last point. This is typically a negative number indicating a distance from u2 towards u1.
shape1 (afem.topology.entities.Shape) – A shape to define the first point. This shape is intersected with the edge or wire.
shape2 (afem.topology.entities.Shape) – A shape to define the last point. This shape is intersected with the edge or wire.
- Raises
TypeError – If shape if not an edge or wire.
RuntimeError – If OCC method fails.
PointsAlongShapeByDistance¶
-
class
afem.topology.create.PointsAlongShapeByDistance(shape, maxd, d1=None, d2=None, shape1=None, shape2=None, nmin=0)¶ Create a specified number of points along an edge or wire.
- Parameters
shape (afem.topology.entities.Edge or afem.topology.entities.Wire) – The shape.
maxd (float) – The maximum allowed spacing between points. The actual spacing will be adjusted to not to exceed this value.
d1 (float) – An offset distance for the first point. This is typically a positive number indicating a distance from u1 towards u2.
d2 (float) – An offset distance for the last point. This is typically a negative number indicating a distance from u2 towards u1.
shape1 (afem.topology.entities.Shape) – A shape to define the first point. This shape is intersected with the edge or wire.
shape2 (afem.topology.entities.Shape) – A shape to define the last point. This shape is intersected with the edge or wire.
nmin (int) – Minimum number of points to create.
- Raises
TypeError – If shape if not a curve or wire.
RuntimeError – If OCC method fails.
PlaneByEdges¶
-
class
afem.topology.create.PlaneByEdges(shape, tol=- 1.0)¶ Create a plane by fitting it to all the edges of a shape.
- Parameters
shape (afem.topology.entities.Shape) – The shape containing the edges.
tol (float) – Edges must be within this planar tolerance. The tolerance is the largest value between the value provided or the largest tolerance of any one of the edges in the shape.
PlaneByIntersectingShapes¶
-
class
afem.topology.create.PlaneByIntersectingShapes(shape1, shape2, pnt=None, tol=- 1.0)¶ Create a plane by intersection two shapes. If no additional point is provided, then
PlaneByEdges. is used. If a point is provided, then the edges are tessellated and the point is added to this list. Then the toolPlaneByApproxis used.- Parameters
shape1 (afem.topology.entities.Shape) – The first shape.
shape2 (afem.topology.entities.Shape) – The second shape.
pnt (afem.geometry.entities.Point) – Additional point to add to the edges since they might be collinear.
tol (float) – Edges must be within this planar tolerance. The tolerance is the largest value between the value provided or the largest tolerance of any one of the edges in the shape.
- Raises
ValueError – If there are less than three points after tessellating the edges.
PlanesAlongShapeByNumber¶
-
class
afem.topology.create.PlanesAlongShapeByNumber(shape, n, ref_pln=None, d1=None, d2=None, shape1=None, shape2=None)¶ Create a specified number of planes along an edge or wire.
- Parameters
shape (afem.topology.entities.Edge or afem.topology.entities.Wire) – The shape.
n (int) – Number of points to create (n > 0).
ref_pln (afem.geometry.entities.Plane) – The normal of this plane will be used to define the normal of all planes along the curve. If no plane is provided, then the first derivative of the curve will define the plane normal.
d1 (float) – An offset distance for the first point. This is typically a positive number indicating a distance from u1 towards u2.
d2 (float) – An offset distance for the last point. This is typically a negative number indicating a distance from u2 towards u1.
shape1 (afem.topology.entities.Shape) – A shape to define the first point. This shape is intersected with the edge or wire.
shape2 (afem.topology.entities.Shape) – A shape to define the last point. This shape is intersected with the edge or wire.
- Raises
TypeError – If shape if not an edge or wire.
RuntimeError – If OCC method fails.
PlanesAlongShapeByDistance¶
-
class
afem.topology.create.PlanesAlongShapeByDistance(shape, maxd, ref_pln=None, d1=None, d2=None, shape1=None, shape2=None, nmin=0)¶ Create planes along an edge or wire by distance between them.
- Parameters
shape (afem.topology.entities.Edge or afem.topology.entities.Wire) – The shape.
maxd (float) – The maximum allowed spacing between planes. The actual spacing will be adjusted to not to exceed this value.
ref_pln (afem.geometry.entities.Plane) – The normal of this plane will be used to define the normal of all planes along the curve. If no plane is provided, then the first derivative of the curve will define the plane normal.
d1 (float) – An offset distance for the first point. This is typically a positive number indicating a distance from u1 towards u2.
d2 (float) – An offset distance for the last point. This is typically a negative number indicating a distance from u2 towards u1.
shape1 (afem.topology.entities.Shape) – A shape to define the first point. This shape is intersected with the edge or wire.
shape2 (afem.topology.entities.Shape) – A shape to define the last point. This shape is intersected with the edge or wire.
nmin (int) – Minimum number of planes to create.
- Raises
TypeError – If shape if not an edge or wire.
RuntimeError – If OCC method fails.
Explore¶
ExploreWire¶
-
class
afem.topology.explore.ExploreWire(wire, face=None)¶ Explore the edges of a wire.
- Parameters
wire (afem.topology.entities.Wire) – The wire.
face (afem.topology.entities.Face) – The face.
ExploreFreeEdges¶
-
class
afem.topology.explore.ExploreFreeEdges(shape)¶ Explore the free bounds of a shape.
- Parameters
shape (afem.topology.entities.Shape) – The shape.
Modify¶
DivideClosedShape¶
-
class
afem.topology.modify.DivideClosedShape(shape)¶ Divide all closed faces in a shape.
- Parameters
shape (afem.topology.entities.Shape) – The shape.
DivideContinuityShape¶
-
class
afem.topology.modify.DivideContinuityShape(shape, tol=0.001, continuity=GeomAbs_Shape.GeomAbs_C1)¶ Divide a shape for a given continuity and tolerance.
- Parameters
shape (afem.topology.entities.Shape) – The shape.
tol (float) – The tolerance.
continuity (OCCT.GeomAbs.GeomAbs_Shape) – The continuity to divide.
DivideC0Shape¶
-
class
afem.topology.modify.DivideC0Shape(shape, tol=0.001)¶ Divide a shape at all C0 boundaries to form a C1 shape.
- Parameters
shape (afem.topology.entities.Shape) – The shape.
tol (float) – The tolerance.
UnifyShape¶
-
class
afem.topology.modify.UnifyShape(shape, edges=True, faces=True, bsplines=False)¶ Unify edges and faces of a shape that lie on the same geometry.
- Parameters
shape (afem.topology.entities.Shape) – The shape.
edges (bool) – Option to unify all possible edges.
faces (bool) – Option to unify all possible faces.
bsplines (bool) – Option to concatenate the curves of edges if they are C1 continuous.
SewShape¶
-
class
afem.topology.modify.SewShape(shape=None, tol=None, min_tol=None, max_tol=None, cut_free_edges=False, non_manifold=False)¶ Sew the shape.
- Parameters
shape (afem.topology.entities.Shape) – The context shape to sew.
tol (float) – Sewing tolerance. If None is provided then the average tolerance of the shape will be used. If no shape is provided, then a default value of 1.0e-7 is used.
min_tol (float) – Minimum tolerance.
max_tol (float) – Maximum tolerance.
cut_free_edges (bool) – Option for cutting of free edges.
non_manifold (bool) – Option for non-manifold processing.
Note
If shape is None then the user is expected to manually load the shape and perform the operation.
RebuildShapeWithShapes¶
-
class
afem.topology.modify.RebuildShapeWithShapes(old_shape)¶ Rebuild a shape by requesting substitutions on a shape.
- Parameters
old_shape (afem.topology.entities.Shape) – The old shape.
RebuildShapeByTool¶
-
class
afem.topology.modify.RebuildShapeByTool(old_shape, tool)¶ Rebuild a shape using a supported tool.
- Parameters
old_shape (afem.topology.entities.Shape) – The old shape.
tool (afem.topology.bop.BopCore) – The tool.
- Raises
ValueError – If there are no sub-shapes to substitute.
Note
This tool will first try to make substitutions on the faces of the shape. If no faces exist, it will try the edges. If no edges exist it will try the vertices.
RebuildShapesByTool¶
-
class
afem.topology.modify.RebuildShapesByTool(old_shapes, tool)¶ Rebuild multiple shapes using a supported tool. This method is intended to address the case where modified shapes from an old shape are not duplicated in adjacent shapes, like what would happen if rebuilding a single shape at a time without any context. If a modified shape has already been replaced in an old shape and is encountered again, it is not substituted in the later shape. This method will first try to make substitutions on the faces of the shape. If not faces exist it will try the edges. If no edges exist it will try the vertices.
- Parameters
old_shapes (collections.Sequence(afem.topology.entities.Shape)) – The old shapes.
tool (afem.topology.bop.BopCore) – The tool.
ShapeBSplineRestriction¶
-
class
afem.topology.modify.ShapeBSplineRestriction(shape, is_mutable=False, approx_srf=True, approx_crv3d=True, approx_crv2d=True, tol3d=0.01, tol2d=1e-06, dmax=9, nmax=10000, degree=True, rational=False, continuity3d=GeomAbs_Shape.GeomAbs_C1, continuity2d=GeomAbs_Shape.GeomAbs_C2)¶ Re-approximate shape surfaces with B-splines.
- Parameters
shape (afem.topology.entities.Shape) – The shape.
is_mutable (bool) – Flag for mutable input.
approx_srf (bool) – Flag to approximate surface.
approx_crv3d (bool) – Flag to approximate 3-d curves.
approx_crv2d (bool) – Flag to approximate 2-d curves.
tol3d (float) – Tolerance for 3-d approximations.
tol2d (float) – Tolerance for 2-d approximations.
dmax (int) – Maximum allowed degree for approximation.
nmax (int) – Maximum allowed number of segments for approximation.
degree (bool) – If True, the approximation is made with degree limited by dmax but at the expense of nmax. If False, the approximation is made with number of spans limited by nmax but at the expense of dmax.
rational (bool) – If True, the approximation for rational B-Spline and Bezier are converted to polynomial.
continuity3d (OCCT.GeomAbs.GeomAbs_Shape) – Desired continuity for 3-d curve and surface approximation.
continuity2d (OCCT.GeomAbs.GeomAbs_Shape) – Desired continuity for 2-d curve and surface approximation.
Boolean¶
BopCore¶
-
class
afem.topology.bop.BopCore¶ Core class for Boolean operations and enabling attributes and methods for rebuilding shapes.
BopAlgo¶
-
class
afem.topology.bop.BopAlgo(shape1, shape2, fuzzy_val, nondestructive, bop)¶ Base class for Boolean operations.
- Parameters
shape1 (afem.topology.entities.Shape or None) – The first shape.
shape2 (afem.topology.entities.Shape or None) – The second shape.
fuzzy_val (float) – Fuzzy tolerance value.
nondestructive (bool) – Option to not modify the input shapes.
bop – The OpenCASCADE class for the Boolean operation.
Note
If shape1 or shape2 is None then the user is expected to manually set the arguments and tools and build the result.
FuseShapes¶
-
class
afem.topology.bop.FuseShapes(shape1=None, shape2=None, fuzzy_val=None, nondestructive=False)¶ Boolean fuse operation.
- Parameters
shape1 (afem.topology.entities.Shape or None) – The first shape.
shape2 (afem.topology.entities.Shape or None) – The second shape.
fuzzy_val (float) – Fuzzy tolerance value.
nondestructive (bool) – Option to not modify the input shapes.
Note
If shape1 or shape2 is None then the user is expected to manually set the arguments and tools and build the result.
CutShapes¶
-
class
afem.topology.bop.CutShapes(shape1=None, shape2=None, fuzzy_val=None, nondestructive=False)¶ Boolean cut operation.
- Parameters
shape1 (afem.topology.entities.Shape or None) – The first shape.
shape2 (afem.topology.entities.Shape or None) – The second shape.
fuzzy_val (float) – Fuzzy tolerance value.
nondestructive (bool) – Option to not modify the input shapes.
Note
If shape1 or shape2 is None then the user is expected to manually set the arguments and tools and build the result.
CommonShapes¶
-
class
afem.topology.bop.CommonShapes(shape1=None, shape2=None, fuzzy_val=None, nondestructive=False)¶ Boolean common operation.
- Parameters
shape1 (afem.topology.entities.Shape or None) – The first shape.
shape2 (afem.topology.entities.Shape or None) – The second shape.
fuzzy_val (float) – Fuzzy tolerance value.
nondestructive (bool) – Option to not modify the input shapes.
Note
If shape1 or shape2 is None then the user is expected to manually set the arguments and tools and build the result.
IntersectShapes¶
-
class
afem.topology.bop.IntersectShapes(shape1=None, shape2=None, compute_pcurve1=False, compute_pcurve2=False, approximate=False, fuzzy_val=None, nondestructive=False)¶ Boolean intersect operation.
- Parameters
shape1 (afem.topology.entities.Shape or afem.geometry.entities.Surface) – The first shape.
shape2 (afem.topology.entities.Shape or afem.geometry.entities.Surface) – The second shape.
compute_pcurve1 (bool) – Option to compute p-curves on shape 1.
compute_pcurve2 (bool) – Option to compute p-curves on shape 2.
approximate (bool) – Option to approximate intersection curves.
fuzzy_val (float) – Fuzzy tolerance value.
nondestructive (bool) – Option to not modify the input shapes.
Note
If shape1 or shape2 is None then the user is expected to manually set the arguments and tools and build the result.
SplitShapes¶
-
class
afem.topology.bop.SplitShapes(shape1=None, shape2=None, fuzzy_val=None, nondestructive=False)¶ Split arbitrary shapes. This is a wrapper for the SALOME GEOMAlgo_Splitter tool.
- Parameters
shape1 (afem.topology.entities.Shape or None) – The first shape.
shape2 (afem.topology.entities.Shape or None) – The second shape.
fuzzy_val (float) – Fuzzy tolerance value.
nondestructive (bool) – Option to not modify the input shapes.
Note
If shape1 or shape2 is None then the user is expected to manually set the arguments and tools and build the result.
VolumesFromShapes¶
-
class
afem.topology.bop.VolumesFromShapes(shapes, intersect=False, fuzzy_val=None, nondestructive=False)¶ Build solids from a list of shapes.
- Parameters
shapes (list(afem.topology.entities.Shape)) – The shapes.
intersect (bool) – Option to intersect the shapes before building solids.
fuzzy_val (float) – Fuzzy tolerance value.
nondestructive (bool) – Option to not modify the input shapes.
CutCylindricalHole¶
-
class
afem.topology.bop.CutCylindricalHole(shape, radius, ax1, fuzzy_val=None, nondestructive=False)¶ Cut a cylindrical hole on a shape.
- Parameters
shape (afem.topology.entities.Shape) – The shape.
radius (float) – The radius of the hole.
afem.geometry.entities.Axis1 – The axis for the hole.
fuzzy_val (float) – Fuzzy tolerance value.
nondestructive (bool) – Option to not modify the input shapes.
LocalSplit¶
-
class
afem.topology.bop.LocalSplit(shape, tool, basis_shape, approximate=False, fuzzy_val=None, nondestructive=False)¶ Perform a local split of a shape in the context of a basis shape. This tool only splits faces.
- Parameters
shape (afem.topology.entities.Shape) – The local shape.
tool (afem.topology.entities.Shape or afem.geometry.entities.Surface) – The tool to split with.
basis_shape (afem.topology.entities.Shape) – The basis shape that the local shape is part of.
approximate (bool) – Option to approximate intersection curves.
fuzzy_val (float) – Fuzzy tolerance value.
nondestructive (bool) – Option to not modify the input shapes.
SplitShapeByEdges¶
-
class
afem.topology.bop.SplitShapeByEdges(shape, edges=None, check_interior=True)¶ Split a shape using edges.
- Parameters
shape (afem.topology.entities.Shape) – The basis shape.
edges (collections.Sequence(afem.topology.entities.Edge) or None) – The edges to split the shape with. If provided, then the results will be built during initialization. If none are provided then the user is expected to add edges and build manually.
check_interior (bool) – Option to check internal intersections.
SplitWire¶
-
class
afem.topology.bop.SplitWire(wire, splitter)¶ Split a wire with a shape.
- Parameters
wire (afem.topology.entities.Wire) – The wire.
splitter (afem.topology.entities.Shape) – The splitter shape.
- Raises
RuntimeError – If the splitting algorithm fails.
TrimOpenWire¶
-
class
afem.topology.bop.TrimOpenWire(wire, shape1, shape2=None)¶ Trim an open wire between one or two shapes.
- Parameters
wire (afem.topology.entities.Wire) – The wire.
shape1 (afem.topology.entities.Shape or afem.geometry.entities.Geometry) – The first shape.
shape2 (afem.topology.entities.Shape or afem.geometry.entities.Geometry) – The second shape.
- Raises
TypeError – If a wire is not provided or it is closed.
RuntimeError – If zero or more than two split locations are found. The split shapes must result in one or two split locations. That is, they should intersect the wire at only one location.
Offset¶
ProjectShape¶
-
class
afem.topology.offset.ProjectShape(shape, to_project, tol3d=0.0001, tol2d=None, continuity=GeomAbs_Shape.GeomAbs_C2, max_degree=14, max_seg=16, max_dist=None, limit=True)¶ Project edges and wires onto a basis shape.
- Parameters
shape (afem.topology.entities.Shape) – The shape to project to.
to_project (collections.Sequence(afem.topology.entities.Edge or afem.topology.entities.Wire)) – List of edges or wires to project.
tol3d (float) – The 3-D tolerance.
tol2d (float) – The 2-D tolerance. If not provided then sqrt(tol3d) is used.
continuity (OCCT.GeomAbs.GeomAbs_Shape) – Desired continuity.
max_degree (int) – Max degree.
max_seg (int) – Max segments.
max_dist (float) – Max distance between target shape and shapes to project. If not satisfied then results for the corresponding shape are discarded.
limit (bool) – Option to limit projected edges to the face boundaries.
OffsetShape¶
-
class
afem.topology.offset.OffsetShape(shape, offset, tol=None, join_mode=GeomAbs_JoinType.GeomAbs_Arc, remove_internal_edges=False, perform_simple=False)¶ Offset a shape.
- Parameters
shape (afem.topology.entities.Shape) – The shape. It may be a face, shell, a solid, or a compound of these kinds.
offset (float) – The offset value. The offset will be outside the shape if positive and inside if negative.
tol (float) – Tolerance for coincidence for generated shapes. If not provided the average tolerance of the shape is used.
join_mode (OCCT.GeomAbs.GeomAbs_JoinType) – Option for how to fill holes that may appear when offsetting two adjacent faces.
remove_internal_edges (bool) – Option to remove internal edges from the result.
perform_simple (bool) – Option to use simple algorithm without intersection computation.
LoftShape¶
-
class
afem.topology.offset.LoftShape(sections, is_solid=False, make_ruled=False, pres3d=1e-06, check_compatibility=None, use_smoothing=None, par_type=None, continuity=None, max_degree=None)¶ Loft a shape using a sequence of sections.
- Parameters
sections (collections.Sequence(afem.topology.entities.Vertex or afem.topology.entities.Edge or afem.topology.entities.Wire)) – The sections of the loft. These are usually wires but the first and last section can be vertices. Edges are converted to wires before adding to the loft tool.
is_solid (bool) – If True the tool will build a solid, otherwise it will build a shell.
make_ruled (bool) – If True the faces between sections will be ruled surfaces, otherwise they are smoothed out by approximation.
pres3d (float) – Defines the precision for the approximation algorithm.
check_compatibility (bool) – Option to check the orientation of the sections to avoid twisted results and update to have the same number of edges.
use_smoothing (bool) – Option to use approximation algorithm.
par_type (OCCT.Approx.Approx_ParametrizationType) – Parametrization type.
continuity (OCCT.GeomAbs.GeomAbs_Shape) – The desired continuity.
max_degree (int) – The maximum degree for the approximation algorithm.
- Raises
TypeError – If any of the sections cannot be added to the tool because they are of the wrong type.
SweepShape¶
-
class
afem.topology.offset.SweepShape(spine, profile)¶ Sweep a profile along a spine.
- Parameters
spine (afem.geometry.entities.Curve or afem.topology.entities.Edge or afem.topology.entities.Wire) – The path for the sweep. This must be at least G1 continuous.
profile (afem.geometry.entities.Geometry or afem.topology.entities.Shape) – The profile.
- Raises
TypeError – If
spineis not or cannot be converted to a wire.
SweepShapeWithNormal¶
-
class
afem.topology.offset.SweepShapeWithNormal(spine, spine_support=None, tol3d=0.0001, tol_bound=0.0001, tol_angular=0.01, max_degree=None, max_segments=None, force_c1=None, transition_mode=BRepBuilderAPI_TransitionMode.BRepBuilderAPI_Transformed)¶ Sweep sections along a spine using a support shape to define the local orientation.
- Parameters
spine (afem.topology.entities.Wire) – The spine.
spine_support (afem.topology.entities.Shape) – The shape that will define the normal during the sweeping algorithm. To be effective, each edge of the spine must have a representation on one face of the spine support.
tol3d (float) – The 3-D tolerance.
tol_bound (float) – The boundary tolerance.
tol_angular (float) – The angular tolerance.
max_degree (int) – The maximum degree allowed in the resulting surface.
max_segments (int) – The maximum number of segments allowed in the resulting surface.
force_c1 (bool) – If True, the tool will attempt to approximate a C1 surface if a swept surface proved to be C0.
transition_mode (OCCT.BRepBuilderAPI.BRepBuilderAPI_TransitionMode) – The transition mode to manage discontinuities on the swept shape.
Distance¶
DistanceShapeToShape¶
-
class
afem.topology.distance.DistanceShapeToShape(shape1, shape2, deflection=1e-07)¶ Calculate minimum distance between two shapes. If geometry is provided it will be converted to a shape.
- Parameters
shape1 (afem.topology.entities.Shape or afem.geometry.entities.Geometry) – The first shape or geometry.
shape2 (afem.topology.entities.Shape or afem.geometry.entities.Geometry) – The second or geometry.
DistanceShapeToShapes¶
-
class
afem.topology.distance.DistanceShapeToShapes(shape, other_shapes)¶ Calculate the minimum distance between a shape and other shapes. Sort the results by distance.
- Parameters
shape (afem.topology.entities.Shape) – The main shape.
other_shapes (list(afem.topology.entities.Shape)) – The other shapes.
Fix¶
FixShape¶
-
class
afem.topology.fix.FixShape(shape, precision=None, min_tol=None, max_tol=None, context=None)¶ Attempt to fix the shape by applying a number of general fixes.
- Parameters
shape (afem.topology.entities.Shape) – The shape.
precision (float) – Basic precision value.
min_tol (float) – Minimum allowed tolerance.
max_tol (float) – Maximum allowed tolerance.
context (afem.topology.entities.Shape) – The context shape.
Note
By default, the precision, minimum, and maximum tolerance values are Precision::Confusion() with OCCT, which is typically 1.0e-7.
Properties¶
LinearProps¶
-
class
afem.topology.props.LinearProps(shape, skip_shared=True)¶ Calculate linear properties of a shape.
- Parameters
shape (afem.topology.entities.Shape) – The shape.
skip_shared (bool) – If True, edges shared by two or more faces are taken into calculation only once.
SurfaceProps¶
-
class
afem.topology.props.SurfaceProps(shape, tol=1e-07, skip_shared=False)¶ Calculate surface properties of a shape.
- Parameters
shape (afem.topology.entities.Shape) – The shape.
tol (float) – Maximum relative error of computed area for each face.
skip_shared (bool) – If True, faces shared by two or more shells are taken into calculation only once.
VolumeProps¶
-
class
afem.topology.props.VolumeProps(shape, tol=1e-07, only_closed=False, skip_shared=False)¶ Calculate volume properties of a shape.
- Parameters
shape (afem.topology.entities.Shape) – The shape.
tol (float) – Maximum relative error of computed volume for each solid.
only_closed (bool) – If True, then faces must belong to closed shells.
skip_shared (bool) – If True, volumes formed by equal faces (i.e., the same TShape, location, and orientation) are taken into calculation only once.
LengthOfShapes¶
-
class
afem.topology.props.LengthOfShapes(shapes)¶ Calculate the total length of all edges of each shape and sort the results.
- Parameters
shapes (collections.Sequence(afem.topology.entities.Shape)) – The shapes.
AreaOfShapes¶
-
class
afem.topology.props.AreaOfShapes(shapes)¶ Calculate the total area of each face for each shape and sort the results.
- Parameters
shapes (collections.Sequence(afem.topology.entities.Shape)) – The shapes.
Check¶
CheckShape¶
-
class
afem.topology.check.CheckShape(shape, geom=True)¶ Check shape and its sub-shapes for errors.
- Parameters
shape (afem.topology.entities.Shape) – The shape.
geom (bool) – Option to check geometry in additional to topology.
ClassifyPointInSolid¶
-
class
afem.topology.check.ClassifyPointInSolid(solid, pnt=None, tol=1e-07)¶ Classify a point in a solid.
- Parameters
solid (afem.topology.entities.Solid) – The solid.
pnt (point_like) – The point. If not provided the perform() method will need to be used.
tol (float) – The tolerance.