# 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

#### CapsuleShape

#### Cone

#### Cuboid

#### Cylinder

#### Ellipsoid

#### FilledTorus

#### Hexahedron

#### Parallelepiped

#### Prism

#### Polyhedron

#### Pyramid

#### SphericalShell

#### Tetrahedron

### Extended Solid 3D Primitives

*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.

Partial tori are also possible.

### Surfaces Primitives

It is also possible to create instances of surface graphics primitives embedded in 3D. These represent face type *OpenCascade* objects.

#### BSplineSurface

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

Closed B-splines are supported as long as the knots and weights are set to Automatic.

#### Polygon

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

A shell is a collection of faces.

#### Triangle

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

### Surfaces Meshes

#### ElementMesh

An ElementMesh is the mesh structure used in the wolfram language for finite element analysis. The creation of ElementMesh is documented in the reference pages of ToBoundaryMesh and ToElementMesh or the ElementMesh generation tutorial.

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.

### Wire Primitives

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

#### Line

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

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.

"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.

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.

#### Extracting parts

#### Translations, rotations, mirroring and other transformations

As an alternative, the TransformationFunction can directly be applied during the creation of the *OpenCascade* shape by making use of a TransformedRegion.

To mirror a shape ReflectionTransform can be used.

#### Sewing

Surfaces that share edges can be sewn together.

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.

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

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

Note, here the ordering of the control points is important. The orientation of the resulting surfaces can be fixed with OpenCascadeShapeFix as shown further down.

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.

#### RotationalSweeps

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

*OpenCascade* can also perform rotational sweeps on wire objects.

Rotational sweeps can not be performed on Solid or CompoundSolid OpenCascade shape types.

*OpenCascade* can also perform rotational sweeps on edge objects.

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.

*OpenCascade* can also perform linear sweeps on wire objects.

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.

The loft command will greate a surface or a solid by creating surfaces that pass through the given objects.

Loft can be generated from "Wire" or "Face" shape objects. All objects need to be of the same type though.

By default, a loft created from wire objects will return an open shell.

To generate a solid suitable for a full mesh generation set the option "BuildSolid"True.

When a loft is generated from faces, a solid is returned automatically.

### Boolean Operations

Some restrictions in computing Boolean operations are detailed in the Boolean possible issues section and the Boolean operations on solids section.

Boolean operations will always return compound objects.

#### Difference

Compute geometric differences of shapes.

#### Union

Compute geometric unions of shapes.

#### Intersection

Compute geometric intersection of shapes.

Intersections can also be generated from lower dimensional region objects.

#### Simplifications of Boolean operations

In some cases the surfaces resulting from Boolean operations can be simplified.

#### BooleanRegion

The *OpenCascadeLink* provides functionality to directly work with BooleanRegion objects.

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

#### Boolean operations on solids

*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

##### Solids touching at a face

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.

Since there are no solids and no faces the conversion to a boundary element mesh will fail.

Note that the resulting full mesh will be open at the touching faces.

Note that the resulting solid has it's surface split according to the shape of the touching object.

Note that the resulting solid has it's surface split according to the shape of the touching object.

##### Solids touching at an edge

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.

Note that the edge of resulting full mesh will be split at the touching edges.

Note that the edge of resulting boundary mesh will be split at the touching edges.

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 for creating geometric models with multiple materials.

#### Internal boundaries by union of faces

Forming the union of solids will leave the position of the over lap open.

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.

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.

Note that computing the intersection returns a closed shape.

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.

### Fillets

*OpenCascade* provides functionality to fillet shapes.

It is also possible to fillet only selected edges.

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.

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

### 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.

### Shelling

*OpenCascade* provides functionality to shell shapes.

### De-featuring

*OpenCascade* provides functionality to de-feature shapes.

### Shape Simplification

*OpenCascade* provides functionality to simplify shapes.

### Shape Healing

*OpenCascade* provides functionality to heal shapes. Healing means that, for example, broken ordering of surfaces can be fixed.

### 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.

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.

#### STL Import

*OpenCascade* can import STL files.* *

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.

This may not be wanted. To avoid that the options "MarkerMethod""ElementMesh" or "MarkerMethod"None may be specified.

#### Step Export

*OpenCascade* can export STEP files.* *

#### Step Import

*OpenCascade* can import STEP files.* *

#### BRep Export

*OpenCascade* can export BRep files.* *

#### BRep Import

*OpenCascade* can import BRep files.* *

### 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.

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

Consider the case of a face and a cuboid touching.

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.