def test_convert_xyz_returns_correct_X_Y_Z_for_simple_array(self): test_array = np.array([[1, 1, 1], [2, 2, 2], [3, 3, 3], [4, 4, 4]]) result = GLConverter().convert_xyz(test_array) self.assertEqual((4, 8), result.shape) self.assertListAlmostEqual([1, 1, 1], result[0][:3]) self.assertListAlmostEqual([2, 2, 2], result[1][:3]) self.assertListAlmostEqual([3, 3, 3], result[2][:3]) self.assertListAlmostEqual([4, 4, 4], result[3][:3])
def test_convert_xyz_returns_correct_X_Y_Z_for_simple_array_with_scale( self): test_array = np.array([[9, 8, 8], [7, 6, 8], [5, 4, 8], [3, 2, 8]]) result = GLConverter().convert_xyz(test_array, scale=0.1) self.assertEqual((4, 8), result.shape) self.assertListAlmostEqual([0.9, 0.8, 0.8], result[0, :3]) self.assertListAlmostEqual([0.7, 0.6, 0.8], result[1, :3]) self.assertListAlmostEqual([0.5, 0.4, 0.8], result[2, :3]) self.assertListAlmostEqual([0.3, 0.2, 0.8], result[3, :3])
def test_convert_xyz_calculates_texture_coordanates(self): test_array = np.array([[1, 1, 1], [-1, -1, -1], [-1, 1, 1], [1, -1, -1]]) result = GLConverter().convert_xyz(test_array) self.assertEqual((4, 8), result.shape) self.assertListAlmostEqual([0.125, 0.644], result[0, 6:8], decimals=3) self.assertListAlmostEqual([0.625, 0.356], result[1, 6:8], decimals=3) self.assertListAlmostEqual([0.875, 0.644], result[2, 6:8], decimals=3) self.assertListAlmostEqual([0.375, 0.356], result[3, 6:8], decimals=3)
def test_convert_xyz_calculates_simple_normals(self): test_array = np.array([[9, 8, 8], [7, 6, 8], [5, 4, 8], [3, 2, 8]]) unit_vectors = test_array / np.linalg.norm(test_array) result = GLConverter().convert_xyz(test_array) self.assertEqual((4, 8), result.shape) self.assertListAlmostEqual(unit_vectors[0], result[0, 3:6]) self.assertListAlmostEqual(unit_vectors[1], result[1, 3:6]) self.assertListAlmostEqual(unit_vectors[2], result[2, 3:6]) self.assertListAlmostEqual(unit_vectors[3], result[3, 3:6])
def test_convert_xyz_is_fast(self): points = 10000 test_array = np.random.rand(points, 3) start = time.time() result = GLConverter().convert_xyz(test_array) total = time.time() - start print "Total time: {}".format(total) print "ms per point: {}".format((total * 1000) / points) print "pps: {:.0f}".format(points / total) self.assertTrue(total < 1 / 120.0)
def setUp(self): self.stub_point_thinner = StubPointThinner() self.writer = PLYWriter(GLConverter(), self.stub_point_thinner)
def __init__(self, scanner, **kwargs): super(PointsCapture, self).__init__(**kwargs) self.scanner = scanner self._converter = GLConverter() self.raw_points_xyz = np.array([])
def save_points(self, path, filename): with open(os.path.join(path, filename), 'w') as afile: thinner = PointThinner() converter = GLConverter() PLYWriter(converter, thinner).write_cartisien_points(afile, self.raw_points_xyz) self.dismiss_popup()
def test_convert_xyz_returns_empty_for_empty_array(self): result = GLConverter().convert_xyz(np.array([])) self.assertEqual(0, len(result))