Files
OpenNest/OpenNest.Desktop/Interaction/HeatEstimate.cs
T
ajandClaude Sonnet 5.5 7388843338 feat(thermal): log color scale and scale bar for the heat map
On a linear scale topped by the cells at the torch, nearly the whole
sheet drew in the coolest blue. Color rises logarithmically from 10 °C
to the 99.5th percentile of the cut's peaks, held between 100 and
1000 °C, and label the colors with a bar down the plate view's right
edge.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-12-02 21:14:04 -05:00

65 lines
2.3 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using OpenNest.CNC;
using OpenNest.CNC.Thermal;
namespace OpenNest.Desktop.Interaction;
/// <summary>
/// A heat model run over its whole cut, ready to play: what the cut simulator does off the UI
/// thread before it shows the heat layer.
/// </summary>
public sealed class HeatEstimate
{
private HeatEstimate(PlateHeatSimulation heat, float scale)
{
Heat = heat;
Scale = scale;
}
/// <summary>The model, back at the start.</summary>
public PlateHeatSimulation Heat { get; }
/// <summary>
/// The rise to color as hottest, the top of the <see cref="HeatColorScale"/>. Pierces leave
/// single very hot cells, so this is where the hottest half percent begins, held within the
/// scale's limits.
/// </summary>
public float Scale { get; }
/// <summary>Builds and runs the model.</summary>
public static HeatEstimate Run(Plate plate, CutSimulation simulation, ThermalParameters parameters,
CancellationToken cancellationToken = default)
{
cancellationToken.ThrowIfCancellationRequested();
var heat = new PlateHeatSimulation(plate, simulation, parameters);
heat.RunToEnd(cancellationToken: cancellationToken);
var scale = HeatColorScale.Top(HotRise(heat));
heat.Reset();
return new HeatEstimate(heat, scale);
}
/// <summary>True when both timelines cut and travel the same, at the same times.</summary>
public static bool SameMoves(CutSimulation a, CutSimulation b) =>
a != null && b != null && a.Steps.Count == b.Steps.Count
&& a.Steps.Zip(b.Steps).All(pair => Move(pair.First).Equals(Move(pair.Second)));
private static object Move(CutSimulationStep s) =>
(s.Kind, s.Start, s.End, s.IsArc, s.Center, s.Sweep, s.StartTime, s.Duration, (s.Layer, s.IsHole, s.ContourIndex));
private static float HotRise(PlateHeatSimulation heat)
{
var all = heat.Peaks;
var peaks = new List<float>();
for (var i = 0; i < all.Length; i++)
{
if (!heat.IsRemoved(i) && all[i] > 0)
peaks.Add(all[i]);
}
peaks.Sort();
return peaks.Count == 0 ? 0 : peaks[(int)(0.995 * (peaks.Count - 1))];
}
}