mpri-graphics-project/tools/test_marching_cubes_generator.py
Théophile Bastian 62730a03b4 March gen: add some testing and viz capabilities
This allows to visualize easily a generated configuration, thus allowing
testing
2018-02-09 20:07:54 +01:00

52 lines
1.3 KiB
Python

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()