Skip to content

Commit

Permalink
Added a relative and absolute simplification tolerance
Browse files Browse the repository at this point in the history
The simplification tolerance is based on the bounding box if using a relative option
  • Loading branch information
drlukeparry committed May 11, 2021
1 parent b6e88ad commit 078cc55
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions pyslm/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,14 +470,16 @@ def getTrimeshSlice(self, z: float) -> trimesh.path.Path2D:
return planarSection

def getVectorSlice(self, z: float, returnCoordPaths: bool = True,
simplificationFactor:bool = None, simplificationPreserveTopology: Optional[bool] = True) -> Any:
simplificationFactor:bool = None, simplificationPreserveTopology: Optional[bool] = True,
simplificationFactorAbsolute = False) -> Any:
"""
The vector slice is created by using `trimesh` to slice the mesh into a polygon
:param z: The slice's z-position
:param returnCoordPaths: If True returns a list of closed paths representing the polygon, otherwise Shapely Polygons
:param simplificationFactor: Simplification factor used for the boundary
:param simplificationPreserveTopology: Preserves the slice's topology when using simplification algorithm
:param simplificationFactorAbsolute: Set `True` to use absolute simplification distance
:return: The vector slice at the given z level
"""
Expand All @@ -490,10 +492,17 @@ def getVectorSlice(self, z: float, returnCoordPaths: bool = True,
polygons = planarSection.polygons_full

if simplificationFactor:

if simplificationFactorAbsolute:
simpFactor = simplificationFactor
else:
maxLen = np.max(planarSection.extents)
simpFactor = simplificationFactor * maxLen

simpPolys = []

for polygon in polygons:
simpPolys.append(polygon.simplify(simplificationFactor, preserve_topology=simplificationPreserveTopology))
simpPolys.append(polygon.simplify(simpFactor, preserve_topology=simplificationPreserveTopology))

polygons = simpPolys

Expand Down

0 comments on commit 078cc55

Please sign in to comment.