Skip to content

Commit

Permalink
Added an option to change order of scanning for contour & hatch vectors
Browse files Browse the repository at this point in the history
  • Loading branch information
drlukeparry committed Apr 10, 2021
1 parent 0f2304f commit 1120ee5
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions pyslm/hatching/hatching.py
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,7 @@ def __init__(self):
super().__init__()

# Contour private attributes
self._scanContourFirst = False
self._numInnerContours = 1
self._numOuterContours = 1
self._spotCompensation = 0.08 # mm
Expand Down Expand Up @@ -759,12 +760,24 @@ def hatchSortMethod(self):
return self._hatchSortMethod

@hatchSortMethod.setter
def hatchSortMethod(self, sortObj):
def hatchSortMethod(self, sortObj: Any):
if not isinstance(sortObj, BaseSort):
raise TypeError("The Hatch Sort Method should be derived from the BaseSort class")

self._hatchSortMethod = sortObj

@property
def scanContourFirst(self) -> bool:
"""
Determines if the contour/border vectors :class:`LayerGeometry` are scanned first before the hatch vectors. By
default this is set to `False`.
"""
return self._scanContourFirst

@scanContourFirst.setter
def scanContourFirst(self, value: bool):
self._scanContourFirst = value

@property
def numInnerContours(self) -> int:
"""
Expand Down Expand Up @@ -818,14 +831,18 @@ def hatch(self, boundaryFeature):
:return: A :class:`Layer` object containing a list of :class:`LayerGeometry` objects generated
"""
if len(boundaryFeature) == 0:
return
return None

layer = Layer(0, 0)
# First generate a boundary with the spot compensation applied

offsetDelta = 0.0
offsetDelta -= self._spotCompensation

# Store all contour layer geometries to before adding at the end of each layer
contourLayerGeometries = []
hatchLayerGeometries = []

for i in range(self._numOuterContours):
offsetDelta -= self._contourOffset
offsetBoundary = self.offsetBoundary(boundaryFeature, offsetDelta)
Expand All @@ -835,7 +852,7 @@ def hatch(self, boundaryFeature):
contourGeometry = ContourGeometry()
contourGeometry.coords = np.array(path)[:, :2]
contourGeometry.subType = "outer"
layer.geometry.append(contourGeometry) # Append to the layer
contourLayerGeometries.append(contourGeometry) # Append to the layer

# Repeat for inner contours
for i in range(self._numInnerContours):
Expand All @@ -848,7 +865,7 @@ def hatch(self, boundaryFeature):
contourGeometry = ContourGeometry()
contourGeometry.coords = np.array(path)[:, :2]
contourGeometry.subType = "inner"
layer.geometry.append(contourGeometry) # Append to the layer
contourLayerGeometries.append(contourGeometry) # Append to the layer

# The final offset is applied to the boundary

Expand Down Expand Up @@ -920,7 +937,6 @@ def hatch(self, boundaryFeature):

scanVectors.append(clippedLines)


if len(clippedLines) > 0:
# Scan vectors have been created for the hatched region

Expand All @@ -929,16 +945,21 @@ def hatch(self, boundaryFeature):

# Only copy the (x,y) points from the coordinate array.
hatchVectors = np.vstack(scanVectors)
hatchVectors = hatchVectors[:, :, :2].reshape(-1, 2)
hatchVectors = hatchVectors[:, :, :2].reshape(-1, 2)

# Note the does not require positional sorting
if self.hatchSortMethod:
hatchVectors = self.hatchSortMethod.sort(hatchVectors)

hatchGeom.coords = hatchVectors
hatchLayerGeometries.append(hatchGeom)

layer.geometry.append(hatchGeom)
if self._scanContourFirst:
layer.geometry.extend(contourLayerGeometries + hatchLayerGeometries)
else:
layer.geometry.extend(hatchLayerGeometries + contourLayerGeometries)

# Append the contours hatch vecotrs
return layer


Expand Down

0 comments on commit 1120ee5

Please sign in to comment.