Part¶
- class pyslm.core.Part(name)¶
Bases:
DocumentObjectPart 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 usingsetGeometryByMesh()orsetGeometry()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 thegeometry.The part is currently based on using a faceted mesh, internally building on capabilities of the Trimesh.
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 ofshapely.geometry.Polygon. A bitmap slice can alternatively be obtained for certain AM process usinggetBitmapSlice()in similar manner.Attributes Summary
Constant value used for repairing invalid/broken polygon regions obtained using
getVectorSlice()Default value is equivalent to 1 micron.The bounding box of the geometry transformed in the global coordinate frame \((X,Y,Z)\).
The extents the geometry transformed in the global coordinate frame \((X,Y,Z)\).
The geometry of the part with the transformations applied.
The origin or the translation of the part
The Part type.
The part rotation is a 1x3 numpy array representing the rotations \((\alpha, \beta, \gamma)\) in degrees about X, Y, Z, applied sequentially in that order.
The scale factor is a 1x3 matrix \((s_x, s_y, s_z)\) representing the scale factor of the part
The total surface area of the part geometry
The volume of the part geometry
Methods Summary
dropToPlatform([zPos])Drops the part at a set height (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.
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.
Returns the transformation matrix (3x3 numpy matrix) used for the
Partconsisting of a translation (origin), arotationand ascaleFactorThe vector slice is created by using trimesh to slice the mesh into a polygon - returns a Path2D object
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. Trimesh Path2D).
Regenerate the geometry
setGeometry(geometry[, fixGeometry, ...])Sets the Part geometry based on either a
trimesh.Trimeshobject or a file path to a mesh that is importable by Trimesh.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 a numpy array consisting of the minimum coordinates followed by the maximum coordinates for the corners of the bounding box.
- extents¶
The extents the geometry transformed in the global coordinate frame \((X,Y,Z)\). The extents is a 1x3 numpy array consisting of the linear Cartesian dimensions of the part.
- geometry¶
The geometry of the part with the transformations applied.
- origin¶
The origin or the translation of the part
- partType¶
The Part type. This will be used in future for the document tree.
- rotation¶
The part rotation is a 1x3 numpy 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¶
The total surface area of the part geometry
- volume¶
The volume of the part geometry
Note
The volume is calculated using the Trimesh volume property therefore the part must be water-tight to obtain correct volumes.
Methods Documentation
- checkGeometry()¶
- Return type:
bool
- dropToPlatform(zPos=0.0)¶
Drops the part at a set height (zPos) from its lowest point from the platform (assumed \(z=0\)).
- Parameters:
zPos (
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 (
float) – The z-position for slicing the meshresolution (
float) – The resolution of the bitmap to generate [pixels/length unit]origin (
Optional[ndarray]) – The offset for (0,0) in the bitmap image - defaults to the bounding box minimum (optional)
- Return type:
ndarray- Returns:
A bitmap image for the current slice at position
- getProjectedArea()¶
The resultant projected area of the part projected on the z-axis.
- Return type:
Polygon- 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.
- Parameters:
returnPoly (
Optional[bool]) – Returns a Shapely Polygon if True otherwise a numpy array of the convex hull vertices- Return type:
Union[Polygon,ndarray]- Returns:
The convex hull of the part
- getTransform()¶
Returns the transformation matrix (3x3 numpy matrix) used for the
Partconsisting of a translation (origin), arotationand ascaleFactor- Return type:
ndarray
- getTrimeshSlice(z)¶
The vector slice is created by using trimesh to slice the mesh into a polygon - returns a Path2D object
- Parameters:
z (
float) – The slice’s z-position- Return type:
Optional[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-positionreturnCoordPaths (
bool) – If True returns a list of closed paths representing the polygon, otherwise Shapely PolygonsfixPolygons (
bool) – Fixes any polygons during slicing by offset by epsilon valuesimplificationFactor (
Optional[float]) – Simplification factor used for the boundarysimplificationPreserveTopology (
bool) – Preserves the slice’s topology when using simplification algorithmsimplificationFactorMode (
str) – Set mode (‘absolute’, ‘line’) for the simplification tolerance calculation
- Return type:
List[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
- static 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 off`setting with the internal PyClipper package.
- Parameters:
shapes (
List[Polygon]) – A list ofshapely.geometry.Polygonrepresenting 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 either a
trimesh.Trimeshobject or a file path to a mesh that is importable by Trimesh.- Parameters:
geometry (
Any) – The geometry (can be a trimesh or filename to load from)fixGeometry (
bool) – Use Trimesh’s utilities to fix the mesh: Default = TruemergeVertices (
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