| 1 |
import pycolmap |
| 2 |
|
| 3 |
|
| 4 |
def _make_sensor(sensor_type, sensor_id): |
| 5 |
return pycolmap.sensor_t(type=sensor_type, id=sensor_id) |
| 6 |
|
| 7 |
|
| 8 |
def test_rig_init(): |
| 9 |
rig = pycolmap.Rig() |
| 10 |
assert rig is not None |
| 11 |
|
| 12 |
|
| 13 |
def test_rig_rig_id_readwrite(): |
| 14 |
rig = pycolmap.Rig() |
| 15 |
rig.rig_id = 5 |
| 16 |
assert rig.rig_id == 5 |
| 17 |
|
| 18 |
|
| 19 |
def test_rig_add_ref_sensor(): |
| 20 |
rig = pycolmap.Rig() |
| 21 |
ref_sensor = _make_sensor(pycolmap.SensorType.CAMERA, 0) |
| 22 |
rig.add_ref_sensor(ref_sensor) |
| 23 |
assert rig.has_sensor(ref_sensor) |
| 24 |
assert rig.is_ref_sensor(ref_sensor) |
| 25 |
|
| 26 |
|
| 27 |
def test_rig_add_sensor(): |
| 28 |
rig = pycolmap.Rig() |
| 29 |
ref_sensor = _make_sensor(pycolmap.SensorType.CAMERA, 0) |
| 30 |
other_sensor = _make_sensor(pycolmap.SensorType.CAMERA, 1) |
| 31 |
rig.add_ref_sensor(ref_sensor) |
| 32 |
rig.add_sensor(other_sensor, None) |
| 33 |
assert rig.has_sensor(other_sensor) |
| 34 |
|
| 35 |
|
| 36 |
def test_rig_has_sensor(): |
| 37 |
rig = pycolmap.Rig() |
| 38 |
ref_sensor = _make_sensor(pycolmap.SensorType.CAMERA, 0) |
| 39 |
missing_sensor = _make_sensor(pycolmap.SensorType.CAMERA, 99) |
| 40 |
rig.add_ref_sensor(ref_sensor) |
| 41 |
assert rig.has_sensor(ref_sensor) |
| 42 |
assert not rig.has_sensor(missing_sensor) |
| 43 |
|
| 44 |
|
| 45 |
def test_rig_is_ref_sensor(): |
| 46 |
rig = pycolmap.Rig() |
| 47 |
ref_sensor = _make_sensor(pycolmap.SensorType.CAMERA, 0) |
| 48 |
other_sensor = _make_sensor(pycolmap.SensorType.CAMERA, 1) |
| 49 |
rig.add_ref_sensor(ref_sensor) |
| 50 |
rig.add_sensor(other_sensor, None) |
| 51 |
assert rig.is_ref_sensor(ref_sensor) |
| 52 |
assert not rig.is_ref_sensor(other_sensor) |
| 53 |
|
| 54 |
|
| 55 |
def test_rig_num_sensors(): |
| 56 |
rig = pycolmap.Rig() |
| 57 |
ref_sensor = _make_sensor(pycolmap.SensorType.CAMERA, 0) |
| 58 |
rig.add_ref_sensor(ref_sensor) |
| 59 |
assert rig.num_sensors() == 1 |
| 60 |
other_sensor = _make_sensor(pycolmap.SensorType.CAMERA, 1) |
| 61 |
rig.add_sensor(other_sensor, None) |
| 62 |
assert rig.num_sensors() == 2 |
| 63 |
|
| 64 |
|
| 65 |
def test_rig_ref_sensor_id(): |
| 66 |
rig = pycolmap.Rig() |
| 67 |
ref_sensor = _make_sensor(pycolmap.SensorType.CAMERA, 0) |
| 68 |
rig.add_ref_sensor(ref_sensor) |
| 69 |
assert rig.ref_sensor_id == ref_sensor |
| 70 |
|
| 71 |
|
| 72 |
def test_rig_sensor_ids(): |
| 73 |
rig = pycolmap.Rig() |
| 74 |
ref_sensor = _make_sensor(pycolmap.SensorType.CAMERA, 0) |
| 75 |
other_sensor = _make_sensor(pycolmap.SensorType.CAMERA, 1) |
| 76 |
rig.add_ref_sensor(ref_sensor) |
| 77 |
rig.add_sensor(other_sensor, None) |
| 78 |
sensor_ids = rig.sensor_ids() |
| 79 |
assert ref_sensor in sensor_ids |
| 80 |
assert other_sensor in sensor_ids |
| 81 |
|
| 82 |
|
| 83 |
def test_rig_non_ref_sensors(): |
| 84 |
rig = pycolmap.Rig() |
| 85 |
ref_sensor = _make_sensor(pycolmap.SensorType.CAMERA, 0) |
| 86 |
other_sensor = _make_sensor(pycolmap.SensorType.CAMERA, 1) |
| 87 |
rig.add_ref_sensor(ref_sensor) |
| 88 |
rig.add_sensor(other_sensor, None) |
| 89 |
non_ref = rig.non_ref_sensors |
| 90 |
assert other_sensor in non_ref |
| 91 |
|
| 92 |
|
| 93 |
def test_rig_has_sensor_from_rig(): |
| 94 |
rig = pycolmap.Rig() |
| 95 |
ref_sensor = _make_sensor(pycolmap.SensorType.CAMERA, 0) |
| 96 |
other_sensor = _make_sensor(pycolmap.SensorType.CAMERA, 1) |
| 97 |
rig.add_ref_sensor(ref_sensor) |
| 98 |
rig.add_sensor(other_sensor, None) |
| 99 |
# No transform set yet. |
| 100 |
assert not rig.has_sensor_from_rig(other_sensor) |
| 101 |
|
| 102 |
|
| 103 |
def test_rig_sensor_from_rig(): |
| 104 |
rig = pycolmap.Rig() |
| 105 |
ref_sensor = _make_sensor(pycolmap.SensorType.CAMERA, 0) |
| 106 |
other_sensor = _make_sensor(pycolmap.SensorType.CAMERA, 1) |
| 107 |
rig.add_ref_sensor(ref_sensor) |
| 108 |
rig.add_sensor(other_sensor, None) |
| 109 |
# Returns optional, should be None since not set. |
| 110 |
result = rig.sensor_from_rig(other_sensor) |
| 111 |
assert result is None |
| 112 |
|
| 113 |
|
| 114 |
def test_rig_set_sensor_from_rig(): |
| 115 |
rig = pycolmap.Rig() |
| 116 |
ref_sensor = _make_sensor(pycolmap.SensorType.CAMERA, 0) |
| 117 |
other_sensor = _make_sensor(pycolmap.SensorType.CAMERA, 1) |
| 118 |
rig.add_ref_sensor(ref_sensor) |
| 119 |
rig.add_sensor(other_sensor, None) |
| 120 |
transform = pycolmap.Rigid3d() |
| 121 |
rig.set_sensor_from_rig(other_sensor, transform) |
| 122 |
assert rig.has_sensor_from_rig(other_sensor) |
| 123 |
|
| 124 |
|
| 125 |
def test_rig_reset_sensor_from_rig(): |
| 126 |
rig = pycolmap.Rig() |
| 127 |
ref_sensor = _make_sensor(pycolmap.SensorType.CAMERA, 0) |
| 128 |
other_sensor = _make_sensor(pycolmap.SensorType.CAMERA, 1) |
| 129 |
rig.add_ref_sensor(ref_sensor) |
| 130 |
rig.add_sensor(other_sensor, pycolmap.Rigid3d()) |
| 131 |
assert rig.has_sensor_from_rig(other_sensor) |
| 132 |
rig.reset_sensor_from_rig(other_sensor) |
| 133 |
assert not rig.has_sensor_from_rig(other_sensor) |
| 134 |
|
| 135 |
|
| 136 |
def test_rig_map_empty(): |
| 137 |
rig_map = pycolmap.RigMap() |
| 138 |
assert len(rig_map) == 0 |
| 139 |
|
| 140 |
|
| 141 |
def test_rig_map_insert_and_access(): |
| 142 |
rig_map = pycolmap.RigMap() |
| 143 |
rig = pycolmap.Rig() |
| 144 |
rig.rig_id = 1 |
| 145 |
rig_map[1] = rig |
| 146 |
assert len(rig_map) == 1 |
| 147 |
assert rig_map[1].rig_id == 1 |