From 62730a03b44bb17fbb5ae0949db0b78f21470889 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophile=20Bastian?= Date: Fri, 9 Feb 2018 20:07:54 +0100 Subject: [PATCH] March gen: add some testing and viz capabilities This allows to visualize easily a generated configuration, thus allowing testing --- tools/test_marching_cubes_generator.py | 52 ++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 tools/test_marching_cubes_generator.py diff --git a/tools/test_marching_cubes_generator.py b/tools/test_marching_cubes_generator.py new file mode 100644 index 0000000..1bb5c20 --- /dev/null +++ b/tools/test_marching_cubes_generator.py @@ -0,0 +1,52 @@ +import gen_marching_cubes_conf as gen +import matplotlib.pyplot as plt +from mpl_toolkits.mplot3d import axes3d +import random + + +def split_pt_list(pts): + splitted = [[], [], []] + for point in pts: + for i in range(3): + splitted[i].append(point[i]) + return splitted + + +def pt_of_edge(edge): + def avg(val0, val1): + return (val0 + val1) / 2 + + vert0 = edge.vert[0] + vert1 = edge.vert[1] + + return (avg(vert0[0], vert1[0]), + avg(vert0[1], vert1[1]), + avg(vert0[2], vert1[2])) + + +def tri_repr(tri, subplt): + pts = [pt_of_edge(tri[i]) for i in range(3)] + + x_val, y_val, z_val = split_pt_list(pts) + x_val = [val + random.random() / 10**5 for val in x_val] + y_val = [val + random.random() / 10**5 for val in y_val] + + subplt.plot_trisurf(x_val, y_val, z_val) + + +def display_case(tri_cube): + figure = plt.figure() + subplt = figure.add_subplot(111, projection='3d') + + actives = split_pt_list(list(tri_cube.activated)) + inactives = split_pt_list(list(tri_cube.non_activated)) + + subplt.scatter3D(actives[0], actives[1], actives[2], + c='r', marker='o') + subplt.scatter3D(inactives[0], inactives[1], inactives[2], + c='b', marker='.') + + for triangle in tri_cube.triangles: + tri_repr(triangle, subplt) + + plt.show()