Option to drop short stitches (#1693)

pull/1702/head
Kaalleen 2022-06-22 15:22:34 +02:00 zatwierdzone przez GitHub
rodzic 75fc4ce869
commit b6bde000fe
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
10 zmienionych plików z 29 dodań i 13 usunięć

Wyświetl plik

@ -18,7 +18,8 @@ def get_stitch_plan():
metadata = g.extension.get_inkstitch_metadata()
collapse_len = metadata['collapse_len_mm']
min_stitch_len = metadata['min_stitch_len_mm']
patches = g.extension.elements_to_stitch_groups(g.extension.elements)
stitch_plan = stitch_groups_to_stitch_plan(patches, collapse_len=collapse_len)
stitch_plan = stitch_groups_to_stitch_plan(patches, collapse_len=collapse_len, min_stitch_len=min_stitch_len)
return jsonify(stitch_plan)

Wyświetl plik

@ -16,7 +16,12 @@ class EmbroiderSettings(InkstitchExtension):
action="store", type=float,
dest="collapse_length_mm", default=3.0,
help="max collapse length (mm)")
self.arg_parser.add_argument("-l", "--min_stitch_len_mm",
action="store", type=float,
dest="min_stitch_len_mm", default=0,
help="minimum stitch length (mm)")
def effect(self):
self.metadata = self.get_inkstitch_metadata()
self.metadata['collapse_len_mm'] = self.options.collapse_length_mm
self.metadata['min_stitch_len_mm'] = self.options.min_stitch_len_mm

Wyświetl plik

@ -73,7 +73,7 @@ class GeneratePalette(InkstitchExtension):
else:
number = 0
name = ' '.join(color_name)
color = "\n%s\t%s\t%s\t%s %s" % (str(color[0]).rjust(3), str(color[1]).rjust(3), str(color[2]).rjust(3), name.rjust(30), number)
color = "\n%s\t%s\t%s\t%s %s" % (str(color[0]).rjust(3), str(color[1]).rjust(3), str(color[2]).rjust(3), name.rjust(30), number)
colors.append(color)
return colors

Wyświetl plik

@ -52,8 +52,10 @@ class Output(InkstitchExtension):
self.metadata = self.get_inkstitch_metadata()
collapse_len = self.metadata['collapse_len_mm']
min_stitch_len = self.metadata['min_stitch_len_mm']
patches = self.elements_to_stitch_groups(self.elements)
stitch_plan = stitch_groups_to_stitch_plan(patches, collapse_len=collapse_len, disable_ties=self.settings.get('laser_mode', False))
stitch_plan = stitch_groups_to_stitch_plan(patches, collapse_len=collapse_len, disable_ties=self.settings.get('laser_mode', False),
min_stitch_len=min_stitch_len)
temp_file = tempfile.NamedTemporaryFile(suffix=".%s" % self.file_extension, delete=False)

Wyświetl plik

@ -308,8 +308,9 @@ class Print(InkstitchExtension):
self.metadata = self.get_inkstitch_metadata()
collapse_len = self.metadata['collapse_len_mm']
min_stitch_len = self.metadata['min_stitch_len_mm']
patches = self.elements_to_stitch_groups(self.elements)
stitch_plan = stitch_groups_to_stitch_plan(patches, collapse_len=collapse_len)
stitch_plan = stitch_groups_to_stitch_plan(patches, collapse_len=collapse_len, min_stitch_len=min_stitch_len)
palette = ThreadCatalog().match_and_apply_palette(stitch_plan, self.get_inkstitch_metadata()['thread-palette'])
overview_svg, color_block_svgs = self.render_svgs(stitch_plan, realistic=False)

Wyświetl plik

@ -35,8 +35,9 @@ class StitchPlanPreview(InkstitchExtension):
visual_commands = True
self.metadata = self.get_inkstitch_metadata()
collapse_len = self.metadata['collapse_len_mm']
min_stitch_len = self.metadata['min_stitch_len_mm']
patches = self.elements_to_stitch_groups(self.elements)
stitch_plan = stitch_groups_to_stitch_plan(patches, collapse_len=collapse_len)
stitch_plan = stitch_groups_to_stitch_plan(patches, collapse_len=collapse_len, min_stitch_len=min_stitch_len)
render_stitch_plan(svg, stitch_plan, realistic, visual_commands)
# apply options

Wyświetl plik

@ -43,8 +43,9 @@ class Zip(InkstitchExtension):
self.metadata = self.get_inkstitch_metadata()
collapse_len = self.metadata['collapse_len_mm']
min_stitch_len = self.metadata['min_stitch_len_mm']
patches = self.elements_to_stitch_groups(self.elements)
stitch_plan = stitch_groups_to_stitch_plan(patches, collapse_len=collapse_len)
stitch_plan = stitch_groups_to_stitch_plan(patches, collapse_len=collapse_len, min_stitch_len=min_stitch_len)
base_file_name = self.get_base_file_name()
path = tempfile.mkdtemp()

Wyświetl plik

@ -98,19 +98,21 @@ class ColorBlock(object):
return False
def filter_duplicate_stitches(self):
def filter_duplicate_stitches(self, min_stitch_len=0.1):
if not self.stitches:
return
stitches = [self.stitches[0]]
if min_stitch_len is None:
min_stitch_len = 0.1
stitches = [self.stitches[0]]
for stitch in self.stitches[1:]:
if stitches[-1].jump or stitch.stop or stitch.trim or stitch.color_change:
# Don't consider jumps, stops, color changes, or trims as candidates for filtering
pass
else:
length = (stitch - stitches[-1]).length()
if length <= 0.1 * PIXELS_PER_MM:
if length <= min_stitch_len * PIXELS_PER_MM:
# duplicate stitch, skip this one
continue

Wyświetl plik

@ -13,7 +13,7 @@ from .color_block import ColorBlock
from .ties import add_ties
def stitch_groups_to_stitch_plan(stitch_groups, collapse_len=None, disable_ties=False): # noqa: C901
def stitch_groups_to_stitch_plan(stitch_groups, collapse_len=None, min_stitch_len=0.1, disable_ties=False): # noqa: C901
"""Convert a collection of StitchGroups to a StitchPlan.
@ -71,7 +71,7 @@ def stitch_groups_to_stitch_plan(stitch_groups, collapse_len=None, disable_ties=
# last block ended in a stop, so now we have an empty block
del stitch_plan.color_blocks[-1]
stitch_plan.filter_duplicate_stitches()
stitch_plan.filter_duplicate_stitches(min_stitch_len)
if not disable_ties:
stitch_plan.add_ties()
@ -101,9 +101,9 @@ class StitchPlan(object):
def add_color_block(self, color_block):
self.color_blocks.append(color_block)
def filter_duplicate_stitches(self):
def filter_duplicate_stitches(self, min_stitch_len):
for color_block in self:
color_block.filter_duplicate_stitches()
color_block.filter_duplicate_stitches(min_stitch_len)
def add_ties(self):
# see ties.py

Wyświetl plik

@ -15,6 +15,9 @@
<param name="collapse_len_mm" type="float" precision="1" min="0" max="10"
gui-text="Collapse length (mm)"
gui-description="Jump stitches smaller than this will be treated as normal stitches.">3</param>
<param name="min_stitch_len_mm" type="float" precision="1" min="0" max="10"
gui-text="Minimal stitch length (mm)"
gui-description="Drop stitches smaller than this value.">0.1</param>
<script>
{{ command_tag | safe }}
</script>