Using OpenCascadeLink

This section shows some of the ways that OpenCascadeLink can be applied. To use OpenCascadeLink, it must first be loaded.

Since many of the OpenCascade examples interact with the finite element mesh functionality the finite element package is also loaded.

Solid 3D Primitives

Various Wolfram Language Graphics3D primitives can be represented in OpenCascade. These primitives are represented as solids.

Ball

Create two distinct Ball primitives in OpenCascade.
Look at the OpenCascade shape type.
Generate a boundary ElementMesh from the first OpenCascade shape.
Generate a boundary ElementMesh from the second OpenCascade shape.
Visualize the boundary ElementMesh.
Generate the full ElementMesh.
Generate several Ball primitives in OpenCascade.

CapsuleShape

Create a CapsuleShape primitive in OpenCascade.
Look at the OpenCascade shape type.
Generate a boundary ElementMesh from the OpenCascade shape.
Visualize the boundary ElementMesh.
Visualize the fully meshed ElementMesh.

Cone

Create a Cone primitive in OpenCascade.
Look at the OpenCascade shape type.
Generate a boundary ElementMesh from the OpenCascade shape.
Visualize the boundary ElementMesh.
Visualize the fully meshed ElementMesh.

Cuboid

Create a Cuboid primitive in OpenCascade.
Look at the OpenCascade shape type.
Generate a boundary ElementMesh from the OpenCascade shape.
Visualize the boundary ElementMesh.
Visualize the fully meshed ElementMesh.

Cylinder

Create a Cylinder primitive in OpenCascade.
Look at the OpenCascade shape type.
Generate a boundary ElementMesh from the OpenCascade shape.
Visualize the boundary ElementMesh and the graphics primitive.
Visualize the fully meshed ElementMesh.

Ellipsoid

Create a Ellipsoid primitive in OpenCascade.
Look at the OpenCascade shape type.
Generate a boundary ElementMesh from the OpenCascade shape.
Visualize the boundary ElementMesh and the graphics primitive.
Visualize the fully meshed ElementMesh.

Hexahedron

Create a Hexahedron primitive in OpenCascade.
Look at the OpenCascade shape type.
Generate a boundary ElementMesh from the OpenCascade shape.
Visualize the boundary ElementMesh.
Visualize the fully meshed ElementMesh.

Parallelepiped

Create a Parallelepiped primitive in OpenCascade.
Extract and visualize the boundary mesh and the Parallelepiped.

Prism

Create a Prism primitive in OpenCascade.
Look at the OpenCascade shape type.
Generate a boundary ElementMesh from the OpenCascade shape.
Visualize the boundary ElementMesh and the graphics primitive.
Visualize the fully meshed ElementMesh.

Polyhedron

Create a Polyhedron primitive in OpenCascade.
Look at the OpenCascade shape type.
Generate a boundary ElementMesh from the OpenCascade shape.
Visualize the boundary ElementMesh.
Visualize the fully meshed ElementMesh.
Look at the boundary element marker union and create colors for the markers.
Visualize the boundary ElementMesh with markers highlighted.
Create a Polyhedron primitive in OpenCascade.
Look at the OpenCascade shape type.
Generate a boundary ElementMesh from the OpenCascade shape.
Visualize the boundary ElementMesh.
Visualize the fully meshed ElementMesh.

Pyramid

Create a Pyramid primitive in OpenCascade.
Look at the OpenCascade shape type.
Generate a boundary ElementMesh from the OpenCascade shape.
Visualize the boundary ElementMesh.
Visualize the fully meshed ElementMesh.

SphericalShell

Create a SphericalShell primitive in OpenCascade.
Look at the OpenCascade shape type.
Generate a boundary ElementMesh from the OpenCascade shape.
Visualize the boundary ElementMesh.
Mesh the region while keeping a region hole. Visualize the fully meshed ElementMesh.

Tetrahedron

Create a Tetrahedron primitive in OpenCascade.
Look at the OpenCascade shape type.
Generate a boundary ElementMesh from the OpenCascade shape.
Visualize the boundary ElementMesh.
Visualize the fully meshed ElementMesh.

Surfaces Primitives

It is also possible to create instances of surface graphics primitives embedded in 3D.

BSplineSurface

Set up a pipe section using a B-spline surface with weights:
Create a BSplineSurface primitive in OpenCascade.
Look at the OpenCascade shape type.
Generate a boundary ElementMesh from the OpenCascade shape.
Visualize the boundary ElementMesh with the B-spline surface.

A fully meshed ElementMesh can not be created from a non closed surface.

Polygon

Create a Polygon primitive in OpenCascade.
Look at the OpenCascade shape type.
Generate a boundary ElementMesh from the OpenCascade shape.
Visualize the boundary ElementMesh.

A fully meshed ElementMesh can not be created from a non closed surface.

Create a Polygon with a hole in OpenCascade.
Look at the OpenCascade shape type.
Generate a boundary ElementMesh from the OpenCascade shape.
Visualize the boundary ElementMesh.
Specify a self intersecting Polygon in OpenCascade.
Look at the OpenCascade shape type.
Surface meshes can not be generated from a self intersecting Polygon.

Triangle

Create a Triangle primitive in OpenCascade.
Look at the OpenCascade shape type.
Generate a boundary ElementMesh from the OpenCascade shape.
Visualize the boundary ElementMesh.

A fully meshed ElementMesh can not be created from a non closed surface.

Surfaces Meshes

ElementMesh

Create and visualize a boundary ElementMesh.
Convert a boundary ElementMesh to an OpenCascade object.

The conversion is computationally expensive since every surface element is mapped into an OpenCascade object and then sewed together.

Both, open and closed surfaces can be converted.

Create and visualize a boundary ElementMesh.
Convert a boundary ElementMesh to an OpenCascade object.

Edge Primitives

It is also possible to create instances of edge graphics primitives embedded in 3D.

Line

Create a Line primitive in OpenCascade.
Look at the OpenCascade shape type.

A boundary ElementMesh can not be created from an OpenCascade shape of type wire. Wire objects can, however, be used for rotational or linear sweeps.

Operations on Surfaces

SurfaceMesh

Surfaces of OpenCascade objects can be meshed.

Generate an OpenCascade object.
Generate a surface mesh.
Extract and visualize the coordinates from the meshed shape.
Extract and visualize the surface elements from the meshed shape.
OpenCascadeShapeSurfaceMesh has the following options:

"AngularDeflection" and "LinearDeflection" specify the maximum amount a segment may deviate from the true surface. The concepts are best explained with the following illustration.

"AngularDeflection" specifies the maximum deflection angle α at the end nodes of a segment while "LinearDeflection" specifies the maximum deflection to the true curve within a segment. The Automatic default for the "AngularDeflection" is set to 0.5 and the Automatic default for the "LinearDeflection" is set to 0.01. For more information please consult the OpenCascade Documentation.

"ComputeInParallel" specifies if the surface discretization should be performed on multiple CPU cores. The Automatic default is set to False.

"RelativeDeflection" specifies if the deflection is relative or absolute to the size of the geometry. The Automatic default is set to True.

To make working with OpenCascade and the finite element method easier a function to mesh the surface and return a boundary ElementMesh is provided.

Extract a boundary ElementMesh from the OpenCascde shape.
Visualize the boundary ElementMesh extracted from the OpenCascde shape.
Note that sub-surfaces have appropriate boundary markers.
Create and visualize a full mesh.
OpenCascadeShapeSurfaceMeshToBoundaryMesh has the following options:

All options that are relevant for the ElementMesh generation can be specified via "ElementMeshOptions" and options relevant for OpenCascadeShapeSurfaceMesh can be specified via "ShapeSurfaceMeshOptions".

Extract a boundary ElementMesh from the OpenCascde shape with an
Visualize the boundary ElementMesh extracted from the OpenCascde shape.

Sewing

Surfaces that share edges can be sewn together.

Generate a list of polygons.
Create the polygons in OpenCacade.
Look at the OpenCascade shape type.
Sew the faces together.
Look at the OpenCascade shape type.
Extract and visualize the boundary ElementMesh.
Create and visualize a full mesh.

Sewing of B-Spline surfaces with other objects is possible. However, nodes need to match.

Create a PolarPlot.
Extract the coordinates from the PolarPlot.
Make use of a function to parameterize the coordinates of the shape.
Construct the BSplineSurface.
Visualize the BSplineSurface and the top and bottom cap.
Construct the surfaces in OpenCascade.
Sew the surfaces together.
Look at the OpenCascade shape type.
Extract and visualize the boundary mesh.
Generate a full mesh.

As a further example an Ellipsoid is created from 8 BSplineSurface patches.

Create and visualize an Ellipsoid.
Compute the eigenvalues and eigenvectors of the Ellipsoid.
Compute the TransformationFunction to map a unit Ball onto the Ellipsoid.
Set up the control points for 8 B-Spline surfaces and generate the surfaces.

Note, here the ordering of the control points is important as explained further down.

Convert the B-Spline surfaces into OpenCascade expressions.
Sew the surfaces together.
Look at the OpenCascade shape type.
Extract and visualize the boundary mesh.

A possible issue is that OpenCascade is sensitive to the ordering of the surfaces given for sewing. This may be tricky to note as a displayed surface might look good but when, for example, Boolean operations are performed on the object unexpected results may happen.

Compute the Boolean union of a the ellipsoid and a cuboid.
An ordering of control points that results in a bad union of the Cuboid and the Ellipsoid.

RotationalSweeps

OpenCascde can perform rotational sweeps. For this a surface is rotated around an axis. The rotation can be less than a full rotation.

Create a polygon face in OpenCascade.
Look at the OpenCascade shape type.
Specify a rotation axis and the amount of the rotation.
Look at the OpenCascade shape type.
Extract and visualize the boundary mesh, the rotation axis of rotation and the polygon face.
Generate a full mesh.

OpenCascde can also perform rotational sweeps on wire objects.

Create a Line primitive in OpenCascade.
Look at the OpenCascade shape type.
Specify a rotation axis and the amount of the rotation.
Look at the OpenCascade shape type.
Extract and visualize the boundary mesh, the rotation axis of rotation and the Line edge.

LinearSweeps

For a linear sweep of a surface a starting point on the surface and destination point are given and the surface is swept to the destination point.

Create a polygon face in OpenCascade.
Look at the OpenCascade shape type.
Seep the surface from {1/2,1/2,0} to {1,1,1}.
Look at the OpenCascade shape type.
Extract and visualize the boundary mesh, the rotation axis of rotation and the polygon face.
Generate a full mesh.

OpenCascde can also perform linear sweeps on wire objects.

Create a Line primitive in OpenCascade.
Look at the OpenCascade shape type.
Seep the surface from {1/2,1/2,0} to {1,1,1}.
Look at the OpenCascade shape type.
Extract and visualize the boundary mesh, the rotation axis of rotation and the Line edge.

Boolean Operations

Difference

Compute geometric differences of shapes.

Generate two Ball shapes.
Look at the OpenCascade shape type.
Compute the geometric difference between the two shapes
Look at the OpenCascade shape type.
Extract the boundary mesh.
Look at the boundary element marker union and create colors for the markers.
Visualize the boundary ElementMesh with markers highlighted.
Generate a full mesh.
Generate a Prism and a Ball Graphics3D primitive.
Visualize the scene.
Generate the OpenCascade shape instances.
Compute the geometric difference.
Look at the OpenCascade shape type.
Extract the boundary mesh.
Look at the boundary element marker union and create colors for the markers.
Visualize the boundary ElementMesh with markers highlighted.
Generate a full mesh.
Create a SphericalShell and a Cylinder shape.
Compute the geometric difference of the shapes
Extract the boundary mesh.
Look at the boundary element marker union and create colors for the markers.
Visualize the boundary ElementMesh with markers highlighted.
Generate a full mesh.
Create a Polyhedron and a Ball primitive in OpenCascade.
Compute the geometric difference of the shapes
Extract the boundary mesh.
Look at the boundary element marker union and create colors for the markers.
Visualize a cross section through the boundary ElementMesh with markers highlighted.
Generate a full mesh.

Union

Compute geometric unions of shapes.

Generate two Ball shapes.
Look at the OpenCascade shape type.
Compute the geometric union.
Look at the OpenCascade shape type.
Extract the boundary mesh.
Look at the boundary element marker union and create colors for the markers.
Visualize the boundary ElementMesh with markers highlighted.
Generate a full mesh.
Create a Ball and a Hexahedron shape.
Compute the geometric union of the shapes
Extract the boundary mesh.
Look at the boundary element marker union and create colors for the markers.
Visualize the boundary ElementMesh with markers highlighted.
Generate a full mesh.
Create a Ball and a Pyramid shape.
Compute the geometric union of the shapes
Extract the boundary mesh.
Look at the boundary element marker union and create colors for the markers.
Visualize the boundary ElementMesh with markers highlighted.
Generate a full mesh.
Create a SphericalShell and a Cylinder shape.
Look at the OpenCascade shape type.
Compute the geometric union of the shapes
Look at the OpenCascade shape type.
Extract the boundary mesh.
Visualize the boundary ElementMesh..
Generate a full mesh.

Intersection

Compute geometric intersection of shapes.

Generate two Ball shapes.
Compute the geometric union.
Extract the boundary mesh.
Look at the boundary element marker union and create colors for the markers.
Visualize the boundary ElementMesh with markers highlighted.
Generate a full mesh.
Create a Ball and a Hexahedron shape.
Compute the geometric intersection of the shapes
Extract the boundary mesh.
Look at the boundary element marker union and create colors for the markers.
Visualize the boundary ElementMesh with markers highlighted.
Generate a full mesh.
Create a Ball and a Pyramid shape.
Compute the geometric intersection of the shapes
Extract the boundary mesh.
Look at the boundary element marker union and create colors for the markers.
Visualize the boundary ElementMesh with markers highlighted.
Generate a full mesh.
Create a SphericalShell and a Cylinder shape.
Look at the OpenCascade shape type.
Compute the geometric intersection of the shapes.
Look at the OpenCascade shape type.
Extract the boundary mesh.
Visualize the boundary ElementMesh..
Generate a full mesh.

Intersections can also be generated from lower dimensional region objects.

Create a Cone and a Polygon shape.
Look at the OpenCascade shape type.
Compute the geometric intersection of the shapes.
Look at the OpenCascade shape type.
Extract the boundary mesh.
Visualize the boundary ElementMesh.
Visualize the boundary ElementMesh in the Cone.

BooleanRegion

The OpenCascadeLink provides functionality to directly work with BooleanRegion objects.

Generate a BooleanRegion shape.

As a convenience it is also possible to use OpenCascadeShape for BooleanRegion objects directly.

Alternative to generate a BooleanRegion shape.
Extract the boundary mesh.
Look at the boundary element marker union and create colors for the markers.
Visualize the boundary ElementMesh with markers highlighted.
Generate a full mesh.
Generate a BooleanRegion shape.
Extract and visualize the boundary mesh.
Generate a BooleanRegion shape.
Extract and visualize the boundary mesh.

Internal boundaries

Shape sewing can also be used to generate shapes that have internal boundaries.

Generate two shapes.
Compute the geometric union between the two shapes.
Visualize the resulting union.
Compute the geometric intersection between the two shapes.
Visualize the resulting intersection.

Note that computing the intersection returns a closed shape.

Sew the faces together.
Extract the boundary mesh.
Look at the boundary element marker union and create colors for the markers.
Visualize the boundary ElementMesh with markers highlighted.

Since the intersection of the two shapes is closed by sewing that closed shape into the union of the shapes we have three internal regions. One in the cylinder on top of the cuboid, one in the cylinder that is inside the cuboid and one in the remaining cuboid.

Generate a full mesh.
Check that all markers are present.
Visualize the parts specified by the markers.
Visualize a cross section through the mesh with markers highlighted.

Fillets

OpenCascade provides functionality to fillet shapes.

Generate a shape.
Look at the OpenCascade shape type.
Fillet all edges with a radius of 0.25.
Look at the OpenCascade shape type.
Extract the boundary mesh.
Look at the boundary element marker union and create colors for the markers.
Visualize the boundary ElementMesh with markers highlighted.
Generate a full mesh.

It is also possible to fillet only selected edges.

Generate a shape.
Look at the number of edges in the shape.

In OpenCasacde every faces has access to all the edges the face is comprised of. In the case of the cube each face is connected to 4 edges. Since there are 6 faces this makes a total of 24 edges that can be addressed of which 12 are duplicated.

Fillet edges number 1 and 7 with a radius of 0.25.
Extract the boundary mesh.
Look at the boundary element marker union and create colors for the markers.
Visualize the boundary ElementMesh with markers highlighted.
Generate a shape.
Fillet the shape with a radius of 0.125.
Extract the boundary mesh.
Visualize the boundary ElementMesh.

If the requested fillet radius is too large then the filleting will fail.

Filleting a shape with too large a radius will fail.
Use a radius that can be filleted.
Extract the boundary mesh.

Chamfers

Chamfers are similar to fillets. The difference is that chamfers are not rounded but planes.

Generate a shape.
Look at the OpenCascade shape type.
Apply chamfer to edges 1 and 2.
Look at the OpenCascade shape type.
Extract the boundary mesh.
Look at the boundary element marker union and create colors for the markers.
Visualize the boundary ElementMesh with markers highlighted.
Generate the full mesh.

Shelling

OpenCascade provides functionality to shell shapes.

Generate a shape.
Look at the OpenCascade shape type.
Find the number of faces in the shape.
Shell the shape by removing faces 2 and 3.
Look at the OpenCascade shape type.
Extract the boundary mesh.
Look at the boundary element marker union and create colors for the markers.
Visualize the boundary ElementMesh with markers highlighted.
Generate the full mesh.

De-featuring

OpenCascade provides functionality to de-feature shapes.

Generate a shape.
Look at the OpenCascade shape type.
Extract the boundary mesh.
Find the number of faces.
Extract the boundary element markers.
Visualize the boundary ElementMesh with faces 11 and 12 highlighted.
De-feature the shape by removing faces 11 and 12.
Extract and visualize the boundary ElementMesh of the de-featured shape.
Visualize the boundary ElementMesh with faces 8 and 12 highlighted.
De-feature the shape by removing faces 8 and 12.
Extract and visualize the boundary ElementMesh of the de-featured shape.
Look at the OpenCascade shape type.

Import/Export

OpenCascade can read and write various computer aided design relevant file formats. Import and Export of the these file formats is partially implemented.

STL Export

OpenCascade can export STL files.

Create a shape.
Export the shape as a STL file.
Import the generated STL with Import.
Visualize the boundary ElementMesh.

STL Import

OpenCascade can import STL files.

Import a STL file.
Extract the boundary mesh.
Visualize the boundary ElementMesh.

Step Export

OpenCascade can export STEP files.

Create a shape.
Export the shape as a STEP file.

Step Import

OpenCascade can import STEP files.

Set up the example directory path.
Import a step file.
Extract the boundary mesh.
Look at the boundary element marker union and create colors for the markers.
Visualize the boundary ElementMesh with markers highlighted.
Generate the full mesh.
Import a step file.
Extract the boundary mesh.
Look at the boundary element marker union and create colors for the markers.
Visualize the boundary ElementMesh with markers highlighted.
Generate the full mesh.

BRep Export

OpenCascade can export BRep files.

Create a shape.
Export the shape as a BRep file.

BRep Import

OpenCascade can import BRep files.

Set up the example directory path.
Import a brep file.
Extract the boundary mesh.
Look at the boundary element marker union and create colors for the markers.
Visualize the boundary ElementMesh with markers highlighted.
Generate the full mesh.

Possible issue

The lowest dimensional object that can be returned from an OpenCascase Boolean operation is that of the minimal dimension of any argument given to the Boolean operation. For example, a Boolean operation of two OpenCascade solids can not return an OpenCascade face object.

Create two touching cubes.
Create two OpenCascade shapes.
Look at the OpenCascade shape types.
Construct the intersection.
Look at the intersection shape type.

A boundary mesh can not be generated because the resulting OpenCascade shape intersection does not contain information on the lower dimensional face object.

Extract the boundary mesh.

Consider the case of a face and a cuboid touching.

Create two OpenCascade shapes.
Look at the OpenCascade shape types.
Construct the intersection.
Look at the intersection shape type.

The lowest dimensional argument to the OpenCascade Boolean intersection operation was the face object. Since the resulting operation is also a face object the object information is present in the resulting shape object and can be meshed.

Visualize the boundary mesh.