March gen: refactor for easier testing

This commit is contained in:
Théophile Bastian 2018-02-09 01:52:00 +01:00
parent 0f60c717f0
commit f15151ff57

View file

@ -171,7 +171,7 @@ def all_transforms():
return output
def do_main(base_cases):
def gen_index(base_cases):
transforms = all_transforms()
index = [None for x in range(256)]
for case in base_cases:
@ -197,365 +197,379 @@ def do_main(base_cases):
if has_unbound:
raise RuntimeError("Some cases were not generated.")
print(PREAMBLE)
print(("static const TriVect edges_of_intersection[256] = {"))
return index
def pretty_print(index):
output = ""
output += PREAMBLE
output += "static const TriVect edges_of_intersection[256] = {\n"
for (case_id, case) in enumerate(index):
print("\tTriVect({")
output += "\tTriVect({\n"
for (tri_id, tri) in enumerate(case.triangles):
print('\t\t' + dump_tri(tri),
end=",\n" if tri_id != len(case.triangles) - 1 else '\n')
print('\t\t})', end=',\n' if case_id != len(index) - 1 else '\n')
print("};")
output += '\t\t{}{}'.format(
dump_tri(tri),
",\n" if tri_id != len(case.triangles) - 1 else '\n')
output += '\t\t})' + (',\n' if case_id != len(index) - 1 else '\n')
output += "};\n"
return output
def do_main(base_cases):
print(pretty_print(gen_index(base_cases)))
BASE_CASES = [
# Source: <https://en.wikipedia.org/wiki/File:MarchingCubes.svg>
# -- 1 --
TriangulatedCube(set(), []),
# -- 2 --
TriangulatedCube(
{
Vert.frnt_bot_l,
},
[
[
Edg.frnt_bot,
Edg.bot_l,
Edg.frnt_l,
],
]),
# -- 3 --
TriangulatedCube(
{
Vert.frnt_bot_l,
Vert.frnt_bot_r,
},
[
[
Edg.frnt_l,
Edg.bot_l,
Edg.bot_r,
],
[
Edg.frnt_l,
Edg.frnt_r,
Edg.bot_r,
],
]),
# -- 4 --
TriangulatedCube(
{
Vert.frnt_bot_l,
Vert.frnt_top_r,
},
[
[
Edg.frnt_bot,
Edg.bot_l,
Edg.frnt_l,
],
[
Edg.frnt_top,
Edg.top_r,
Edg.frnt_r,
],
]),
# -- 5 --
TriangulatedCube(
{
Vert.frnt_bot_r,
Vert.back_bot_r,
Vert.back_bot_l,
},
[
[
Edg.frnt_r,
Edg.back_r,
Edg.back_l,
],
[
Edg.bot_l,
Edg.frnt_bot,
Edg.frnt_r,
],
[
Edg.frnt_r,
Edg.back_l,
Edg.bot_l,
],
]),
# -- 6 --
TriangulatedCube(
{
Vert.frnt_bot_l,
Vert.back_bot_l,
Vert.frnt_bot_r,
Vert.back_bot_r,
},
[
[
Edg.frnt_l,
Edg.frnt_r,
Edg.back_r,
],
[
Edg.back_r,
Edg.back_l,
Edg.frnt_l,
],
]),
# -- 7 --
TriangulatedCube(
{
Vert.frnt_top_l,
Vert.back_bot_l,
Vert.frnt_bot_r,
Vert.back_bot_r,
},
[
[
Edg.frnt_r,
Edg.back_r,
Edg.back_l,
],
[
Edg.bot_l,
Edg.frnt_bot,
Edg.frnt_r,
],
[
Edg.frnt_r,
Edg.back_l,
Edg.bot_l,
],
[
Edg.frnt_l,
Edg.frnt_top,
Edg.top_l,
],
]),
# -- 8 --
TriangulatedCube(
{
Vert.frnt_bot_l,
Vert.back_bot_r,
Vert.frnt_top_r,
Vert.back_top_l,
},
[
[
Edg.frnt_bot,
Edg.bot_l,
Edg.frnt_l,
],
[
Edg.frnt_top,
Edg.top_r,
Edg.frnt_r,
],
[
Edg.back_bot,
Edg.bot_r,
Edg.back_r,
],
[
Edg.back_top,
Edg.top_l,
Edg.back_l,
],
]),
# -- 9 --
TriangulatedCube(
{
Vert.back_bot_l,
Vert.back_bot_r,
Vert.back_top_l,
Vert.frnt_bot_l,
},
[
[
Edg.top_l,
Edg.frnt_l,
Edg.back_top,
],
[
Edg.frnt_l,
Edg.back_top,
Edg.frnt_bot,
],
[
Edg.back_top,
Edg.frnt_bot,
Edg.back_r,
],
[
Edg.frnt_bot,
Edg.back_r,
Edg.bot_r,
],
]),
# -- 10 --
TriangulatedCube(
{
Vert.back_top_l,
Vert.back_bot_l,
Vert.back_bot_r,
Vert.frnt_bot_r,
},
[
[
Edg.bot_l,
Edg.frnt_bot,
Edg.top_l,
],
[
Edg.frnt_bot,
Edg.top_l,
Edg.back_r,
],
[
Edg.top_l,
Edg.back_r,
Edg.back_top,
],
[
Edg.frnt_bot,
Edg.back_r,
Edg.frnt_r,
],
]),
# -- 11 --
TriangulatedCube(
{
Vert.frnt_bot_l,
Vert.back_top_r,
},
[
[
Edg.frnt_bot,
Edg.frnt_l,
Edg.bot_l,
],
[
Edg.back_top,
Edg.back_r,
Edg.top_r,
],
]),
# -- 12 --
TriangulatedCube(
{
Vert.frnt_bot_l,
Vert.frnt_bot_r,
Vert.back_top_r,
},
[
[
Edg.frnt_l,
Edg.bot_l,
Edg.bot_r,
],
[
Edg.frnt_l,
Edg.frnt_r,
Edg.bot_r,
],
[
Edg.back_top,
Edg.back_r,
Edg.top_r,
],
]),
# -- 13 --
TriangulatedCube(
{
Vert.frnt_top_l,
Vert.frnt_bot_r,
Vert.back_top_r,
},
[
[
Edg.frnt_l,
Edg.frnt_top,
Edg.top_l,
],
[
Edg.frnt_r,
Edg.frnt_bot,
Edg.bot_r,
],
[
Edg.back_r,
Edg.back_top,
Edg.top_r,
],
]),
# -- 14 --
TriangulatedCube(
{
Vert.frnt_bot_l,
Vert.frnt_top_l,
Vert.back_bot_r,
Vert.back_top_r,
},
[
[
Edg.frnt_top,
Edg.frnt_bot,
Edg.top_l,
],
[
Edg.frnt_bot,
Edg.top_l,
Edg.bot_l,
],
[
Edg.back_bot,
Edg.back_top,
Edg.bot_r,
],
[
Edg.back_top,
Edg.bot_r,
Edg.top_r,
],
]),
# -- 15 --
TriangulatedCube(
{
Vert.frnt_bot_l,
Vert.back_bot_l,
Vert.back_bot_r,
Vert.back_top_r,
},
[
[
Edg.frnt_l,
Edg.frnt_bot,
Edg.back_l,
],
[
Edg.frnt_bot,
Edg.back_l,
Edg.top_r,
],
[
Edg.back_l,
Edg.top_r,
Edg.back_top,
],
[
Edg.frnt_bot,
Edg.top_r,
Edg.bot_r,
],
]),
]
def main():
base_cases = [
# Source: <https://en.wikipedia.org/wiki/File:MarchingCubes.svg>
# -- 1 --
TriangulatedCube(set(), []),
# -- 2 --
TriangulatedCube(
{
Vert.frnt_bot_l,
},
[
[
Edg.frnt_bot,
Edg.bot_l,
Edg.frnt_l,
],
]),
# -- 3 --
TriangulatedCube(
{
Vert.frnt_bot_l,
Vert.frnt_bot_r,
},
[
[
Edg.frnt_l,
Edg.bot_l,
Edg.bot_r,
],
[
Edg.frnt_l,
Edg.frnt_r,
Edg.bot_r,
],
]),
# -- 4 --
TriangulatedCube(
{
Vert.frnt_bot_l,
Vert.frnt_top_r,
},
[
[
Edg.frnt_bot,
Edg.bot_l,
Edg.frnt_l,
],
[
Edg.frnt_top,
Edg.top_r,
Edg.frnt_r,
],
]),
# -- 5 --
TriangulatedCube(
{
Vert.frnt_bot_r,
Vert.back_bot_r,
Vert.back_bot_l,
},
[
[
Edg.frnt_r,
Edg.back_r,
Edg.back_l,
],
[
Edg.bot_l,
Edg.frnt_bot,
Edg.frnt_r,
],
[
Edg.frnt_r,
Edg.back_l,
Edg.bot_l,
],
]),
# -- 6 --
TriangulatedCube(
{
Vert.frnt_bot_l,
Vert.back_bot_l,
Vert.frnt_bot_r,
Vert.back_bot_r,
},
[
[
Edg.frnt_l,
Edg.frnt_r,
Edg.back_r,
],
[
Edg.back_r,
Edg.back_l,
Edg.frnt_l,
],
]),
# -- 7 --
TriangulatedCube(
{
Vert.frnt_top_l,
Vert.back_bot_l,
Vert.frnt_bot_r,
Vert.back_bot_r,
},
[
[
Edg.frnt_r,
Edg.back_r,
Edg.back_l,
],
[
Edg.bot_l,
Edg.frnt_bot,
Edg.frnt_r,
],
[
Edg.frnt_r,
Edg.back_l,
Edg.bot_l,
],
[
Edg.frnt_l,
Edg.frnt_top,
Edg.top_l,
],
]),
# -- 8 --
TriangulatedCube(
{
Vert.frnt_bot_l,
Vert.back_bot_r,
Vert.frnt_top_r,
Vert.back_top_l,
},
[
[
Edg.frnt_bot,
Edg.bot_l,
Edg.frnt_l,
],
[
Edg.frnt_top,
Edg.top_r,
Edg.frnt_r,
],
[
Edg.back_bot,
Edg.bot_r,
Edg.back_r,
],
[
Edg.back_top,
Edg.top_l,
Edg.back_l,
],
]),
# -- 9 --
TriangulatedCube(
{
Vert.back_bot_l,
Vert.back_bot_r,
Vert.back_top_l,
Vert.frnt_bot_l,
},
[
[
Edg.top_l,
Edg.frnt_l,
Edg.back_top,
],
[
Edg.frnt_l,
Edg.back_top,
Edg.frnt_bot,
],
[
Edg.back_top,
Edg.frnt_bot,
Edg.back_r,
],
[
Edg.frnt_bot,
Edg.back_r,
Edg.bot_r,
],
]),
# -- 10 --
TriangulatedCube(
{
Vert.back_top_l,
Vert.back_bot_l,
Vert.back_bot_r,
Vert.frnt_bot_r,
},
[
[
Edg.bot_l,
Edg.frnt_bot,
Edg.top_l,
],
[
Edg.frnt_bot,
Edg.top_l,
Edg.back_r,
],
[
Edg.top_l,
Edg.back_r,
Edg.back_top,
],
[
Edg.frnt_bot,
Edg.back_r,
Edg.frnt_r,
],
]),
# -- 11 --
TriangulatedCube(
{
Vert.frnt_bot_l,
Vert.back_top_r,
},
[
[
Edg.frnt_bot,
Edg.frnt_l,
Edg.bot_l,
],
[
Edg.back_top,
Edg.back_r,
Edg.top_r,
],
]),
# -- 12 --
TriangulatedCube(
{
Vert.frnt_bot_l,
Vert.frnt_bot_r,
Vert.back_top_r,
},
[
[
Edg.frnt_l,
Edg.bot_l,
Edg.bot_r,
],
[
Edg.frnt_l,
Edg.frnt_r,
Edg.bot_r,
],
[
Edg.back_top,
Edg.back_r,
Edg.top_r,
],
]),
# -- 13 --
TriangulatedCube(
{
Vert.frnt_top_l,
Vert.frnt_bot_r,
Vert.back_top_r,
},
[
[
Edg.frnt_l,
Edg.frnt_top,
Edg.top_l,
],
[
Edg.frnt_r,
Edg.frnt_bot,
Edg.bot_r,
],
[
Edg.back_r,
Edg.back_top,
Edg.top_r,
],
]),
# -- 14 --
TriangulatedCube(
{
Vert.frnt_bot_l,
Vert.frnt_top_l,
Vert.back_bot_r,
Vert.back_top_r,
},
[
[
Edg.frnt_top,
Edg.frnt_bot,
Edg.top_l,
],
[
Edg.frnt_bot,
Edg.top_l,
Edg.bot_l,
],
[
Edg.back_bot,
Edg.back_top,
Edg.bot_r,
],
[
Edg.back_top,
Edg.bot_r,
Edg.top_r,
],
]),
# -- 15 --
TriangulatedCube(
{
Vert.frnt_bot_l,
Vert.back_bot_l,
Vert.back_bot_r,
Vert.back_top_r,
},
[
[
Edg.frnt_l,
Edg.frnt_bot,
Edg.back_l,
],
[
Edg.frnt_bot,
Edg.back_l,
Edg.top_r,
],
[
Edg.back_l,
Edg.top_r,
Edg.back_top,
],
[
Edg.frnt_bot,
Edg.top_r,
Edg.bot_r,
],
]),
]
do_main(base_cases)
do_main(BASE_CASES)
if __name__ == "__main__":