Several years ago, we faced a decision on how to import information from CAD programs into MetaMesh, our 3D mesh generator. There was a sense of urgency for two reasons: 1) we had a consulting project with shaped electrodes that were beyond the capabilities of the native solid models of MetaMesh and 2) users increasingly expected to be able to port models from SolidWorks and other programs. We rejected so-called standardized file types like IGES and STEP because the proprietary format specifications were not generally available and the files contained far more information than was needed for our application. Working directly through the APIs of popular CAD programs would have required adding several full-time staff members. Fortunately, there was a simple and effective alternative: the STL (stero-lithography) file. It has several attractive features:
- The format contains only geometric information. It defines the surface of a solid as a set of contiguous triangular facets. This is exactly what we needed, and nothing more.
- The format is a standard for controlling 3D machine tools; therefore, all CAD programs must support STL export.
- The format is simple and cast in concrete. No manufacturer or group can add proprietary features.
Since that time, our decision to go with STL has proved even more (pick one):
First, interest in 3D printing has exploded. STL is the format of choice for this application. Second, powerful software resources are available to correct and to modify STL files. This means that even if you get a clunker file, you can still make a good mesh for field calculations.
In this article, I’ll give a quick introduction to MeshLab, a wonderful open-source program that is a must-have for anyone working with STL files. The functions of the program range from basic to beyond-PhD — in other words, it may be intimidating at first. My purpose in the tutorial is to focus on features useful for MetaMesh import. Once you get the basic ideas, MeshLab is easy to use. I’ll illustrate with a specific example. Suppose we want a human-shaped phantom for a GamBet dose calculation. There are many Internet sites offering free STL files to support the 3D printing community. I found the following file of the human female figure, body30.stl. The raw file (content shown in Fig. 1), has a multitude of flaws that we will fix with MeshLab:
- The number of facets is large (83,078), far more than is needed. For example, it’s not necessary to resolve the swimsuit lines for the application.
- There are orphan facets (for example near the fingers).
- The file has logical errors such as redundant vertices, so that it cannot be read directly by Geometer and MetaMesh.
Install and run MeshLab. If you find the sophisticated Italian color scheme distracting, you can dull it down as I did. Click Tools/Options and change BackgroundBotColor, BackgroundTopColor and LogAreaColor. When you find a good color, be sure to press the Save button so that the program remembers it for next time. MeshLab starts in the default Project_1. To add the STL mesh to the project, click File/Import mesh and choose body30.stl. Accept the program prompt to unify duplicate vertices. We’ve already achieved some benefit at this point. Choose File/Export as, pick the STL format and supply the name body30fixed.stl. The result is a logically-correct file that can now be loaded into the Geometer STL Viewer of Fig. 1.
In the Export as operation, it was apparent that MeshLab can deal with a lot of formats besides STL. These formats can include extensive information, such as texture and even PNG images associated with facets. The implication is that there are many operations in MeshLab that are not relevant to STL files.
MeshLab displays the facets of body30.stl from a viewpoint above the head (Fig. 2). To begin, let’s learn some basics of changing the view:
1) To rotate the viewpoint, move the cursor inside the display area, hold down the left mouse button and drag the mouse.
2) To pan, do the same thing but hold down the control key.
3) Use the mouse control wheel to zoom in and out.
4) Change the rendition method using the circled tools in Fig. 2.
Using the view controls, create an expanded view of the hand region as shown in Fig. 3. There are orphan facets, edges are spiky, surfaces are noisy and there are many more facets than we need. The symptoms are typical of a 3D scanner. Clearly, it’s impractical to do individual editing on 83,078 facets. Instead, we will apply the automatic filters available in MeshLab. If you click on Filters and check out the sub-directories, there are a dizzying number of arcane options. Fortunately, only a small subset is useful for STL files intended for mesh generation.
- Normals, Curvature and Orientation/Transform …
- Smoothing, Faring and Deformation/Laplacian Smooth
- Cleaning and Repairing/Remove Isolated Pieces (wrt Diameter)
- Remeshing, Simplification and Reconstruction/Surface Reconstruction (Poisson)
Transformations modify the coordinates of the facet vertices. With them, you can move and rotate the object and change the size. One application is to create an assembly of STL objects using files that were recorded in local coordinate systems. Alternatively, you can use the transformation operations in Geometer or add Shift and Rotation commands in the MetaMesh script.
The smoothing operation iteratively averages coordinates of neighboring vertices. Figure 4 shows the effect. The filter is useful to reduce small holes or noise from scans. The Remove Isolated Pieces filter can be applied to eliminate disconnected facets such as those near the fingertips (Fig. 5). First, we need a scale size for the disconnected pieces. Activate the Measuring Tool and click on two points that span the orphan facets. We’ll remove any objects with a diameter smaller than 15.0. Figure 5 shows a before-and-after shot along with the dialog settings. The figure is now self-connected, a big plus for a MetaMesh analysis.
The Surface Reconstruction (Poisson) filter is the most useful operation. It often accomplishes everything we want in one step: consolidation and smoothing combined with a reduction in the number of facets. We’ll check it out in detail. Close the project, start a new project and reload the raw mesh body30.stl. Then apply the Surface Reconstruction (Poisson) filter with the parameters shown in Fig. 6. The first two parameters give the inverse of the level of simplification: 6 gives less detail and 8 gives more detail. The other two parameters should be left at a value of unity. Higher values significantly reduce the size of the object. Values of 0 crash the program.
When you apply the filter, the mesh does not appear to change. It certainly does not look like Fig. 6. In contrast to the previous operations, the reconstruction filter creates a new mesh rather than modifying the present one. The display shows a superposition of the two meshes. How do we know there are two meshes? We need to activate the Layer Dialog. Right-click anywhere in the menu or toolbar to bring up the pop-up menu at the top-right of Fig. 6 and check Project_1. The program adds the list of layers displayed on the right-hand side of Fig. 6. It contains the original mesh and the modified one. Turn off the visibility of the original mesh to see the display of Fig. 6. You can experiment with the reconstruction command, adding additional meshes. Right click within the Layer dialog for a set of options such a deleting a mesh.
The mesh shown is ideal for the radiology application. It is self-connected with no spurious details, providing a good definition of the human-body volume. The number of facets has been reduced by about a factor of 5 to 16,008. To save the mesh, highlight it in the Layer Dialog and choose Export Mesh As in the File menu. Save it as an STL file with the name simplify8.stl.
I generated STL files for Poisson parameters 6 (3968 facets), 7 (16008 facets) and 8 (64120 facets). Here is a simple MetaMesh test script:
GLOBAL XMesh -7.50000E+01 7.50000E+01 2.50000E+00 End YMesh -9.00000E+01 9.00000E+01 2.50000E+00 End ZMesh -2.50000E+02 2.50000E+02 2.50000E+00 End RegName( 1): SolutionVolume RegName( 2): HumanBody Parallel 4 END PART Region: SolutionVolume Name: SolutionVolume Type: Box Fab: 1.50000E+02 1.80000E+02 5.00000E+02 END PART Region: HumanBody Name: HumanBody Type: STL Simplify7 Fit Fab: 8.00000E-01 3.00000E-01 Surface Region SolutionVolume END ENDFILE
At a resolution of 0.25, the mesh contained 864,000 elements. Figure 7 shows the resulting meshes for Poisson parameters of 6, 7 and 8. The choice of 7 was well suited for the application. The processing time in MetaMesh was 31 seconds. For the radiology application, a resolution of 0.5 is probably sufficient. In this case, the total number of elements is 108,000 with processing time of 6 seconds.
Corrections in MeshLab work well when the surfaces of the object are relatively smooth and the facets have approximately the same areas (as in the current example). On the other hand, STL files exported from 3D CAD programs may have sharp edges and very large variations of facet size. The Poisson correction method fails for such a file. In this case, you should use the export controls in the CAD program to control the facet resolution.
Finally, MeshLab and the Geometer STL Viewer have relative merits as general-purpose STL displays. MeshLab has more responsive controls and display options, but is limited to the perspective view of Fig. 2. On the other hand, Geometer supports both the perspective view and the precise projection view of Fig. 1. This view is better suited for extracting quantitative data.
 MeshLab always starts in full screen mode. It would certainly be nice if the program remembered its previous window.
 Contact us : firstname.lastname@example.org.
 Field Precision home page: www.fieldp.com.