read_gcode.py 881 Bytes
Newer Older
Nicholas Gar Hei Chan's avatar
Nicholas Gar Hei Chan committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/bin/python3
from mpl_toolkits import mplot3d
import os
import sys
import matplotlib.pyplot as plt
import time
import random
import numpy as np

sys.path.append(os.path.abspath(".."))

import gcodeparser as gcp

start = time.time()
model = gcp.parse_gcode(os.path.abspath("LM_rocktopus.gcode"))
print("Execution time: {} seconds".format(time.time()-start))

layer = model.layers[10]
pts = layer.get_points()

num_samples = 10

sample_pts = list(np.random.randint(0,pts['num_pts'],num_samples))

25
26
27
28
#model.layers[10].plot_layer()

layer.get_sample_points('random', 10)

Nicholas Gar Hei Chan's avatar
Nicholas Gar Hei Chan committed
29
30
31
32
33
34
35
36
37
38
39
for pt in sample_pts:
    plt.plot(pts['x'][pt], pts['y'][pt], 'ro')

plt.show()

"""
Uncomment this block to save each layer to an SVG image
into a folder called "layers"
"""
#for layer_index, layer in enumerate(model.layers):
#    layer.to_svg(model.max_y, model.max_x, "layers/{}.svg".format(layer_index))