Commit d454cac2 authored by Nicholas Gar Hei Chan's avatar Nicholas Gar Hei Chan
Browse files

Added sample generation logic to parse_gcode()

parent fb73925b
......@@ -94,6 +94,8 @@ class Layer():
self.prev_e = 0
self.prev_g = -1
self.z_height = z_height
self.sample_points = dict([('x', []), ('y', [])])
def append_coords(self, x, y, e, g):
"""
......@@ -190,16 +192,17 @@ class Layer():
return dict([('x', x_pts), ('y', y_pts), ('num_pts', len(x_pts))])
def get_sample_points(self, method, num_samples):
def gen_sample_points(self, method, num_samples):
points = self.get_points()
if method == "random":
sample_pts = list(np.random.randint(0, points['num_pts'], num_samples))
x_pts = [points['x'][i] for i in sample_pts]
y_pts = [points['y'][i] for i in sample_pts]
return dict([('x', x_pts), ('y', y_pts)])
def parse_gcode(filename):
self.sample_points = dict([('x', x_pts), ('y', y_pts)])
if method == "none":
self.sample_points dict([('x', []), ('y', [])])
def parse_gcode(filename, sample_spacing, samples_per_layer):
layers = []
num_layers = 0
layer_heights = []
......@@ -275,5 +278,12 @@ def parse_gcode(filename):
layers[index[zs[i]]].append_coords(xs[i],ys[i],es[i],Gs[i]) # Append each command into the model list
layers = [layer for layer in layers if layer.len() > 0]
for i in range(len(layers)):
if (i % sample_spacing) == 0 and (i != 0):
layers[i].gen_sample_points("random", samples_per_layer)
else:
layers[i].gen_sample_points("none", 0)
model = Model(layers, max(xs), max(ys), max(zs), min(xs), min(ys), min(zs))
return model
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment