-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_element_info.py
More file actions
169 lines (119 loc) · 4.67 KB
/
check_element_info.py
File metadata and controls
169 lines (119 loc) · 4.67 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
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
import ifcopenshell
import ifcopenshell.util.placement
import ifcopenshell.geom
import numpy as np
import matplotlib.pyplot as plt
import numpy as np
import numpy as np
def calcular_extremos(array):
# Obtener los valores máximos y mínimos en cada dimensión
min_x = np.min(array[:,0])
max_x = np.max(array[:,0])
min_y = np.min(array[:,1])
max_y = np.max(array[:,1])
min_z = np.min(array[:,2])
max_z = np.max(array[:,2])
# Crear arrays para los mínimos y máximos de cada dimensión
extremos_x = np.array([min_x, max_x])
extremos_y = np.array([min_y, max_y])
extremos_z = np.array([min_z, max_z])
# Crear combinaciones de puntos
combinaciones = []
for x in extremos_x:
for y in extremos_y:
for z in extremos_z:
combinaciones.append([x, y, z])
return np.array(combinaciones)
def calcular_puntos_medios(points, n=1):
new_points = list(points)
for _ in range(n):
temp_points = list(new_points)
for i in range(len(points)):
p1 = temp_points[i]
p2 = temp_points[(i + 1) % len(points)] # El último punto se conecta con el primero
medio = (p1 + p2) / 2.0
# Verificar si el punto medio ya está en la lista antes de agregarlo
if not any(np.array_equal(medio, p) for p in new_points):
new_points.append(medio)
return np.array(new_points)
def calcular_centro(vertices):
vertices = np.array(vertices).reshape(-1, 3)
centro = np.mean(vertices, axis=0)
return centro
#Inicializacion del archivo IFC
model = ifcopenshell.open('model.ifc')
settings = ifcopenshell.geom.settings()
#Elementos a representar
walls = model.by_type('IfcWall')
doors = model.by_type('IfcDoor')
columns = model.by_type('IfcColumn')
# Crear un archivo de texto para guardar los puntos y centros
output_file_gt_3 = open('puertas_z_mayor_3.txt', 'w')
output_file_lt_3 = open('puertas_z_menor_3.txt', 'w')
count = 0
normal_walls = 0
rare_walls = 0
# Crear una figura 3D para visualizar los puntos
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
for wall in walls:
matrix = ifcopenshell.util.placement.get_local_placement(wall.ObjectPlacement)
shape = ifcopenshell.geom.create_shape(settings, wall)
points = np.array(shape.geometry.verts).reshape(-1, 3)
# Calcular el centro de la pared
centro = matrix[:,3][:3]
rotation_matrix = matrix[:3, :3]
points = np.dot(points, rotation_matrix)
# Sumar el centro a las coordenadas de los puntos para obtener su posicion global
points = points + centro
if(len(points) > 8):
points = calcular_extremos(points)
# # Escribir los puntos de la pared en el archivo
# for i, point in enumerate(points):
# output_file.write(f'{count} {point[0]} {point[1]} {point[2]}\n')
# Visualizar los puntos en la matriz 3D
if(len(points)):
ax.scatter(points[:, 0], points[:, 1], points[:, 2], marker='.', c='red')
count += 1
count = 0
for door in doors:
matrix = ifcopenshell.util.placement.get_local_placement(door.ObjectPlacement)
shape = ifcopenshell.geom.create_shape(settings, door)
points = np.array(shape.geometry.verts).reshape(-1, 3)
# Calcular el centro de la puerta
centro = matrix[:,3][:3]
rotation_matrix = matrix[:3, :3]
points = np.dot(points, rotation_matrix)
# Sumar el centro a las coordenadas de los puntos
points = points + centro
if(len(points)):
ax.scatter(points[:, 0], points[:, 1], points[:, 2], marker='.', c='blue')
if centro[2] > 3:
for point in points:
output_file_gt_3.write(f'{count} {point[0]} {point[1]} {point[2]}\n')
else:
for point in points:
output_file_lt_3.write(f'{count} {point[0]} {point[1]} {point[2]}\n')
# Visualizar los puntos en la matriz 3D
count += 1
count = 0
for column in columns:
matrix = ifcopenshell.util.placement.get_local_placement(column.ObjectPlacement)
shape = ifcopenshell.geom.create_shape(settings, column)
points = np.array(shape.geometry.verts).reshape(-1, 3)
# Calcular el centro de la puerta
centro = matrix[:,3][:3]
rotation_matrix = matrix[:3, :3]
points = np.dot(points, rotation_matrix)
# Sumar el centro a las coordenadas de los puntos
points = points + centro
#Visualizar los puntos en la matriz 3D
if(len(points)):
ax.scatter(points[:, 0], points[:, 1], points[:, 2], marker='.', c='green')
count += 1
# Mostrar la matriz 3D
ax.axis("equal")
plt.show()
# Cerrar el archivo de texto
output_file_gt_3.close()
output_file_lt_3.close()