OpenCascade provides some primitives that do not have a direct correspondence in the Wolfram language.
Torus
Here the arguments are an axis around which the torus is located, a radius from the axis to the interior of the torus and a second radius specifying the the radius of the interior of the torus.
Create a Torus primitive in OpenCascade.
Look at the OpenCascade shape type.
Generate a boundary ElementMesh from the first OpenCascade shape.
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.
Look at the OpenCascade shape type.
Both, open and closed surfaces can be converted.
Create and visualize a boundary ElementMesh.
Convert a boundary ElementMesh to an OpenCascade object.
Look at the OpenCascade shape type.
Wire 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 or combined with other wire or edge objects.
Extended Wire Primitives
OpenCascade provides some primitives that do not have a direct correspondence in the Wolfram language.
Circle in 3D
Visualize a circle that has it's center at {0,0,1} and a plane with a normal in direction {0,-1,0}, a radius of 1/2 and an arc length from π to 2 π.
Create a OpenCascadeCircle 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 or combined with other wire or edge objects.
Operations on OpenCascade objects
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 degrees and the Automatic default for the "LinearDeflection" is set to 0.01 units of the relative size of the shape. 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 OpenCascade shape.
Visualize the boundary ElementMesh extracted from the OpenCascade 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".
The "MarkerMethod" option allows to specify if markers should be added and if where they should be computed. The default is to use "OpenCascade". Other options are "ElementMesh" and None to switch off markers entirely. Using "ElementMesh" as a "MarkerMethod" option can be useful if the generated surface consists of many single surface elements. In that case the "OpenCascade" method would attribute each element a unique marker which may be undesirable. With the method "ElementMesh", however, the markers are added based on their face normals and if those deviate by a certain amount. The ToBoundaryMesh reference page has more information on this topic.
Extract a boundary ElementMesh from the OpenCascade shape with a refined surface mesh.
Visualize the boundary ElementMesh extracted from the OpenCascade shape.
Extracting parts
Create a shape.
Extract the number of faces.
Extract the faces.
Extract the type.
Generate a boundary mesh from one of the faces.
Extract the number of vertices.
Extract the vertices.
Extract the type.
Translations, rotations, mirroring and other transformations
Create a shape.
Rotate the shape.
Extract a boundary ElementMesh from the OpenCascade shape.
Visualize the boundary ElementMesh and the shape rotated in the Wolfram language.
Extract and visualize the boundary ElementMesh and the shape rotated in the Wolfram language.
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.
A shell is a collection of faces. To create a solid either an option can be used during the sewing process or the function OpenCascadeShapeSolid can be used.
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 and make the shape a solid.
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
OpenCascade 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.
OpenCascade 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.
Rotational sweeps can not be performed on Solid or CompoundSolid OpenCascade shape types.
OpenCascade can also perform rotational sweeps on edge objects.
Visualize a Circle in 3D.
Create a OpenCascadeCricle 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.
Rotational sweeps can not be performed on Solid or CompoundSolid OpenCascade shape types.
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.
Sweep 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.
OpenCascade can also perform linear sweeps on wire objects.
Create a Line primitive in OpenCascade.
Look at the OpenCascade shape type.
Sweep 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.
Linear sweeps can not be performed on Solid or CompundSolid OpenCascade shape types.
Loft
A loft is surface or solid the is generated by creating surfaces that pass through wires. The concept is easily understood once a visualization has explained it.
Create and visualize a set of Line objects.
The loft command will greate a surface or a solid by creating surfaces that pass through the given objects.
Convert the graphics primitives to OpenCascade shapes.
Loft can be generated from "Wire" or "Face" shape objects. All objects need to be of the same type though.
Inspect the types of the shapes.
Create a loft.
Visualize the loft and the original wires
By default, a loft created from wire objects will return an open shell.
Inspect the shape type of the loft.
To generate a solid suitable for a full mesh generation set the option "BuildSolid"True.
Generate solid loft.
Generate and visualize a full mesh.
Visualize the mesh and the wires
When a loft is generated from faces, a solid is returned automatically.
OpenCascade handles Boolean operations in a slightly different manner than the Wolfram Language Boolean operators RegionUnion, RegionIntersection and RegionDifference. It's illustrative to walk through several examples.
Solids overlapping
Create two overlapping cubes.
Setup the shapes.
Intersection
Compute the intersection.
Visualize the Boolean operation.
Union
Compute the union.
Visualize the Boolean operation.
Difference
Compute the first difference.
Visualize the Boolean operation.
Compute the second difference.
Visualize the Boolean operation.
Solids touching at a face
Create two touching cubes.
Setup the shapes.
Intersection
Compute the intersection.
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.
Extract the number of faces.
Since there are not solids and no faces the conversion to a boundary element mesh will fail.
Converting a shape with no faces or solids will fail.
Union
Compute the union.
Visualize the Boolean operation.
Note that the resulting full mesh will be open at the touching faces.
Visualize the full mesh and note that the union of the solids is open at the touching faces.
Difference
Compute the first difference.
Visualize the Boolean operation.
Note that the resulting solid has it's surface split according to the shape of the touching object.
Visualize the boundary mesh and it's split surface.
Compute the second difference.
Visualize the Boolean operation.
Note that the resulting solid has it's surface split according to the shape of the touching object.
Solids touching at an edge
Create two touching cubes that touch at an edge.
Setup the shapes.
Intersection
Compute the intersection.
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.
Extract the number of edges.
Union
Compute the union.
Visualize the Boolean operation.
Note that the edge of resulting full mesh will be split at the touching edges.
Visualize the full mesh and note that the union of the solids is split at the touching edges.
Difference
Compute the first difference.
Visualize the Boolean operation.
Note that the edge of resulting boundary mesh will be split at the touching edges.
Visualize the boundary mesh and it's split surface.
Compute the second difference.
Visualize the Boolean operation.
Note that the edge of resulting boundary mesh will be split at the touching edges.
Internal boundaries
OpenCascade offers several ways to include internal boundaries.
Internal boundaries by union of faces
Forming the union of solids will leave the position of the over lap open.
Create two touching cubes that touch at an edge.
Create the OpenCascade shapes.
Form the union and visualize the full mesh.
Note that at the overlap where the two cuboids touched the union is not closed. This may be undesirable if one is working with a multiple material region. One option to close the face at the overlap is to compute the union of all faces of the solids.
Extract all faces from the solids and compute the union of the faces.
Visualize the full mesh.
Extract the boundary mesh.
Note that now an interface exists between the two solids.
Internal boundaries by sewing
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 OpenCascade every face 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.
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. The chamfers created are symmetric and the function's parameter specifies the distance tangential to which the chamfer surface will be created.
Generate a shape.
Look at the OpenCascade shape type.
Apply chamfer to edges 5 and 6.
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.
Boundary normals in OpenCascade are in the opposite direction then what they are in the wolfram language. If an exported STL shows signs of the normals being in the 'wrong' direction one can convert the shape to an ElementMesh and that to a MeshRegion. The MeshRegion can then be exported as a STL file with Export.
Note that an import of an STL file with OpenCascadeShapeImport will result in a boundary mesh that has a unique marker assigned to each surface element.
Inspect the boundary element markers.
This may not be wanted. To avoid that the options "MarkerMethod""ElementMesh" or "MarkerMethod"None may be specified.
Extract the boundary mesh and have the markers computed in the Wolfram language.
Inspect the boundary element markers.
Visualize the boundary ElementMesh with markers highlighted.
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 with mesh order 1.
Possible issues
Boolean operation issues
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.
Look at the number of faces.
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.