Interactive 2D wave optics simulator. Turn any image into a refractive scene, add sources, watch waves refract, diffract and interfere. Probes, intensity maps, video export.
C#
Source markers in exports: the enabled sources drawn over exported frames as a Display option
Alexander Graeff0042d291f90
diff --git a/CLAUDE.md b/CLAUDE.mdindex 047f3a0..52a98f3 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -179,8 +179,10 @@ FrameStore: native memory up to the budget, the rest in a temp file (%LOCALAPPDAat quality 100; 4:4:4 at 90 beat it in every channel at half the size), and**OpenEXR sequences or stills** (2026-10-18, the user's choice for data export to NumPy, MATLAB, Octave add-onsand viewers such as DJV): the stored halves themselves, one uncompressed "Y" channel per file, no colours,- brightness, outline or boxes; a sink that `WantsHalves` gets the plane from the job unrendered. Harness- hooks: `WAVEDUDE_EXPORT_PATH`, `WAVEDUDE_DISCARD_EDITS=1`.+ brightness, outline or boxes; a sink that `WantsHalves` gets the plane from the job unrendered. **Source markers**+ (2026-10-21, Display, off by default, the user's choices): the preview's marker, a composite source's dots and the+ name, enabled sources only, scaled like the probe labels, under the probe markers and boxes. Harness hooks:+ `WAVEDUDE_EXPORT_PATH`, `WAVEDUDE_DISCARD_EDITS=1`.- **Optical parts** (2026-10-18, stages 1 and 2 of `OpticalParts.md`): `OpticalPart` subclasses `LensPart` (mirror flag),the shapes under `ShapePart` (`PolygonPart` regular, `RectanglePart`, `EllipsePart` as a polygon of a vertex per 3 px ofcircumference, 2026-10-20; both carry a `Linked` flag, the chain toggle between width and length of the image editors,diff --git a/WaveDudeNext.WPF/MainWindow.Export.cs b/WaveDudeNext.WPF/MainWindow.Export.csindex f236c0a..6a12bbb 100644--- a/WaveDudeNext.WPF/MainWindow.Export.cs+++ b/WaveDudeNext.WPF/MainWindow.Export.cs@@ -314,11 +314,23 @@ public partial class MainWindowLogger.Debug("Export outline: {State}", edges != null ? "computed from the scene image" : "none (no image scene)");}ProbeGraphPainter? painter = display.ProbeGraphsInExport || display.ProbeMarkersInExport ? new ProbeGraphPainter(Project, run, display.ProbeGraphsInExport, display.ProbeMarkersInExport) : null;+ // the sources on both pictures, under the probes' markers and boxes (as in the preview, where the boxes lie over every handle)+ SourceMarkerPainter? sources = display.SourceMarkersInExport ? new SourceMarkerPainter(Project, run.Spec.Width, run.Spec.Height) : null;+ if (sources is { IsEmpty: true })+ {+ Logger.Debug("Export source markers: none (no enabled source)");+ sources = null;+ }foreach ((FrameLayer layer, string path) in outputs){DisplayLayer settings = layer == FrameLayer.Field ? display.Field : display.Intensity;int[]? lut = ColorSchemeCatalog.Instance.LutFor(Project, settings.ColorScheme, settings.BlackLevel);- Action<int, Memory<int>>? decorate = painter?.For(layer == FrameLayer.Field ? ProbeLayer.Field : ProbeLayer.Intensity);+ Action<int, Memory<int>>? probes = painter?.For(layer == FrameLayer.Field ? ProbeLayer.Field : ProbeLayer.Intensity);+ Action<int, Memory<int>>? decorate = sources == null ? probes : (frame, pixels) =>+ {+ sources.Paint(pixels);+ probes?.Invoke(frame, pixels);+ };var exportLayer = new ExportLayer(layer, lut, (float)settings.Brightness, settings.OverlayInExport ? edges : null, settings.OverlayGain, decorate);// the sink is opened by the job on its thread (a Media Foundation writer must stay on one thread)int width = run.Spec.Width;@@ -336,8 +348,8 @@ public partial class MainWindow}else{- Logger.Debug("Export target {Layer}: scheme '{Scheme}' (black level {Black}), brightness {Brightness}, outline {Outline}, probe boxes {Boxes}, markers {Markers}, to {Output}",- layer, settings.ColorScheme, settings.BlackLevel, settings.Brightness, settings.OverlayInExport && edges != null ? "gain " + settings.OverlayGain : "off", display.ProbeGraphsInExport ? "on" : "off", display.ProbeMarkersInExport ? "on" : "off", output);+ Logger.Debug("Export target {Layer}: scheme '{Scheme}' (black level {Black}), brightness {Brightness}, outline {Outline}, probe boxes {Boxes}, markers {Markers}, sources {Sources}, to {Output}",+ layer, settings.ColorScheme, settings.BlackLevel, settings.Brightness, settings.OverlayInExport && edges != null ? "gain " + settings.OverlayGain : "off", display.ProbeGraphsInExport ? "on" : "off", display.ProbeMarkersInExport ? "on" : "off", sources != null ? "on" : "off", output);}}if (!still && format == ExportFormat.Mpeg1)diff --git a/WaveDudeNext.WPF/Rendering/SourceMarkerPainter.cs b/WaveDudeNext.WPF/Rendering/SourceMarkerPainter.csnew file mode 100644index 0000000..3c8e2b8--- /dev/null+++ b/WaveDudeNext.WPF/Rendering/SourceMarkerPainter.cs@@ -0,0 +1,152 @@+// SPDX-License-Identifier: GPL-3.0-or-later+// Copyright (C) 2026 Alexander Graef <[email protected]>+//+// This file is part of WaveDude Next, a 2D wave simulator.+//+// Based on the work of+// Jeroen Vleggaar (Huygens Optics), author of Wave Dude 2D, Copyright (C) 2026+// <https://www.youtube.com/@HuygensOptics>, <https://www.huygensoptics.com>+// 0x23 (Diffraction Limited), author of WaveSimulator2D+// <https://www.youtube.com/@DiffractionLimited>, <https://github.com/0x23/WaveSimulator2D>+//+// WaveDude Next is free software: you can redistribute it and/or modify it under+// the terms of the GNU General Public License as published by the Free Software+// Foundation, either version 3 of the License, or (at your option) any later+// version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or+// <https://www.gnu.org/licenses/>.++using System.Globalization;+using System.Windows;+using System.Windows.Media;+using System.Windows.Media.Imaging;+using WaveDudeNext.Export;+using WaveDudeNext.Model;++namespace WaveDudeNext.WPF.Rendering;++/// <summary>+/// Draws the enabled sources into exported frames (2026-10-21, <see cref="Display.SourceMarkersInExport"/>) as the+/// preview shows them: the source marker (a ring of radius 6 with four ticks of its crosshair and a dot in the middle,+/// white over a dark halo, on a faint dark disc), a composite source's emitter dots (radius 2.5 with a dark rim), and+/// the name in Segoe UI outlined in dark, beside a point source and below a composite one (whose rotation handle sits+/// beside it in the preview). Everything is scaled from the preview's sizes by the ratio of the probe labels'+/// size at the frame's height to the preview's 11 px labels (<see cref="ProbeMarkers.FontSize"/>), so sources and+/// probe numbers read alike. The sources do not move during a run, so the markers are rendered once, on the export's+/// own thread at the first frame, into a premultiplied layer of the frame's size, whose covered pixels are then+/// blended over each frame. Built on the UI thread from the project (positions and names are copied, so edits during+/// the export change nothing).+/// </summary>+public sealed class SourceMarkerPainter+{+ /// <summary>The preview's label size in pixels, the reference of the scale.</summary>+ private const double PreviewLabelSize = 11.0;++ private static readonly Typeface LabelTypeface = new("Segoe UI");+ private static readonly Geometry Glyph = Frozen(Geometry.Parse("M4,10 A6,6 0 1 1 16,10 A6,6 0 1 1 4,10 M10,0 L10,2.5 M10,17.5 L10,20 M0,10 L2.5,10 M17.5,10 L20,10"));+ private static readonly Brush Halo = Frozen(new SolidColorBrush(Color.FromArgb(191, 0, 0, 0)));+ private static readonly Brush Disc = Frozen(new SolidColorBrush(Color.FromArgb(0x60, 0, 0, 0)));++ private readonly (int X, int Y, string Name, (int X, int Y)[]? Elements)[] _sources;+ private readonly int _width;+ private readonly int _height;+ private (int Index, int Bgra)[]? _covered;++ /// <param name="project">The project whose enabled sources are drawn.</param>+ /// <param name="width">Frame width in pixels (the canvas's: exports are at full resolution).</param>+ /// <param name="height">Frame height in pixels.</param>+ public SourceMarkerPainter(Project project, int width, int height)+ {+ _sources = [.. project.Sources.Where(source => source.Enabled)+ .Select(source => (source.X, source.Y, source.Name, source.Array != null ? source.Elements.Select(e => (e.X, e.Y)).ToArray() : null))];+ _width = width;+ _height = height;+ }++ /// <summary>Whether there is anything to draw.</summary>+ public bool IsEmpty => _sources.Length == 0;++ /// <summary>Draws the markers over one frame (packed BGRA32, the frame's size). Export thread.</summary>+ public void Paint(Memory<int> pixels)+ {+ _covered ??= Render();+ Span<int> frame = pixels.Span;+ foreach ((int index, int bgra) in _covered)+ {+ int a = (bgra >> 24) & 0xFF;+ int inverse = 255 - a;+ int argb = frame[index];+ int b = (bgra & 0xFF) + ((argb & 0xFF) * inverse + 127) / 255;+ int g = ((bgra >> 8) & 0xFF) + (((argb >> 8) & 0xFF) * inverse + 127) / 255;+ int r = ((bgra >> 16) & 0xFF) + (((argb >> 16) & 0xFF) * inverse + 127) / 255;+ frame[index] = unchecked((int)0xFF000000) | (Math.Min(255, r) << 16) | (Math.Min(255, g) << 8) | Math.Min(255, b);+ }+ }++ /// <summary>Renders every marker once and keeps the pixels it covers with their premultiplied colour. Export thread (an STA).</summary>+ private (int Index, int Bgra)[] Render()+ {+ double scale = ProbeMarkers.FontSize(_height) / PreviewLabelSize;+ var visual = new DrawingVisual();+ using (DrawingContext dc = visual.RenderOpen())+ {+ var dotRim = new Pen(Halo, 1.5 * scale);+ foreach ((int x, int y, string _, (int X, int Y)[]? elements) in _sources)+ {+ foreach ((int ex, int ey) in elements ?? [])+ {+ dc.DrawEllipse(Brushes.White, dotRim, Centre(ex, ey), 2.5 * scale, 2.5 * scale);+ }+ }+ var haloPen = new Pen(Halo, (1.5 + 2.0) * scale) { StartLineCap = PenLineCap.Round, EndLineCap = PenLineCap.Round };+ var whitePen = new Pen(Brushes.White, 1.5 * scale) { StartLineCap = PenLineCap.Round, EndLineCap = PenLineCap.Round };+ foreach ((int x, int y, string name, (int X, int Y)[]? elements) in _sources)+ {+ Point centre = Centre(x, y);+ // the glyph's 20 × 20 box centred on the source, at the export's scale+ dc.PushTransform(new MatrixTransform(scale, 0, 0, scale, centre.X - 10 * scale, centre.Y - 10 * scale));+ dc.DrawEllipse(Disc, null, new Point(10, 10), 6, 6);+ dc.Pop();+ Geometry glyph = Glyph.Clone();+ glyph.Transform = new MatrixTransform(scale, 0, 0, scale, centre.X - 10 * scale, centre.Y - 10 * scale);+ dc.DrawGeometry(null, haloPen, glyph);+ dc.DrawGeometry(null, whitePen, glyph);+ dc.DrawEllipse(Halo, null, centre, 2.5 * scale, 2.5 * scale);+ dc.DrawEllipse(Brushes.White, null, centre, 1.5 * scale, 1.5 * scale);+ if (name.Length == 0)+ {+ continue;+ }+ var label = new FormattedText(name, CultureInfo.CurrentUICulture, FlowDirection.LeftToRight, LabelTypeface, PreviewLabelSize * scale, Brushes.White, 1.0);+ double offset = 13 * scale;+ bool below = elements != null;+ double lx = below ? Math.Clamp(centre.X - label.Width / 2, 0, Math.Max(0, _width - label.Width)) : Math.Min(centre.X + offset, Math.Max(0, _width - label.Width));+ double ly = below ? Math.Min(centre.Y + offset, Math.Max(0, _height - label.Height)) : Math.Clamp(centre.Y - label.Height / 2, 0, Math.Max(0, _height - label.Height));+ var origin = new Point(lx, ly);+ dc.DrawGeometry(null, new Pen(Halo, 3.0 * scale) { LineJoin = PenLineJoin.Round }, label.BuildGeometry(origin));+ dc.DrawText(label, origin);+ }+ }+ var bitmap = new RenderTargetBitmap(_width, _height, 96, 96, PixelFormats.Pbgra32);+ bitmap.Render(visual);+ int[] layer = new int[_width * _height];+ bitmap.CopyPixels(layer, _width * 4, 0);+ var covered = new List<(int, int)>();+ for (int i = 0; i < layer.Length; i++)+ {+ if (((layer[i] >> 24) & 0xFF) != 0)+ {+ covered.Add((i, layer[i]));+ }+ }+ return [.. covered];+ }++ /// <summary>The centre of canvas pixel (<paramref name="x"/>, <paramref name="y"/>) in the frame's coordinates, where the preview puts a handle.</summary>+ private static Point Centre(int x, int y) => new(x + 0.5, y + 0.5);++ private static T Frozen<T>(T freezable) where T : Freezable+ {+ freezable.Freeze();+ return freezable;+ }+}diff --git a/WaveDudeNext.WPF/Strings/Strings.DE.xaml b/WaveDudeNext.WPF/Strings/Strings.DE.xamlindex 927de06..864eda1 100644--- a/WaveDudeNext.WPF/Strings/Strings.DE.xaml+++ b/WaveDudeNext.WPF/Strings/Strings.DE.xaml@@ -334,6 +334,8 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or<s:String x:Key="Hint.DisplayLayer.Preview">Diese Ausgabe in der Live-Vorschau zeigen.</s:String><s:String x:Key="Label.DisplayLayer.Overlay">Umriss in der Vorschau</s:String><s:String x:Key="Hint.DisplayLayer.Overlay">Den Leuchtkanten-Umriss des Szenenbilds in der Vorschau über diese Ausgabe legen.</s:String>+ <s:String x:Key="Label.Display.SourceMarkersInExport">Quellenmarkierungen im Export</s:String>+ <s:String x:Key="Hint.Display.SourceMarkersInExport">Die aktiven Quellen (die Markierung, die Emitterpunkte einer zusammengesetzten Quelle, den Namen) in exportierte Bilder und Videos zeichnen.</s:String><s:String x:Key="Label.DisplayLayer.OverlayGain">Umrisshelligkeit</s:String><s:String x:Key="Hint.DisplayLayer.OverlayGain">Faktor des Umrisses: 1 wie berechnet, höher hebt schwache Kanten an, 0 blendet ihn aus.</s:String><s:String x:Key="Label.DisplayLayer.OverlayInExport">Umriss im Export</s:String>diff --git a/WaveDudeNext.WPF/Strings/Strings.EN.xaml b/WaveDudeNext.WPF/Strings/Strings.EN.xamlindex 2767c88..f66f96b 100644--- a/WaveDudeNext.WPF/Strings/Strings.EN.xaml+++ b/WaveDudeNext.WPF/Strings/Strings.EN.xaml@@ -336,6 +336,8 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or<s:String x:Key="Hint.DisplayLayer.Preview">Show this output in the live preview.</s:String><s:String x:Key="Label.DisplayLayer.Overlay">Outline in the preview</s:String><s:String x:Key="Hint.DisplayLayer.Overlay">Lay the scene image's glowing-edges outline over this output in the preview.</s:String>+ <s:String x:Key="Label.Display.SourceMarkersInExport">Source markers in the export</s:String>+ <s:String x:Key="Hint.Display.SourceMarkersInExport">Draw the enabled sources (the marker, a composite source's emitter dots, the name) over exported frames and videos.</s:String><s:String x:Key="Label.DisplayLayer.OverlayGain">Outline brightness</s:String><s:String x:Key="Hint.DisplayLayer.OverlayGain">Multiplier of the outline: 1 as computed, higher lifts faint edges, 0 hides it.</s:String><s:String x:Key="Label.DisplayLayer.OverlayInExport">Outline in the export</s:String>diff --git a/WaveDudeNext.WPF/Strings/Strings.FR.xaml b/WaveDudeNext.WPF/Strings/Strings.FR.xamlindex 72f2958..b724411 100644--- a/WaveDudeNext.WPF/Strings/Strings.FR.xaml+++ b/WaveDudeNext.WPF/Strings/Strings.FR.xaml@@ -334,6 +334,8 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or<s:String x:Key="Hint.DisplayLayer.Preview">Afficher cette sortie dans l'aperçu en direct.</s:String><s:String x:Key="Label.DisplayLayer.Overlay">Contour dans l'aperçu</s:String><s:String x:Key="Hint.DisplayLayer.Overlay">Superposer le contour « bords lumineux » de l'image de scène à cette sortie dans l'aperçu.</s:String>+ <s:String x:Key="Label.Display.SourceMarkersInExport">Marqueurs des sources dans l'export</s:String>+ <s:String x:Key="Hint.Display.SourceMarkersInExport">Dessiner les sources actives (le marqueur, les points émetteurs d'une source composée, le nom) sur les images et vidéos exportées.</s:String><s:String x:Key="Label.DisplayLayer.OverlayGain">Luminosité du contour</s:String><s:String x:Key="Hint.DisplayLayer.OverlayGain">Multiplicateur du contour : 1 tel que calculé, plus haut relève les bords faibles, 0 le masque.</s:String><s:String x:Key="Label.DisplayLayer.OverlayInExport">Contour dans l'export</s:String>diff --git a/WaveDudeNext.WPF/Strings/Strings.NL.xaml b/WaveDudeNext.WPF/Strings/Strings.NL.xamlindex 5526038..1dd2083 100644--- a/WaveDudeNext.WPF/Strings/Strings.NL.xaml+++ b/WaveDudeNext.WPF/Strings/Strings.NL.xaml@@ -334,6 +334,8 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or<s:String x:Key="Hint.DisplayLayer.Preview">Deze uitvoer in het live-voorbeeld tonen.</s:String><s:String x:Key="Label.DisplayLayer.Overlay">Omtrek in het voorbeeld</s:String><s:String x:Key="Hint.DisplayLayer.Overlay">De gloeiende-randen-omtrek van de scèneafbeelding in het voorbeeld over deze uitvoer leggen.</s:String>+ <s:String x:Key="Label.Display.SourceMarkersInExport">Bronmarkeringen in de export</s:String>+ <s:String x:Key="Hint.Display.SourceMarkersInExport">De ingeschakelde bronnen (de markering, de emitterpunten van een samengestelde bron, de naam) over geëxporteerde beelden en video's tekenen.</s:String><s:String x:Key="Label.DisplayLayer.OverlayGain">Omtrekhelderheid</s:String><s:String x:Key="Hint.DisplayLayer.OverlayGain">Factor van de omtrek: 1 zoals berekend, hoger versterkt zwakke randen, 0 verbergt hem.</s:String><s:String x:Key="Label.DisplayLayer.OverlayInExport">Omtrek in de export</s:String>diff --git a/WaveDudeNext.WPF/Views/DisplayView.xaml b/WaveDudeNext.WPF/Views/DisplayView.xamlindex ae49060..5db54ef 100644--- a/WaveDudeNext.WPF/Views/DisplayView.xaml+++ b/WaveDudeNext.WPF/Views/DisplayView.xaml@@ -45,6 +45,8 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file orIsChecked="{Binding ProbeGraphsInExport}" ToolTip="{meta:Hint model:Display.ProbeGraphsInExport}" /><CheckBox controls:FormPanel.FullWidth="True" Content="{meta:Label model:Display.ProbeMarkersInExport}"IsChecked="{Binding ProbeMarkersInExport}" ToolTip="{meta:Hint model:Display.ProbeMarkersInExport}" />+ <CheckBox controls:FormPanel.FullWidth="True" Content="{meta:Label model:Display.SourceMarkersInExport}"+ IsChecked="{Binding SourceMarkersInExport}" ToolTip="{meta:Hint model:Display.SourceMarkersInExport}" /></controls:FormPanel><Label Style="{StaticResource FormSection}" Content="{DynamicResource SectionVideo}" />diff --git a/WaveDudeNext/Model/Display.cs b/WaveDudeNext/Model/Display.csindex 24fc53b..0513e80 100644--- a/WaveDudeNext/Model/Display.cs+++ b/WaveDudeNext/Model/Display.cs@@ -39,6 +39,7 @@ public sealed class Display : ObservableObjectprivate int _exportTo;private bool _probeGraphsInExport = true;private bool _probeMarkersInExport = true;+ private bool _sourceMarkersInExport;/// <summary>Rendering of the wave field.</summary>[XmlElement]@@ -128,6 +129,23 @@ public sealed class Display : ObservableObjectset => SetProperty(ref _probeMarkersInExport, value);}+ /// <summary>+ /// Whether an export draws the enabled sources over the frames of both layers (2026-10-21, the user's request; off+ /// by default, so existing projects export as before): the preview's source marker (a ring with a crosshair over a+ /// dark halo), a composite source's emitter dots, and the source's name, scaled to the canvas like the probe+ /// labels, under the probe markers and graph boxes. Jeroen's program drew sources only on its Sources tab.+ /// </summary>+ [XmlAttribute]+ [DefaultValue(false)]+ [Category("Export")]+ [DisplayName("Source markers in the export")]+ [Description("Draw the enabled sources (the marker, a composite source's emitter dots, the name) over exported frames and videos.")]+ public bool SourceMarkersInExport+ {+ get => _sourceMarkersInExport;+ set => SetProperty(ref _sourceMarkersInExport, value);+ }+/// <summary>Tells <see cref="XmlSerializer"/> to leave all-default video settings out of the file.</summary>public bool ShouldSerializeVideo() => Video.Fps != Video.DefaultFps || Video.Quality != Video.DefaultQuality;