Skip to content

Multi-head 7/7: Color grouping mode - #102

Merged
vycdev merged 10 commits into
vycdev:developfrom
Bjohnson131:mph-split-7-color-grouping
Nov 1, 2026
Merged

vycdev merged 10 commits into
vycdev:developfrom
Bjohnson131:mph-split-7-color-grouping

Conversation

@Bjohnson131

Copy link
Copy Markdown
Contributor

Last of seven PRs splitting up #38 (Multi Print Head Capability).

Depends on #96-#101, mainly #100 (the UI) and #101 (the docs it extends). Until they merge, this diff also shows them. The new work is buildColorGroupedPixels and the colorMode parameter in multiHeadAnalysisColorFirst.ts, the selector, the docs section and tests/multiHeadColorModeImprovement.test.ts.

What

A Color grouping control on the Multi-head panel:

  • Layer-based (default, the existing behavior) merges colors that share a printer layer, so distinct colors are capped at the layer count.
  • Color-based keeps distinct hues as separate optimizer groups (bounded by a cap, deterministic), so more of the image's colors survive.

The setting is plumbed through the worker, hook and persistence, with a Color Grouping docs section and a changelog update.

Measured improvement

On the Rocco test image (64-color palette, balanced search, 8-color calibrated frontlit profile), pixel-weighted mean CIEDE2000 drops about 2-3 points of roughly 30 (about 8-10%), and distinct printed colors roughly double:

Heads Layer-based ΔE / colors Color-based ΔE / colors
2 31.2 / 12 29.3 / 21
3 29.1 / 12 26.6 / 20
4 31.1 / 10 28.1 / 23

Single-head baseline: 31.5 ΔE, 12 colors. The metric prints each palette color at its luminance height on the 18-layer stack, so treat it as a comparison between modes, not absolute print quality. The gain is config-dependent: with few heads it can be small, and it costs more compute.

Tests

tests/multiHeadColorModeImprovement.test.ts pins the improvement on tests/assets/rocco__source.png (376 KB, new fixture): Color-based beats Layer-based on mean ΔE and distinct colors at 2, 3 and 4 heads, never regresses against single-head printing, and gains at least 1 ΔE on average. Color-grouping unit tests were also added to tests/multiHeadAnalysisColorFirst.test.ts. tsc is clean and the full unit suite passes (990 tests, 0 failures, 1 skipped).

Series

  1. Export and meshing (Multi-head 1/7: 3MF export and combined-mask meshing #96)
  2. Analysis core (Multi-head 2/7: window analysis core #97)
  3. Run-based analysis engine (Multi-head 3/7: run-based analysis engine #98)
  4. Head schedule and plan conversion (Multi-head 4/7: head schedule and plan conversion #99)
  5. Worker, UI and export wiring (Multi-head 5/7: worker, UI and export wiring #100)
  6. Docs and diagrams (Multi-head 6/7: documentation page and diagrams #101)
  7. This PR: Color grouping mode

🤖 Generated with Claude Code

Bjohnson131 and others added 2 commits October 22, 2026 23:37
New "Color grouping" control on the multi-head panel. Layer-based (the
default) merges colors that share a printer layer, capping distinct
colors at the layer count. Color-based keeps distinct hues as separate
optimizer groups (bounded by a cap, deterministic) so more of the
image's colors survive. The setting is plumbed through the worker,
hook, persistence and docs.

Measured on the Rocco test image (64-color palette, balanced search),
Color-based lowers pixel-weighted mean CIEDE2000 from 31.2/29.1/31.1 to
29.3/26.6/28.1 at 2/3/4 heads and raises distinct printed colors from
12/12/10 to 21/20/23; a regression test pins this.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@Bjohnson131

Copy link
Copy Markdown
Contributor Author

Unit test results for this branch (npm test on mph-split-7-color-grouping): 990 tests, 989 passed, 0 failed, 1 skipped. Full output: https://gist.github.com/Bjohnson131/58348b01975e2da17ab1f0eab5c7603f (file test-results-mph-split-7-color-grouping.txt).

@vycdev vycdev left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Automated code review

Verdict: Needs changes · Findings: 3 (3 inline)

Scope: only what this PR adds on top of #101; the earlier PRs in this stack are reviewed in their own threads.

The grouping mode is wired through the worker and build state, but capped groups can be scored at the wrong layer, and the selection misses settings synchronization. All 59 focused tests, TypeScript checks, and ESLint passed; the full suite had 989 passes and one failure in an unchanged Windows association test. The translation checker also flags four new untranslated strings.


Reviewed by GPT 6.1 Sol

Comment thread src/lib/multiHeadAnalysisColorFirst.ts Outdated
const targetRgb: RGB = { r: c.r, g: c.g, b: c.b };
const lum = getLuminance(targetRgb) / 255;
const h = luminanceToHeight(lum, transitionZones, totalHeight, firstLayerHeight);
const layerIdx = findLayerIdxAtHeight(layers, h);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

[medium] Capped groups can be optimized at the wrong physical layer

When palettes exceed 200 colors, cluster members can have different original print heights, but all inherit this centroid-derived layerIdx. In a 256-color, 12-layer reproduction, #bcc4e4 belongs to layer 9 but its group is evaluated at layer 10. A candidate window ending at layer 9 consequently scores an additional layer that this pixel never prints and chooses the wrong filament order. Preserve members' original home layers during scoring, and add a regression covering a cluster spanning a layer boundary.

Reviewed by GPT 6.1 Sol

const [multiHeadSearchDepth, setMultiHeadSearchDepth] = useState<
'fast' | 'balanced' | 'thorough'
>(persisted?.multiHeadSearchDepth ?? 'balanced');
const [multiHeadColorMode, setMultiHeadColorMode] = useState<'luminance' | 'color'>(

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

[medium] Color grouping changes are not persisted before building

multiHeadColorMode is missing from both the payload and dependencies of the existing onSettingsChange effect. Selecting Color-based and reloading before building therefore restores the previous selection, unlike head count and search depth. The new value reaches the parent only through handleApply; include it in the settings-sync effect so persistence works when the control changes.

Reviewed by GPT 6.1 Sol

Comment thread src/components/AutoPaintTab.tsx Outdated
</p>
<div className="flex items-center gap-2">
<Label htmlFor="multi-head-color-mode" className="text-xs text-muted-foreground whitespace-nowrap">
Color grouping

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

[medium] The new grouping labels fail the required translation check

The new label, two options, and explanatory paragraph are literal English JSX. node scripts/check-i18n-ui.mjs reports four additional coverage errors for these strings, and npm run build runs that checker before compilation. Add the corresponding translation entries and render them through this component's existing t(...) function.

Reviewed by GPT 6.1 Sol

- Preserve reviewed mappings, optics, reconciliation, scheduling, routing, and build lifecycle
- Integrate Color grouping with final-stack analysis and build snapshots
- Localize grouping controls and combine guide and changelog changes
- Adapt integration regressions while preserving localized guides for the next step
- Preserve original physical layers when capping color groups
- Persist grouping selections immediately before building
- Complete guide translations and align quality claims with measurements
- Add layer-boundary regressions and report corrected benchmark metrics
@vycdev

vycdev commented Oct 29, 2026

Copy link
Copy Markdown
Owner

Fixes for the automated review

Pushed 1d069b2 to this branch.

This branch also merges the fixed lower layers (#101), so it builds on the corrected code.

Findings

  • ✅ Capped groups can be optimized at the wrong physical layer: Map swatches before clustering and restrict clusters to their original physical layers. Reserve one group per occupied layer, bounding groups by max(200, occupied layers). Added boundary, 256-color palette, determinism, and unprinted-suffix regressions.

  • ✅ Color grouping changes are not persisted before building: Added multiHeadColorMode to the settings-sync effect payload and dependencies in ThreeDControls.tsx.

  • ➖ The new grouping labels fail the required translation check: Already resolved by merge commit 532bee4: all four strings use t(...) with entries in all 12 catalogs. Retained that wiring and verified the required checks pass.

Also fixed

  • Complete guide translations and correct improvement claims: Translated the Color grouping section into all 11 localized guides. Updated English and translated help, guide text, and the existing Added changelog entry to describe physical-layer preservation, immediate persistence, and the measured quality limitations. Benchmark diagnostics now report both error metrics and printed-color counts.

Corrected Color grouping measurements

Rocco test image (64-color palette), calibrated 8-filament frontlit profile, Balanced search, pixel-weighted errors on the final printable stack:

Configuration Mean CIEDE2000 Mean CIE76 Printed colors
Single-head baseline 19.66 30.53 6
2 heads, Layer-based 18.29 29.70 6
2 heads, Color-based 18.21 29.34 10
3 heads, Layer-based 19.08 29.56 6
3 heads, Color-based 19.42 29.02 10
4 heads, Layer-based 21.79 32.84 6
4 heads, Color-based 18.98 28.57 12

At 3 heads, Color-based improves CIE76 and color count while worsening CIEDE2000.

The improvement table in the PR description was measured with a luminance-height shortcut; on the final printable stack the gain is mostly more distinct printed colors rather than a 2-3 ΔE drop, so the changelog, guide and help text now say that. Not fixed here: with 4 heads, the default Layer-based mode scores worse than single-head on both metrics in this benchmark, which points at the lower analysis layers' improvement check.

Verification: Full unit suite 1,035/1,035 passes; docs E2E, the browser export flow and the browser multi-head check (routed 3-head 3MF with matching extruders and pauses) pass.


Fixed by GPT 6.1 Sol

@vycdev vycdev left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Automated code review: second pass

Verdict: Looks good · New or remaining findings: 0

Reviewed head 1d069b2, which includes the fixes for the first review. Scope: only what this PR adds on top of #101; the other PRs in this stack are reviewed in their own threads.

All three first-pass findings are resolved. Color-based grouping now preserves physical home layers, persists immediately, and has translated controls and guidance. The 119 focused tests, five documentation tests, TypeScript, changed-file ESLint, and full i18n checks pass; benchmark diagnostics match the corrected measurements. I found no further defects in this PR’s changes over #101 or semantic conflicts with newer develop changes.

First-pass findings

  • ✅ Resolved: Capped groups can be optimized at the wrong physical layer. Swatches are mapped before clustering, and cluster membership is restricted to the original physical layer. The 256-color, boundary, determinism, and unprinted-suffix regressions pass.
  • ✅ Resolved: Color grouping changes are not persisted before building. multiHeadColorMode is included in the settings-sync payload and dependencies, with parent storage and reload wiring present.
  • ✅ Resolved: The new grouping labels fail the required translation check. All four strings use t(...) with entries in all 12 catalogs. The full i18n check passes.

Reviewed by GPT 6.1 Sol

@vycdev

vycdev commented Oct 29, 2026

Copy link
Copy Markdown
Owner

Second-round fixes merged in

Pushed 542f888 to this branch.

This branch merges the second-round fixes from the lower layers (#101), so it builds on the corrected code. The second review found nothing new in this PR's own changes, so there are no other edits here.

Verification: After the merge: full unit suite 1,048/1,048, tsc -b, lint, test:docs and npm run build pass. On the top of the stack (#102 with every fix merged), a browser run with an 8-filament profile built routed 3-head models (no smoothing and Medium smoothing) and a routed 4-head model. The meshes were tagged with the scheduled heads, the 3MF used matching extruders and M600 pause markers, and every exported mesh was closed and consistently wound (each edge shared by exactly two triangles). The smoke e2e suite passed 64/66; the two failures are landing-page specs this stack does not touch, and develop has since fixed the landing credit link and updated both specs.


Reviewed by GPT 6.1 Sol

- Assert that layer-based grouping does not raise the mean search error
  above single-head printing at 2-4 heads; with mismatched per-color
  rendering optics, four heads measured worse than one
@vycdev

vycdev commented Oct 29, 2026

Copy link
Copy Markdown
Owner

Corrected multi-head measurements

Pushed 82efc12 to this branch, plus a merge of the #98–#101 fixes.

The "4 heads, Layer-based scores worse than single-head" result in the earlier fix comment came from the per-color rendering bug fixed on #99, not from the analysis. Corrected measurements for the same benchmark (Rocco test image, 64-color palette, calibrated 8-filament frontlit profile, Balanced search, pixel-weighted errors on the final printable stack):

Configuration Mean CIEDE2000 Mean CIE76 Printed colors
Single-head baseline 19.66 30.53 6
2 heads, Layer-based 19.05 29.99 6
2 heads, Color-based 18.27 28.74 10
3 heads, Layer-based 18.85 29.31 6
3 heads, Color-based 18.15 26.15 11
4 heads, Layer-based 19.62 27.45 6
4 heads, Color-based 17.23 24.50 13

Both modes now beat single-head on the search objective at every head count. Color-based grouping also lowers CIEDE2000 by 1.4–2.4. The guide and changelog wording ("does not guarantee lower color error") is still accurate, so it is unchanged.

Verification: after the merge, full unit suite 1,053/1,053, tsc -b, lint, test:docs and npm run build pass. A browser run with an 8-filament profile built routed 3-head (Medium smoothing) and 4-head models with matching extruders and M600 markers, and every exported mesh was closed and consistently wound. The smoke e2e suite passed 64/66; the two failures are the landing-page specs this stack does not touch. On that browser image, 8 heads still falls back, because of the sampling limit described on #98.


Fixed by Claude Opus 5.5

@vycdev

vycdev commented Oct 29, 2026

Copy link
Copy Markdown
Owner

Search fix merged in

Pushed 7822077 to this branch. It merges the #98 sampling fix, so large windows keep the reorders that smaller windows find. There are no other changes in this PR.

Verification: after the merge, full unit suite 1,055/1,055, tsc -b, lint, test:docs and npm run build pass. A browser run with an 8-filament profile now builds routed 8-head (heads 1–7 used, the 8th empty), 7-head (Medium smoothing) and 4-head models with matching extruders and M600 markers, and every exported mesh is closed and consistently wound. Before this fix, 7 and 8 heads fell back to single-head on that image. The corrected Rocco measurements in my previous comment are unchanged.


Fixed by Claude Opus 5.5

…o mph-split-7-color-grouping

# Conflicts:
#	CHANGELOG.md
@vycdev

vycdev commented Oct 31, 2026

Copy link
Copy Markdown
Owner

Note

🤖 Claude Opus 5.5 responding on behalf of Victor Sandu

The appearance-corrected previews and gain check are merged in, and the top of the stack passes in the browser. Pushed 9a9c4a0; this PR has no other changes.

This changes how to read the Rocco table in my earlier comment. That benchmark has no proofs, so it never exercised appearance corrections. Under the gain check, Layer-based at 4–6 heads now falls back on Rocco, and on the measured profile the gains are much smaller. Color-based at 4 heads on cats gains 0.40 mean CIEDE2000, compared with 2.43 on Rocco. See #100 for which head counts route.

Verified:

  • Checks: unit suite 1,060/1,060, tsc -b, lint, test:docs and npm run build pass.
  • Browser, 5/5 multi-head cases: 5 heads Layer-based and 4 heads Color-based build routed models with matching extruders and M600 markers. A layout with a predicted loss and one with a tiny gain both fall back with the notice. The measured profile runs with its evidence active (1,030 anchors) and falls back on that palette. Every exported mesh is closed.
  • Smoke e2e: the only failures are the two landing-page specs this stack doesn't touch, which develop has already fixed.

One thing not verified: a routed 256×192 export didn't finish in 7.5 minutes in headless Chromium, on the previous head as well as this one. Every browser action took about 12 s there, which points at software rendering of about 1.5 million triangles. In Node with no rendering, 1024×768 takes 1.4 s for geometry and 8.8 s for export. I haven't tried it on a real GPU.

@vycdev
vycdev merged commit 3ede317 into vycdev:develop Nov 1, 2026
@vycdev vycdev mentioned this pull request Nov 22, 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