mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-12-04 07:19:24 -05:00
With short steps only around the torch, the processor is faster than the card at the quarter-inch cells full sheets use, and the card only gained at a cell size they do not use. Drop OpenNest.Gpu, the ILGPU dependency and the accelerator interface; the heat map runs the same on every computer. The measured card timings stay in docs/plate-heat-map.md. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
64 lines
2.2 KiB
C#
64 lines
2.2 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. Pierces leave single very hot cells, and scaling to them
|
|
/// would wash out the areas where heat builds up, so this is the hottest half percent.
|
|
/// </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 = ColorScale(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 ColorScale(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 ? 1f : peaks[(int)(0.995 * (peaks.Count - 1))];
|
|
}
|
|
}
|