Workflow for rapid prototyping of 3D reconstructed surfaces, applications to rock art

Written by Paul Bourke
September 2013


The following describes one of many possible pipelines for rapid prototyping (RP) 3D reconstructed surfaces. While some comments will be made regarding the reconstruction process, that is covered in other places. The RP system will be based upon the on-line service offered by Shapeways, but the printable models created will be applicable to any RP facility capable of supporting colour. Note that as with any documentation of this type it can become out of date as time goes on, new releases of the software etc. This is especially so since some of the work flows described here result from bugs or other inadequacies in the various software tools available. The software used here and version numbers are as follows:

  • PhotoScan, version 0.9.1

  • Blender, version 2.6.3

  • MeshLab, version 1.3.2 64 bit

  • Mac OSX, version 10.8.4

The overall summary of the process is as follows

  • Reconstruct the surface from the photographs.

  • Remove parts of the model not required and apply any other editing.

  • Scale the model to the desired size.

  • Thicken the surface.

  • Export in a format suitable for the RP process.

Reconstruction

There are a number of software candidates for 3D reconstruction, while this is not intended to be a comprehensive survey or evaluation of the options, two of the main players to date are AutoDesks 123D Catch and PhotoScan. While 123D Catch is free, it is cloud based and thus problematic when working in the field. PhotoScan is modestly priced and has good cross platform support, unlike 123D Catch which is MSWindows only. For the purposes of this document PhotoScan is used mainly because 123D Catch has some major problems with its OBJ export which is often faulty, that is, it generates degenerate mesh triangles and other problems that adversely affect the RP process.

Model editing

Most RP machine software place some expectations on the models being printed, Shapeways is particularly sensitive, overly so in the authors opinion. For example, models must be "watertight", otherwise referred to as manifold. There is often a minimum thickness realisable, and so on. As such, some care needs to be taken when preparing models. There are three places, at least, where editing can be performed. They are:

  • In the reconstruction software itself. Indeed PhotoScan has a reasonable set of tools for choosing a subset of the selected mesh, removing extraneous triangles, and so on. In the example here PhotoScan was employed, export as OBJ format for subsequent processing in MeshLab and Blender as below.

  • MeshLab can be used to close holes, select regions, remove triangles, along with a whole range of other operations.

  • There are many other 3D modelling packages that may be used to edit the mesh resulting from the reconstruction, including Blender.

Before and after screen shots are shown below.

Scale

As a general rule the result of a 3D reconstruction is of arbitrary scale. At the time of writing when one uploads to Shapeways one may choose units of millimeters, inches, or meters. mm are recommended, after all, who still uses "inches"! Note: one cannot scale after uploading, a particularly frustrating aspect of Shapeways. Scaling can obviously be done in almost any 3D package, MeshLab is chosen here, the procedure is normally to scale to a unit bounding box, found in the "normals, curvatures and orientation" menu, followed by scaling to the desired size. The author also generally first translates the centroid of the object to the origin, found in the same menu: "Transform: move, translate, center".

Thicken

Any rapid prototyping of the sort relevant here requires a solid object, to date the process has been working on a single infinitely thin mesh. There are a number of algorithms for doing this, a popular one being called the "rolling ball" algorithm, one imagines a ball (sphere) rolling around on the surface and the most distant point of the sphere from the surface defines an offset surface. The approach taken here is to use the "solidify" modifier found in Blender. Import the OBJ file, select the mesh and choose the "Add modifier" option.

The thickness required for a particular RP machine varies. The most common colour printer at the time of writing is the ZCORP, known as the "full colour sandstone" on ShapeWays. The author finds that 5mm is a safe minimum, noting of course that one gets charged per volume of model so the thinnest is usually desirable.

Export for upload

Not all formats traditionally used for RP support colour let alone a textured surface, for example STL cannot define a colour surface. Shapeways supports a number of file formats for colour models, namely DAE, WRL, X3D, X3DB, X3DV. Some of these are antiquated (eg: WRL) and others are proprietary (eg: DAE), the author has found X3D to be have the most reliable support.


Note: Shapeways (at the time of writing) does not seem to be able to handle the (perfectly ok) zip files created by Mac OSX. That is, by selecting a folder or files and right clicking and choosing "Compress". The solution is to use the command line options of the UNIX based version of zip, namely:

zip outputfilename.zip -xi file1 file2 file3 ...


Workflow for rapid prototyping of molecular data

Written by Paul Bourke
February 2012, Updated October 2013


The following describes one of possibly many pipelines for taking PDB models and producing physical representations using Rapid Prototyping (RP). In what follows various packages will be used to create representations, generally of PDB files. The RP system will be based upon the online service offered by Shapeways (see appendix), but the printable models created will be applicable to any RP facility based upon the two main machines in this area, namely the ZCORP and ObJet. Note that as with any documentation of this type it can become out of date as time goes on, new releases of the software etc. This is especially so since some of the work flows described here result from bugs or other inadequacies in the chemistry software or the Shapeways software.

The software used here and versions numbers are as follows:

  • VMD, Mac version 1.9.1

  • MacPyMol, version 1.5.0.5

  • MeshLab, version 1.3.2 64 bit

  • Mac OSX, version 10.8.2

The requirements for any model destined for RP processing are

  • It must be "watertight", otherwise referred to as manifold.

  • It must be the correct dimensions. Many of the file formats (STL, x3D, wrl ....) do not explicitly define units, as such RP software has some license in what units to apply.

  • The mesh approximation of the shape is ideally not evident in the final 3D print.

  • In the case of colour prints, the intention here, there is a limited set of file formats that support colour and are supported by RP suppliers.

The examples provided here will use the following structure: example.pdb


VMD - sphere models

  • Render as VDW

  • Adjust the size of the spheres so it will be structurally sound and connected, nothing that smaller spheres will result in less material and hence lower printing costs.

  • Turn axes off since they will be exported as geometry however they can also be deleted later in MeshLab.

  • Render to OBJ file. This will produce two files, a .obj file and a .mtl file. For example: vmdspheres.zip. VMD seems to sometimes create an incorrect reference to the .mtl file, this will result in no colour when importing into Meshlab (or other obj file readers). This can be fixed by editing the .obj file and correcting the name of the .mtl file in the header.

  • Import the .obj file into Meshlab. The .obj models from VMD are very inefficient, each face of each sphere do not share vertices. There is a bug in Meshlab whereby if the duplicate vertices are removed (normally a good thing) then the resulting wrl file is corrupt.

  • Scale to unit bounding box, found in the "normals, curvatures and orientation" menu. Scale to known size, on import Shapeways will give the option to use units of mm.

  • Unfortunately the sphere resolution option in MatLab is not reflected in the exported geometry. If the spheres are considered too course refine the mesh using midpoint subdivision surfaces, see the "remeshing, simplification and reconstruction" menu.

  • Apply a Laplacian smooth, this can be found in the "smoothing pairing and deformation" menu.

  • Export as wrl and optionally zip the result for faster upload. Example: vmdsphereswrl.zip.

  • Upload wrl file to Shapeways (see appendix).



PyMol sphere models

  • Turn off all representations except spheres

  • In the prompt region type "set sphere_scale,0.7", or a size that retains connectivity but minimised printed volume.

  • Save image as PovRay, file menu. PyMol does allow a model to be saved as wrl but there is no straightforward way to scale for the RP process. Note that in the prompt region it is also possible to save a PovRay model file by typing "ray renderer=1".

The PovRay format was chosen since it is a relatively easy format to parse in order to extract the spheres, their radius and colour, and then scale and save as wrl for upload to Shapeways (see appendix).

Usage: pymol2wrl [options] povfilename
Options:
    -s n    scale factor

An example of the povray file is: example.pov and an example of the output wrl file is example.wrl. Note that spheres can be represented in wrl files in multiple ways. One, and is used here is to use the sphere primitive. The risk with that is that you are relying on the RP software to tessellate the sphere suitably. The alternative is to tessellate the sphere oneself at a higher resolution, see reference to WRLSphere3() in the code above.

At the time of writing Shapeways allows one to upload wrl files and select units of millimeters, inches, or meters.

Examples of final printed models.





PyMol surface models

Rapid prototyping of PyMol surface models is relatively straight forward, the following outlines the steps used to create models accepted by Shapeways (see appendix). Software used is just PyMol and MeshLab.

In PyMol

  • Turn off all representations other than the surface.

  • Set the surface resolution, the default is rather low. This is achieved with the following command "set surface_quality, 1". Higher numbers can be used but note ShapeWays has (at the time of writing) a 64MB file size limit or 1 million faces, which ever comes first.

  • Save the file to a wrl file, as "save something.wrl".

In MeshLab

  • Open the wrl file as saved from PyMol.

  • Check the faces count.

  • In the Normals, Curvature, and Orientations menus scale the model to the desired size. Since there is no known size, first scale to a unit cube, then scale to the desired size. Note that ShapeWays expects mm for the dimensionless file format to be used here.

  • Export to as x3d, choose vertex normals rather than face normals.


Appendix: Shapeways

Unfortunately the model testing at Shapeways is overly conservative. Models that are perfectly acceptable for printing on the ZCorp printer are regularly rejected. While people creating models manually in a 3D package can normally correct such problems, there is not always the opportunity to fix models created from scientific data. At the time of writing the author is preferring to use local RP companies instead of Shapeways.



Experiments in Rapid Prototyping

Written by Paul Bourke
January 2005


The testing here of the ZCorp colour rapid prototyping machine were geared towards determining how far one can push the technology and how useful it might be for mathematical and scientific visualisation. While these particular machines are one of the most advanced and general, they still place some significant constraints on the models they can represent. Perhaps the most serious involves the infusion process after the model has been built, the model can be extra delicate during this infusion process. This places an extra constraint on the thinnest structure over and above what the machine process can create.

The machine in question has a volume of about 200 x 200 x 250 mm. The first tests below were intended to investigate the value of creating solid models of mathematical shapes, in this case supershapes.

Supershapes
  Fractal, Sierpinski sponge

Character from an animated movie (by Russell Scott)

The following model is somewhat more demanding, firstly the wings are very thin, and secondly the model is not free standing so until it is infused with hardener it can't easily support itself. Indeed most damage to the model occurred not by the "printing" process but by the infusion process which removed the structural strength from a number of parts of the model, this seems to occur when the infusing fluid saturates right through the model.

Colour

The STL format used to represent the monochrome models here has no support for colour. The software that drives the machine expects VRML descriptions for colour models. VRML models are not difficult to create in code given parametric equations for the surfaces. The quality of the colour, see elliptic torus, was surprisingly good. This model was created intentionally with a continuous colour ramp to test this.

With regard to mathematical visualisation, it is immediately obvious once it is placed on a table that the tetrahedral ellipse is perfectly flat on all sides, something that is not at all obvious from computer based exploration.


Elliptic Torus and Tetrahedral Ellipse

Astronomer by Russell Scott




Building physical models
using the ZCorp Z402 3D Printer

Written by Paul Bourke

See also Borromean rings
and specification of the STL format. October 2000


In 2000 ZCorp introduced a new range of rapid prototyping machines. This was a good opportunity to create a physical object from one (or more) of my favourite 3D models. The model I chose first was the Borromean rings. Many 3D printers for rapid prototyping are based upon liquid polymers and lasers that trace out the contours. These present serious restrictions on the types of models because it is difficult to create models that require self supporting structures during their creation. The ZCorp type of device (and others) use a powder which supports structures as necessary as the model is being built. In addition, a feature not used here, their device can create colour models.

The model chosen is defined by 3 interlocking curves in 3D space. The industry standard format for describing models for stereo-lithography is called the STL format and it only describes solid objects not curves, lines and points. There a number of ways of forming solid pipes, a rather inefficient method was chosen here but one that is easy to create, can be extended to all curve based forms, and reliably represents the curve. The method is simply to "stack" spheres (described as STL format) along the curve. The thickness of the curve can be controlled by using different radii. Depending on how close the spheres are placed the thick curve can be given a smooth, ribbed, or beaded look. A subsequent implementation that is much more efficient and doesn't have the ribbed surface effect is to use cylindrical elements for straight sections of the curve.

The top curve on the right is the one actually used to create the model. The second and third images show a smooth and rougher version.

Source code

The source code that creates the model used in this discussion is given here. It can be readily modified to create any mathematical curve. The most useful part will be the function that creates a sphere in STL and geom format. The geom format is the format used locally to view stereographic images, in this case it was used to test the appearance of the model before sending it off to be created.

And finally here's the finished product. The three links are loose and can be moved around as one would expect. The bone-like fell of the material is not unattractive.

STL format

Representing triangular facets in the STL format is simple, for example below is the first polygon from the model created here. All the polygons are normally encapsulated between "solid" / "endsolid" tags.

facet normal -0.194944 0.980048 -0.0387767
outer loop
   vertex 1 0.37735 -0.333333
   vertex 1.07071 0.392574 -0.304044
   vertex 1.07654 0.392574 -0.333333
endloop
endfacet
The whole model as a compressed STL file: borromean_stl.gz.

Example 2 - Knot

The mathematics behind this object is given here as knot 3.

The model as a compressed STL file: knot3stl.gz.

The source code that creates the model is knot3stl.c.

 





Other examples (2007)

ASKAP telescope model

 

Rocks and fossils





Sirovision cliff face models

In the following a terrain (cliff) was recreated, the original surface and texture map is automatically generated by taking two photographs of the cliff face. Software called "Sirvision" can then recreate a 3D mesh surface from the two images, one of the images can additionally be applied as a texture map.

In general successful rapid prototyping require solid objects, not just (infinitely thin) surfaces. This is certainly true for the ZCORP machines, while the model can be structurally strong after curing, it can be quite delicate beforehand. The surface mesh here is simply extruded a fixed distance, this works because the surfaces here don't have "caves".

Top surface

Underneath

The following are two images of the modelled surface.

 

400 million year old Placoderm embryo

Calabi-Yau model

Examples from 2012-2014

Photogrammetrically derived bust of Socrates, UWA.

Peptide

Mine Pit

Earths Oceans

Knots

Chain mail



PhotoScan to Shapeways

Written by Paul Bourke
June 2015


The following are some brief notes around the conversion of PhotoScan reconstructed models to Shapeways for 3D printing. Some additional notes can be found here around editing in MeshLab and thickening in Blender. This document is mostly aimed at the file formats available from PhotoScan and the requirements for Shapeways. As is often the case the difficulty here arises from poor software support, in this case it arises from deficiencies on the Shapeways site, they are: incomplete support for textured meshes through OBJ and 3ds files, the incomplete support for zip archives (in this case those created on the Mac by MacOSX).

Build model in PhotoScan

It is assumed here that the model is a closed surface, that is, has no holes. PhotoScan has a number of tools to facilitate this, see the hole closing and the extrapolation option in the mesh building stage.


Example used in this tutorial

Export

At the time of writing the following formats are recommended on the Shapeways site.

The following export formats are available from PhotoScan.

A commentary/comparison of the formats in common is

  • wrl, in the authors opinion, is not an encouraged format. wrl was never intended as an interchange format and is often fraught with problems as a consequence.

  • stl does not support textured colour but would generally be the choice for monochrome models, highly reliable due to its extreme simplicity (albeit inefficiency due to not sharing vertices). It was designed explicitly for rapid prototyping.

  • obj saved models consist of at least three files, sometimes more. These will be a .obj file which contains the mesh geometry, a .mtl file which is a description of the textures, and one or more texture files. Unfortunately, while Shapeways used to support textured .obj files which are semi standard for reconstruction work, they recently removed that capability, disappointing.

  • 3ds will consist of at least 2 files, the geometry file with a .3ds extension, and one or more texture files. PhotoScan can export textures as JPG or png images as required by Shapeways, see the "Export model" dialog options.

  • dae will consist of at least 2 files, the geometry file with a .dae extension, and one or more texture files.

Zip

The preferred formats then are: obj, 3ds and dae. Unfortunately Shapeways has discontinued obj support. At the time of writing Shapeways rejects the 3ds file from PhotoScan, despite every other package tried working fine.

So, only dae left. The last part of the story is how to combine all the assets (geometry file and texture) into one package for Shapeways. Instead of offering multiple file uploads of the assets, pretty simple these days, they insist on a single zip file. Unfortunately it seems Shapeways is a little fussy over what can be in the zip file. Specifically, the zip file that MacOSX creates by selecting files and right clicking isn't accepted, despite every other unzip (and other 3D printing companies) accepting it.

If one is familiar with the command line then this creates a zip file that Shapeways can handle.

   zip slab3.zip slab3.jpg slab3.dae

There are no doubt zip utilities that create zip files acceptable to Shapeways, however iZip does not work, the uploaded zip files seem to crash the Shapeways upload system. Keka does seem to work. YemuZip does seem to work. Others can be tried by the reader ... note that the issue seems to be around other files some zip applications include in the archive, so disabling that in the applications preferences (if possible) is encouraged.


Notes

  • Now that Shapeways offers a scaling feature, going straight from PhotoScan to Shapeways should now be a viable route. Since PhotoScan models can be arbitrary dimensions, in the past it was necessary to scale prior to Shapeways upload.

  • It would be "nice" if Shapeways supported a format that encapsulates all the assets without the need to zip the collection, the obvious choice would be u3d.