-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.py
250 lines (178 loc) · 6.05 KB
/
test.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
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
import os
import sys
import datetime
import configparser
# import scipy
print(os.getpid())
print(datetime.datetime.now())
sys.path.insert(
0, '/home/mephisto/repos/linkml_cpp/build/')
import _core
from _core import *
# Actions
# PARSE_DATASET: bool = False
# ANNOTATE: bool = False
# REGISTER: bool = False
# FILTER: bool = False
# MERGE: bool = False
# DOWNSAMPLE: bool = False
# CLUSTER: bool = False
# REGION_GROWING: bool = False
# SOLIDIFY: bool = True
# UPLOAD: bool = False
# PARSE_DATASET: bool = False
# ANNOTATE: bool = False
# REGISTER: bool = False
# FILTER: bool = False
# MERGE: bool = False
# DOWNSAMPLE: bool = False
# CLUSTER: bool = False
# REGION_GROWING: bool = True
# SOLIDIFY: bool = True
# UPLOAD: bool = False
# PARSE_DATASET: bool = False
# ANNOTATE: bool = False
# REGISTER: bool = False
# FILTER: bool = False
# MERGE: bool = False
# DOWNSAMPLE: bool = True
# CLUSTER: bool = True
# REGION_GROWING: bool = True
# SOLIDIFY: bool = True
# UPLOAD: bool = False
PARSE_DATASET: bool = False
ANNOTATE: bool = False
REGISTER: bool = False
FILTER: bool = False
MERGE: bool = False
DOWNSAMPLE: bool = False
CLUSTER: bool = False
REGION_GROWING: bool = False
SOLIDIFY: bool = False
UPLOAD: bool = False
print("LinkML-Py loaded")
def chunks(lst, n):
"""Yield successive n-sized chunks from lst."""
for i in range(0, len(lst), n):
yield lst[i:i + n]
dataset_path = None
# dataset_path = "/home/mephisto/server_data/stray_scans/0ba33d855b/" # CPC Office
# dataset_path = "/home/mephisto/server_data/stray_scans/7092626a22/" # Aarhus Office
# dataset_path = "/home/mephisto/server_data/stray_scans/665518e46a/" # Lobby (School)
# Aarhus
# dataset_path = "/home/mephisto/server_data/stray_scans/8c0e3c381c/" # New scan small Basement <- Selected (Needs compleate rerun)
# dataset_path = "/home/mephisto/server_data/stray_scans/3c670b035f/" # Amtssygehus
# Roskilde
# dataset_path = "/home/mephisto/server_data/stray_scans/fc5fa7fa4e/" # Skate hall
# dataset_path = "/home/mephisto/server_data/stray_scans/088a8f84be/" # Stadium
# dataset_path = "/home/mephisto/server_data/stray_scans/73b319729d/" # Library <- Selected
# Soagerskole
# dataset_path = "/home/mephisto/server_data/stray_scans/b6b9b53142/" # School gym
# dataset_path = "/home/mephisto/server_data/stray_scans/88d7ea3e5f/" # School 1
# dataset_path = "/home/mephisto/server_data/stray_scans/bc53387047/" # School 2
# For Rune
# dataset_path = "/home/mephisto/server_data/stray_scans/3c670b035f/" # Amtssygehus
# dataset_path = "/home/mephisto/server_data/stray_scans/8c0e3c381c/" # Amtssygehus Basement
# dataset_path = "/home/mephisto/server_data/stray_scans/15a7dbf663/" # ??? 7.4 GB
# dataset_path = "/home/mephisto/server_data/stray_scans/afb3234950/" # ???
# dataset_path = "/home/mephisto/server_data/stray_scans/c582d1f758/" # ???
# 5672fda3aaf
# id = "bf96883816" # bf96883816
id = "bf96883816" #
dataset_path = f"/home/mephisto/server_data/stray_scans/{id}/"
dataset = None
name = None
tmp_folder = None
if dataset_path:
dataset = Dataset(dataset_path)
name = f"./{dataset.name}.pcd"
tmp_folder = f"./{dataset.name}/"
print(f"Dataset: {dataset.name} at {dataset_path}")
print(f"temp folder: {tmp_folder}")
# Parse dataset
if (PARSE_DATASET):
# Remove temp data
if not os.path.exists(tmp_folder):
os.makedirs(tmp_folder)
else:
for file in os.listdir(tmp_folder):
os.remove(os.path.join(tmp_folder, file))
parse_dataset(dataset, tmp_folder, step=4)
if tmp_folder is not None and os.path.exists(tmp_folder):
clouds = PointCloudsOnDisk(tmp_folder)
#clouds = PointCloudsInMemory(tmp_folder)
# Annotate
if (ANNOTATE):
for idx, subset in enumerate(chunks(clouds, 1000)):
subset.annotate("./yolov8x-seg.onnx", dataset)
print(f"Annotated {idx+1}th subset of {len(clouds)/1000} subsets")
#clouds.annotate("./yolov8x-seg.onnx", dataset)
# Registration
if (REGISTER):
clouds.register()
# Filter
if (FILTER):
clouds.filter()
# Merge
if (MERGE):
cloud = clouds.merge()
cloud.save(name)
# cloud.display()
# name = "/home/mephisto/server_data/test_export 2.pcd"
# if (not os.path.exists(name)):
# print(f"File \"{name}\" not found")
# exit(1)
print(f"Loading \"{name}\" ...")
cloud = PointCloud(name)
print("Done loading!")
# Downsample
if (DOWNSAMPLE):
cloud.downsample(0.05)
cloud.save(name)
# Clustering
if (CLUSTER):
cloud.clustering(
cluster_tolerance = 0.1, # 0.02,
min_cluster_size = 100
)
cloud.save(name)
# cloud.display()
# Region growing
if (REGION_GROWING):
cloud.region_growing(
#angle_threshold = float(0.96592583),
#plane_dist_threshold = float(0.1),
minClusterSize = 500,
#early_stop = float(0.3),
radius = float(0.3),
#interval_0 = float(16),
#interval_factor = float(1.5),
)
cloud.save(name)
# cloud.display()
# Solidify
brep_folder = f"./breps/"
if dataset is not None:
brep_folder = f"./{dataset.name}_breps/"
# brep_folder = f"./soagerskole_breps/"
if (SOLIDIFY):
breps = cloud.solidify()
# Remove existing breps
if not os.path.exists(brep_folder):
os.makedirs(brep_folder)
else:
for file in os.listdir(brep_folder):
os.remove(os.path.join(brep_folder, file))
# Save breps
for idx, brep in enumerate(breps):
brep.save(brep_folder + f"{dataset.name}_{idx}.off")
if dataset is not None:
dataset.display(dataset.name, False)
if os.path.exists(brep_folder):
for file in os.listdir(brep_folder):
brep = Brep.load(brep_folder + file)
brep.display(file, False)
else:
print(f"Breps folder \"{brep_folder}\" not found")
cloud.display()
print("Done")