diff --git a/.idea/workspace.xml b/.idea/workspace.xml index a80e1db..897bb25 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -3,7 +3,29 @@ + + + + + + + + + + + + + + + + + + + + + + - + - - + + @@ -94,8 +116,8 @@ - - + + @@ -126,6 +148,23 @@ + + + + + + + + + + + + + + + + + @@ -137,7 +176,6 @@ - 512 TYPE_JUMP getCoordinate PECColors @@ -167,6 +205,7 @@ slope closest mode + JUMP @@ -188,8 +227,8 @@ @@ -423,12 +462,12 @@ - + - + @@ -574,21 +613,6 @@ - - - - - - - - - - - - - - - @@ -664,20 +688,35 @@ - - + + - - + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/DATA/Results/1.5w.jpg b/DATA/Results/1.5w.jpg new file mode 100644 index 0000000..d88cac4 Binary files /dev/null and b/DATA/Results/1.5w.jpg differ diff --git a/DATA/Results/1.5w_20m.jpg b/DATA/Results/1.5w_20m.jpg new file mode 100644 index 0000000..5aedf60 Binary files /dev/null and b/DATA/Results/1.5w_20m.jpg differ diff --git a/DATA/Results/10m.jpg b/DATA/Results/10m.jpg new file mode 100644 index 0000000..a1babdd Binary files /dev/null and b/DATA/Results/10m.jpg differ diff --git a/DATA/Results/15m.jpg b/DATA/Results/15m.jpg new file mode 100644 index 0000000..f8f1dc1 Binary files /dev/null and b/DATA/Results/15m.jpg differ diff --git a/DATA/Results/2.5w.jpg b/DATA/Results/2.5w.jpg new file mode 100644 index 0000000..3bce26f Binary files /dev/null and b/DATA/Results/2.5w.jpg differ diff --git a/DATA/Results/20m.jpg b/DATA/Results/20m.jpg new file mode 100644 index 0000000..8d707ac Binary files /dev/null and b/DATA/Results/20m.jpg differ diff --git a/DATA/Results/3.5w.jpg b/DATA/Results/3.5w.jpg new file mode 100644 index 0000000..5cf431b Binary files /dev/null and b/DATA/Results/3.5w.jpg differ diff --git a/DATA/Results/4.5w.jpg b/DATA/Results/4.5w.jpg new file mode 100644 index 0000000..1eebe46 Binary files /dev/null and b/DATA/Results/4.5w.jpg differ diff --git a/DATA/Results/5m.jpg b/DATA/Results/5m.jpg new file mode 100644 index 0000000..ae8b5cd Binary files /dev/null and b/DATA/Results/5m.jpg differ diff --git a/DATA/Results/StitchModeZigzag_w2.5_d20.jpeg b/DATA/Results/StitchModeZigzag_w2.5_d20.jpeg new file mode 100644 index 0000000..c2e8271 Binary files /dev/null and b/DATA/Results/StitchModeZigzag_w2.5_d20.jpeg differ diff --git a/DATA/Results/apple.JPG b/DATA/Results/apple.JPG new file mode 100644 index 0000000..9625198 Binary files /dev/null and b/DATA/Results/apple.JPG differ diff --git a/DATA/Results/droplet.JPG b/DATA/Results/droplet.JPG new file mode 100644 index 0000000..451d697 Binary files /dev/null and b/DATA/Results/droplet.JPG differ diff --git a/DATA/Results/methodClosest.jpg b/DATA/Results/methodClosest.jpg new file mode 100644 index 0000000..2f14086 Binary files /dev/null and b/DATA/Results/methodClosest.jpg differ diff --git a/DATA/Results/tree.JPG b/DATA/Results/tree.JPG new file mode 100644 index 0000000..22b5223 Binary files /dev/null and b/DATA/Results/tree.JPG differ diff --git a/DATA/Results/zigzag.JPG b/DATA/Results/zigzag.JPG new file mode 100644 index 0000000..82774d0 Binary files /dev/null and b/DATA/Results/zigzag.JPG differ diff --git a/DATA/TestOutput/debugPicturesimplePath.png b/DATA/TestOutput/debugPicturesimplePath.png index 86bb352..93fb591 100644 Binary files a/DATA/TestOutput/debugPicturesimplePath.png and b/DATA/TestOutput/debugPicturesimplePath.png differ diff --git a/DATA/TestOutput/debugPicturesimplePathClosest.png b/DATA/TestOutput/debugPicturesimplePathClosest.png index 86bb352..2730e85 100644 Binary files a/DATA/TestOutput/debugPicturesimplePathClosest.png and b/DATA/TestOutput/debugPicturesimplePathClosest.png differ diff --git a/DATA/TestOutput/debugPicturesimplePathZigzag.png b/DATA/TestOutput/debugPicturesimplePathZigzag.png index 7834331..91a5906 100644 Binary files a/DATA/TestOutput/debugPicturesimplePathZigzag.png and b/DATA/TestOutput/debugPicturesimplePathZigzag.png differ diff --git a/DATA/TestOutput/debugPicturetree.png b/DATA/TestOutput/debugPicturetree.png index 1879f62..60b5a47 100644 Binary files a/DATA/TestOutput/debugPicturetree.png and b/DATA/TestOutput/debugPicturetree.png differ diff --git a/DATA/TestOutput/debugPictureugliestApple.png b/DATA/TestOutput/debugPictureugliestApple.png index 006d2f1..1bc7118 100644 Binary files a/DATA/TestOutput/debugPictureugliestApple.png and b/DATA/TestOutput/debugPictureugliestApple.png differ diff --git a/DATA/TestOutput/debugPicturezigzag.png b/DATA/TestOutput/debugPicturezigzag.png index dad4366..d8bd723 100644 Binary files a/DATA/TestOutput/debugPicturezigzag.png and b/DATA/TestOutput/debugPicturezigzag.png differ diff --git a/DATA/TestOutput/simplePath.pes b/DATA/TestOutput/simplePath.pes index 417dae8..7536e62 100644 Binary files a/DATA/TestOutput/simplePath.pes and b/DATA/TestOutput/simplePath.pes differ diff --git a/DATA/TestOutput/simplePathClosest.pes b/DATA/TestOutput/simplePathClosest.pes index e3da306..e4320e5 100644 Binary files a/DATA/TestOutput/simplePathClosest.pes and b/DATA/TestOutput/simplePathClosest.pes differ diff --git a/DATA/TestOutput/simplePathD-10.pes b/DATA/TestOutput/simplePathD-10.pes index 79f5b2d..f7adcc3 100644 Binary files a/DATA/TestOutput/simplePathD-10.pes and b/DATA/TestOutput/simplePathD-10.pes differ diff --git a/DATA/TestOutput/simplePathD-15.pes b/DATA/TestOutput/simplePathD-15.pes index f64ae67..6da6967 100644 Binary files a/DATA/TestOutput/simplePathD-15.pes and b/DATA/TestOutput/simplePathD-15.pes differ diff --git a/DATA/TestOutput/simplePathD-20.pes b/DATA/TestOutput/simplePathD-20.pes index 8342b26..9d52b59 100644 Binary files a/DATA/TestOutput/simplePathD-20.pes and b/DATA/TestOutput/simplePathD-20.pes differ diff --git a/DATA/TestOutput/simplePathD-5.pes b/DATA/TestOutput/simplePathD-5.pes index 5e36b78..cad7033 100644 Binary files a/DATA/TestOutput/simplePathD-5.pes and b/DATA/TestOutput/simplePathD-5.pes differ diff --git a/DATA/TestOutput/simplePathZigzag.pes b/DATA/TestOutput/simplePathZigzag.pes index fd35074..738d676 100644 Binary files a/DATA/TestOutput/simplePathZigzag.pes and b/DATA/TestOutput/simplePathZigzag.pes differ diff --git a/DATA/TestOutput/simplePath_1_5.pes b/DATA/TestOutput/simplePath_1_5.pes index 376d7e9..218a923 100644 Binary files a/DATA/TestOutput/simplePath_1_5.pes and b/DATA/TestOutput/simplePath_1_5.pes differ diff --git a/DATA/TestOutput/simplePath_2_5.pes b/DATA/TestOutput/simplePath_2_5.pes index 7b23137..f9029e2 100644 Binary files a/DATA/TestOutput/simplePath_2_5.pes and b/DATA/TestOutput/simplePath_2_5.pes differ diff --git a/DATA/TestOutput/simplePath_3_5.pes b/DATA/TestOutput/simplePath_3_5.pes index 9d25a42..d97c282 100644 Binary files a/DATA/TestOutput/simplePath_3_5.pes and b/DATA/TestOutput/simplePath_3_5.pes differ diff --git a/DATA/TestOutput/simplePath_4_5.pes b/DATA/TestOutput/simplePath_4_5.pes index 9509eab..5cb8ec2 100644 Binary files a/DATA/TestOutput/simplePath_4_5.pes and b/DATA/TestOutput/simplePath_4_5.pes differ diff --git a/DATA/TestOutput/tree.pes b/DATA/TestOutput/tree.pes index 45ef1b9..786f33f 100644 Binary files a/DATA/TestOutput/tree.pes and b/DATA/TestOutput/tree.pes differ diff --git a/DATA/TestOutput/ugliestApple.pes b/DATA/TestOutput/ugliestApple.pes index 481f43d..15ac4bf 100644 Binary files a/DATA/TestOutput/ugliestApple.pes and b/DATA/TestOutput/ugliestApple.pes differ diff --git a/DATA/TestOutput/zigzag.pes b/DATA/TestOutput/zigzag.pes index 42c8db7..dd60b11 100644 Binary files a/DATA/TestOutput/zigzag.pes and b/DATA/TestOutput/zigzag.pes differ diff --git a/DATA/runTests.sh b/DATA/runTests.sh index 14f8e0b..6247b9d 100755 --- a/DATA/runTests.sh +++ b/DATA/runTests.sh @@ -1,13 +1,13 @@ # Generate PES files for the four test shapes -python ../src/main.py -i "./TestInput/simplePath.svg" -o ./TestOutput/simplePath.pes -r -python ../src/main.py -i "./TestInput/tree.svg" -o ./TestOutput/tree.pes -r -python ../src/main.py -i "./TestInput/ugliestApple.svg" -o ./TestOutput/ugliestApple.pes -r -python ../src/main.py -i "./TestInput/zigzag.svg" -o ./TestOutput/zigzag.pes -r +python ../src/main.py -i "./TestInput/simplePath.svg" -o ./TestOutput/simplePath.pes -r -t 1.5 -m 20 +python ../src/main.py -i "./TestInput/tree.svg" -o ./TestOutput/tree.pes -r -t 1.5 -m 20 +python ../src/main.py -i "./TestInput/ugliestApple.svg" -o ./TestOutput/ugliestApple.pes -r -t 1.5 -m 20 +python ../src/main.py -i "./TestInput/zigzag.svg" -o ./TestOutput/zigzag.pes -r -t 1.5 -m 20 # Generate PES files for different stitch widths -python ../src/main.py -i "./TestInput/simplePath.svg" -o ./TestOutput/simplePath_4_5.pes -r -t 4.5 -python ../src/main.py -i "./TestInput/simplePath.svg" -o ./TestOutput/simplePath_3_5.pes -r -t 3.5 -python ../src/main.py -i "./TestInput/simplePath.svg" -o ./TestOutput/simplePath_2_5.pes -r -t 2.5 -python ../src/main.py -i "./TestInput/simplePath.svg" -o ./TestOutput/simplePath_1_5.pes -r -t 1.5 +python ../src/main.py -i "./TestInput/simplePath.svg" -o ./TestOutput/simplePath_4_5.pes -r -t 4.5 -m 10 +python ../src/main.py -i "./TestInput/simplePath.svg" -o ./TestOutput/simplePath_3_5.pes -r -t 3.5 -m 10 +python ../src/main.py -i "./TestInput/simplePath.svg" -o ./TestOutput/simplePath_2_5.pes -r -t 2.5 -m 10 +python ../src/main.py -i "./TestInput/simplePath.svg" -o ./TestOutput/simplePath_1_5.pes -r -t 1.5 -m 10 # Generate PES files for different minimum stitch distances python ../src/main.py -i "./TestInput/simplePath.svg" -o ./TestOutput/simplePathD-20.pes -r -t 2.5 -m 20 @@ -16,5 +16,7 @@ python ../src/main.py -i "./TestInput/simplePath.svg" -o ./TestOutput/simplePath python ../src/main.py -i "./TestInput/simplePath.svg" -o ./TestOutput/simplePathD-5.pes -r -t 2.5 -m 5 # Closest vs Zigzag stitch methods -python ../src/main.py -i "./TestInput/simplePath.svg" -o ./TestOutput/simplePathClosest.pes -r -s closest -python ../src/main.py -i "./TestInput/simplePath.svg" -o ./TestOutput/simplePathZigzag.pes -r -s zigzag \ No newline at end of file +python ../src/main.py -i "./TestInput/simplePath.svg" -o ./TestOutput/simplePathClosest.pes -r -s closest -m 20 -t 2.5 +python ../src/main.py -i "./TestInput/simplePath.svg" -o ./TestOutput/simplePathZigzag.pes -r -s zigzag -m 20 -t 2.5 + + diff --git a/README.md b/README.md index b8bc9ec..1104e0d 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,13 @@ This project is a program for a CAD tool design class (ECE 487) at Miami University. The tool converts .SVG vector graphics to .PES embroidery files that can be used by machines such as the Brother SE600. +# Examples + +![Apple](./DATA/Results/apple.jpg) +![Tree](./DATA/Results/tree.jpg) +![Droplet](./DATA/Results/droplet.jpg) +![Zigzag](./DATA/Results/zigzag.jpg) + # Installation Python is required to run the program. @@ -31,8 +38,8 @@ For decimal parameters, 10 units are equal to 1mm. - `-h` Display parameter help. - `-i [path]` The full path of the input SVG file. - `-o [path]` The full path of the output PES file. -- `-t [decimal number]` This will be used as the distance between parallel stitches. Default is 2.5. -- `-m [decimal number]` This is the max distance the sewing machine will travel between stitches. Default is 10. +- `-t [decimal number]` This will be used as the distance between parallel stitches. Default is 1.5. +- `-m [decimal number]` This is the max distance the sewing machine will travel between stitches. Default is 20. - `-l [decimal number]` This is the mathematical slope that the stitch lines will have. Default is a slope of 1. - `-s ['closest' or 'zigzag']` This is the stitch style for connecting parallel stitch groups. The default is closest. - `--noOutline` If this flag is specified, the embroidery design will not contain stitches that outline each shape. @@ -46,4 +53,14 @@ For decimal parameters, 10 units are equal to 1mm. # References -Colors for PES version 1 were taken from [here.](https://edutechwiki.unige.ch/en/Embroidery_format_PEC#Stitch) \ No newline at end of file +General PES/PEC information from [here.](https://github.com/frno7/libpes/wiki/PES-format) + +General PES/PEC information and colors for PES version 1 taken from [here.](https://edutechwiki.unige.ch/en/Embroidery_format_PEC#Stitch) + +[svgPathTools](https://pypi.org/project/svgpathtools/) + +[numpy](https://pypi.org/project/numpy/) + +[pyEmbroidery](https://pypi.org/project/pyembroidery/) + +Tux embroidery demo file from [here.](https://github.com/t2b/embroidery) \ No newline at end of file diff --git a/REPORT/SVGExample.jpg b/REPORT/SVGExample.jpg new file mode 100644 index 0000000..d7d77cc Binary files /dev/null and b/REPORT/SVGExample.jpg differ diff --git a/REPORT/larkina3-final-report.tex b/REPORT/larkina3-final-report.tex new file mode 100644 index 0000000..03abe09 --- /dev/null +++ b/REPORT/larkina3-final-report.tex @@ -0,0 +1,66 @@ +\documentclass{article} +\usepackage[utf8]{inputenc} +\usepackage{natbib} +\usepackage{graphicx} +\usepackage{float} +\usepackage{chngcntr} +\counterwithin{figure}{section} + +\title{SVG to PES CAD Tool} +\author{Austyn Larkin} +\date{2018-11-14} + +\pdfpagewidth 8.5in +\pdfpageheight 11in + +\begin{document} +\maketitle +\section{Intro} +Home sewing machines are becoming so advanced that some now include the ability to embroider designs onto cloth. Pre-made designs can be selected from the machine's memory or new designs can be downloaded to the machine using a USB flash drive. If a user wants to make their own design, they need to download embroidery software to their desktop computer. However, most embroidery software is very expensive and is not affordable for hobbyists or home users. In this paper, we propose a new CAD tool to convert a common vector shape format (.SVG) to the embroidery format used by machines such as the Brother® SE600 (.PES). + +\section{Background} + +\subsection{The SVG File Format} + +\cite{SVGFormat} describes the SVG file format in detail. An SVG is a scalable vector graphic. It utilizes XML to allow for the description of two-dimensional vector graphics. Although the SVG format can be used to describe a number of common shapes, the only aspect of interest will be the paths. Paths within the SVG format allow for the description of arbitrary vector shapes. These paths are made up of quadratic and cubic Bézier curves. Each test SVG design is exclusively made up of one or more paths. The svgPathTools library \cite{svgpathtools} will be used to read and perform intersections on the test SVG paths. The SVG file format was chosen as it is a common and widely supported. Free software such as Inkscape [4] can export user designs to the SVG format. An example of an SVG can be seen in Figure \ref{apple}. + +\begin{figure}[H] + \centering + \includegraphics[width=2in]{SVGExample} + \caption{An SVG that contains three separate paths.} + \label{apple} +\end{figure} + +\subsection{The PES File Format} + +Although the PES file format is proprietary, major parts of the format have been reverse engineered \cite{PESFormat}. The file format is primarily used by Brother and Bernina International machines. The format can be divided by its three major parts: the header, the PES section, and the PEC section. + +The header starts with the "magic number" that specifies that the file is a PES file. This is simply the four characters that spell out "\#PES". Four more characters follow after which determine the version number. + +The PES section contains higher level stitch information. These include actual stitches that an embroidery machine would make, but later versions allow common shapes to be specified. This portion of the file was largely ignored as it's used by desktop embroidery software and not by the embroidery machine. + +The PEC section contains the actual commands and data that the embroidery machine uses to embroider a design. The major aspects are listed as follows: The header contains the thread colors that should be used when embroidering the design. For PES version 1, thread colors are represented as integer indices in a known list of thread colors specific to the format. Each thread color index is listed in the PEC header and will show up on the embroidery machine in the order they should be loaded. The command list is made up of four different command types: short stitch, long stitch, jump stitch, and color change. Short stitches are two bytes. Each byte specifies how far to move in the X and Y directions before making the next stitch. A long stitch is similar, except each axis takes up two bytes. This is to allow for extra movement distance and some bit flags. If the 12th bit is set in a long stitch command, the command is a jump stitch command. This tells the sewing machine to make a loose stitch that can be cut away later. These stitches are necessary so the machine can jump between discontinuous stitch regions in the design. The last command is a color change command. It tells the machine to stop so the user can swap out the thread color before continuing. + +\section{Software Description} + +The software was written as a command line tool in Python. A number of arguments can be passed to the program. This allows the user to set parameters such as parallel stitch distance and max stitch length. The program takes an SVG file as an input and produces a PES file as an output. The software works by intersecting each path in the SVG shape with an array of parallel lines. From these lines, the software figures out where stitches should go. It then takes these stitches and makes them continuous. It finishes by encoding the stitches in the PES format and saving the file to disk. A much more detailed version of this process is described by Figures \ref{p-1} through \ref{}. + +\begin{figure}[H] + \centering + \includegraphics[width=3in]{p-1} + \caption{} + \label{p-1} +\end{figure} + + +\section{Experimental Setup} + +\section{Results} + +\section{Conclusion} + +\section{Future Ideas} + +\bibliographystyle{plain} +\bibliography{references} +\end{document} \ No newline at end of file diff --git a/src/main.py b/src/main.py index a59b739..bf25e99 100644 --- a/src/main.py +++ b/src/main.py @@ -11,9 +11,9 @@ parser = argparse.ArgumentParser(description="Converts an SVG file into a PES em parser.add_argument("-i", dest="inputFile", type=str, action='store', required=True, help="The SVG file to be converted.") parser.add_argument("-o", dest="outputFile", type=str, action='store', default="output.PES", required=False, help="The output PES file.") -parser.add_argument("-t", dest="threadWidth", type=float, action='store', default=2.5, required=False, +parser.add_argument("-t", dest="threadWidth", type=float, action='store', default=1.5, required=False, help="The thread width to use. This controls how close parallel stitches are to one another.") -parser.add_argument("-m", dest="maxStitchDistance", type=float, action='store', default=10.0, required=False, +parser.add_argument("-m", dest="maxStitchDistance", type=float, action='store', default=20.0, required=False, help="The maximum distance the sewing machine can traverse before it has to make a stitch.") parser.add_argument("-l", dest="slope", type=float, action='store', default=-1.0, required=False, help="The slope of the line to use when performing intersections.")