-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
107 lines (76 loc) · 3.28 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
from os import path, scandir
from Dijkstra import FindPath
from Parser import Parse
from Graph import ParseIntoGraph
from Writer import OutputPathAsWavefront
def main():
use_examples = input("Use Examples? (y)/n: ")
if(use_examples.upper() == "N"):
use_examples = False
else:
use_examples = True
final_file_path = ""
if use_examples:
examples_dir = "examples"
while(not path.isdir(examples_dir)):
choice = input(f"Examples directory not found at {path.abspath(examples_dir)}, would you like to specify an examples directory? y/(n): ")
if(choice.upper() != "Y"):
use_examples = False
break
examples_dir = input("Enter path to examples directory: ")
options = []
for thing in scandir(examples_dir):
if(thing.is_file and thing.name.endswith(".obj")):
options.append(thing.name)
print()
for (i, obj) in enumerate(options):
print(f"{i+1}: {obj}")
choice = 0
while choice not in range(1, len(options)+1):
choice = input(f"Choose (1 to {len(options)}): ")
if(not choice.isnumeric):
print("Not a valid choice")
continue
choice = int(choice)
if(choice not in range(1, len(options)+1)):
print("Not a valid choice")
continue
final_file_path = path.join(examples_dir, options[choice-1])
if not use_examples:
file_path = input("Enter Path to .obj File: ")
if(not path.exists(file_path)):
print(f"File {path.abspath(file_path)} not found.")
exit(1)
final_file_path = file_path
results = None
with open(final_file_path, "r") as f:
results = Parse(f)
graph = ParseIntoGraph(results)
n = len(graph.data)
accepted = False
while not accepted:
start_node = input(f"Enter start face (1 - {n}): ")
end_node = input(f"Enter end face (1 - {n}): ")
if(not (start_node.isdigit() and end_node.isdigit())):
print("Those are not numbers.")
continue
start_node = int(start_node)
end_node = int(end_node)
if(not (start_node in range(1, n+1) and end_node in range(1, n+1))):
print("That is out of the range.")
continue
if(start_node == end_node):
print("That is the same node twice. What are you doing?")
continue
accepted = True
shortest_path = FindPath(graph, start_node - 1, end_node - 1)
faces_repr = [repr(results.faces[start_node-1]) + f" at {results.faces[start_node-1].get_face_center(results)}", repr(results.faces[end_node-1]) + f" at {results.faces[end_node-1].get_face_center(results)}"]
if shortest_path == []:
print(f"No path found from face {faces_repr[0]} to face {faces_repr[1]}")
exit(0)
print(f"Shortest path from face {faces_repr[0]} to face {faces_repr[1]}: {shortest_path}")
with open("examples/out.obj", "w") as f:
OutputPathAsWavefront(shortest_path, f, results)
print(f"Outputted path to {path.abspath('out.obj')}")
if __name__ == "__main__":
main()