-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_points_distances.py
70 lines (48 loc) · 3.45 KB
/
create_points_distances.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
import csv
import sys
from decimal import Decimal
from create_classification_array import average_values
import numpy
import math
filename = "Coherent_data/Slim_unique_csv_NaN_Removed.csv"
filename_output_csv = "Point_distances/point_distances_coherent.csv"
d= ["CH1_X1","CH1_Y1","CH1_Z1","CH2_X2","CH2_Y2","CH2_Z2","CH3_X3","CH3_Y3","CH3_Z3","FH1_X4","FH1_Y4","FH1_Z4","FH2_X5","FH2_Y5","FH2_Z5","FH3_X6","FH3_Y6","FH3_Z6","LC1_X7","LC1_Y7","LC1_Z7","LC2_X8","LC2_Y8","LC2_Z8","LC3_X9","LC3_Y9","LC3_Z9","LC4_X10","LC4_Y10","LC4_Z10","LC5_X11","LC5_Y11","LC5_Z11","LC6_X12","LC6_Y12","LC6_Z12","LC7_X13","LC7_Y13","LC7_Z13","LC8_X14","LC8_Y14","LC8_Z14","RC1_X15","RC1_Y15","RC1_Z15","RC2_X16","RC2_Y16","RC2_Z16","RC3_X17","RC3_Y17","RC3_Z17","RC4_X18","RC4_Y18","RC4_Z18","RC5_X19","RC5_Y19","RC5_Z19","RC6_X20","RC6_Y20","RC6_Z20","RC7_X21","RC7_Y21","RC7_Z21","RC8_X22","RC8_Y22","RC8_Z22","LLID_X23","LLID_Y23","LLID_Z23","RLID_X24","RLID_Y24","RLID_Z24","MH_X25","MH_Y25","MH_Z25","MNOSE_X26","MNOSE_Y26","MNOSE_Z26","LNSTRL_X27","LNSTRL_Y27","LNSTRL_Z27","TNOSE_X28","TNOSE_Y28","TNOSE_Z28","RNSTRL_X29","RNSTRL_Y29","RNSTRL_Z29","LBM0_X30","LBM0_Y30","LBM0_Z30","LBM1_X31","LBM1_Y31","LBM1_Z31","LBM2_X32","LBM2_Y32","LBM2_Z32","LBM3_X33","LBM3_Y33","LBM3_Z33","RBM0_X34","RBM0_Y34","RBM0_Z34","RBM1_X35","RBM1_Y35","RBM1_Z35","RBM2_X36","RBM2_Y36","RBM2_Z36","RBM3_X37","RBM3_Y37","RBM3_Z37","LBRO1_X38","LBRO1_Y38","LBRO1_Z38","LBRO2_X39","LBRO2_Y39","LBRO2_Z39","LBRO3_X40","LBRO3_Y40","LBRO3_Z40","LBRO4_X41","LBRO4_Y41","LBRO4_Z41","RBRO1_X42","RBRO1_Y42","RBRO1_Z42","RBRO2_X43","RBRO2_Y43","RBRO2_Z43","RBRO3_X44","RBRO3_Y44","RBRO3_Z44","RBRO4_X45","RBRO4_Y45","RBRO4_Z45","Mou1_X46","Mou1_Y46","Mou1_Z46","Mou2_X47","Mou2_Y47","Mou2_Z47","Mou3_X48","Mou3_Y48","Mou3_Z48","Mou4_X49","Mou4_Y49","Mou4_Z49","Mou5_X50","Mou5_Y50","Mou5_Z50","Mou6_X51","Mou6_Y51","Mou6_Z51","Mou7_X52","Mou7_Y52","Mou7_Z52","Mou8_X53","Mou8_Y53","Mou8_Z53","LHD_X60","LHD_Y60","LHD_Z60","RHD_X61","RHD_Y61","RHD_Z61","video_name","Class"]
new_string = []
i = 0
while i<= 156: #156 perchè non consideriamo RDH e LDH che sono i due punti della testa
j=i+3
while j<=156:
distanceIJ = d[i][0:-3] + d[j][0:-3]
new_string.append(distanceIJ)
j+=3
i+=3
with open(filename_output_csv, 'w') as f:
writer = csv.writer(f)
new_string.append("video_name")
new_string.append("Class")
writer.writerow(new_string)
f.close()
#print(len(new_string))
def calculate_point_distance( x1, y1, z1, x2, y2, z2):
result = math.sqrt( (x2 - x1)**2 + (y2 - y1)**2 + (z2 - z1)**2 )
#print(str (result))
return result
with open(filename, 'r') as inp, open(filename_output_csv, 'a') as out:
writer = csv.writer(out)
inp.readline()
current_row = 1
for row in csv.reader(inp):
print("working on row " + str(current_row))
new_distances_row = []
i = 0
while i<= 156:
j=i+3
while j<=156:
distanceIJ = calculate_point_distance(float(row[i]),float(row[i+1]),float(row[i+2]),float(row[j]),float(row[j+1]),float(row[j+2]))
new_distances_row.append(distanceIJ)
j+=3
i+=3
new_distances_row.append(row[165])
new_distances_row.append(row[166])
writer.writerow(new_distances_row)
current_row +=1