-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEdge_Classifier_Logical.py
More file actions
69 lines (59 loc) · 2.75 KB
/
Edge_Classifier_Logical.py
File metadata and controls
69 lines (59 loc) · 2.75 KB
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
import numpy as np
from pathlib import Path
import matplotlib.pyplot as plt
from Functions.Graph_Extraction_Functions import *
from Functions.Edge_Classification_Functions import *
def Plot_Graph_Classified(Graph_2D_type, Lines = False, Points = False):
"""
Function to plot 2D graph with classified edges
\nInput:
\nGraph_2D_type: List of classified lines
\nOutput:
\nPlot of 2D graph with classified edges and points at the corner
"""
for G in Graph_2D_type:
Line = np.array(G[0])
Color = G[2]
X = Line[:,0]
Y = Line[:,1]
if Lines:
plt.plot(X, Y, color = Color, linewidth = 1)
if Points:
plt.scatter(X, Y, color = 'black', s = 30)
def edge_classifire(OBJ_file_path, Perspective_Graph, Cam_Distance, Save = False, Save_Path = None):
"""
Edge Classifire Function
\nInputs:
\nOBJ_file_path(str): Path to the .obj file
\nPerspective_Graph(array): An array with shape M * 4 (each row shows a line whit format [x1, y1, x2, y2] which are start and end points coordinates)
\nSave(bool): Boolean parameter to save graph lines as .json file
\nSave_Path(str): Path to save .json file (if not defind the .json file will be saved in the .obj file location with same name)
\nOutput:
\nClassified_Graph(list): A list of lists where each list has format of [[[x1, y1], [x2, y2]], Edge Type, Edge Color]
"""
# Loading .obj File
Roof = trimesh.load(OBJ_file_path)
# Calculating Parameters for Edge Classification
Rotation_Angle = 0
#Cam_Distance = int(Roof.bounds[1][2]) * 25
#if Cam_Distance > 160:
# Cam_Distance = 160
Cam_Roof = camera_Mesh(Roof, 30, 1, -1, 100, 0, 0, Cam_Distance)
# Classifying Edges
Pre_Classified_Graph = Edge_Type(Cam_Roof, Perspective_Graph)
Classified_Graph = Classification_Correction(Roof,
Cam_Roof,
Perspective_Graph.tolist(),
Pre_Classified_Graph,
Rotation_Angle,
Cam_Distance)
if Save:
if Save_Path == None:
Save_Path = str(Path(OBJ_file_path).parent)
File_Name = f"{Save_Path}/{OBJ_file_path[len(Save_Path)+1:][:-4]}_Classified_Graph.json"
Classified_Edges_Json(Classified_Graph, File_Name)
else:
File_Name = f"{Save_Path}/{OBJ_file_path[len(Save_Path)+1:][:-4]}_Classified_Graph.json"
Classified_Edges_Json(Classified_Graph, File_Name)
print(f"Extracted classified graph file is save to {File_Name}")
return Classified_Graph