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
|
import unittest
import numpy as np
import mrol_mapping.pointcloud as pointcloud
basedir = 'data/'
visualize = True
class TestPointCloud(unittest.TestCase):
def setUp(self):
X = np.random.random((10,3))
self.A = X[:7, :]
self.B = X[5:, :]
self.PCA = pointcloud.PointCloud(self.A)
self.PCB = pointcloud.PointCloud(self.B)
self.PCC = pointcloud.PointCloud(self.A[:-2])
self.PCcol = pointcloud.load(basedir + 'coloured_pc.npy')
def tearDown(self):
pass
def test_nearest_neighbour(self):
NN_dists, NN_inds = pointcloud.nearest_neighbour(self.A, self.B)
self.assertEqual([5,6], list(np.where(NN_dists < 0.00001)[0]))
def test_equal(self):
import copy
self.assertTrue(self.PCA == self.PCA)
self.assertTrue(self.PCA == copy.deepcopy(self.PCA))
self.assertFalse(self.PCA == self.PCB)
self.assertFalse(self.PCA == self.PCC)
def test_save_load(self):
pointcloud.save('/tmp/PCA.txt', self.PCA.points, text=True)
self.assertTrue(self.PCA == pointcloud.load('/tmp/PCA.txt'))
self.PCB.save('/tmp/PCB.npy')
self.assertTrue(self.PCB == pointcloud.load('/tmp/PCB.npy'))
def test_vis_boxfilt(self):
# TODO: An assert statement!
xmax=1.5
self.PCcol.display()
self.assertTrue(np.max(self.PCcol.points[:,0]) > xmax)
self.PCcol.boxfilter(xmax=xmax)
self.PCcol.display()
self.assertTrue(np.max(self.PCcol.points[:,0]) <= xmax)
def test_volumetric_sample(self):
res = 0.1
startshape = self.PCcol.points.shape
mins = np.min(self.PCcol.points[:,:3],axis=0)
maxs = np.max(self.PCcol.points[:,:3],axis=0)
sample = self.PCcol.volumetricsample(res)
newshape = sample.points.shape
newmins = np.min(sample.points[:,:3],axis=0)
newmaxs = np.max(sample.points[:,:3],axis=0)
#print "start shape:", startshape, "new shape:", newshape
#print "mins:", mins, "new mins:", newmins
#print "maxs:", maxs, "new maxs:", newmaxs
self.assertTrue((mins > newmins - res*0.49).all())
self.assertTrue((mins < newmins + res*0.51).all())
self.assertTrue((maxs > newmaxs - res*0.49).all())
self.assertTrue((maxs < newmaxs + res*0.51).all())
self.assertTrue(startshape[0] > newshape[0])
self.assertTrue(startshape[1] == newshape[1])
if __name__ == '__main__':
unittest.main()
|