| 1 |
import numpy as np |
| 2 |
|
| 3 |
import pycolmap |
| 4 |
|
| 5 |
|
| 6 |
def test_rigid3d_default_init(): |
| 7 |
rigid = pycolmap.Rigid3d() |
| 8 |
assert rigid is not None |
| 9 |
|
| 10 |
|
| 11 |
def test_rigid3d_init_rotation_translation(): |
| 12 |
rotation = pycolmap.Rotation3d() |
| 13 |
translation = np.array([1.0, 2.0, 3.0]) |
| 14 |
rigid = pycolmap.Rigid3d(rotation=rotation, translation=translation) |
| 15 |
assert rigid is not None |
| 16 |
|
| 17 |
|
| 18 |
def test_rigid3d_init_from_matrix(): |
| 19 |
matrix = np.eye(3, 4) |
| 20 |
rigid = pycolmap.Rigid3d(matrix=matrix) |
| 21 |
assert rigid is not None |
| 22 |
|
| 23 |
|
| 24 |
def test_rigid3d_params_readwrite(): |
| 25 |
rigid = pycolmap.Rigid3d() |
| 26 |
params = rigid.params |
| 27 |
assert params.shape == (7,) |
| 28 |
new_params = np.array([0.0, 0.0, 0.0, 1.0, 1.0, 2.0, 3.0]) |
| 29 |
rigid.params = new_params |
| 30 |
np.testing.assert_array_almost_equal(rigid.params, new_params) |
| 31 |
|
| 32 |
|
| 33 |
def test_rigid3d_rotation_property(): |
| 34 |
rigid = pycolmap.Rigid3d() |
| 35 |
rotation = rigid.rotation |
| 36 |
assert isinstance(rotation, pycolmap.Rotation3d) |
| 37 |
|
| 38 |
|
| 39 |
def test_rigid3d_translation_readwrite(): |
| 40 |
rigid = pycolmap.Rigid3d() |
| 41 |
translation = rigid.translation |
| 42 |
assert np.array(translation).shape == (3,) |
| 43 |
rigid.translation = np.array([4.0, 5.0, 6.0]) |
| 44 |
np.testing.assert_array_almost_equal(rigid.translation, [4.0, 5.0, 6.0]) |
| 45 |
|
| 46 |
|
| 47 |
def test_rigid3d_matrix(): |
| 48 |
rigid = pycolmap.Rigid3d() |
| 49 |
matrix = rigid.matrix() |
| 50 |
assert matrix.shape == (3, 4) |
| 51 |
|
| 52 |
|
| 53 |
def test_rigid3d_tgt_origin_in_src(): |
| 54 |
rigid = pycolmap.Rigid3d() |
| 55 |
rigid.translation = np.array([1.0, 2.0, 3.0]) |
| 56 |
result = rigid.tgt_origin_in_src() |
| 57 |
assert result.shape == (3,) |
| 58 |
|
| 59 |
|
| 60 |
def test_rigid3d_adjoint(): |
| 61 |
rigid = pycolmap.Rigid3d() |
| 62 |
adjoint = rigid.adjoint() |
| 63 |
assert adjoint.shape == (6, 6) |
| 64 |
|
| 65 |
|
| 66 |
def test_rigid3d_adjoint_inverse(): |
| 67 |
rigid = pycolmap.Rigid3d() |
| 68 |
adjoint_inverse = rigid.adjoint_inverse() |
| 69 |
assert adjoint_inverse.shape == (6, 6) |
| 70 |
|
| 71 |
|
| 72 |
def test_rigid3d_inverse(): |
| 73 |
rigid = pycolmap.Rigid3d() |
| 74 |
rigid.translation = np.array([1.0, 2.0, 3.0]) |
| 75 |
inverse = rigid.inverse() |
| 76 |
assert isinstance(inverse, pycolmap.Rigid3d) |
| 77 |
|
| 78 |
|
| 79 |
def test_rigid3d_multiply_rigid3d(): |
| 80 |
rigid1 = pycolmap.Rigid3d() |
| 81 |
rigid2 = pycolmap.Rigid3d() |
| 82 |
result = rigid1 * rigid2 |
| 83 |
assert isinstance(result, pycolmap.Rigid3d) |
| 84 |
|
| 85 |
|
| 86 |
def test_rigid3d_multiply_vector3d(): |
| 87 |
rigid = pycolmap.Rigid3d() |
| 88 |
rigid.translation = np.array([1.0, 0.0, 0.0]) |
| 89 |
vector = np.array([0.0, 0.0, 0.0]) |
| 90 |
result = rigid * vector |
| 91 |
assert result.shape == (3,) |
| 92 |
|
| 93 |
|
| 94 |
def test_rigid3d_multiply_nx3_matrix(): |
| 95 |
rigid = pycolmap.Rigid3d() |
| 96 |
points = np.array([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]]) |
| 97 |
result = rigid * points |
| 98 |
assert result.shape == (2, 3) |
| 99 |
|
| 100 |
|
| 101 |
def test_rigid3d_interpolate(): |
| 102 |
rigid1 = pycolmap.Rigid3d() |
| 103 |
rigid2 = pycolmap.Rigid3d() |
| 104 |
rigid2.translation = np.array([2.0, 0.0, 0.0]) |
| 105 |
result = pycolmap.Rigid3d.interpolate(rigid1, rigid2, 0.5) |
| 106 |
assert isinstance(result, pycolmap.Rigid3d) |
| 107 |
|
| 108 |
|
| 109 |
def test_get_covariance_for_inverse(): |
| 110 |
rigid = pycolmap.Rigid3d() |
| 111 |
covariance = np.eye(6) |
| 112 |
result = pycolmap.get_covariance_for_inverse(rigid, covariance) |
| 113 |
assert result.shape == (6, 6) |
| 114 |
|
| 115 |
|
| 116 |
def test_get_covariance_for_composed_rigid3d(): |
| 117 |
rigid = pycolmap.Rigid3d() |
| 118 |
joint_covariance = np.eye(12) |
| 119 |
result = pycolmap.get_covariance_for_composed_rigid3d( |
| 120 |
rigid, joint_covariance |
| 121 |
) |
| 122 |
assert result.shape == (6, 6) |
| 123 |
|
| 124 |
|
| 125 |
def test_get_covariance_for_relative_rigid3d(): |
| 126 |
rigid1 = pycolmap.Rigid3d() |
| 127 |
rigid2 = pycolmap.Rigid3d() |
| 128 |
joint_covariance = np.eye(12) |
| 129 |
result = pycolmap.get_covariance_for_relative_rigid3d( |
| 130 |
rigid1, rigid2, joint_covariance |
| 131 |
) |
| 132 |
assert result.shape == (6, 6) |
| 133 |
|
| 134 |
|
| 135 |
def test_average_quaternions(): |
| 136 |
rotation1 = pycolmap.Rotation3d() |
| 137 |
rotation2 = pycolmap.Rotation3d() |
| 138 |
result = pycolmap.average_quaternions([rotation1, rotation2], [1.0, 1.0]) |
| 139 |
assert result is not None |
| 140 |
|
| 141 |
|
| 142 |
def test_interpolate_camera_poses(): |
| 143 |
rigid1 = pycolmap.Rigid3d() |
| 144 |
rigid2 = pycolmap.Rigid3d() |
| 145 |
rigid2.translation = np.array([2.0, 0.0, 0.0]) |
| 146 |
result = pycolmap.interpolate_camera_poses(rigid1, rigid2, 0.5) |
| 147 |
assert isinstance(result, pycolmap.Rigid3d) |