This reposetory containes python implementations for for extracting 2D orthogonal and perspective graphs from 3D roof file (.obj file). Moreover, using this implementation, edges on the roof can be classified. Also, the visible block on the rooftop as well as their bounding box can be extracted using the 3D file.
3.9 or higher
- numpy
- pandas
- shapely
- trimesh
- PyGLM
- scikit-learn
To install required libraries you can run the following command.
pip install -r requirements.txt
Run the "Execution.py" and change the output path to where you want to save files.
After the execution is done, In the chosen folder as output There will folders for each generared roof in each roof specific folder will be a 3D file with ".obj" format and five files (2 csv files and 3 json files). The 2 csv files are orthogonal, perspective graph keypoints and the json files containe edges on the roof with their classifications, blocks graph keypoints and each block bounding box as well as visible key points of that block.
import matplotlib.pyplot as plt
from Functions.Additional_Functions import *
from Functions.Edge_Classification_Functions import *
from Functions.Graph_Extraction_Functions import *
from Functions.Plot_Functions import *
from Functions.Base_Block_Functions import *
from Functions.Complex_One_Floor_Roofs import *
from Functions.Complex_Multi_Floor_Roofs import *
from Functions.Constrains_Functions import *
from Functions.Block_Extraction_Functions import *
Roof_Path = r"Path\To\3D_File.obj"
Roof = trimesh.load_mesh(Roof_Path)
Cam_Roof = camera_Mesh(Roof, 30, 1, -1, 100, 0, 0, 80)
Roof_Graph, Graph_Blocks_Ortho = Graph_Extraction(Roof, Cam_Roof, 0.02, 0.01)
List_of_Polygons_Points_Normal_Orthogonal = Poly_Point_Normal(Roof_Graph)
Orthogonal_Graph_Key_Points = KeyPoint_Extraction(List_of_Polygons_Points_Normal_Orthogonal)
Roof_Path = r"Path\To\3D_File.obj"
Roof = trimesh.load_mesh(Roof_Path)
Cam_Roof = camera_Mesh(Roof, 30, 1, -1, 100, 0, 0, 80)
Pre_Perspective_Graph, _ = Graph_Extraction(Roof, Cam_Roof, 0.001, 0.001, Perspective = True)
Perspective_Graph = remove_extra_walls(Pre_Perspective_Graph)
List_of_Polygons_Points_Normal_Perspective = Poly_Point_Normal(Perspective_Graph)
Perspective_Graph_Key_Points = KeyPoint_Extraction(List_of_Polygons_Points_Normal_Perspective)
Roof_Path = r"Path\To\3D_File.obj"
Roof = trimesh.load_mesh(Roof_Path)
Cam_Roof = camera_Mesh(Roof, 30, 1, -1, 100, 0, 0, 80)
Roof_Graph, Graph_Blocks_Ortho = Graph_Extraction(Roof, Cam_Roof, 0.02, 0.01)
List_of_Polygons_Points_Normal_Orthogonal = Poly_Point_Normal(Roof_Graph)
Classified_Graph, _ = Classification_Correction(Roof, Cam_Roof, List_of_Polygons_Points_Normal_Perspective)
Roof_Path = r"Path\To\3D_File.obj"
Roof = trimesh.load_mesh(Roof_Path)
Cam_Roof = camera_Mesh(Roof, 30, 1, -1, 100, 0, 0, 80)
_, Graph_Blocks_Perspective = Graph_Extraction(Roof, Cam_Roof, 0.001, 0.001, Perspective = True)
Blocks_KeyPoint_Type_Bbox, Blocks_Graph_Plot = Block_Extraction(Roof, Cam_Roof, Graph_Blocks_Perspective)
import pandas as pd
import matplotlib.pyplot as plt
KeyPoints = pd.read_csv(r"Path\to\csv\file")
for i in range(len(KeyPoints)):
Points = KeyPoints.loc[i]
X = np.array([Points[0], Points[2]]).T
Y = np.array([Points[1], Points[3]]).T
plt.plot(X, Y, color = 'blue', linewidth = 1.5)
plt.scatter(X, Y, color = 'black', s = 50)
import json
import matplotlib.pyplot as plt
with open('Classified_Graph_json_file.json', 'r') as f:
Classified_Graph = json.load(f)
Plot_Graph_Classified(Classified_Graph)
import json
import matplotlib.pyplot as plt
with open('Blocks_Graph_json_file.json', 'r') as f:
Blocks_Graph_Plot = json.load(f)
Plot_Graph_KeyPoint(Blocks_Graph_Plot)
import json
import matplotlib.pyplot as plt
with open('Blocks_Graph_json_file.json', 'r') as f:
Blocks_Graph_Plot = json.load(f)
with open('Blocks_Graph_Bbox_json_file.json', 'r') as f:
Blocks_KeyPoint_Type_Bbox = json.load(f)
Plot_CutBlocks_Bbox(Blocks_KeyPoint_Type_Bbox, Blocks_Graph_Plot)