From 029169eb2152978eb92ab3605835641dddcda1fc Mon Sep 17 00:00:00 2001 From: Mario Voigt Date: Sat, 24 Apr 2021 13:00:24 +0200 Subject: [PATCH] added transform fix into imagetracer.js --- .../cutoptim/Debug_CutOptim.txt | 60 ------------------- .../imagetracer.js/imagetracerjs.py | 19 +++--- 2 files changed, 11 insertions(+), 68 deletions(-) delete mode 100644 extensions/fablabchemnitz/cutoptim/Debug_CutOptim.txt diff --git a/extensions/fablabchemnitz/cutoptim/Debug_CutOptim.txt b/extensions/fablabchemnitz/cutoptim/Debug_CutOptim.txt deleted file mode 100644 index f50a5465..00000000 --- a/extensions/fablabchemnitz/cutoptim/Debug_CutOptim.txt +++ /dev/null @@ -1,60 +0,0 @@ -Entering TransformPaths -Shape 0 id:path1141 Stroke[1 000000] width:0.264583 -Shape 1 id:path1141-8 Stroke[1 000000] width:0.264583 -Shape 2 id:path1141-9 Stroke[1 000000] width:0.264583 -Shape 3 id:path1141-0 Stroke[1 000000] width:0.264583 -Transform paths pass 2 : checking if paths are included in other ones -End of Transform paths ----------------- Entering EnlargePaths, elapsed time: 3ms ----------------- Exit EnlargePaths, elapsed time: 3ms - - ----------------- Entering BreakLongerEdges, elapsed time: 3ms ----------------- Exit BreakLongerEdges, elapsed time: 3ms - - --------- BuilSingleListPath : There are 4 paths in the list - Path 0 id: path1141-8_0 area 2004.46mm2 and 0 children - Path 1 id: path1141-9_0 area 2004.46mm2 and 0 children - Path 2 id: path1141_0 area 2004.46mm2 and 0 children - Path 3 id: path1141-0_0 area 2004.46mm2 and 0 children ------------ End of BuilSingleListPath --------------------------- - - -Time: 3.000000ms Enter Optimize with Optimizing level set to 5 ------ Placing first polygon (path1141-8_0) ----------- -Entering PlaceFirst... -First polygon placed with rotation 0.000000° and translation (3.280817,0.000000) --------------------- Placing Polygon (Free rotation)1: path1141-9_0 ------------------------------ -Elapsed time 0.000000ms, for last polygon 0.000000ms -Level 1: Applying best move : (-97.181078,-42.337603)/180.000000° to polygon 3 will place vertex 2 on vertex 1 of polygon 2 - new hull with 5 vertices, area 8034.754228 Fixed polygon area 8017.823036 - LargeConvexHull area :8034.754228 Cost= 8034.754228 - CurFloating.Size=0 -Level 2: Applying best move : (1.434374,-9.167470)/0.000000° to polygon 2 will place vertex 3 on vertex 0 of polygon 1 - new hull with 6 vertices, area 6021.832982 Fixed polygon area 6013.367409 - LargeConvexHull area :6021.832982 Cost= 8034.754228 - CurFloating.Size=1 - Element 1: Translation=(-97.181078,-42.337603) rot=180.000000 Hull area=8034.754228 -Level 3: Applying best move : (-102.821809,-27.175084)/180.000000° to polygon 1 will place vertex 2 on vertex 1 of polygon 0 - new hull with 4 vertices, area 4017.377123 Fixed polygon area 4008.911749 - LargeConvexHull area :4017.377123 Cost= 8034.754228 - CurFloating.Size=2 - Element 1: Translation=(1.434374,-9.167470) rot=0.000000 Hull area=6021.832982 - Element 2: Translation=(-97.181078,-42.337603) rot=180.000000 Hull area=8034.754228 --------------------- Placing Polygon (Free rotation)2: path1141_0 ------------------------------ -Elapsed time 2.000000ms, for last polygon 2.000000ms -###### Unable to place polygon 2, aborting --------------------- Placing Polygon (Free rotation)3: path1141-0_0 ------------------------------ -Elapsed time 3.000000ms, for last polygon 1.000000ms -###### Unable to place polygon 3, aborting -Optimization finished, elapsed time 0.003000s -nbRotation: 226 -nbTranslation: 226 -nbPointInPoly: 622 -nbIntersectPoly: 57 -nbPlacementImpossible: 207 -nbCheckAngles=392 -CacheMiss=392 -CacheHit OK=0 -CacheHit KO=1272 diff --git a/extensions/fablabchemnitz/imagetracer.js/imagetracerjs.py b/extensions/fablabchemnitz/imagetracer.js/imagetracerjs.py index 3a37dfeb..1496d706 100644 --- a/extensions/fablabchemnitz/imagetracer.js/imagetracerjs.py +++ b/extensions/fablabchemnitz/imagetracer.js/imagetracerjs.py @@ -17,17 +17,11 @@ Features Author: Mario Voigt / FabLab Chemnitz Mail: mario.voigt@stadtfabrikanten.org Date: 18.08.2020 -Last patch: 23.04.2021 +Last patch: 24.04.2021 License: GNU GPL v3 Used version of imagetracerjs: https://github.com/jankovicsandras/imagetracerjs/commit/4d0f429efbb936db1a43db80815007a2cb113b34 -ToDo: - - fix resizing if one or all of the following sizes are zero: - img_w = image.get('width') - img_h = image.get('height') - img_x = image.get('x') - img_y = image.get('y') """ class Imagetracerjs (inkex.EffectExtension): @@ -162,15 +156,24 @@ class Imagetracerjs (inkex.EffectExtension): trace_width = viewBox.split(' ')[2] trace_height = viewBox.split(' ')[3] + # add transformation to fit previous XY coordinates and width/height img_w = image.get('width') img_h = image.get('height') img_x = image.get('x') img_y = image.get('y') - if img_w is not None and img_h is not None and img_x is not None and img_y is not None: transform = "matrix({:1.6f}, 0, 0, {:1.6f}, {:1.6f}, {:1.6f})"\ .format(float(img_w) / float(trace_width), float(img_h) / float(trace_height), float(img_x), float(img_y)) newGroup.attrib['transform'] = transform + else: + t = image.composed_transform() + img_w = t.a + img_h = t.d + img_x = t.e + img_y = t.f + transform = "matrix({:1.6f}, 0, 0, {:1.6f}, {:1.6f}, {:1.6f})"\ + .format(float(img_w) / float(trace_width), float(img_h) / float(trace_height), float(img_x), float(img_y)) + newGroup.attrib['transform'] = transform for child in doc.getchildren(): newGroup.append(child)