PDF

Remeshing an Imported Mesh: STL Import of a Vertebra1
Introduction
The STL file format is one of the standard file formats for 3D printing, and it is also often used as a format for exchanging 3D scan data. STL files contain only the triangulated surface, which we can also call a surface mesh, of a 3D object. The triangles in the file are identified by their normals and vertex coordinates.
COMSOL Multiphysics supports import of surface meshes from STL files. This tutorial series focuses on using available tools to edit imported surface meshes, different ways of repairing the meshes, and then either generate a geometry, or work with the mesh directly to prepare it for simulation. There are certain things to consider when choosing whether to create a geometry or not. Working with the mesh directly can be faster, while creating a geometry may allow for more flexibility. It is recommended that you create a geometry if your steps to prepare the imported mesh for simulation involve one or more of the following steps:
Using a Swept mesh operation to create a structured mesh.
This tutorial, the second in the series, demonstrates a workflow where a simulation mesh is generated by remeshing the imported surface mesh, without creating a geometry. The steps from importing the STL file to creating the final mesh are described in detail and include repairing of the imported mesh, combining the imported mesh with a mesh generated to represent a surrounding volume, intersecting the mesh with a plane, remeshing, creating domains, generating the tetrahedral mesh, and finally visualizing the mesh elements using a mesh plot.
From Surface Mesh to Geometry: STL Import of a Vertebra, the first part of this tutorial series, describes the process of creating a geometry from an imported STL file.
The two tutorials in this series are complementary, and intend to provide a detailed insight into how to work with imported meshes. Apart from arriving at a simulation mesh in two different ways, the tutorials also cover repairing different types of defects, and different ways of visualizing the mesh. Depending on your application and the imported mesh at hand, pick and choose from the tools detailed in the tutorials to arrive at a mesh that suits your needs.
Lastly, it is important to mention that the techniques used in the tutorial series apply to any type of imported surface meshes, such as the formats PLY and 3MF. They also apply when creating a mesh from a Filter or Partition dataset, which you would do when using the results of a simulation as the mesh for a new simulation, for example during a topology optimization study.
Model Definition
Import the STL file of a vertebra geometry shown below.
Follow the instructions in this tutorial to
Application Library path: COMSOL_Multiphysics/Meshing_Tutorials/stl_vertebra_mesh_import
Modeling Instructions
From the File menu, choose New.
New
In the New window, click  Model Wizard.
Model Wizard
1
In the Model Wizard window, click  3D.
2
Geometry 1
1
In the Model Builder window, under Component 1 (comp1) click Geometry 1.
2
In the Settings window for Geometry, locate the Units section.
3
From the Length unit list, choose mm.
This will set the same length unit also for the mesh.
Mesh 1
Import 1
1
In the Mesh toolbar, click  Import.
2
In the Settings window for Import, locate the Import section.
3
Click Browse.
4
5
From the Boundary partitioning list, choose Minimal.
This setting is suitable when importing mesh files that have no obvious boundary partitioning, for example meshes generated by medical imaging techniques. After the import, the mesh will usually consist of only one boundary that you can partition as needed, using the available tools. Use the Automatic or Detect boundaries settings when importing meshes that contain planar faces and fillets, which can then be detected to partition the mesh accordingly.
6
Click Import.
Create Domains 1
1
In the Mesh toolbar, click  Create Entities and choose Create Domains.
This operation is needed before you can generate a tetrahedral mesh. It checks if the imported surface mesh forms any watertight regions, and if so, it forms domains.
2
In the Settings window for Create Domains, click  Build Selected.
Warning 1
A warning is displayed indicating that the mesh of the vertebra does not form a watertight component. The edge that appears in the selection for the warning is only adjacent to one face. This means that the edge is an exterior edge that is adjacent to a hole in the mesh. Only the first such edge is indicated in the warning. If more holes exist, you can find them by visually inspecting the mesh, or by building the Create Domains operation again after repairing the first hole. But first, let’s take a closer look at the edge listed here.
1
In the Model Builder window, click Warning 1.
2
In the Settings window for Warning, locate the Geometric Entity Selection section.
3
4
Click  Zoom to Selection.
The highlighted edge is next to a triangular hole that seems to be caused by a missing mesh element. Let’s continue with checking for other holes in the mesh. Since the imported mesh consists of only one boundary, all edges that we find are exterior edges located next to holes in the mesh. Follow the steps below to highlight all edges to easily see them in the Graphics window.
5
Click the  Mesh Rendering button in the Graphics toolbar.
6
Clear the  Activate Selection toggle button.
7
Click the  Select All button in the Graphics toolbar.
8
Click the  Go to Default View button in the Graphics toolbar to view the entire geometry. You can zoom in a little bit to see the highlighted edges more clearly.
There are three holes, which are all located on the same side of the vertebra. The easiest way to verify this is to turn on Wireframe Rendering to make sure there are no other edges hiding behind the faces of the vertebra. If you do, remember to turn Wireframe Rendering off again before continuing.
The two additional holes located on the upper half of the image (highlighted in blue) are both slit like holes that have zero or almost zero area. Such slits usually result when the vertices of the imported mesh triangles do not match within the specified import tolerance.
The different type of holes require different kind of treatment. Of the three holes in the image above, first we will repair the one in the upper right corner of the image, we will continue with the small hole in the upper left (both holes are highlighted in blue). Lastly, we will fill in the triangular hole (highlighted in green) in the bottom left.
9
Open up the Selection List from the Windows menu on the Home toolbar. If there are more than 3 edges listed in the Selection List, go back to the Import 1 node and make sure that the setting Boundary partitioning is set to Minimal, then reimport the mesh. Keep the Selection List open as you will use it later on.
10
11
Click the  Zoom to Selection button in the Graphics toolbar.
12
Click the  Mesh Rendering button in the Graphics toolbar. You may need to rotate and zoom the mesh to get the same view as below.
The selected edge is next to a very narrow slit that has the same number of edge elements on both sides. Zoom in further towards the end of the slit with the small mesh elements (upper left in the image above).
The corners of the triangular elements do not match since the corresponding mesh vertices were not merged during the import. To fix this, reimport the file using a larger tolerance.
Import 1
1
In the Model Builder window, click Import 1.
2
In the Settings window for Import, locate the Import section.
3
From the Repair tolerance list, choose Absolute.
4
In the Absolute tolerance text field, type 1e-4[mm].
5
Click Import.
The mesh vertices are now merged, thereby eliminating the hole and the edge adjacent to it. You can easily verify this by hovering over the location of the hole with the pointer: no edge becomes highlighted.
Next, repair the other slit in the mesh.
6
Go to the Selection List.
7
8
Click the  Zoom to Selection button in the Graphics toolbar.
You may need to zoom out a bit, rotate, and then click the Zoom to Selection button again to get the edge into view. Make sure the Mesh Rendering is turned on so that the triangles in the mesh are visible.
On one side of the slit (on the left side of the blue edge in the figure) there is one triangle element, whereas on the other side there are two elements. Since the import functionality cannot partition elements or add new elements, the mesh edges on the two sides of the slit could not be merged even with the larger tolerance. To repair the slit you will first manually partition it to create a small face around the slit. Next, delete this face to leave a hole, for which you can then generate a new meshed face.
Create Edges 1
1
In the Mesh toolbar, click  Create Entities and choose Create Edges.
2
Go to the Model Builder window.
Note that the Create Edges 1 node is inserted after the Import 1 node in the model tree since the Import 1 was the current node. The current node is indicated by a frame around its icon, either green (node is built) or yellow (node is not built). It is desired to insert operations that fix the holes before creating a domain, so leave the Create Domains 1 node unbuilt for now.
3
In the Graphics window, select element edges as in the image below (highlighted in blue and green) by clicking on the mesh edges with the mouse cursor.
It is important that the selected element edges form a closed loop, either by themselves, or, as here, together with an existing edge. It is also important to include as few triangle elements as possible inside the loop to avoid loosing too much curvature information when deleting the face in the next step.
4
In the Settings window for Create Edges, click  Build Selected.
Delete Entities 1
1
In the Mesh toolbar, click  Delete Entities.
2
3
In the Settings window for Delete Entities, click  Build Selected.
Now, there are two triangular holes in the mesh. Use the Fill Holes operation to automatically fill these.
Fill Holes 1
1
In the Mesh toolbar, click  Create Entities and choose Fill Holes.
2
3
In the Settings window for Fill Holes, click  Build Selected.
The hole is filled by a triangle that is automatically joined with the surrounding mesh face. Now, let’s find out if the third hole is also repaired.
4
Click the  Mesh Rendering button in the Graphics toolbar, then zoom out to check if any edges remain.
The original triangular hole (bottom left corner in the above image) remains since it is larger than the automatically determined tolerance for Fill Holes. By measuring the perimeter of the remaining hole, you can obtain an estimate for the tolerance value to use with the Fill Holes feature.
5
Click the  Select Edges button in the Graphics toolbar.
6
7
In the Mesh toolbar, click  Measure.
The length of the edge is reported in the Messages window. It is about 2.2 mm long.
8
Locate the Fill Holes section. From the Fill holes tolerance list, choose Manual.
9
In the Maximum hole perimeter text field, type 2.3[mm]. The value you enter here should be slightly larger than the measured hole perimeter.
10
Click  Build Selected.
This concludes the repair of the imported mesh, which now forms a watertight boundary. Continue with the steps below to learn how to combine the imported mesh with a block you create in a separate component to generate a volume mesh both inside and outside the vertebra, and how to intersect the mesh with a plane to delete a portion of the mesh. The mesh of the block could just as well be imported from file, if available.
Add Component
In the Model Builder window, right-click the root node and choose Add Component>3D.
Geometry 2
1
In the Settings window for Geometry, locate the Units section.
2
From the Length unit list, choose mm.
Block 1 (blk1)
1
In the Geometry toolbar, click  Block.
2
In the Settings window for Block, locate the Object Type section.
3
From the Type list, choose Surface.
You do not need to create a solid block, since you will only import a surface mesh for the block to the meshing sequence of the vertebra. Continue with choosing the size and position of the block such that it will contain the vertebra mesh, as overlaps between mesh elements are not supported.
4
Locate the Size and Shape section. In the Width text field, type 30[mm].
5
In the Depth text field, type 20[mm].
6
In the Height text field, type 25[mm].
7
Locate the Position section. In the x text field, type -5[mm].
8
In the y text field, type 80[mm].
9
In the z text field, type -5[mm].
10
Click  Build Selected.
Mesh 2
Generate the mesh for the block using default settings.
1
In the Model Builder window, under Component 2 (comp2) right-click Mesh 2 and choose Build All.
Mesh 1
Next, import the mesh of the block into Component 1.
1
In the Model Builder window, under Component 1 (comp1) click Mesh 1.
Import 2
1
In the Mesh toolbar, click  Import. Make sure the Import 2 node is added after Fill Holes 1 in the model tree.
2
In the Settings window for Import, locate the Import section.
3
From the Source list, choose Meshing sequence. This will automatically suggest to import Mesh 2, which is the mesh of the block.
4
Click Import.
5
Click the  Mesh Rendering button in the Graphics toolbar.
6
Click the  Go to Default View button in the Graphics toolbar.
7
Click the  Transparency button in the Graphics toolbar, to see the vertebra inside the block.
8
Rotate the mesh in the Graphics window to check that the vertebra is fully contained in the block, the two meshes should not intersect.
You can also use mesh Statistics to check that only triangle elements were imported for the block.
9
Right-click Mesh 1 in the Model Builder and select Statistics.
10
Make sure that Geometric entity level is set to Entire Geometry.
The mesh should only consist of triangles, edge elements, and vertex elements. If tetrahedra are present, or if the meshes intersect, check and make sure that the settings for Block 1 in Component 2 are correct, then reimport the mesh of the block.
In the Statistics window, we can also see that the Minimum element quality of the surface mesh is rather low (about 1.7e-4). Furthermore, the histogram reveals that a large portion of the elements have low quality. You will remesh the vertebra further ahead to get a higher element quality.
Continue with intersecting the mesh of the block and vertebra with an assumed symmetry plane.
Intersect with Plane 1
1
In the Mesh toolbar, click  Intersections and Partitions and choose Intersect with Plane.
2
In the Settings window for Intersect with Plane, locate the Plane Definition section.
3
From the Plane list, choose yz-plane.
4
In the x-coordinate text field, type 10[mm].
5
Locate the Cleanup section. From the Repair tolerance list, choose Absolute.
The Absolute tolerance is set to 0.01 mm by default, which is the value we will use here. The Automatic setting uses a higher tolerance (0.09 mm).
6
Click  Build Selected.
You should now be able to see in the Graphics window that the mesh of the vertebra and the block have been partitioned by the plane. A new mesh face that connects the vertebra and the block along the plane has also been created inside the block. This is controlled by the Create intersection faces check box. When it is selected, the operation creates planar faces inside closed edge loops generated by the intersection.
Intersecting a mesh can introduce small and sliver mesh elements. The cleanup part of the operation collapses these, but in doing so it may change the shape of the mesh that is intersected to ensure a planar intersection face. A lower tolerance will preserve the original shape of the mesh better, but will also keep more of the small and sliver elements introduced by the intersection. Here, the lower tolerance helps to avoid the small faces that result when mesh elements on the vertebra that are very close to the intersecting plane are collapsed onto the plane.
After intersecting a mesh with a plane, remeshing is usually needed to eliminate small elements that often result from the intersection. Also, the mesh on intersection faces is always generated as coarsely as possible, and will typically need to be refined. Remeshing the faces will result in mesh elements of more uniform size, and also result in triangles that are closer to the wanted equilateral shape. But, before coming to that, delete the part of the mesh on one side of the symmetry plane.
Delete Entities 2
1
In the Mesh toolbar, click  Delete Entities.
2
In the Selection List window, choose 1 (meshed), 2 (meshed), 3 (meshed), 4 (meshed), 5 (meshed), and 6 (meshed) by pressing down the Ctrl key at the same time as clicking them in the list.
3
Click Add to Selection in the window toolbar.
Delete Entities 2
1
In the Model Builder window, click Delete Entities 2.
2
In the Settings window for Delete Entities, click  Build Selected to delete the part of the vertebra and block on one side of the symmetry plane.
3
In the Selection list, confirm that we have the expected nine boundaries; six for the block and three for the vertebra. If there are more than 9 boundaries in the list, check the tolerance setting for the Intersect with plane operation.
4
Click the  Transparency button in the Graphics toolbar as this makes it easier to see the mesh on the outside of the block. Also, if you have turned off Mesh Rendering earlier, turn it on again.
Next, you will remesh the faces with the Free Triangular operation to generate a finer mesh and improve element quality. This may be needed when the quality of an imported mesh is not suitable for the simulation at hand or, as discussed earlier, to improve the mesh on the intersection faces and close to the intersection edges.
Free Triangular 1
1
In the Mesh toolbar, click  Boundary and choose Free Triangular.
2
The mesh on the far end of the block (Boundary 1) has not been modified, and is of good quality. Therefore there is no need to remesh it.
3
In the Settings window for Free Triangular, click to expand the Mesh Preprocessing section.
4
In the Relative simplification tolerance text field, type 0.001. The lowered tolerance allows for a closer representation of the curved parts of the vertebra faces with smaller radius.
Size 1
1
In the Model Builder window, right-click Free Triangular 1 and choose Size to set a finer mesh size on the face of the vertebra.
2
In the Settings window for Size, locate the Geometric Entity Selection section.
3
Click  Clear Selection.
4
5
Locate the Element Size section. From the Predefined list, choose Fine.
6
Click  Build Selected.
This will mesh the face of the vertebra with a finer mesh size than the planar faces where Normal size is used.
7
Click the  Click and Hide button in the Graphics toolbar.
Hide boundaries 2,6, and 8 by clicking on them in the graphics to arrive at the image below.
8
Click the  Click and Hide button in the Graphics toolbar again to deactivate the functionality to avoid hiding more boundaries.
When generating a new mesh with the Free Triangular operation, smooth surfaces are first created in the background, based on the original mesh. These surfaces are then used when the new mesh is generated. See the discussion in the section Comparing Mesh of Created Geometry with Imported STL Mesh in the tutorial From Surface Mesh to Geometry: STL Import of a Vertebra for more information on how the Relative simplification tolerance influences the shape of the faces to remesh.
Compare Free Triangular to modifying the mesh using the Adapt operation, as is done in the tutorial Bracket Topology Optimization in the Optimization Module. The Adapt operation is placing all new mesh vertices on the original mesh. This means that an adapted mesh will typically keep the original shape of the mesh to a greater extent than a mesh created with the Free Triangular operation.
9
On the Mesh toolbar, click Statistics in the Evaluate section.
In the Messages window, you can verify that the Minimum element quality is now much improved (0.41).
As the face mesh is ready, build the Create Domains 1 node.
Create Domains 1
1
In the Model Builder window, right-click Create Domains 1 and choose Build Selected.
2
Check the Messages window. Two domains were created; one for the vertebra and one for the domain of the surrounding block.
Now, fill the domains with a volume mesh.
Free Tetrahedral 1
1
In the Mesh toolbar, click  Free Tetrahedral.
2
In the Settings window for Free Tetrahedral, click  Build Selected.
The Messages window reports that the two domains contain about 53 000 domain elements. If you check the Selection List window, you can also see that the two domains listed there ar marked as ’(meshed)’. This mesh is now ready and can be used to set up materials and physics for a 3D simulation in the software.
Before concluding the tutorial let’s take a closer look at how to create and customize a mesh plot for a visual inspection of the mesh.
3
In the Mesh toolbar, click  Plot.
The default mesh plot shows the quality of the mesh elements. Green color indicates a good quality mesh (quality close to 1). Follow the steps below to create a plot of the volume elements colored according to the domain they belong to, and filtering applied to see inside the mesh.
Results
Mesh 1
1
In the Settings window for Mesh, locate the Coloring and Style section.
2
From the Element color list, choose White to color the mesh elements white.
3
Click to expand the Element Filter section. Select the Enable filter check box.
4
In the Expression text field, type x>11[mm] to inspect the volume mesh inside the domain.
5
In the Mesh Plot 1 toolbar, click  Plot.
Next, add a Selection to the plot node and select the vertebra domain.
Selection 1
1
Right-click Mesh 1 and choose Selection.
2
3
In the Mesh Plot 1 toolbar, click  Plot.
Now, duplicate the Mesh 1 plot node and make some changes to color the surrounding elements in a light blue color.
Mesh 2
Right-click Mesh 1 and choose Duplicate.
Selection 1
1
In the Model Builder window, expand the Mesh 2 node, then click Selection 1.
2
In the Settings window for Selection, locate the Selection section.
3
Click  Clear Selection.
4
Mesh 2
1
In the Model Builder window, click Mesh 2.
2
In the Settings window for Mesh, locate the Coloring and Style section.
3
From the Element color list, choose Cyan.
4
Locate the Element Filter section. In the Expression text field, type y>90[mm].
5
Click to expand the Shrink Elements section. In the Element scale factor text field, type 0.8.
6
In the Mesh Plot 1 toolbar, click  Plot.
Setting the Element scale factor to a value smaller than 1 makes it possible to inspect how individual mesh elements are connected as it is possible to see the parts of the surrounding elements that would otherwise be hidden behind the first layer of elements in the view. It is also possible to set a value larger than 1 to increase the size. That can be used to inspect the shape of individual elements that are really small, especially when filtering out a small number of elements.
 

1
The STL geometry is provided courtesy of Mark Yeoman, Continuum Blue, UK.