Optics: add PSF luminance cutoff

This commit is contained in:
wyj committed 2026-08-30 15:10:14 -04:00
1 parent 9e23c3fcdb
commit e8deb1ff19
7 files changed
+123 -38

No files matched your search

+27 -10
View File
@@ -79,11 +79,21 @@ int main(void) {
const size_t images =
frame_splat_catalog(&mesh, &catalog, hdr, width, height, test_exposure,
&psf, NULL, INFINITY, 1.0, psf_relative_tail,
0, 1, NULL, NULL, NULL);
0.0, 0, 1, NULL, NULL, NULL);
if (images != 1 || hdr[3 * (50 * width + 50)] <= 0.0) {
fputs("flat-space inverse lens-map regression failed\n", stderr);
goto done;
}
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,
&psf, NULL, INFINITY, 1.0, psf_relative_tail,
1e300, 0, 1, NULL, &min_y_stats, NULL) != 1 ||
min_y_stats.discarded_below_min_y != 1 ||
hdr[3 * (50 * width + 50)] != 0.0) {
fputs("PSF minimum-Y discard regression failed\n", stderr);
goto done;
}
/* Private HDR accumulation must preserve the serial splat result. */
double *serial_hdr = calloc((size_t)width * height * 3, sizeof *serial_hdr);
double *parallel_hdr = calloc((size_t)width * height * 3, sizeof *parallel_hdr);
@@ -97,11 +107,11 @@ int main(void) {
omp_set_num_threads(1);
const size_t serial_images = frame_splat_catalog(
&mesh, &catalog, serial_hdr, width, height, test_exposure, &psf, NULL,
INFINITY, 1.0, psf_relative_tail, 0, 1, NULL, NULL, NULL);
INFINITY, 1.0, psf_relative_tail, 0.0, 0, 1, NULL, NULL, NULL);
omp_set_num_threads(4);
const size_t parallel_images = frame_splat_catalog(
&mesh, &catalog, parallel_hdr, width, height, test_exposure, &psf, NULL,
INFINITY, 1.0, psf_relative_tail, 0, 1, NULL, NULL, NULL);
INFINITY, 1.0, psf_relative_tail, 0.0, 0, 1, NULL, NULL, NULL);
omp_set_num_threads(original_threads);
for (int value = 0; value < width * height * 3; ++value)
if (fabs(serial_hdr[value] - parallel_hdr[value]) >
@@ -128,7 +138,7 @@ int main(void) {
* beyond the former Gaussian's 3-sigma raster box. */
memset(hdr, 0, (size_t)width * height * 3 * sizeof *hdr);
splat_moffat(hdr, width, height, 50.5, 50.5,
(LinearRgb){1.0, 1.0, 1.0}, 1.0, &psf, psf_relative_tail);
(LinearRgb){1.0, 1.0, 1.0}, 1.0, &psf, psf_relative_tail, 0.0);
double moffat_flux = 0.0;
for (int pixel = 0; pixel < width * height; ++pixel)
moffat_flux += hdr[3 * pixel];
@@ -167,14 +177,14 @@ int main(void) {
memset(reference_hdr, 0, (size_t)width * height * 3 * sizeof *reference_hdr);
if (splat_moffat_cached(cached_hdr, width, height, 50.0 + phases[phase][0],
50.0 + phases[phase][1], (LinearRgb){1.0, 1.0, 1.0},
1.0, &psf, &cache, 1.0, psf_relative_tail) != 0) {
1.0, &psf, &cache, 1.0, psf_relative_tail, 0.0) != 0) {
fputs("ordinary PSF cache unexpectedly fell back\n", stderr);
free(cached_hdr); free(reference_hdr); psf_kernel_cache_destroy(&cache);
goto done;
}
splat_moffat_direct(reference_hdr, width, height,
50.0 + phases[phase][0], 50.0 + phases[phase][1],
(LinearRgb){1.0, 1.0, 1.0}, 1.0, &psf, psf_relative_tail);
(LinearRgb){1.0, 1.0, 1.0}, 1.0, &psf, psf_relative_tail, 0.0);
double peak = 0.0, max_error = 0.0;
for (int value = 0; value < width * height * 3; ++value) {
peak = fmax(peak, reference_hdr[value]);
@@ -186,11 +196,18 @@ int main(void) {
goto done;
}
}
if (splat_moffat_cached(cached_hdr, width, height, 50.5, 50.5,
(LinearRgb){1.0, 1.0, 1.0}, 1.0, &psf, &cache,
1.0, psf_relative_tail, 1.0) != 3) {
fputs("PSF minimum-Y cached discard regression failed\n", stderr);
free(cached_hdr); free(reference_hdr); psf_kernel_cache_destroy(&cache);
goto done;
}
/* A bright event must avoid a cached hard cutoff by selecting the direct
* reference path when the requested support exceeds the cache. */
if (splat_moffat_cached(cached_hdr, width, height, 50.5, 50.5,
(LinearRgb){1.0, 1.0, 1.0}, 1000.0, &psf, &cache, 1.0,
psf_relative_tail) != 1) {
psf_relative_tail, 0.0) != 1) {
fputs("bright PSF direct-fallback regression failed\n", stderr);
free(cached_hdr); free(reference_hdr); psf_kernel_cache_destroy(&cache);
goto done;
@@ -199,13 +216,13 @@ int main(void) {
memset(reference_hdr, 0, (size_t)width * height * 3 * sizeof *reference_hdr);
if (splat_moffat_cached(cached_hdr, width, height, 50.5, 50.5,
(LinearRgb){1.0, 1.0, 1.0}, 1000.0, &psf, &cache,
1000.0, psf_relative_tail) != 2) {
1000.0, psf_relative_tail, 0.0) != 2) {
fputs("bright PSF cached-wing-clipping regression failed\n", stderr);
free(cached_hdr); free(reference_hdr); psf_kernel_cache_destroy(&cache);
goto done;
}
splat_moffat_direct(reference_hdr, width, height, 50.5, 50.5,
(LinearRgb){1.0, 1.0, 1.0}, 1000.0, &psf, psf_relative_tail);
(LinearRgb){1.0, 1.0, 1.0}, 1000.0, &psf, psf_relative_tail, 0.0);
const size_t center = 3 * (50 * width + 50);
if (cached_hdr[center] <= 0.0 ||
fabs(cached_hdr[center] - reference_hdr[center]) >
@@ -237,7 +254,7 @@ int main(void) {
frame_lens_mesh_trace(&fine_mesh, &spacetime, &observer, &trace) ||
frame_splat_catalog(&fine_mesh, &fine_catalog, hdr, width, height,
test_exposure, &psf, NULL, INFINITY, 1.0,
psf_relative_tail, 0, 1, NULL,
psf_relative_tail, 0.0, 0, 1, NULL,
NULL, NULL) != 1) {
fputs("fine source-triangle containment regression failed\n", stderr);
frame_lens_mesh_destroy(&fine_mesh);