Skip to content

Commit

Permalink
Updated examples
Browse files Browse the repository at this point in the history
  • Loading branch information
drlukeparry committed Apr 6, 2022
1 parent 8b9ccfb commit 639e042
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 43 deletions.
19 changes: 10 additions & 9 deletions examples/example.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
"""
A simple example showing how t use PySLM for generating a Stripe Scan Strategy across a single layer.
A simple example showing how to use PySLM for generating a Stripe Scan Strategy across a single layer.
"""
import numpy as np
import pyslm
import pyslm.analysis.utils as analysis
import pyslm.visualise
import pyslm.analysis
from pyslm import hatching as hatching

# Imports the part and sets the geometry to an STL file (frameGuide.stl)
Expand All @@ -24,7 +25,7 @@
# Set te slice layer position
z = 1.0

# Create a BasicIslandHatcher object for performing any hatching operations (
# Create a BasicIslandHatcher object for performing any hatching operations
myHatcher = hatching.BasicIslandHatcher()
myHatcher.islandWidth = 3.0
myHatcher.stripeWidth = 5.0
Expand Down Expand Up @@ -72,8 +73,9 @@

bstyle = pyslm.geometry.BuildStyle()
bstyle.bid = 1
bstyle.laserSpeed = 200 # [mm/s]
bstyle.laserPower = 200 # [W]
bstyle.laserSpeed = 200 # [mm/s]
bstyle.laserPower = 200 # [W]
bstyle.jumpSpeed = 5000 # [mm/s]

model = pyslm.geometry.Model()
model.mid = 1
Expand All @@ -83,7 +85,6 @@
Analyse the layers using the analysis module. The path distance and the estimate time taken to scan the layer can be
predicted.
"""
print('Total Path Distance: {:.1f} mm'.format(analysis.getLayerPathLength(layer)))
print('Total jump distance {:.1f} mm'.format(analysis.getLayerJumpLength(layer)))
print('Time taken {:.1f} s'.format(analysis.getLayerTime(layer, model)) )

print('Total Path Distance: {:.1f} mm'.format(pyslm.analysis.getLayerPathLength(layer)))
print('Total jump distance {:.1f} mm'.format(pyslm.analysis.getLayerJumpLength(layer)))
print('Time taken {:.1f} s'.format(pyslm.analysis.getLayerTime(layer, [model])) )
16 changes: 8 additions & 8 deletions examples/example_build_time_analysis.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""
A simple example showing how to use PySLM for calculating the build time estimate.
THis example takes advantage of the multi-processing module to run across more threads.
This example takes advantage of the multi-processing module to run across more threads.
"""

import pyslm
import shapely
from pyslm import hatching as hatching
Expand All @@ -17,9 +18,9 @@
"""
layerThickness = 0.03 # [mm]
rotation = [60, 0.0, 45]
layerRecoatTime = 30 # [s]
contourLaserScanSpeed = 250 # [mm/s]
hatchLaserScanSpeed = 1000 # [mm/s]
layerRecoatTime = 30.0 # [s]
contourLaserScanSpeed = 250.0 # [mm/s]
hatchLaserScanSpeed = 1000.0 # [mm/s]
eos_m280_alsi10mg_brate = 4.8*3600/1000 # [cm3/hr]
hatchDistance = 0.16
numCountourOffsets = 1
Expand All @@ -34,7 +35,7 @@ def calculateLayer(input):

# Slice the boundary
geomSlice = solidPart.getVectorSlice(zid*layerThickness, returnCoordPaths=False)
#print(geomSlice)

if len(geomSlice) > 0:
return geomSlice
else:
Expand All @@ -52,7 +53,6 @@ def main():
solidPart.scaleFactor = 1.0
solidPart.rotation = rotation
solidPart.dropToPlatform()
print(solidPart.boundingBox)

# Create the multi-threaded map function using the Python multiprocessing library
layers = []
Expand Down Expand Up @@ -80,7 +80,7 @@ def main():
layers = p.map(calculateLayer, processList)
p.close()

print('\t Multiprocessing time', time.time() - startTime)
print('\t Multiprocessing time {:.1f}'.format(time.time() - startTime))
print('Slicing Finished')

polys = []
Expand Down Expand Up @@ -134,7 +134,7 @@ def main():
approxScanTime = solidPart.volume/(hatchDistance * hatchLaserScanSpeed * layerThickness) + solidPart.surfaceArea / (contourLaserScanSpeed*layerThickness)
approxProjectedScanTime = solidPart.volume / (hatchDistance * hatchLaserScanSpeed * layerThickness) + projectedArea / (
contourLaserScanSpeed * layerThickness)
print('\tApprox scan time *surface) {:.2f} hr'.format(approxScanTime/3600))
print('\tApprox scan time (surface) {:.2f} hr'.format(approxScanTime/3600))
print('\tApprox scan time (using projected area): {:.2f} hr'.format(approxProjectedScanTime/3600))


Expand Down
13 changes: 3 additions & 10 deletions examples/example_custom_island_hatcher.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
A simple example showing how to use PySLM with the IslandHatcher approach, which decomposes the layer into several
A simple example showing how to use PySLM with the IslandHatcher approach, which decomposes the layer into several
island regions, which are tested for intersection and then the hatches generated are more efficiently clipped.
"""

Expand Down Expand Up @@ -60,7 +60,6 @@ def localBoundary(self) -> np.ndarray:

return HexIsland._boundary


def generateInternalHatch(self, isOdd = True) -> np.ndarray:
"""
Generates a set of hatches orthogonal to the island's coordinate system :math:`(x\\prime, y\\prime)`.
Expand Down Expand Up @@ -117,8 +116,6 @@ def generateInternalHatch(self, isOdd = True) -> np.ndarray:
return coordsUp




class HexIslandHatcher(hatching.IslandHatcher):

def __init__(self):
Expand All @@ -137,7 +134,6 @@ def generateIslands(self, paths, hatchAngle: float = 90.0):
# Get the bounding box of the boundary
bbox = self.boundaryBoundingBox(paths)

print('bounding box bbox', bbox)
# Expand the bounding box
bboxCentre = np.mean(bbox.reshape(2, 2), axis=0)

Expand All @@ -160,15 +156,14 @@ def generateIslands(self, paths, hatchAngle: float = 90.0):
islands = []
id = 0

print('island width', self._islandWidth)

print('Island width:', self._islandWidth)

for i in np.arange(0, numIslandsX):
for j in np.arange(0, numIslandsY):

# gGenerate the island position
startX = -bboxRadius + i * self._islandWidth + np.mod(j, 2) * self._islandWidth / 2
startY = -bboxRadius + j * (self._islandWidth) * np.sin(2*np.pi/numPoints)
startY = -bboxRadius + j * self._islandWidth * np.sin(2*np.pi/numPoints)

pos = np.array([(startX, startY)])

Expand All @@ -190,7 +185,6 @@ def generateIslands(self, paths, hatchAngle: float = 90.0):
return islands



# Imports the part and sets the geometry to an STL file (frameGuide.stl)
solidPart = pyslm.Part('inversePyramid')
solidPart.setGeometry('../models/frameGuide.stl')
Expand All @@ -200,7 +194,6 @@ def generateIslands(self, paths, hatchAngle: float = 90.0):
solidPart.origin[1] = 2.5
solidPart.scaleFactor = 2.0
solidPart.rotation = [0, 0.0, np.pi]
print(solidPart.boundingBox)

# Set te slice layer position
z = 14.99
Expand Down
12 changes: 4 additions & 8 deletions examples/example_custom_sinusoidal_hatching.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
solidPart.rotation = np.array([0, 0, 30])
solidPart.dropToPlatform()

print(solidPart.boundingBox)

class WavyHatcher(pyslm.hatching.Hatcher):

Expand Down Expand Up @@ -153,8 +152,6 @@ def hatch(self, boundaryFeature):

layer.geometry.append(contourGeom)



else:
# Iterate through each closed polygon region in the slice. The currently individually sliced.
for contour in curBoundary:
Expand Down Expand Up @@ -189,7 +186,6 @@ def hatch(self, boundaryFeature):

scanVectors.append(clippedLines)


return layer

def generateHatching(self, paths, hatchSpacing: float, hatchAngle: Optional[float] = 90.0) -> np.ndarray:
Expand Down Expand Up @@ -296,7 +292,6 @@ def generateHatching(self, paths, hatchSpacing: float, hatchAngle: Optional[floa
geomSlice = solidPart.getVectorSlice(z, simplificationFactor=0.1)
layer = myHatcher.hatch(geomSlice)


"""
Plot the layer geometries using matplotlib
The order of scanning for the hatch region can be displayed by setting the parameter (plotOrderLine=True)
Expand All @@ -318,8 +313,9 @@ def generateHatching(self, paths, hatchSpacing: float, hatchAngle: Optional[floa

bstyle = pyslm.geometry.BuildStyle()
bstyle.bid = 1
bstyle.laserSpeed = 200 # [mm/s]
bstyle.laserPower = 200 # [W]
bstyle.laserSpeed = 200 # [mm/s]
bstyle.laserPower = 200 # [W]
bstyle.jumpSpeed = 5000 # [mm/s]

model = pyslm.geometry.Model()
model.mid = 1
Expand All @@ -331,5 +327,5 @@ def generateHatching(self, paths, hatchSpacing: float, hatchAngle: Optional[floa
"""
print('Total Path Distance: {:.1f} mm'.format(pyslm.analysis.getLayerPathLength(layer)))
print('Total jump distance {:.1f} mm'.format(pyslm.analysis.getLayerJumpLength(layer)))
print('Time taken {:.1f} s'.format(pyslm.analysis.getLayerTime(layer, [model])) )
print('Time taken {:.1f} s'.format(pyslm.analysis.getLayerTime(layer, [model])))

4 changes: 2 additions & 2 deletions examples/example_exporting.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
# Depending on the file format the version should be provided as a tuple
header.version = (1,2)

# The zUnit is the uniform layer thickness as an integer unit in microns
# The zUnit is the uniform layer thickness as an integer unit in microns. Normally should be set to 1000
header.zUnit = 1000 # μm

"""
Expand Down Expand Up @@ -106,7 +106,7 @@
"""
from libSLM import mtt

"Create the initial object"
"Create the initial MTT Writer Object and set the filename"
mttWriter = mtt.Writer()
mttWriter.setFilePath("build.mtt")
mttWriter.write(header, models, layers)
Expand Down
8 changes: 3 additions & 5 deletions examples/example_heatmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
solidPart.rotation = np.array([0, 0, 30])
solidPart.dropToPlatform()

print(solidPart.boundingBox)

# Set te slice layer position
z = 23.

Expand Down Expand Up @@ -54,9 +52,9 @@
bstyle = pyslm.geometry.BuildStyle()
bstyle.bid = 1
bstyle.laserSpeed = 200.0 # [mm/s]
bstyle.laserPower = 200 # [W]#
bstyle.pointDistance = 60 # (60 microns)
bstyle.pointExposureTime = 30 #
bstyle.laserPower = 200 # [W]
bstyle.pointDistance = 60 # [μm]
bstyle.pointExposureTime = 30 # [μs]

model = pyslm.geometry.Model()
model.mid = 1
Expand Down
2 changes: 1 addition & 1 deletion examples/example_laser_iterator.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
A simple example showing how to use PySLM for generating slices across a 3D model
A simple example showing how to iterate across a part using the analysis.Iterator classes
"""
import numpy as np
import pyslm
Expand Down

0 comments on commit 639e042

Please sign in to comment.