Part

class pyslm.core.Part(name)

Bases: pyslm.core.DocumentObject

Part represents a solid geometry within the document object tree. Currently, this just represents a single part that will eventually be later sliced as part of a document tree structure.

The part can be transformed and has a position (origin), rotation (rotation) and additional scale factor (scaleFactor), which are collectively applied to the geometry in its local coordinate system \((x,y,z)\). Changing the geometry using setGeometryByMesh() or setGeometry() along with any of the transformation attributes will set the part dirty and forcing the transformation and geometry to be re-computed on the next call in order to obtain the geometry.

The part is currently based off a faceted mesh, internally building on capabilities of the Trimesh packages.

Generally for AM and 3D printing the following function getVectorSlice() is the most useful. This method provides the user with a slice for a given z-plane containing the boundaries consisting of a series of polygons. The output from this function is either a list of closed paths (coordinates) or a list of shapely.geometry.Polygon. A bitmap slice can alternatively be obtained for certain AM process using getBitmapSlice() in similar manner.

Attributes Summary

POLYGON_FIX_EPSILON

Constant value used for repairing invalid/broken polygon regions obtained using getVectorSlice() Default value is equivalent to 1 micron.

boundingBox

The bounding box of the geometry transformed in the global coordinate frame \((X,Y,Z)\).

extents

The extents the geometry transformed in the global coordinate frame \((X,Y,Z)\).

geometry

The geometry of the part with all transformations applied.

origin

The origin or the translation of the part

partType

The Part type.

rotation

The part rotation is a 1x3 array representing the rotations \((\alpha, \beta, \gamma)\) in degrees about X, Y, Z, applied sequentially in that order.

scaleFactor

The scale factor is a 1x3 matrix \((s_x, s_y, s_z)\) representing the scale factor of the part

surfaceArea

Surface area of the part geometry

volume

rtype:

float

Methods Summary

checkGeometry()

rtype:

bool

dropToPlatform([zPos])

Drops the part at a set height (parameter zPos) from its lowest point from the platform (assumed \(z=0\)).

getBitmapSlice(z, resolution[, origin])

Returns a bitmap (binary) image of the slice at position \(z\) position.

getProjectedArea()

The resultant projected area of the part projected on the z-axis.

getProjectedHull([returnPoly])

The convex hull of the part projected in the Z-direction.

getTransform()

Returns the transformation matrix (3x3 numpy matrix) used for the Part consisting of a translation (origin), a rotation and a scaleFactor

getTrimeshSlice(z)

The vector slice is created by using trimesh to slice the mesh into a polygon - returns a shapely polygon.

getVectorSlice(z[, returnCoordPaths, …])

The vector slice is created by using trimesh to slice the mesh into a polygon

isDirty()

When a transformation or the geometry object has been changed via methods in the part, the state is toggled dirty and the transformation matrix must be re-applied to generate a new internal representation of the geometry , which is then cached for future use.

path2DToPathList(shapes)

Returns the list of paths and coordinates from a cross-section (i.e.

regenerate()

Regenerate the geometry

setGeometry(geometry[, fixGeometry, …])

Sets the Part geometry based on a mesh filename.

setGeometryByMesh(mesh)

Sets the Part geometry based on an existing Trimesh object.

Attributes Documentation

POLYGON_FIX_EPSILON = 0.001

Constant value used for repairing invalid/broken polygon regions obtained using getVectorSlice() Default value is equivalent to 1 micron.

boundingBox

The bounding box of the geometry transformed in the global coordinate frame \((X,Y,Z)\). The bounding box is a 1x6 array consisting of the minimum coordinates followed by the maximum coordinates for the corners of the bounding box.

Return type:

ndarray

extents

The extents the geometry transformed in the global coordinate frame \((X,Y,Z)\). The extents is a 1x3 array consisting of the linear dimensions of the part.

Return type:

ndarray

geometry

The geometry of the part with all transformations applied.

Return type:

Trimesh

origin

The origin or the translation of the part

Return type:

ndarray

partType

The Part type. This will be used in future for the document tree.

Return type:

str

rotation

The part rotation is a 1x3 array representing the rotations \((\alpha, \beta, \gamma)\) in degrees about X, Y, Z, applied sequentially in that order.

Return type:

ndarray

scaleFactor

The scale factor is a 1x3 matrix \((s_x, s_y, s_z)\) representing the scale factor of the part

Return type:

ndarray

surfaceArea

Surface area of the part geometry

Return type:

float

volume
Return type:

float

Methods Documentation

checkGeometry()
Return type:

bool

dropToPlatform(zPos=0.0)

Drops the part at a set height (parameter zPos) from its lowest point from the platform (assumed \(z=0\)).

Parameters:

zPos (Optional[float]) – The position the bottom of the part should be suspended above \(z=0\)

Return type:

None

getBitmapSlice(z, resolution, origin=None)

Returns a bitmap (binary) image of the slice at position \(z\) position. The resolution parameter can change the required definition for rasterising the slice layer.

Parameters:
  • z – The z-position to take the slice from

  • resolution – The resolution of the bitmap to generate [pixels/length unit]

  • origin – The offset for (0,0) in the bitmap image - defaults to the bounding box minimum (optional)

Returns:

A bitmap image for the current slice at position

getProjectedArea()

The resultant projected area of the part projected on the z-axis.

Returns:

A Shapely Polygon representing the projected area of the part

getProjectedHull(returnPoly=False)

The convex hull of the part projected in the Z-direction. This is for convenience when trying to find the approximate boundary of the part when used for optimising the layout of parts.

Returns:

The convex hull of the part

getTransform()

Returns the transformation matrix (3x3 numpy matrix) used for the Part consisting of a translation (origin), a rotation and a scaleFactor

Return type:

ndarray

getTrimeshSlice(z)

The vector slice is created by using trimesh to slice the mesh into a polygon - returns a shapely polygon.

Parameters:

z (float) – The slice’s z-position

Return type:

Path2D

Returns:

The vector slice at the given z level

getVectorSlice(z, returnCoordPaths=True, fixPolygons=True, simplificationFactor=None, simplificationPreserveTopology=True, simplificationFactorMode='absolute')

The vector slice is created by using trimesh to slice the mesh into a polygon

Parameters:
  • z (float) – The slice’s z-position

  • returnCoordPaths (bool) – If True returns a list of closed paths representing the polygon, otherwise Shapely Polygons

  • fixPolygons (bool) – Fixes any polygons during slicing by offset by epsilon value

  • simplificationFactor (Optional[float]) – Simplification factor used for the boundary

  • simplificationPreserveTopology (Optional[bool]) – Preserves the slice’s topology when using simplification algorithm

  • simplificationFactorMode (str) – Set mode (‘absolute’, ‘line’) for the simplification tolerance calculation

Return type:

Any

Returns:

The vector slice at the given z level

isDirty()

When a transformation or the geometry object has been changed via methods in the part, the state is toggled dirty and the transformation matrix must be re-applied to generate a new internal representation of the geometry , which is then cached for future use.

Return type:

bool

Returns:

The current state of the geometry

path2DToPathList(shapes)

Returns the list of paths and coordinates from a cross-section (i.e. Trimesh Path2D). This is required to be done for performing boolean operations and offsetting with the internal PyClipper package.

Parameters:

shapes (List[Polygon]) – A list of shapely.geometry.Polygon representing a cross-section or container of closed polygons

Return type:

List[ndarray]

Returns:

A list of paths (Numpy Coordinate Arrays) describing fully closed and oriented paths.

regenerate()

Regenerate the geometry

Return type:

None

setGeometry(geometry, fixGeometry=True, mergeVertices=True)

Sets the Part geometry based on a mesh filename. The mesh must have a compatible file that can be imported via trimesh.

Parameters:
  • geometry (Any) – The geometry (can be a trimesh or filename to load from)

  • fixGeometry (Optional[bool]) – Use Trimesh’s utilities to fix the mesh: Default = True

  • mergeVertices (Optional[bool]) – Merges the vertices of the mesh: Default = True

Return type:

None

setGeometryByMesh(mesh)

Sets the Part geometry based on an existing Trimesh object.

Parameters:

mesh (Trimesh) – The trimesh object loaded

Return type:

None