Skip to content

FIX bumpy flatmap smoothing skipped on the left hemisphere - #678

Open
mvdoc wants to merge 1 commit into
mainfrom
fix/bumpyflat-left-hemi-smoothing
Open

FIX bumpy flatmap smoothing skipped on the left hemisphere#678
mvdoc wants to merge 1 commit into
mainfrom
fix/bumpyflat-left-hemi-smoothing

Conversation

@mvdoc

@mvdoc mvdoc commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Splits the bug fix out of #310 (which has been sitting since 2019 and no longer merges cleanly).

The bug

In mriview_surface.js, smoothfactor and smoothiter are declared with var inside the if (this.flatlims !== undefined) block, but used ~25 lines earlier in the same per-hemisphere loop to smooth wmareas and pialareas.

var hoists the declaration to function scope but not the assignment, so on the first iteration of the loop they are still undefined. iterativelySmoothVertexData then runs:

for ( var i = 0; i < undefined; i ++ ) { ... }

0 < undefined is false, so the loop body never executes and the areas come back completely unsmoothed. By the second iteration the values assigned during the first pass are visible, so:

  • left hemisphere — areas unsmoothed
  • right hemisphere — areas smoothed with factor 0.1, 50 iterations

which is why the two hemispheres have visibly different bump relief. I confirmed the bug is still present on current main.

The fix

Declare the parameters above the loop, split them into separate constants for the area and distance passes, and reduce the iteration counts (areas 50 → 5, dists 50 → 20) for a somewhat less smoothed result.

The commit adds a comment explaining why the declarations have to live outside the loop, so the bug does not get quietly reintroduced by re-nesting them.

Note for reviewers

The iteration-count reduction is a deliberate appearance change riding along with the correctness fix — it is part of what @alexhuth was going for in #310 ("I also reduced the amount of smoothing somewhat"), but it is separable if you would rather land the hoist alone first. These are also hardcoded constants; they could reasonably be exposed in [webgl_viewopts] next to bumpy_flatmap.

Testing

node --check passes. Not verified visually — no render was produced.

The lighting half of #310 is split into a separate PR.

🤖 Generated with Claude Code

`smoothfactor` and `smoothiter` were declared with `var` inside the
`if (this.flatlims !== undefined)` block but used earlier in the same
per-hemisphere loop, to smooth `wmareas` and `pialareas`. Hoisting made
the names visible there but left them `undefined` on the first
iteration, so `iterativelySmoothVertexData` ran `for (i = 0; i <
undefined; i++)` -- zero iterations -- and returned the areas
unsmoothed. The second iteration then saw the values assigned during
the first, so the left hemisphere was unsmoothed and the right was
smoothed, giving the two hemispheres visibly different bump relief.

Declare the parameters above the loop, split into separate constants for
the area and distance passes, and reduce the iteration counts (areas
50 -> 5, dists 50 -> 20) for a somewhat less smoothed result.

Split out of #310.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@mvdoc mvdoc mentioned this pull request Aug 20, 2026
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