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

Added random sampler into

parent 51ffa059
"""GCODE Parser
Parses a GCODE file and creates a model reconstruction split into layers and lines.
......@@ -8,6 +7,7 @@ The parse_gcode() function takes a GCODE file and turns it into a Model object.
import re
import numpy as np
import matplotlib.pyplot as plt
......@@ -189,7 +189,16 @@ class Layer():
[y_pts.extend(line.y) for line in self.lines]
return dict([('x', x_pts), ('y', y_pts), ('num_pts', len(x_pts))])
def get_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):
layers = []
num_layers = 0
......@@ -22,7 +22,10 @@ num_samples = 10
sample_pts = list(np.random.randint(0,pts['num_pts'],num_samples))
layer.get_sample_points('random', 10)
for pt in sample_pts:
plt.plot(pts['x'][pt], pts['y'][pt], 'ro')
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