Skip to content

orient: working glass (interfflag) fit for tilted glass; full-precision .addpar - #231

Open
alexlib wants to merge 2 commits into
masterfrom
fix/orient-glass-basis-addpar-precision
Open

alexlib wants to merge 2 commits into
masterfrom
fix/orient-glass-basis-addpar-precision

Conversation

@alexlib

@alexlib alexlib commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

1. The glass-interface fit (interfflag) never moved the glass, and could not fit a tilted one

Both bugs come from the 3DPTV original.

a. Glass updates were wiped every iteration. safety_x/y/z holds the glass vector that the numeric derivatives restore to. It was captured once, before the iteration loop, so every restore discarded the previous iteration's glass update. It is now captured at the start of each iteration.

b. Mistyped tilt directions. e1 and e2 are meant to be two directions perpendicular to the glass normal g: e1 = (1,2,3) × g, e2 = e1 × g. The code had

e1_x = 2*vec_z - 3*vec_x;   /* should be 3*vec_y */
e1_z = 1*vec_y - 2*vec_y;   /* should be 2*vec_x */
e2_x = e1_y*vec_z - e1_z*vec_x;   /* should be e1_z*vec_y */
e2_z = e1_x*vec_y - e1_y*vec_y;   /* should be e1_y*vec_x */

For g along Z the wrong terms are zero, so nothing changes in the usual setup. For a tilted glass, e1 and e2 had components along the normal (e2·ĝ = 0.47 at 30°). A tilt step therefore also moved the glass plane, and one tilt direction could not be represented at all.

New check test test_orient_tilted_glass: glass tilted 20° about Y, start 1° further about Y.

result
master orient does not converge; glass stays 1° off
fix (a) only 0.021° off
(a) + (b) < 0.005°

2. .addpar precision

write_ori used "%.8f", which wrote k3 ≈ 1e-9 as 0 and kept three significant digits of k2 ≈ 1e-6. It now uses "%.10e". read_ori's fscanf("%lf") reads both forms, so existing files and readers are unaffected. New test test_write_addpar_precision.

Testing

libcheck isn't available on my machine. I compiled every liboptv/tests/check_*.c against all of liboptv/src using a minimal stand-in check.h that runs each test directly:

ok fail
master 84 3
this branch 86 (+2 new) same 3
#230 (trafo scx) 87 (+3 new) same 3

The 3 failures (test_volumedimension, track3d_test_cavity, track3d_test_burgers) already fail on master. CI with the real libcheck is still the authority.

The same fixes are in openptv2 (orientation.glass_basis; openptv2 already had fix 1a).

🤖 Generated with Claude Code

alexlib and others added 2 commits October 9, 2026 19:19
Two bugs, both from the 3DPTV original, made the glass-interface fit
ineffective:

1. safety_x/y/z, the glass vector the numeric derivatives restore to, was
   captured once before the iteration loop. Every restore then wiped the
   previous iteration's glass update, so the glass never moved. Now captured
   at the start of each iteration (as openptv2 already does).

2. The tilt directions e1, e2 were mistyped cross products:
       e1 = (2z - 3x, 3x - z, y - 2y)  instead of (1,2,3) x g = (2z - 3y, 3x - z, y - 2x)
       e2_x uses e1_z*x for e1_z*y, e2_z uses e1_y*y for e1_y*x
   For g along Z the wrong terms vanish. For a tilted glass e1, e2 had
   components along the normal, so a tilt step moved the glass plane and one
   tilt direction could not be represented. Unchanged for g along Z.

New check test test_orient_tilted_glass: glass at 20 deg about Y, start 1 deg
further. master: orient does not converge (glass stays 1 deg off); with fix 1
only: 0.021 deg off; with both: < 0.005 deg.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
write_ori wrote the seven .addpar values with "%.8f": k3 ~ 1e-9 became 0
and k2 ~ 1e-6 kept three significant digits. Now "%.10e"; read_ori's
fscanf("%lf") reads both forms, so existing files and readers are unaffected.

New check test test_write_addpar_precision: realistic k1..she survive a
write/read to 1e-9 relative.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings October 9, 2026 16:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The tangent basis remains degenerate and stale for some orientations, while .addpar output still lacks full double precision.

3 open findings
What changed in this PR

Fixes tilted-glass orientation fitting and improves .addpar serialization precision.

Changes:

  • Corrects glass-normal tangent directions.
  • Preserves iterative glass updates.
  • Adds regression tests for tilted glass and coefficient precision.
File Description
liboptv/​src/​orientation.c Corrects and retains glass fitting updates.
liboptv/​src/​calibration.c Writes coefficients using exponent notation.
liboptv/​tests/​check_orientation.c Tests tilted-glass convergence.
liboptv/​tests/​check_calibration.c Tests small-coefficient round trips.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread liboptv/src/orientation.c
Comment on lines +350 to +356
/* The glass vector the numeric derivatives restore to. Captured each
iteration: captured once before the loop, every restore wiped the
previous iteration's glass update (interfflag) and the glass never
moved. */
safety_x = cal->glass_par.vec_x;
safety_y = cal->glass_par.vec_y;
safety_z = cal->glass_par.vec_z;
Comment thread liboptv/src/calibration.c
Comment on lines +54 to +55
fprintf (fp, "%.10e %.10e %.10e %.10e %.10e %.10e %.10e", ap.k1, ap.k2, ap.k3,
ap.p1, ap.p2, ap.scx, ap.she);
Comment thread liboptv/src/orientation.c
Comment on lines +313 to 317
e1_x = 2*cal->glass_par.vec_z - 3*cal->glass_par.vec_y;
e1_y = 3*cal->glass_par.vec_x - 1*cal->glass_par.vec_z;
e1_z = 1*cal->glass_par.vec_y - 2*cal->glass_par.vec_y;
e1_z = 1*cal->glass_par.vec_y - 2*cal->glass_par.vec_x;
vec_set(tmp_vec, e1_x, e1_y, e1_z);
unit_vector(tmp_vec, e1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants