Skip to content

Commit 5b5d9f9

Browse files
committed
Added color scale bounds forcing
Now you can generate images that use the same scale as a previous inspection.
1 parent 1b4c6f6 commit 5b5d9f9

File tree

4 files changed

+115
-50
lines changed

4 files changed

+115
-50
lines changed

BedLeveler.Designer.cs

+76-46
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

BedLeveler.cs

+36-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,14 @@ public partial class BedLeveler : Form
1414
List<Vector3> points = new List<Vector3>();
1515
List<Vector2> toMeasure = new List<Vector2>();
1616

17-
public BedLeveler() { InitializeComponent(); }
17+
float? LowerBound = null;
18+
float? UpperBound = null;
19+
20+
public BedLeveler()
21+
{
22+
InitializeComponent();
23+
Text += $" {Application.ProductVersion}";
24+
}
1825

1926
private void MeasurePoint(float x, float y)
2027
{
@@ -133,13 +140,16 @@ private void BedPaint(object sender, PaintEventArgs e)
133140

134141
float min = (from p in points select p.Z).Min();
135142
float max = (from p in points select p.Z).Max();
143+
if (LowerBound.HasValue) min = LowerBound.Value;
144+
if (UpperBound.HasValue) max = UpperBound.Value;
145+
136146
float range = max - min;
137147

138148
using (Font font = new Font("Arial", 11.0f, FontStyle.Bold))
139149
using (StringFormat format = new StringFormat() { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center })
140150
foreach (var p in points)
141151
{
142-
float zPercent = range < 0.001 ? 1.0f : (p.Z - min) / range;
152+
float zPercent = Math.Max(0.0f, Math.Min(1.0f, range < 0.001 ? 1.0f : (p.Z - min) / range));
143153
float hue = Lerp(0, 240, zPercent);
144154
Color c = ColorFromHSV(hue, 1.0, 1.0);
145155

@@ -228,5 +238,29 @@ private void SetZto5(object sender, EventArgs e)
228238
{
229239
if (port != null) port.Send("G1 Z5 F6000");
230240
}
241+
242+
private void SetBound(object sender, EventArgs e)
243+
{
244+
var tag = ((ToolStripMenuItem)sender).Tag as string;
245+
246+
float? current = null;
247+
if (tag.StartsWith("L")) current = LowerBound;
248+
else current = UpperBound;
249+
250+
string input = Microsoft.VisualBasic.Interaction.InputBox($"Choose a {tag} Bound for color selection. Leave blank to reset to automatic bound. This is for visualization only (to match against subsequent scans).", $"Set {tag} Color Bound", current?.ToString() ?? "");
251+
252+
if (string.IsNullOrWhiteSpace(input))
253+
{
254+
if (tag.StartsWith("L")) LowerBound = null;
255+
else UpperBound = null;
256+
}
257+
else if (float.TryParse(input, out float value))
258+
{
259+
if (tag.StartsWith("L")) LowerBound = value;
260+
else UpperBound = value;
261+
}
262+
263+
bedPicture.Invalidate();
264+
}
231265
}
232266
}

BedLeveler.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
<WarningLevel>4</WarningLevel>
3333
</PropertyGroup>
3434
<ItemGroup>
35+
<Reference Include="Microsoft.VisualBasic" />
3536
<Reference Include="System" />
3637
<Reference Include="System.Core" />
3738
<Reference Include="System.Numerics" />

Properties/AssemblyInfo.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@
3131
// You can specify all the values or you can default the Build and Revision Numbers
3232
// by using the '*' as shown below:
3333
// [assembly: AssemblyVersion("1.0.*")]
34-
[assembly: AssemblyVersion("1.0.0.0")]
35-
[assembly: AssemblyFileVersion("1.0.0.0")]
34+
[assembly: AssemblyVersion("1.1.0.0")]
35+
[assembly: AssemblyFileVersion("1.1.0.0")]

0 commit comments

Comments
 (0)