-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtest.py
executable file
·153 lines (132 loc) · 4.34 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
#!/usr/bin/env python3
'''Script for testing point_cloud library.'''
from time import time
from numpy import abs, array, eye, max, tile, vstack, zeros
from numpy.linalg import norm
import point_cloud
def main():
'''Runs each of the functions in this module that begin with the name Test. Prints pass/fail info.'''
try:
X = point_cloud.LoadPcd("test.pcd")
# point_cloud.Plot(X)
GREEN = '\033[92m'
RED = '\033[91m'
END = '\033[0m'
except Exception as e:
print("Failed to initialize testing.")
print(str(e))
return
items = globals()
for item in items:
if len(item) > 4 and item[:4] == "Test":
try:
result = eval(item + "(X)")
except Exception as e:
print(str(e))
result = False
if result: print("[" + GREEN +"PASS" + END + "] " + item[4:])
else: print("[" + RED +"FAIL" + END + "] " + item[4:])
def TestComputeNormals(X):
N = point_cloud.ComputeNormals(X)
if N.shape[0] != X.shape[0] or N.shape[1] != 3: return False
if max(abs(norm(N, axis=1)-1.0)) > 0.001: return False
V = tile(array([[-1,0,1]]), (X.shape[0],1))
N = point_cloud.ComputeNormals(X, V, kNeighbors=30, rNeighbors=0)
if N.shape[0] != X.shape[0] or N.shape[1] != 3: return False
if max(abs(norm(N, axis=1)-1.0)) > 0.001: return False
return True
def TestExtractEuclideanClusters(X):
clouds, _ = point_cloud.ExtractEuclideanClusters(X, 0.01, 30)
if len(clouds) != 1: return False
return True
def TestIcp(X):
R = eye(4); R[0, 3] = 0.01
Y = point_cloud.Transform(R, X)
T = point_cloud.Icp(Y, X)
if max(abs(T-R)) > 0.001:
print(T)
print(R)
return False
return True
def TestRemoveStatisticalOutliers(X):
outlier = array([0, 0, 10])
Y = vstack((X, outlier))
Z = point_cloud.RemoveStatisticalOutliers(50, 0.05, Y)
if Z.shape[0] != X.shape[0] or Z.shape[1] != 3:
print(X.shape, Z.shape)
return False
return True
def TestRemoveStatisticalOutliersWithNormals(X):
outlier = array([0, 0, 10])
Y = vstack((X, outlier))
N = point_cloud.ComputeNormals(Y)
Y, N = point_cloud.RemoveStatisticalOutliers(50, 0.05, Y, N)
if X.shape[0] != Y.shape[0] or X.shape[0] != Y.shape[0] or Y.shape[1] != 3 or N.shape[1] != 3:
return False
return True
def TestSavePcd(X):
initCount = X.shape[0]
point_cloud.SavePcd("save.pcd", X)
X = point_cloud.LoadPcd("save.pcd")
return X.shape[0] == initCount and X.shape[1] == 3
def TestSegmentPlane(X):
point_cloud.SegmentPlane(X, 0.008)
return True
def TestVoxelize(X):
A = point_cloud.Voxelize(0.010, X)
B = point_cloud.Voxelize(0.005, X)
C = point_cloud.Voxelize(0.002, X)
if A.shape[0] > B.shape[0] or B.shape[0] > C.shape[0] or C.shape[0] > X.shape[0]:
print(X.shape, A.shape, B.shape, C.shape)
return False
if A.shape[1] != 3 or B.shape[1] != 3 or C.shape[1] != 3: return False
return True
def TestVoxelizeWithColors(X):
C = array([[0, 128, 255]], dtype="int32")
C = tile(C, (X.shape[0], 1))
XX, CC = point_cloud.Voxelize(0.005, X, colors = C)
if not CC.shape == XX.shape:
print(CC.shape, XX.shape)
return False
if not all((C[0] == CC).flatten()):
return False
C = array([[0., 128., 255.]]) / 255.0
C = tile(C, (X.shape[0], 1))
XX, CC = point_cloud.Voxelize(0.005, X, colors = C)
if not CC.shape == XX.shape:
print(CC.shape, XX.shape)
return False
if not all((C[0] == CC).flatten()):
return False
return True
def TestVoxelizeWithColorsAndNormals(X):
N = point_cloud.ComputeNormals(X)
C = array([[0.0, 0.5, 1.0]])
C = tile(C, (X.shape[0], 1))
XX, NN, CC = point_cloud.Voxelize(0.005, X, N, C)
if not CC.shape == XX.shape:
print(CC.shape, XX.shape)
return False
if not NN.shape == XX.shape:
print(NN.shape, XX.shape)
return False
if max(abs(CC - C[0])) > (1.0 / 255.0):
return False
return True
def TestVoxelizeWithNormals(X):
N = point_cloud.ComputeNormals(X)
XX, NN = point_cloud.Voxelize(0.005, X, N)
norms = norm(NN, axis=1)
if XX.shape[0] > X.shape[0] or NN.shape[0] > N.shape[0]:
print(X.shape, XX.shape, N.shape, NN.shape)
return False
if XX.shape[0] != NN.shape[0] or XX.shape[1] != NN.shape[1]:
return False
if XX.shape[1] != 3 or NN.shape[1] != 3: return False
if (norms > 1.001).any() or (norms < 0.999).any():
print(max(norms), min(norms))
return False
return True
if __name__ == "__main__":
main()
exit()