slice ($Date: 2008/02/05 $)
index
/home/enrique/Desktop/backup/babbleold/script/reprap/pyRepRap_v0.1/slice.py

Slice is a script to slice a GNU Triangulated Surface file.
 
Slice slices a GNU Triangulated Surface file into gcode extrusion layers.  The 'Extrusion Diameter' is the diameter of the extrusion at the
default extruder speed, this is the most important slice preference.  The 'Extrusion Density' is the density of the extruded shape over the
density of the filament.  The 'Extrusion Width Over Thickness' ratio is the ratio of the extrusion width over the layer thickness.  A ratio of
one means the extrusion is a circle, a typical ratio of 1.5 means the extrusion is a wide oval.
 
Rarely changed preferences are Import Coarseness, Mesh Type, Infill Bridge Width Over Thickness & Infill in Direction
of Bridges.  When the triangle mesh has holes in it, slice switches over to a slow algorithm that spans gaps in the mesh.  The higher the
import coarseness, the wider the gaps in the mesh it will span.  An import coarseness of one means it will span gaps the width of the
extrusion.  When the Mesh Type preference is correct, the mesh will be accurately sliced, and if a hole is found, slice will switch over to
the algorithm that spans gaps.  If the Mesh Type preference is Unproven, slice will use the gap spanning algorithm from the start.  The
problem with the gap spanning algothm is that it will span gaps, even if there actually is a gap in the model.  Infill bridge width
over thickness ratio is the ratio of the extrusion width over the layer thickness on a bridge layer.  If the infill in direction of bridges
preference is chosen, the infill will be in the direction of bridges across gaps, so that the fill will be able to span a bridge easier.  To run
slice, in a shell type:
> python slice.py
 
To run slice, install python 2.x on your machine, which is avaliable from http://www.python.org/download/
 
To use the preferences dialog you'll also need Tkinter, which probably came with the python installation.  If it did not, look for it at:
www.tcl.tk/software/tcltk/
 
To export a GNU Triangulated Surface file from Art of Illusion, you can use the Export GNU Triangulated Surface script at:
http://members.axion.net/~enrique/Export%20GNU%20Triangulated%20Surface.bsh
 
To bring it into Art of Illusion, drop it into the folder ArtOfIllusion/Scripts/Tools/.
 
The GNU Triangulated Surface format is supported by Mesh Viewer, and it is described at:
http://gts.sourceforge.net/reference/gts-surfaces.html#GTS-SURFACE-WRITE
 
To turn an STL file into sliced gcode, first import the file using the STL import plugin in the import submenu of the file menu of Art of Illusion.
Then from the Scripts submenu in the Tools menu, choose 'Export GNU Triangulated Surface' and select the imported STL shape.  Click the
'Export Selected' checkbox and click OK.  Then type 'python slice.py' in a shell in the folder which slice is in and when the dialog pops up, set
the parameters.  Then click 'Slice', choose the file which you exported in 'Export GNU Triangulated Surface' and the sliced file will be saved
with the suffix '_slice'.
 
To write documentation for this program, open a shell in the slice.py directory, then type 'pydoc -w slice', then open 'slice.html' in a browser
or click on the '?' button in the dialog.  To use other functions of slice, type 'python' in a shell to run the python interpreter, then type 'import slice'
to import this program.
 
The computation intensive python modules will use psyco if it is available and run about twice as fast.  Psyco is described at:
http://psyco.sourceforge.net/index.html
 
The psyco download page is:
http://psyco.sourceforge.net/download.html
 
The following examples slice the GNU Triangulated Surface file Hollow Square.gts.  The examples are run in a terminal in the folder which
contains Hollow Square.gts and slice.py.  The preferences can be set in the dialog or by changing the preferences file 'slice.csv' with a text editor
or a spreadsheet program set to separate tabs.
 
 
> pydoc -w slice
wrote slice.html
 
 
> python slice.py
This brings up the dialog, after clicking 'Slice', the following is printed:
File Hollow Square.gcode is being sliced.
The sliced file is saved as Hollow Square_slice.gcode
 
 
>python
Python 2.5.1 (r251:54863, Sep 22 2007, 01:43:31)
[GCC 4.2.1 (SUSE Linux)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import slice
>>> slice.main()
File Hollow Square.gts is being sliced.
The sliced file is saved as Hollow Square_slice.gcode
It took 3 seconds to slice the file.
 
 
>>> slice.sliceFile()
File Hollow Square.gcode is being sliced.
The sliced file is saved as Hollow Square_slice.gcode
It took 3 seconds to slice the file.
 
 
>>> slice.getSliceGcode("
54 162 108 Number of Vertices,Number of Edges,Number of Faces
-5.800000000000001 5.341893939393939 4.017841892579603 Vertex Coordinates XYZ
5.800000000000001 5.341893939393939 4.017841892579603
..
many lines of GNU Triangulated Surface vertices, edges and faces
..
")

 
Modules
       
cStringIO
cmath
euclidean
gcodec
intercircle
math
os
preferences
time
vectorwrite

 
Classes
       
Edge
EdgePair
Face
SlicePreferences
SliceSkein
TriangleMesh

 
class Edge
    An edge of a triangle mesh.
 
  Methods defined here:
__init__(self)
Set the face indexes to None.
__repr__(self)
Get the string representation of this Edge.
addFaceIndex(self, faceIndex)
Add first None face index to input face index.
getFromVertexIndices(self, edgeIndex, vertexIndexFirst, vertexIndexSecond)
Initialize from two vertex indices.

 
class EdgePair
     Methods defined here:
__init__(self)
Pair of edges on a face.
__repr__(self)
Get the string representation of this EdgePair.
addPointsAtZ(self, points, radius, vertices, z)
Add points on the segment between the edge intersections with z.
getFromIndexFirstSecond(self, edgeIndexFirst, edgeIndexSecond, edges)
Initialize from edge indices.

 
class Face
    A face of a triangle mesh.
 
  Methods defined here:
__init__(self)
Set the edge indexes to None.
__repr__(self)
Get the string representation of this Face.
getFromEdgeIndices(self, edges, faceIndex, edgeIndexFirst, edgeIndexSecond, edgeIndexThird)
Initialize from edge indices.

 
class SlicePreferences
    A class to handle the slice preferences.
 
  Methods defined here:
__init__(self)
Set the default preferences, execute title & preferences filename.
execute(self)
Slice button has been clicked.

 
class SliceSkein
    A class to slice a GNU Triangulated Surface.
 
  Methods defined here:
__init__(self)
addFromFile(self, filename)
Add lines of text from the filename.
addFromUpperLowerFile(self, filename)
Add lines of text from the filename or the lowercase filename, if there is no file by the original filename in the directory.
addGcodeFromPerimeterPaths(self, loop, loopLists, radius)
Add the perimeter paths to the output.
addGcodeFromRemainingLoop(self, loop, loopLists, radius)
Add the remainder of the loop which does not overlap the alreadyFilledArounds loops.
addGcodeFromThread(self, thread)
Add a thread to the output.
addGcodeMovement(self, point)
Add a movement to the output.
addInitializationToOutput(self)
Add initialization gcode to the output.
addLine(self, line)
Add a line of text and a newline to the output.
addShutdownToOutput(self)
Add shutdown gcode to the output.
addToZoneArray(self, point, zoneArray, z)
Add a height to the zone array.
getBridgeDirection(self, layerLoops)
Get span direction for the majority of the overhanging extrusion perimeter, if any.
getLoopsFromMesh(self, z)
Get loops from a slice of a mesh.
getZAddExtruderPaths(self, z)
Get next z and add extruder loops.
parseGcode(self, slicePreferences, gnuTriangulatedSurfaceText)
Parse gnu triangulated surface text and store the sliced gcode.

 
class TriangleMesh
    A triangle mesh.
 
  Methods defined here:
__init__(self)
Add empty lists.
__repr__(self)
Get the string representation of this StretchedXSegment.
getFromGNUTriangulatedSurfaceText(self, gnuTriangulatedSurfaceText)
Initialize from gnuTriangulatedSurfaceText.

 
Functions
       
addAlreadyFilledArounds(alreadyFilledArounds, loop, radius)
Add already filled loops around loop to alreadyFilledArounds.
addEdgePair(edgePairTable, edges, faceEdgeIndex, remainingEdgeIndex, remainingEdgeTable)
Add edge pair to the edge pair table.
getCommonVertexIndex(edgeFirst, edgeSecond)
Get the vertex index that both edges have in common.
getDoubledRoundZ(overhangingSegment, segmentRoundZ)
Get doubled plane angle around z of the overhanging segment.
getLoopsFromCorrectMesh(edges, faces, vertices, z)
Get loops from a slice of a correct mesh.
getLoopsFromUnprovenMesh(edges, extrusionWidth, faces, vertices, slicePreferences, z)
Get loops from a slice of an unproven mesh.
getLowestZoneIndex(zoneArray, z)
Get the lowest zone index.
getNextEdgeIndexAroundZ(edge, faces, remainingEdgeTable)
Get the next edge index in the mesh slice.
getOverhangDirection(belowOutsetLoops, segmentBegin, segmentEnd)
Add to span direction from the endpoint segments which overhang the layer below.
getPath(edges, pathIndexes, loop, z)
Get the path from the edge intersections.
getPathIndexesAddPath(edges, faces, loops, remainingEdgeTable, vertices, z)
Get the path indexes around a triangle mesh slice and add the path to the loops.
getRemainingEdgeTable(edges, vertices, z)
Get the remaining edge hashtable.
getSegmentsFromPoints(loopLists, pointBegin, pointEnd)
Get enpoint segments from the beginning and end of a line segment.
getSharedFace(firstEdge, faces, secondEdge)
Get the face which is shared by two edges.
getSliceGcode(gnuTriangulatedSurfaceText, slicePreferences=None)
Slice a GNU Triangulated Surface text.
getSliceIntersectionFromEdge(edge, loop, z)
Get the point where the slice intersects the edge.
isCloseToLast(paths, point, radius)
Determine if the point is close to the last point of the last path.
isIntersectingWithinList(loop, loopList)
Determine if the loop is intersecting or is within the loop list.
isIntersectingWithinLists(loop, loopLists)
Determine if the loop is intersecting or is within the loop lists.
isZInEdge(edge, vertices, z)
Determine if z is inside the edge.
main(hashtable=None)
Display the slice dialog.
sliceFile(filename='')
Slice a GNU Triangulated Surface file.  If no filename is specified, slice the first GNU Triangulated Surface file in this folder.

 
Data
        __author__ = 'Enrique Perez (perez_enrique@yahoo.com)'
__date__ = '$Date: 2008/02/05 $'
__license__ = 'GPL 3.0'

 
Author
        Enrique Perez (perez_enrique@yahoo.com)