#34 gcode algo
closes #34 algorithm that creates a gcode from a path unittest for the algorithm
This commit is contained in:
@@ -1,80 +0,0 @@
|
||||
def scanHorizontal(image, rTool):
|
||||
"""
|
||||
:param image: image to apply the scan
|
||||
:param rTool: tool radius
|
||||
:return: adds 2's where there should be a path for the tool, looking at the image only horizontally
|
||||
"""
|
||||
|
||||
width = len(image[0])
|
||||
height = len(image)
|
||||
|
||||
for line in range(height):
|
||||
for column in range(width):
|
||||
|
||||
if image[line][column] == 1 and image[line][column - 1] != 1:
|
||||
for px in range(2 * rTool + 1):
|
||||
if image[line - rTool + px][column - rTool] == 0:
|
||||
image[line - rTool + px][column - rTool] = 2
|
||||
|
||||
if image[line][column] == 1 and image[line][column + 1] != 1:
|
||||
for px in range(2 * rTool + 1):
|
||||
if image[line - rTool + px][column + rTool] == 0:
|
||||
image[line - rTool + px][column + rTool] = 2
|
||||
|
||||
return image
|
||||
|
||||
|
||||
def scanVertical(image, rTool):
|
||||
"""
|
||||
:param image: image to apply the scan
|
||||
:param rTool: tool radius
|
||||
:return: adds 2's where there should be a path for the tool, looking at the image only vertically
|
||||
"""
|
||||
|
||||
width = len(image[0])
|
||||
height = len(image)
|
||||
|
||||
for line in range(height):
|
||||
for column in range(width):
|
||||
|
||||
if image[line][column] == 1 and image[line - 1][column] != 1:
|
||||
for px in range(2 * rTool + 1):
|
||||
if image[line - rTool][column - rTool + px] == 0:
|
||||
image[line - rTool][column - rTool + px] = 2
|
||||
|
||||
if image[line][column] == 1 and image[line + 1][column] != 1:
|
||||
for px in range(2 * rTool + 1):
|
||||
if image[line + rTool][column - rTool + px] == 0:
|
||||
image[line + rTool][column - rTool + px] = 2
|
||||
|
||||
return image
|
||||
|
||||
def twoRemoving(image, rTool):
|
||||
"""
|
||||
:param image: image to apply the scan
|
||||
:param rTool: tool radius
|
||||
:return: removes unnecessary twos to leave a path of only one pixel large
|
||||
"""
|
||||
|
||||
width = len(image[0])
|
||||
height = len(image)
|
||||
|
||||
for line in range(height):
|
||||
for column in range(width):
|
||||
|
||||
if image[line][column] == 1:
|
||||
for pixelx in range(1, 2 * rTool):
|
||||
for pixely in range(1, 2*rTool):
|
||||
if image[line - rTool + pixelx][column - rTool + pixely] == 2:
|
||||
image[line - rTool + pixelx][column - rTool + pixely] = 0
|
||||
|
||||
print("image width = " + str(width))
|
||||
print("image height = " + str(height))
|
||||
|
||||
return image
|
||||
|
||||
|
||||
def path(image, rTool):
|
||||
return twoRemoving(scanVertical(scanHorizontal(image, rTool), rTool), rTool)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user