From b76d9299ce7a33aa302e302209a0f749995ca64c Mon Sep 17 00:00:00 2001 From: Tobias Pankert Date: Tue, 23 Feb 2021 13:03:32 +0100 Subject: [PATCH 1/2] Allow use of a two-dimensional pitch in Path2D.rasterize --- tests/test_raster.py | 12 ++++++++++++ trimesh/path/path.py | 2 +- trimesh/path/raster.py | 6 +++--- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/tests/test_raster.py b/tests/test_raster.py index a47c129a1..3ea4787e0 100644 --- a/tests/test_raster.py +++ b/tests/test_raster.py @@ -34,8 +34,17 @@ def test_rasterize(self): fill=True, width=2.0) + # rasterize with two-dimensional pitch + pitch = p.extents / 600 + filled_2dpitch = p.rasterize(origin=origin, + pitch=pitch, + resolution=resolution, + fill=True, + width=None) + # count the number of filled pixels fill_cnt = g.np.array(filled).sum() + fill_2dpitch_cnt = g.np.array(filled_2dpitch).sum() both_cnt = g.np.array(both).sum() outl_cnt = g.np.array(outline).sum() @@ -45,6 +54,9 @@ def test_rasterize(self): assert both_cnt > outl_cnt # filled+outline should have more than filled assert both_cnt > fill_cnt + # A different pitch results in a different image + assert fill_2dpitch_cnt != fill_cnt + if __name__ == '__main__': diff --git a/trimesh/path/path.py b/trimesh/path/path.py index 9f2a051db..ec3f1c394 100644 --- a/trimesh/path/path.py +++ b/trimesh/path/path.py @@ -1045,7 +1045,7 @@ def rasterize(self, Parameters ------------ - pitch: float, length in model space of a pixel edge + pitch: float or (2,) float, length(s) in model space of pixel edges origin: (2,) float, origin position in model space resolution: (2,) int, resolution in pixel space fill: bool, if True will return closed regions as filled diff --git a/trimesh/path/raster.py b/trimesh/path/raster.py index 9d1c5b9bf..332489173 100644 --- a/trimesh/path/raster.py +++ b/trimesh/path/raster.py @@ -33,8 +33,8 @@ def rasterize(path, ------------ path : Path2D Original geometry - pitch : float - Length in model space of a pixel edge + pitch : float or (2,) float + Length(s) in model space of pixel edges origin : (2,) float Origin position in model space resolution : (2,) int @@ -51,7 +51,7 @@ def rasterize(path, """ # check inputs - pitch = float(pitch) + pitch = np.asanyarray(pitch, dtype=np.float64) origin = np.asanyarray(origin, dtype=np.float64) # if resolution is None make it larger than path From adec7156fce2ac2f01957008c45fa15253418b1c Mon Sep 17 00:00:00 2001 From: Tobias Pankert Date: Tue, 23 Feb 2021 13:27:30 +0100 Subject: [PATCH 2/2] Fix formatting --- tests/test_raster.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_raster.py b/tests/test_raster.py index 3ea4787e0..ce25b77a2 100644 --- a/tests/test_raster.py +++ b/tests/test_raster.py @@ -58,7 +58,6 @@ def test_rasterize(self): assert fill_2dpitch_cnt != fill_cnt - if __name__ == '__main__': g.trimesh.util.attach_to_log() g.unittest.main()