Skip to content
bitli edited this page Aug 17, 2014 · 1 revision

Slicer

While usually the whole GCode generation process is called Slicing, the slicer in MatterSlice is the piece of code that generates layers. Each layer has closed 2D polygons. These polygons are generated in a 2 step process.

  1. All triangles are cut into lines per layer, for each layer a "line segment" is added to that layer.
  2. All these line-segments are connected to each other to make Polygons. The vertex<->face relations of the OptimizedModel help to make this process fast, as there is a huge chance that 2 connecting faces also make 2 connecting line-segments.

This code also fixes up small holes in the 3D model, so your model doesn't need to be perfect Manifold. It also accounts for incorrect normals, so it can flip around line-segments to fit end-to-end.

After the Slicer we have closed Polygons which can be used in Clipper, as Clipper can only operate on closed 2D polygons.

Implementation notes

The Slicer makes all its operations in its constructor, receiving the OptimizedVolume, slice height and options for repairing the model. It calculates the number of levels and allocate all SliceLayer upfront. Then for each face triangle it checks which layers they cresses. For each triangle/layer cross it calculates the SlicerSegment (a line on the z plane of that layer, expressed using Int64 points). Some cross reference between faces and SliceSegment are calculated and the SliceSegments are added to the SliceLayer (in SegmentList).

Then for each layers the Polygons are calculated by the SlicerLayer.MakePolygons(). The algorithms takes a non yet processed SlicerSegment to create a new Polygon, then it looks at the connected faces to find the segments to add and finally add the polygon to the SlicerLayer. The SlicerSegment added to polygons are marked as processed and the algorithm then proceed to the next unprocessed SlicerSegment. If it was not possible to close the polygon, it is added to the openPolygonList.

The openPolygonList is processed to combine polygons with near points (nearer than 2 micron), if successful they are corrected/combined and added to the polygonList. The next pass looks for the remaining openPolygons and try to combine them possibly by reversing the order of one of them. The repair of extensive stitching and repair outline are optional. The small polygons or open polygons are removed (Q: Could we clean the openPolygonList?) finally the polygons are cleaned, that is points very near each other are suppressed.

The SegmentList is not used after this point and is cleared to save memory.

At the end there is a list of polygons for that layer.

Debug and tracing

The number of layers is logged Should have some statistics on the handling of closed polygons. Maybe also on the suppression of points (this may indicate that the model has too detailed areas).

Clone this wiki locally