Category Archives: Matlab

Preform not (yet) fully compatible with JewelCAD

The challenge

I’ve done some test prints for someone in the jewel industry. They wanted to see the Form1 quality output to maybe use it as a quick prototyping desktop station and get faster development cycles. We discovered that in some conditions JewelCAD is only capable of exporting to STL the positive geometries OR the negative geometries (holes / notch) but not the fused triangle mesh.

The only way to merge both negative and positive geometry is apparently to slice the object and export it as SLC file. This file format was created in 1994 by 3D systems and is now at the second revision. The evolution was mainly to store the data as binary to save space but the content of the file was not changed much.

Preform is unfortunately not capable of reading SLC files nor importing positive and negative bodies to form a finite model. That’s another instance where it would be handy to have the Printer protocol open or at least an API to build our own slicer for the Form1.

Workaround proposals

I can see two ways to solve this challenge:

  1. Use a 3D modeling software to apply the boolean operation
  2. Re-constuct the STL triangle mesh from the SLC slices data

The first option can be done using the free software Blender (see this video tutorial for example). Boolean operations on complex triangles mesh are some time not possible to apply. It’s especially true if the original geometries are not completely clean (holes / inverted triangles…). In the case of my test print, Blender and Netfabb were not able to apply the subtraction.

The picture under is showing that even in a very simple case, subtracting a sphere from a cube in Blender creates a lot of extra triangles. The whole difficulty is to generate precisely the cut/intersection line as explained in this paper by Biermann and Al.

simpleBoolExample

So if the Boolean operation is not possible, we can only regenerate the STL triangles from the SLC data. Provided the original geometry slice thickness was at least the desired print configuration, it should not affect the output quality. Commercial software like SLC2STL or Netfabb seems to be able to perform the conversion but the licenses are expensive for a casual usage (in the $k range).

As the triangle geometry is an interesting algorithm development, I have no option but add it to my TODO list! The first step of this un-slicer is of course to read the SLC data.

Matlab SLC file reader

The SLC format is a simple collection of slices composed of a collection of boundaries. You can read the format specification [here]. Each boundary is a closed polygon (poly-line) defined by a series of [X,Y] vertices with the first point duplicated at the end to close the loop.

I’ve built an viewer in Matlab to explore the content of SLC v2 files. The archive contains 2 example ring slices SLC file. After extracting all the information, the viewer displays a 2 plot window were the user can click on any point in the 3D plot on the right to display the full slice on the left pane.

SLC_view_Ring1

SLC_view_Ring2

The second picture is showing that external (blue) and internal (red) boundaries are drawn in 2 colors. In the SLC format, internal boundaries are stored clockwise while external boundaries are anti-clockwise. Detect reliably the orientation of a poly-line curve is tricky as it must work for concave polygon. The easiest method is to find one point of the convex hull and use a determinant to get the local convexity…

convexPolygonOrientation

concavePolygonOrientation

What’s next?

So while we could dream to have Preform reading the slice directly, it’s probably easier to get one of these software to convert the SLC to STL. This operation is definitely not obvious with many steps to get it working is all circumstances so I probably won’t tackle it anytime soon…

[<<Prev. – Episode 2 : Form1 calibration]    [3D Printer articles]   [Precision VS Accuracy – Next>>]

Impossible Object 3 – Spheroforms Inventor and Matlab versions

July 2013 edit: I finaly printed the spheres see pictures [here]

Here we are back to our Impossible object series, and I promise this is the last time we are going to cover the Reuleaux polygons! Those constant witdth polygons can be extended to 3 dimensions to build non-regular spheres (I.E. spheroforms).

Here is a video of one ‘sphere’ based on a revolve of the Reuleau triangle:

Here is how to build these Reuleaux spheres:

  1. Build half of the Reuleau polygons (see here how), and define the vertical segment as a center line (optional, the revolve command will let you select it anyway). Before closing the sketch, make sure that all the loops are closed with the sketch doctor tool.
    step1
  2. Use full revolve for all the polygons and the circle (you will need to share the sketch). You can now export your spheroforms in STL and print.
    step2

The Inventor file is here, and the STL is here.

These spheroforms are relatively easy to build using Matlab. Here is a parametric script that:

  1. Build the regular polygon
  2. Build the Reuleaux polygon
  3. Rotate it through one axe of symmetry to get the cloud of points
  4. Tessellate and save the result as a STL file

reuleaux_sphere_matlab

Note: The Matlab  scripts are available HERE, Launch it with the start.m script. all code are copyrighted, only usable for non-commercial purpose and provided as is with no guaranty of any sort!

As a final note there are other spheroform like Meissner’s tetrahedron but I’ve covered enough the constant width solids for the moment. Maybe in the future…

[<<Prev. – Non regular Regular Reuleaux]    [3D Printer articles]   [Penrose Triangle – Next>>]

STL geometry file writer

Most of the 3D printer and CAD software are compatible with the STL file format. One of the reason is probably because it’s the least common denominator to describe a 3D geometry tessellation (assembly of triangles files). It can be in ASCII (like a .txt) or, to save some space and accelerate the loading/writing in binary format.

I will concentrate on the binary format as it’s the easiest to handle. The structure of the file is very simple:

  1. A header of 80 character
  2. A number of face/triangle
  3. The list of triangle with:
    • Normal to the surface (optional can be set to 0)
    • 3x Vertex coordinates in space (float32)
    • 1 uin16 for the status (the usage is not normalized, can be used for color or other things)

From the from this description it’s obvious that it’s not very optimized as the normal can be computed from the 3 vertexes and each vertex is stored multiple time for each face in witch is appears. There is also no dimension units it’s just a geometry and the user will have to select before printing if the coordinates are in mm or inches. The usage of the last status bit is not very clear and quite useless.

Everything considered the good thing is it’s very simple to write a STL file. The only caveat is to write the 3 points in the right order to have the normal of the surface pointing outside of the object (uses the write hand rule).

A lot of data can be represented as a color map (the color represent the value of a particular point in the image). So I wanted to be able to transform a map into an printable STL file. The example I will take is a measurement of my hand on a Projected capacitive touch sensor that I find nice. This is the touch technology used in cellphone where each ‘pixel/electrode’ of the image is a touch intensity reading.

handThe matlab writer (zMapToSTL function) is transforming a matrix of value in a block that can be printed. That means a border and some thickness is added under the top surface. One parameter defines the number of interpolation step that needs to be done on the surface data. It is used to smooth the output but generates a lot of extra points (heavy STL).

hand_surface_noInterpGeometry output without Interpolation

The Interpolation parameter makes the number of face grow exponentially and should be used with caution 🙂

  • No Interpolation (0) gives a surface with 10800 triangles and an output STL size of 500kB
  • Interpolation (1) gives a surface with 42000 triangles and an output STL size of 2MB
  • Interpolation (2) gives a surface with 160000 triangles and an output STL size of 8MB

This is a detail of the (nicely) smooth result with interp = 2:

hand_surface_Interp2

The function prototype is:

function zMapToSTL(Zmap, fileName, interpFactor, minThickness, maxThickness, maxWidth)
% Function to convert a Zmap into a STL file + visualisation of the result
% Parameters:
%   - ZMap (compulsory) : Map to represent
%   - fileName (compulsory) : STL file name
%   - interpFactor (default 0) : Interpolation factor of the map (0 = disable)
%  Scaling parameters:
%   - minThickness (default 2) : Minimum thickness of the output solid
%   - maxThickness (default 10) : Maximum thickness of the output solid
%   - maxWidth (default = max dimension of the image) : surface scaling

Note: The Matlab  function and the image are available HERE, all code are copyrighted, only usable for non-commercial purpose and provided as is with no guaranty of any sort,

The resulting STL files are here.

[<<Prev. – TBD]    [3D Printer articles]   [What is a Slicer – Next>>]

Matlab ILD Files Format Reader (laser show animation)

When I started looking at how to find galvanometers for the scanner I quickly realized that my best chance would be to explore the laser show community to learn more about the subject. One of the topic that was coming back often was that the tuning of the “galvos” is an involved operation and to reach a good rendering one has to spend time learning hoe to do it.

Digging a bit more I discovered that the International Laser Display Association (ILDA) has defined a standard exchange format file (ILD extension) to ease the sharing of laser animations between the laserists.The association is closed to the public and most of the freely info available can be found in communities like the photolexicon site forum. The forum is really handy to grasp most of the aspects of laser shows: sample data files, home build setup, configuration and tuning, advices on the hardware…

theRiddle2
One frame decoded with Matlab of “the Riddle” animation found in the Photolexicon site.

On this post I will concentrate on the ILD file format as it’s the main way the galvo movements data, color and blanking information are stored and transmitted. I found the latest ILD file format description that includes all the types of frames commonly used in the wild. The file format is pretty simple and mostly just a collection of coordinates stored with a header. This web page describes graphically all the frame format and also points at a internal feud in the community going on for years.

All comes from the fact that the color information was poorly integrated in the original format so most of the old files rely on some default palette to choose the color of each point. These default palettes are not completely standard and can change with the software implementation. So to solve the issues the ILDA introduced new format (Frame types 4  & 5) that define 24bits full color for each point.

laserboy trueColor
8bit Palette Frame (left) and true color palette on the right (source)

Long story short, I’ve created a ILD file decoder for Matlab with a few examples data files (see at the bottom of the post). I’ve not tested it with Octave but as I’m not using any specific functions it should be pretty much portable. The reader has been optimized to load all the points/colors of a frame with one “fread” call. This enable a very fast decoding (The Riddle file ~20Mb for 5120 images is decoded on my PC in less than 4 seconds).

In an future article I will explore more the galvo tuning principles using the ILDA test patern (available here). The interesting part is that the blue circle is defined outside the square but with a proper tuning is should appears tangent inside the circle. The ILDA used this trick to standardize the dynamic behavior of the scanners mirror servos.

ILDATest               Ilda_c2_proper
The left picture is the content of the ILDA test frame.
The right picture is the proper result expected from a well tuned scanner (source)

Note: All ILD pictures in this post were generated using the Matlab decoding package available HERE, all code are copyrighted, only usable for non-commercial purpose and provided as is with no guaranty of any sort,

[<<Prev. – Scanner Architecture]    [3D Scanner articles]   [First Steps: the galvo & laser – Next>>]