Feat: add reusable lens map files
This commit is contained in:
1 parent
1a54e59eb4
commit
1ee3a8cc26
4 files changed
+388
-6
No files matched your search
@@ -1,4 +1,5 @@
|
||||
#include "frame.h"
|
||||
#include "lens_map.h"
|
||||
#include "optics.h"
|
||||
|
||||
#include <math.h>
|
||||
@@ -6,6 +7,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static int mesh_has_hanging_vertex(const FrameLensMesh *mesh) {
|
||||
for (size_t triangle = 0; triangle < mesh->triangle_count; ++triangle)
|
||||
@@ -84,6 +86,55 @@ int main(void) {
|
||||
fputs("flat-space inverse lens-map regression failed\n", stderr);
|
||||
goto done;
|
||||
}
|
||||
/* A finalized mesh can be persisted independently of spacetime and then
|
||||
* drive the exact same catalog inverse-map and PSF pass. */
|
||||
const char *lens_map_path = "/tmp/gr_lens_map_test.grlens";
|
||||
const LensMapFrame saved_frame = {.frame_id = 7,
|
||||
.coordinate_time = 3.0,
|
||||
.proper_time = 2.0,
|
||||
.mesh = mesh};
|
||||
LensMap loaded_map = {0};
|
||||
double *roundtrip_hdr = calloc((size_t)width * height * 3, sizeof *roundtrip_hdr);
|
||||
if (roundtrip_hdr == NULL ||
|
||||
lens_map_write(lens_map_path, width, height, 30.0, &saved_frame, 1) ||
|
||||
lens_map_read(lens_map_path, &loaded_map) || loaded_map.frame_count != 1 ||
|
||||
loaded_map.frames[0].frame_id != 7 || loaded_map.width != width ||
|
||||
loaded_map.height != height ||
|
||||
loaded_map.frames[0].mesh.vertex_count != mesh.vertex_count ||
|
||||
frame_splat_catalog(&loaded_map.frames[0].mesh, &catalog, roundtrip_hdr,
|
||||
width, height, test_exposure, &psf, NULL, INFINITY,
|
||||
1.0, psf_relative_tail, 0.0, 0, 1, NULL, NULL, NULL) != images) {
|
||||
fputs("lens-map round-trip regression failed\n", stderr);
|
||||
free(roundtrip_hdr); lens_map_destroy(&loaded_map); unlink(lens_map_path);
|
||||
goto done;
|
||||
}
|
||||
for (int value = 0; value < width * height * 3; ++value)
|
||||
if (hdr[value] != roundtrip_hdr[value]) {
|
||||
fputs("lens-map round-trip HDR regression failed\n", stderr);
|
||||
free(roundtrip_hdr); lens_map_destroy(&loaded_map); unlink(lens_map_path);
|
||||
goto done;
|
||||
}
|
||||
free(roundtrip_hdr);
|
||||
lens_map_destroy(&loaded_map);
|
||||
/* A damaged payload must not be mistaken for a reusable physical map. */
|
||||
FILE *damaged = fopen(lens_map_path, "r+b");
|
||||
int damage_failed = damaged == NULL;
|
||||
if (!damage_failed) {
|
||||
if (fseek(damaged, -5L, SEEK_END))
|
||||
damage_failed = 1;
|
||||
const int original = damage_failed ? EOF : fgetc(damaged);
|
||||
if (damage_failed || fseek(damaged, -5L, SEEK_END) || original == EOF ||
|
||||
fputc(original ^ 0xff, damaged) == EOF)
|
||||
damage_failed = 1;
|
||||
}
|
||||
if (damaged != NULL && fclose(damaged))
|
||||
damage_failed = 1;
|
||||
if (damage_failed || !lens_map_read(lens_map_path, &loaded_map)) {
|
||||
fputs("lens-map corruption rejection regression failed\n", stderr);
|
||||
lens_map_destroy(&loaded_map); unlink(lens_map_path);
|
||||
goto done;
|
||||
}
|
||||
unlink(lens_map_path);
|
||||
memset(hdr, 0, (size_t)width * height * 3 * sizeof *hdr);
|
||||
PsfSplatStats min_y_stats = {0};
|
||||
if (frame_splat_catalog(&mesh, &catalog, hdr, width, height, test_exposure,
|
||||
|
||||
Reference in new issue
Block a user