BaseHatcher
- class pyslm.hatching.BaseHatcher
Bases:
ABCThe BaseHatcher class provides common methods used for generating the ‘contour’ and infill ‘hatch’ scan vectors for a geometry slice typically a multi-polygon region.
The class provides an interface to generate a variety of hatching patterns used. The developer should re-implement a subclass and re-define the abstract method,
BaseHatcher.hatch(), which will be called as a minimum. Other behavior can be controlled for the generation of scan vectors includegenerateHatching().The user typically specifies a boundary, which may be offset the boundary of region using
offsetBoundary(). This is typically performed before generating the infill. Following offsetting, then a series of hatch lines are generated usinggenerateHatching()to fill the entire boundary region usingpolygonBoundingBox(). To obtain the final clipped infill, the hatches are clipped usingclipLines()which are clipped in the same sequential order they are generated using a technique explained further in the class method. The generated scan paths should be stored into collections ofLayerGeometryaccordingly.Attributes Summary
The scaling factor used for polygon clipping and offsetting in PyClipr for the decimal component of each polygon coordinate.
Methods Summary
boundaryBoundingBox(boundaries)Returns the bounding box of a list of provided boundaries, typically generated by the tree representation in pyclipr.
clipContourLines(paths, contourPaths)clipLines(paths, lines)clipperToHatchArray(coords)error()Returns the accuracy of the polygon clipping depending on the chosen scale factor.
generateHatching(paths, hatchSpacing[, ...])Generates un-clipped hatches which is guaranteed to cover the entire polygon region base on the maximum extent of the polygon bounding box
hatch(boundaryFeature)The hatch method should be re-implemented by a child class to generate a
Layercontaining the scan vectors used for manufacturing the layer.offsetBoundary(paths, offset)Offsets a single path for a single polygon.
offsetPolygons(polygons, offset)Offsets a set of boundaries across a collection of polygons by the offset distance.
polygonBoundingBox(obj)Returns the bounding box of the polygon - typically this represents a single shape with an exterior and a list of boundaries within an array.
Attributes Documentation
-
CLIPPER_SCALEFACTOR:
int= 100000 The scaling factor used for polygon clipping and offsetting in PyClipr for the decimal component of each polygon coordinate. This should be set to inverse of the required decimal tolerance i.e. 0.01 requires a minimum scale factor of 100. This scaling factor is used in internally in ClipperLib2.
- Note:
From experience, 1e4, mostly works, however, there are some artefacts generated during clipping hatch vectors. Therefore at a small performance cost 1e5 is recommended.
Methods Documentation
- static boundaryBoundingBox(boundaries)
Returns the bounding box of a list of provided boundaries, typically generated by the tree representation in pyclipr. The output of the bounding box takes the form of \(\left(x_{min}, y_{min}, z_{min}, x_{max}, y_{max}, z_{max}\right)\).
- Parameters:
boundaries – A list of polygons
- Return type:
array- Returns:
A \((1 \times 6)\) numpy array of the bounding box
- static clipContourLines(paths, contourPaths)
This function clips a series of (contour paths) across a closed polygon using Pyclipr.
Note
The order is guaranteed from the list of lines used, so these do not require sorting. However, the position may require additional sorting to cater for the user’s requirements.
- Parameters:
paths – The set of boundary paths for trimming the lines
contourPaths (
List[ndarray]) – The un-trimmed complex open paths to be clipped
- Returns:
A list of trimmed lines (open paths)
- static clipLines(paths, lines)
This function clips a series of lines (hatches) across a closed set of polygons using Pyclipr.
Note
The order is guaranteed from the list of lines used, so these do not require sorting usually. However, the position may require additional sorting to cater for the user’s requirements during scanning.
- Parameters:
paths – The set of boundary paths for trimming the lines
lines – The untrimmed lines to clip from the boundary
- Returns:
A list of trimmed lines (open paths)
- static clipperToHatchArray(coords)
A helper method which converts the raw polygon edge lists returned by PyClipr into a numpy array.
- Parameters:
coords (
ndarray) – The list of hatches generated from clipping operations- Return type:
array- Returns:
The hatch coordinates transfromed into a \((n \times 2 \times 3)\) numpy array.
- classmethod error()
Returns the accuracy of the polygon clipping depending on the chosen scale factor.
- Return type:
float
- generateHatching(paths, hatchSpacing, hatchAngle=90.0)
Generates un-clipped hatches which is guaranteed to cover the entire polygon region base on the maximum extent of the polygon bounding box
- Parameters:
paths – The boundary paths for the generated hatch vectors to cover
hatchSpacing (
float) – Hatch spacing to usehatchAngle (
Optional[float]) – Hatch angle (degrees) to rotate the scan vectors
- Return type:
ndarray- Returns:
Returns the list of un-clipped scan vectors
- abstractmethod hatch(boundaryFeature)
The hatch method should be re-implemented by a child class to generate a
Layercontaining the scan vectors used for manufacturing the layer.- Parameters:
boundaryFeature – The collection of boundaries of closed polygons within a layer.
- Raises:
NotImplementedError- Return type:
Optional[Layer]
- static offsetBoundary(paths, offset)
Offsets a single path for a single polygon.
- Parameters:
paths – Closed polygon path list for offsetting
offset (
float) – The offset applied to the poylgon
- Returns:
A list of boundaries offset from the subject
- static offsetPolygons(polygons, offset)
Offsets a set of boundaries across a collection of polygons by the offset distance. A positive offset is the offset applied to the exterior of the polygon, whereas a negative offset is applied to the interior of the boundary.
Note
Note that if any polygons are expanded overlap with adjacent polygons, the offsetting will NOT unify into a single shape.
- Parameters:
polygons – A list of closed polygons which are individually offset from each other.
offset (
float) – The offset distance applied to the polygon
- Returns:
A list of boundaries offset from the subject
- static polygonBoundingBox(obj)
Returns the bounding box of the polygon - typically this represents a single shape with an exterior and a list of boundaries within an array. The output of the bounding box takes the form of \(\left(x_{min}, y_{min}, z_{min}, x_{max}, y_{max}, z_{max}\right)\).
- Parameters:
obj (
Any) – A set of geometries- Return type:
ndarray- Returns:
A \((1 \times 6)\) numpy array representing the bounding box of a polygon
-
CLIPPER_SCALEFACTOR: