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

Added Inside-outside sampling

parent 7eeec907
......@@ -8,7 +8,7 @@ The parse_gcode() function takes a GCODE file and turns it into a Model object.
import re
import numpy as np
from scipy.spatial import ConvexHull
try:
import matplotlib.pyplot as plt
except:
......@@ -238,6 +238,26 @@ class Layer():
x_pts = [points['x'][i] for i in sample_pts]
y_pts = [points['y'][i] for i in sample_pts]
self.sample_points = dict([('x', x_pts), ('y', y_pts)])
elif method == "Inside-outside":
point_list = []
[point_list.append([x,y]) for x,y in zip(points['x'], points['y'])]
features = np.array(point_list)
print(features.shape)
if features.shape[0] < 4:
self.sample_points = dict([('x', []), ('y', [])])
else:
hull = ConvexHull(features)
outside_indx = np.random.choice(hull.vertices, 3)
all_inside_indx = np.arange(1, len(point_list))
all_inside_indx = all_inside_indx[np.isin(all_inside_indx, hull.vertices, invert=True)]
inside_indx = np.random.choice(all_inside_indx, 3)
all_points = np.concatenate((inside_indx, outside_indx));
x_pts = [feature[0] for feature in features[all_points]]
y_pts = [feature[1] for feature in features[all_points]]
self.sample_points = dict([('x', x_pts), ('y', y_pts)])
if method == "none":
self.sample_points = dict([('x', []), ('y', [])])
......
......@@ -14,7 +14,7 @@ sys.path.append(os.path.abspath(".."))
import gcodeparser as gcp
start = time.time()
model = gcp.parse_gcode(os.path.abspath("LM_rocktopus.gcode"), 5, 10, "Min-max")
model = gcp.parse_gcode(os.path.abspath("LM_rocktopus.gcode"), 5, 10, "Inside-outside")
print("Execution time: {} seconds".format(time.time()-start))
layer = model.layers[10]
......@@ -31,14 +31,14 @@ 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))
"""
points = layer.get_points()
point_list = []
[point_list.append([x,y]) for x,y in zip(points['x'], points['y'])]
features = np.array(point_list)
from scipy.spatial import Delaunay
from scipy.spatial import Delaunay, ConvexHull
tri = Delaunay(features)
......@@ -63,3 +63,5 @@ for i, neighbors in enumerate(tri.neighbors[valid_simps]):
plt.triplot(features[:,0], features[:,1], tri.simplices.copy()[bound_simps,:])
plt.show()
"""
......@@ -89,11 +89,10 @@
style="fill:none;stroke:black;stroke-width:0.4;stroke-linejoin:round;stroke-linecap:round" />
<polyline points="84.426,74.393 "
style="fill:none;stroke:black;stroke-width:0.4;stroke-linejoin:round;stroke-linecap:round" />
<circle cx="97.94" cy="92.695" r="1" stroke="red" stroke-width="0" fill="red"></circle>
<circle cx="59.221" cy="98.029" r="1" stroke="red" stroke-width="0" fill="red"></circle>
<circle cx="57.771" cy="90.638" r="1" stroke="red" stroke-width="0" fill="red"></circle>
<circle cx="59.413" cy="64.347" r="1" stroke="red" stroke-width="0" fill="red"></circle>
<circle cx="82.292" cy="60.266" r="1" stroke="red" stroke-width="0" fill="red"></circle>
<circle cx="93.747" cy="67.417" r="1" stroke="red" stroke-width="0" fill="red"></circle>
<circle cx="80.122" cy="103.764" r="1" stroke="red" stroke-width="0" fill="red"></circle>
<circle cx="84.47390322580645" cy="84.47390322580645" r="1" stroke="red" stroke-width="0" fill="red"></circle>
<circle cx="84.41435714285714" cy="70.27206122448979" r="1" stroke="red" stroke-width="0" fill="red"></circle>
<circle cx="87.7826" cy="69.6148" r="1" stroke="red" stroke-width="0" fill="red"></circle>
<circle cx="60.315" cy="63.676" r="1" stroke="red" stroke-width="0" fill="red"></circle>
<circle cx="59.147" cy="64.668" r="1" stroke="red" stroke-width="0" fill="red"></circle>
<circle cx="60.425" cy="63.646" r="1" stroke="red" stroke-width="0" fill="red"></circle>
</svg>
\ No newline at end of file
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