diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index f663097..e21c9b0 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -3,7 +3,9 @@
-
+
+
+
@@ -16,8 +18,8 @@
-
-
+
+
@@ -25,37 +27,37 @@
-
+
-
+
-
-
+
+
-
+
-
+
-
+
-
+
@@ -65,8 +67,8 @@
-
-
+
+
@@ -74,30 +76,30 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -106,8 +108,8 @@
-
-
+
+
@@ -136,17 +138,12 @@
-
+
-
-
+
+
-
-
-
-
-
-
+
@@ -163,28 +160,12 @@
- index
- type(
- enumerate
- colorIndex
- type
- getColorOfPathAtIndex
- closest
- ColorChange
- getClosestColor
- stitchLines
- maxDist
- clearAll
- lineIntersectsAnyBarrier
- intersect(
- StitchLevel
barrier
intersection points for this
intersect
self.b
addPoint
addLine
- endWithinStart
intersectionPointWithInfLine
invertLine
matchInfLine
@@ -193,6 +174,22 @@
renderPECCommands
lineFallsInValidProjection
makeStitchLevels
+ TYPE_JUMP
+ encode
+ color
+ 1095499788
+ a0
+ scale
+ seeking to
+ print
+ Stitch(
+ endWithinStart
+ Stitch
+ <
+ Beep
+ 0x9
+ width
+ size
@@ -207,13 +204,13 @@
-
-
-
+
+
+
@@ -236,6 +233,7 @@
+
@@ -258,6 +256,11 @@
+
+
+
+
+
@@ -266,7 +269,6 @@
-
@@ -294,7 +296,7 @@
-
+
@@ -414,7 +416,7 @@
-
+
@@ -537,10 +539,39 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
@@ -556,21 +587,31 @@
-
-
+
+
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
@@ -588,39 +629,14 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
+
+
diff --git a/PECRender/main.py b/PECRender/main.py
index baa0e87..3d4f255 100644
--- a/PECRender/main.py
+++ b/PECRender/main.py
@@ -12,8 +12,9 @@ window.set_size(1000,1000)
window.set_location(300, 0)
pyglet.gl.glClearColor(0.4,0.4,0.4,1)
-filepath = "/Users/imaustyn/Documents/MiamiUniversity/ECE 487/Project/Understanding2/tux.pes"
+#filepath = "/Users/imaustyn/Documents/MiamiUniversity/ECE 487/Project/Understanding2/tux.pes"
#filepath = "/Users/imaustyn/Downloads/Circle embroidery designs/Circle.pes"
+filepath = "/Users/imaustyn/Documents/MiamiUniversity/ECE 487/Project/PES-Embroidery/TestOutput/simple.PES"
# Global variables
class Global:
@@ -22,8 +23,8 @@ class Global:
x = 0
y = 0
file = None
- xScale = 4.0
- yScale = 4.0
+ xScale = 2.0
+ yScale = 2.0
xOffset = 500.0
yOffset = 500.0
testColors = [(244, 238, 66), (255,255,255), (0,0,0)]
@@ -51,6 +52,7 @@ class Global:
f = cls.file # type: file
print(f.read(8))
PECOffset = struct.unpack(" 0:
# Double length
c = struct.unpack(">H", Global.readBytes(f, 2))[0]
- print("Beep: {}".format(hex(c)))
+ #print("Beep: {}".format(hex(c)))
# Color change
if c == 0xFEB0:
diff --git a/TestOutput/simple.PES b/TestOutput/simple.PES
new file mode 100644
index 0000000..0e4995f
Binary files /dev/null and b/TestOutput/simple.PES differ
diff --git a/Tests/debugPicture.png b/Tests/debugPicture.png
index e740b46..9db732e 100644
Binary files a/Tests/debugPicture.png and b/Tests/debugPicture.png differ
diff --git a/src/PES.py b/src/PES.py
index b142b2d..0bdab09 100644
--- a/src/PES.py
+++ b/src/PES.py
@@ -8,6 +8,9 @@ def encodeU8(num):
def encodeU16(num):
return pack("> 8), total & 0xFF])
def length(self):
return self.line.length()
@@ -271,6 +284,6 @@ class ColorChange:
self.colorIndex = colorIndex
def encode(self, b):
- b.append(ColorChange.TYPE_COLOR_CHANGE_left)
- b.append(ColorChange.TYPE_COLOR_CHANGE_right)
- b.append(self.colorIndex & 0xFF)
\ No newline at end of file
+ b.extend([ ColorChange.TYPE_COLOR_CHANGE_left ])
+ b.extend([ ColorChange.TYPE_COLOR_CHANGE_right ])
+ b.extend([ self.colorIndex & 0xFF ])
\ No newline at end of file
diff --git a/src/PES.pyc b/src/PES.pyc
index 0216030..ec83c15 100644
Binary files a/src/PES.pyc and b/src/PES.pyc differ
diff --git a/src/PES_render_utils.py b/src/PES_render_utils.py
index 9f65fdb..dc9ad15 100644
--- a/src/PES_render_utils.py
+++ b/src/PES_render_utils.py
@@ -14,7 +14,7 @@ class GenericRenderer:
self.lineBatch = pyglet.graphics.Batch()
self.pointBatch = pyglet.graphics.Batch()
- pyglet.gl.glLineWidth(7)#2
+ pyglet.gl.glLineWidth(2)#2
pyglet.gl.glPointSize(4)
self.addLine(Line(start=(0+0j), end=(1000+1000j)), 255, 0, 0)
diff --git a/src/PES_render_utils.pyc b/src/PES_render_utils.pyc
index 5d74694..c0b6343 100644
Binary files a/src/PES_render_utils.pyc and b/src/PES_render_utils.pyc differ
diff --git a/src/main.py b/src/main.py
index 2cd6076..ff06d9d 100644
--- a/src/main.py
+++ b/src/main.py
@@ -26,14 +26,16 @@ paths, attributes = svg
if paths is None:
sys.exit(0)
-threadWidth = 3
+threadWidth = 0.5
# Enumerate the shapes in the SVG to find where stitches should go.
levelGroups = []
fillColors = []
+PECColors = []
for i, shape in enumerate(paths):
fillColor = getColorOfPathAtIndex(attributes,i)
fillColors.append(fillColor)
+ PECColors.append(PES.getClosestColor(fillColor))
print("Doing shape {} with fill color {}".format(shape, fillColor))
print("Closest color: {}".format( PES.getClosestColor(fillColor) ))
@@ -47,16 +49,23 @@ for i, shape in enumerate(paths):
PECCommands = createStitchRoutine(levelGroups, fillColors=fillColors, threadWidth=threadWidth)
# Render the PEC commands
-#renderPECCommands(PECCommands)
+renderPECCommands(PECCommands)
-pes = PES(PECCommands=PECCommands)
-pes.encode()
+pec = PEC(label="pec1", colors=PECColors, commands=PECCommands)
+pes = PES(PEC=pec)
+encodedPES = pes.encode()
+
+with open(args.outputFile, "w") as f:
+ f.write(encodedPES)
+
+print("Wrote {} to disk.".format(args.outputFile))
if args.debug:
loadedPES = pyembroidery.read(args.outputFile)
if loadedPES is not None:
print("Generating debug image.")
pyembroidery.write_png(loadedPES, replaceFilenameAndExtensionFromPath(args.inputFile, "debugPicture", "png"))
+ print("Image written to disk.")
else:
print("Couldn't find output file.")
diff --git a/src/svgFunctions.py b/src/svgFunctions.py
index 70862b3..4e28099 100644
--- a/src/svgFunctions.py
+++ b/src/svgFunctions.py
@@ -218,9 +218,7 @@ def makeStitchLevels(shape, fillColor=(0,0,0), threadWidth=2, slope=1, debug=Fal
def switchPointsInLine(line):
return Line(start=line.end, end=line.start)
-def endWithinStart(l1, l2, dist):
- p1 = l1.end
- p2 = l2.start
+def pointWithinPoint(p1, p2, dist):
return math.sqrt( math.pow(p1.real - p2.real, 2) + math.pow(p1.imag - p2.imag, 2) ) <= dist
# Take all the stitches we created and actually make
@@ -311,16 +309,16 @@ def createStitchRoutine(levelGroups, fillColors, threadWidth=2):
if isinstance(allStitches[-1], Stitch):
lastStitch = allStitches[-1]
# Is the distance greater than the minimum?
- if endWithinStart(lastStitch.line, singleLineGroup[0], maxDist) is not True:
+ if pointWithinPoint(lastStitch.point, singleLineGroup[0].start, maxDist) is not True:
# Jump to the location of this shape.
- jump = Stitch( line=Line(start=lastStitch.line.end, end=singleLineGroup[0].start) )
+ jump = Stitch( singleLineGroup[0].start )
jump.type = Stitch.TYPE_JUMP
allStitches.append(jump)
for singleLine in singleLineGroup:
- # Do I really need to do two stitches per stitch or just one?
- # Maybe I can add different modes for this.
- s = Stitch(singleLine)
+ s = Stitch(singleLine.start)
+ allStitches.append(s)
+ s = Stitch(singleLine.end)
allStitches.append(s)
print("Created {} stitches.".format(len(allStitches)))
@@ -330,24 +328,22 @@ def renderPECCommands(PECCommands):
GenericRenderer.globalRenderer.clearAll()
+ lastPoint = (0+0j)
currentColor = ("None", 0,0,0)
- curIndex = 1
jumps = []
for command in PECCommands:
-
- currentColor = PES.colors[curIndex % len(PES.colors)]
-
if isinstance(command, Stitch):
if command.type is Stitch.TYPE_JUMP:
- jumps.append(command.line)
- #GenericRenderer.globalRenderer.addLine(command.line, 255, 255, 255)
- curIndex = curIndex + 1
+ jumps.append(Line(lastPoint, command.point))
else:
# Regular stitch
- GenericRenderer.globalRenderer.addLine(command.line, currentColor[1], currentColor[2], currentColor[3])
- if isinstance(command, ColorChange):
- None
- #currentColor = PES.colors[command.colorIndex]
+ GenericRenderer.globalRenderer.addLine(Line(lastPoint, command.point), currentColor[1], currentColor[2], currentColor[3])
+ lastPoint = command.point
+
+ if isinstance(command, ColorChange):
+ currentColor = PES.colors[command.colorIndex]
+
+ # Render all the jumps on top
for jump in jumps:
GenericRenderer.globalRenderer.addLine(jump, 255, 255, 255)
\ No newline at end of file
diff --git a/src/svgFunctions.pyc b/src/svgFunctions.pyc
index 3f5cbc0..eb99421 100644
Binary files a/src/svgFunctions.pyc and b/src/svgFunctions.pyc differ