Skip to content

Commit

Permalink
Updated tests.
Browse files Browse the repository at this point in the history
This is all getting rather gross and needs some housekeeping
  • Loading branch information
TheMariday committed Jun 11, 2024
1 parent ed1eca3 commit 037977a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 34 deletions.
17 changes: 10 additions & 7 deletions lib/sfm/sfm.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,17 @@ def run(self):

def reload(self):
maps_2d = get_all_2d_led_maps(self.directory_monitor.directory)
self.process(maps_2d, self.rescale, self.interpolate)
map_3d = self.process(maps_2d, self.rescale, self.interpolate)
map_3d.write_to_file(
self.directory_monitor.directory / "reconstruction.csv"
)
return map_3d

def process(self, maps_2d, rescale=False, interpolate=False):
@staticmethod
def process(maps_2d, rescale=False, interpolate=False):

if len(maps_2d) < 2:
return
return None

with TemporaryDirectory() as temp_dir:
database_path = os.path.join(temp_dir, "database.db")
Expand All @@ -55,7 +60,7 @@ def process(self, maps_2d, rescale=False, interpolate=False):
)

if not os.path.exists(os.path.join(temp_dir, "0", "points3D.bin")):
return False
return None

map_3d, cams = get_map_and_cams(temp_dir)

Expand All @@ -66,6 +71,4 @@ def process(self, maps_2d, rescale=False, interpolate=False):
leds_interpolated = map_cleaner.fill_gaps(map_3d)
cprint(f"Interpolated {leds_interpolated} leds", format=Col.BLUE)

map_3d.write_to_file(
self.directory_monitor.directory / "reconstruction.csv"
)
return map_3d
36 changes: 14 additions & 22 deletions test/test_reconstruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,12 @@ def check_dimensions(map_3d, max_error):
def test_reconstruction():
maps = get_all_2d_led_maps("test/scan")

sfm = SFM(maps)
map_3d = SFM.process(maps)

sfm.process()

sfm.print_points()

assert len(sfm.maps_3d) == 21
assert len(map_3d) == 21

check_dimensions(
sfm.maps_3d, max_error=0.01 # needs to have a max deviation of less than 1%
map_3d, max_error=0.01 # needs to have a max deviation of less than 1%
)


Expand All @@ -54,44 +50,40 @@ def test_sparse_reconstruction():

maps_sparse = [maps[1], maps[3], maps[5], maps[7]]

sfm = SFM(maps_sparse)
map_3d = SFM.process(maps_sparse)

assert sfm.process()
assert map_3d is not None

sfm.print_points()

assert len(sfm.maps_3d) == 21
assert len(map_3d) == 21

check_dimensions(
sfm.maps_3d, max_error=0.03 # needs to have a max deviation of less than 3%
map_3d, max_error=0.03 # needs to have a max deviation of less than 3%
)


def test_2_track_reconstruction():
partial_map = get_all_2d_led_maps("test/scan")[1:3]

sfm = SFM(partial_map)

assert sfm.process()
map_3d = SFM.process(partial_map)

sfm.print_points()
assert map_3d is not None

assert len(sfm.maps_3d) == 15
assert len(map_3d) == 15


def test_invalid_reconstruction_views():
maps = get_all_2d_led_maps("test/scan")

invalid_maps = [maps[0], maps[4], maps[8]] # no useful overlap

sfm = SFM(invalid_maps)
map_3d = SFM.process(invalid_maps)

assert not sfm.process()
assert map_3d is None


def test_reconstruct_higbeam():
highbeam_map = get_all_2d_led_maps("test/MariMapper-Test-Data/highbeam")

sfm = SFM(highbeam_map)
map_3d = SFM.process(highbeam_map)

assert sfm.process()
assert map_3d is not None
8 changes: 3 additions & 5 deletions test/test_remesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@
def test_remesh_higbeam():
highbeam_map = get_all_2d_led_maps("test/MariMapper-Test-Data/highbeam")

sfm = SFM(highbeam_map)
map_3d = SFM.process(highbeam_map)

sfm.process()

mesh_high_res = remesh(sfm.maps_3d, 8)
mesh_high_res = remesh(map_3d, 8)

assert 8000 < len(mesh_high_res.triangles) < 9000

mesh_low_res = remesh(sfm.maps_3d, 4)
mesh_low_res = remesh(map_3d, 4)

assert 2000 < len(mesh_low_res.triangles) < 3000

0 comments on commit 037977a

Please sign in to comment.