Skip to content

ramintkml/Roof_Graph_Extraction

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Roof Graph Extraction

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.

Requirements

Pyhton version

3.9 or higher

Libraries

  1. numpy
  2. pandas
  3. shapely
  4. trimesh
  5. PyGLM
  6. scikit-learn

To install required libraries you can run the following command.

pip install -r requirements.txt

Running the Implementation

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.

How to extract graphs from a 3D file

Imports

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 *

Orthogonal Graph key points Extraction

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)

Perspective Graph key points Extraction

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)

Edge Classification

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)

Blocks Graph Extraction

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)

How to read outputs again and visualise them

Graph Keypoints (CSV files)

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)

Classification and Blocks Graph (Json file)

If you are reading classified graph run the following command

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)

If you are reading blocks graph run the following command

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)

If you are reading blocks graph with bounding boxes run the following command

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)

Releases

No releases published

Packages

No packages published