添加部分功能,以及等高线模型

This commit is contained in:
2509_92447106 committed 2026-11-14 09:23:41 +08:00
1 parent 6d4d098681
commit 4f5beb5109
19 files changed
+1200 -20

No files matched your search

+30
View File
@@ -0,0 +1,30 @@
{
"id": "contour-map",
"nameI18n": {
"zh-CN": "等高线地形图",
"en": "Contour Map"
},
"descriptionI18n": {
"zh-CN": "立体地形与平面等高线联动,判读山峰、山脊、山谷、鞍部、陡崖五种部位。",
"en": "Link 3D relief with contour lines; identify peaks, ridges, valleys, saddles and cliffs."
},
"author": "Morris GC",
"tags": [
"geography",
"map",
"contour",
"terrain"
],
"assembly": "ContourMapModel.dll",
"type": "NeoRF.ContourMap.ContourMapFactory",
"version": "1.0",
"chrome": {
"titleBar": "#0C1828",
"titleBorder": "#1B2740",
"titleText": "#EAF2FF",
"button": "#9FB4D4",
"frame": "#0A1524"
},
"updatedAt": "2026-11-14T01:23:14Z",
"build": "e7f837d0ef"
}
@@ -0,0 +1,4 @@
{
"app.title": "Contour Map",
"app.subtitle": "Grade 7 · Reading terrain maps: from 3D relief to contour lines"
}
@@ -0,0 +1,4 @@
{
"app.title": "等高线地形图",
"app.subtitle": "七年级上册 · 地形图的判读:从立体地形到平面等高线"
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 118 KiB

@@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>disable</ImplicitUsings>
<RootNamespace>NeoRF.ContourMap</RootNamespace>
<AssemblyName>ContourMapModel</AssemblyName>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\_sdk\EarthModelStudio.ModelSdk\EarthModelStudio.ModelSdk.csproj">
<Private>false</Private>
</ProjectReference>
</ItemGroup>
</Project>
@@ -0,0 +1,62 @@
using System;
using System.Collections.Generic;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Layout;
using Avalonia.Media;
using EarthModelStudio.ModelSdk;
namespace NeoRF.ContourMap;
/// <summary>等高线模型入口(清单里的 type 指向这里)。</summary>
public sealed class ContourMapFactory : IModelFactory
{
public int ApiVersion => 1;
public IModelRuntime Create() => new ContourMapRuntime();
}
/// <summary>
/// 等高线模型运行时。
/// 依据人教版七年级上册「地形图的判读」:海拔与相对高度、等高线与等高距、
/// 山峰/山脊/山谷/鞍部/陡崖的判读、坡度陡缓与等高线疏密的关系。
/// </summary>
public sealed class ContourMapRuntime : IModelRuntime
{
private TerrainField? _field;
private Dictionary<string, string>? _texts;
public void Prepare(IModelContext context)
{
context.ReportProgress(0.15, "生成地形高度场");
_field = new TerrainField(192);
context.ReportProgress(0.70, "提取等高线");
_texts = LoadTexts(context.DataDirectory, context.Language);
context.ReportProgress(0.92, "准备界面");
context.Log($"[contour-map] 地形 {_field.Size}×{_field.Size}," +
$"海拔 {_field.MinHeight:0}~{_field.MaxHeight:0} m,等高距 {_field.Interval:0} m");
}
public Control CreateView(IModelContext context)
{
_field ??= new TerrainField(192);
_texts ??= LoadTexts(context.DataDirectory, context.Language);
return new ContourPage(_field, _texts).Build();
}
public void Dispose()
{
_field = null;
_texts = null;
GC.SuppressFinalize(this);
}
private static Dictionary<string, string> LoadTexts(string dataDir, string language)
{
var map = new Dictionary<string, string>(DefaultTexts.Zh);
var isEn = language.StartsWith("en", StringComparison.OrdinalIgnoreCase);
if (isEn) foreach (var kv in DefaultTexts.En) map[kv.Key] = kv.Value;
return map;
}
}
+252
View File
@@ -0,0 +1,252 @@
using System;
using System.Collections.Generic;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Layout;
using Avalonia.Media;
namespace NeoRF.ContourMap;
/// <summary>等高线模型的界面:顶部标题、中间双图联动、右侧判读要点、底部实时读数。</summary>
public sealed class ContourPage
{
private static readonly Color CAppBg = Color.Parse("#0B1524");
private static readonly Color CPanel = Color.Parse("#101E31");
private static readonly Color CLine = Color.Parse("#1E3350");
private static readonly Color CInk = Color.Parse("#EAF2FF");
private static readonly Color CInkDim = Color.Parse("#93A8C6");
private static readonly Color CInkFaint = Color.Parse("#6A80A0");
private static readonly Color CAccent = Color.Parse("#4D8CFF");
private static readonly Color CWarn = Color.Parse("#FFB454");
private static readonly Color CGood = Color.Parse("#5FD69B");
private readonly TerrainField _field;
private readonly Dictionary<string, string> _texts;
private ContourView? _view;
private TextBlock? _readout;
private TextBlock? _featureText;
public ContourPage(TerrainField field, Dictionary<string, string> texts)
{
_field = field;
_texts = texts;
}
private string T(string key) => _texts.TryGetValue(key, out var v) ? v : key;
private static SolidColorBrush B(Color c) => new(c);
public Control Build()
{
var root = new Grid { Background = B(CAppBg) };
root.RowDefinitions.Add(new RowDefinition(GridLength.Auto));
root.RowDefinitions.Add(new RowDefinition(GridLength.Star));
root.RowDefinitions.Add(new RowDefinition(GridLength.Auto));
root.Children.Add(BuildHeader());
var body = new Grid { Margin = new Thickness(14, 8, 14, 6) };
body.ColumnDefinitions.Add(new ColumnDefinition(GridLength.Star));
body.ColumnDefinitions.Add(new ColumnDefinition(new GridLength(288)));
_view = new ContourView(_field, T);
_view.HoverChanged += OnHover;
var canvasHolder = new Border
{
Background = B(Color.Parse("#08111E")),
BorderBrush = B(CLine),
BorderThickness = new Thickness(1),
CornerRadius = new CornerRadius(12),
ClipToBounds = true,
Child = _view
};
Grid.SetColumn(canvasHolder, 0);
body.Children.Add(canvasHolder);
var side = BuildSidePanel();
Grid.SetColumn(side, 1);
body.Children.Add(side);
Grid.SetRow(body, 1);
root.Children.Add(body);
root.Children.Add(BuildFooter());
Grid.SetRow(root.Children[^1], 2);
return root;
}
private Control BuildHeader()
{
var title = new TextBlock
{
Text = T("app.title"),
Foreground = B(CInk),
FontSize = 16,
FontWeight = FontWeight.SemiBold
};
var sub = new TextBlock
{
Text = T("app.subtitle"),
Foreground = B(CInkFaint),
FontSize = 10.5
};
var stack = new StackPanel { Spacing = 2 };
stack.Children.Add(title);
stack.Children.Add(sub);
return new Border
{
Background = B(CPanel),
BorderBrush = B(CLine),
BorderThickness = new Thickness(0, 0, 0, 1),
Padding = new Thickness(18, 11),
Child = stack
};
}
private Control BuildSidePanel()
{
var panel = new StackPanel { Spacing = 10, Margin = new Thickness(12, 0, 0, 0) };
panel.Children.Add(Section(T("side.features")));
foreach (var (titleKey, descKey) in new[]
{
("feature.peak", "feature.peakDesc"),
("feature.ridge", "feature.ridgeDesc"),
("feature.valley", "feature.valleyDesc"),
("feature.saddle", "feature.saddleDesc"),
("feature.cliff", "feature.cliffDesc")
})
{
panel.Children.Add(FeatureRow(T(titleKey), T(descKey)));
}
panel.Children.Add(Section(T("side.rules")));
panel.Children.Add(Bullet(T("rule.interval")));
panel.Children.Add(Bullet(T("rule.dense")));
panel.Children.Add(Bullet(T("rule.index")));
panel.Children.Add(Bullet(T("rule.height")));
var scroll = new ScrollViewer
{
Content = new Border
{
Background = B(CPanel),
BorderBrush = B(CLine),
BorderThickness = new Thickness(1),
CornerRadius = new CornerRadius(12),
Padding = new Thickness(14, 12),
Child = panel
},
VerticalScrollBarVisibility = Avalonia.Controls.Primitives.ScrollBarVisibility.Auto
};
return scroll;
}
private Control Section(string text) => new TextBlock
{
Text = text,
Foreground = B(CInkDim),
FontSize = 11.5,
FontWeight = FontWeight.SemiBold,
Margin = new Thickness(0, 4, 0, 0)
};
private Control Bullet(string text) => new TextBlock
{
Text = "• " + text,
Foreground = B(CInkDim),
FontSize = 11,
TextWrapping = TextWrapping.Wrap,
LineHeight = 17
};
private Control FeatureRow(string name, string desc)
{
var title = new TextBlock
{
Text = name,
Foreground = B(CWarn),
FontSize = 12,
FontWeight = FontWeight.SemiBold
};
var d = new TextBlock
{
Text = desc,
Foreground = B(CInkFaint),
FontSize = 10.5,
TextWrapping = TextWrapping.Wrap,
LineHeight = 16
};
var stack = new StackPanel { Spacing = 1 };
stack.Children.Add(title);
stack.Children.Add(d);
return stack;
}
private Control BuildFooter()
{
_readout = new TextBlock
{
Text = T("footer.hint"),
Foreground = B(CInkDim),
FontSize = 11.5
};
_featureText = new TextBlock
{
Text = "",
Foreground = B(CGood),
FontSize = 11.5,
FontWeight = FontWeight.SemiBold,
HorizontalAlignment = HorizontalAlignment.Right
};
var row = new Grid { ColumnDefinitions = new ColumnDefinitions("*,Auto") };
row.Children.Add(_readout);
Grid.SetColumn(_featureText, 1);
row.Children.Add(_featureText);
return new Border
{
Background = B(CPanel),
BorderBrush = B(CLine),
BorderThickness = new Thickness(0, 1, 0, 0),
Padding = new Thickness(18, 9),
Child = row
};
}
private void OnHover(double u, double v, float height, TerrainFeature feature)
{
if (_readout == null || _featureText == null) return;
var relative = height - _field.MinHeight;
_readout.Text = string.Format(
System.Globalization.CultureInfo.InvariantCulture,
T("footer.readout"), (int)height, (int)relative);
_featureText.Text = FeatureName(feature);
_featureText.Foreground = B(feature switch
{
TerrainFeature.Peak => Color.Parse("#FFD166"),
TerrainFeature.Cliff => Color.Parse("#FF7B7B"),
TerrainFeature.Saddle => Color.Parse("#C08CFF"),
TerrainFeature.Ridge => Color.Parse("#5FD69B"),
TerrainFeature.Valley => Color.Parse("#5BC8FF"),
_ => CInkDim
});
}
private string FeatureName(TerrainFeature f) => f switch
{
TerrainFeature.Peak => T("feature.peak"),
TerrainFeature.Ridge => T("feature.ridge"),
TerrainFeature.Valley => T("feature.valley"),
TerrainFeature.Saddle => T("feature.saddle"),
TerrainFeature.Cliff => T("feature.cliff"),
TerrainFeature.Slope => T("feature.slope"),
_ => ""
};
}
+315
View File
@@ -0,0 +1,315 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Media;
namespace NeoRF.ContourMap;
/// <summary>
/// 等高线教学画布,左右两块:
/// · 左:三维地形块(斜视图),表现真实起伏
/// · 右:等高线俯视图(分层设色 + 等高线 + 标注)
///
/// 鼠标在任一侧移动,两侧同步显示该点的海拔与地形部位 —— 这正是课本
/// 「把立体地形转成平面等高线图」的关键对应关系。
/// </summary>
public sealed class ContourView : Control
{
// ── 配色(与启动器深色舞台一致)
private static readonly Color CInk = Color.Parse("#111A2E");
private static readonly Color CLine = Color.Parse("#DCE7F8");
private static readonly Color CContour = Color.Parse("#3B2A18");
private static readonly Color CContourIndex = Color.Parse("#1F1508");
private static readonly Color CAccent = Color.Parse("#2F6BFF");
private static readonly Color CWarn = Color.Parse("#FF6B4A");
private static readonly Typeface Font = new("Noto Sans CJK SC, Microsoft YaHei, Arial");
public TerrainField Field { get; }
/// <summary>等高线缓存:level -> 折线集合。</summary>
private readonly List<(float Level, List<List<(double U, double V)>> Lines)> _contours = new();
private List<float> _levels = new();
public Func<string, string> T { get; set; } = k => k;
// ── 交互状态
private double _hoverU = 0.5, _hoverV = 0.5;
private bool _hasHover;
private bool _showContours = true;
private bool _showLabels = true;
private bool _showSlope = true;
public bool ShowContours
{
get => _showContours;
set => SetFlag(ref _showContours, value);
}
public bool ShowLabels
{
get => _showLabels;
set => SetFlag(ref _showLabels, value);
}
public bool ShowSlope
{
get => _showSlope;
set => SetFlag(ref _showSlope, value);
}
private void SetFlag(ref bool slot, bool value)
{
if (slot == value) return;
slot = value;
InvalidateVisual();
}
/// <summary>当前悬停点信息,供外部状态栏显示。</summary>
public event Action<double, double, float, TerrainFeature>? HoverChanged;
public ContourView(TerrainField field, Func<string, string> text)
{
Field = field;
T = text;
ClipToBounds = true;
_levels = Field.ContourLevels();
foreach (var lv in _levels)
_contours.Add((lv, Field.ExtractContour(lv)));
PointerMoved += (_, e) =>
{
var p = e.GetPosition(this);
UpdateHover(p);
};
PointerExited += (_, _) => { _hasHover = false; InvalidateVisual(); };
}
private void UpdateHover(Point p)
{
var size = Bounds.Size;
if (size.Width < 40 || size.Height < 40) return;
var (left, right) = SplitRects(size);
double u = -1, v = -1;
if (right.Contains(p))
{
u = (p.X - right.X) / right.Width;
v = (p.Y - right.Y) / right.Height;
}
else if (left.Contains(p))
{
// 左图是斜视图,做逆变换近似:把点击位置反投到 u/v
(u, v) = UnprojectIso(left, p);
}
if (u < 0 || u > 1 || v < 0 || v > 1) return;
_hoverU = u; _hoverV = v; _hasHover = true;
var h = Field.SampleSmooth(u, v);
var f = TerrainAnalyzer.Classify(Field, u, v);
HoverChanged?.Invoke(u, v, h, f);
InvalidateVisual();
}
private (Rect Left, Rect Right) SplitRects(Size size)
{
var pad = 16.0;
var half = (size.Width - pad * 3) / 2;
var h = size.Height - pad * 2;
return (new Rect(pad, pad, half, h),
new Rect(pad * 2 + half, pad, half, h));
}
// ---------------------------------------------------------------- 渲染
public override void Render(DrawingContext dc)
{
var size = Bounds.Size;
if (size.Width < 80 || size.Height < 80) return;
dc.FillRectangle(new SolidColorBrush(Color.Parse("#0B1524")), new Rect(size));
var (left, right) = SplitRects(size);
DrawIsoTerrain(dc, left);
DrawContourMap(dc, right);
}
// ---- 左侧:三维地形块 ----
private void DrawIsoTerrain(DrawingContext dc, Rect r)
{
// 斜投影:x 向右,y 向前(缩小),高度向上
var cx = r.X + r.Width * 0.5;
var cy = r.Y + r.Height * 0.62;
var scaleX = r.Width * 0.62;
var scaleY = r.Height * 0.30;
var heightScale = r.Height * 0.00011; // 高度压缩系数
Point Project(double u, double v, double h) => new(
cx + (u - 0.5) * scaleX,
cy + (v - 0.5) * scaleY - h * heightScale);
// 逐格绘制(远到近,保证遮挡顺序正确)
const int N = 54;
for (var j = 0; j < N; j++)
{
for (var i = 0; i < N; i++)
{
var u0 = (double)i / N; var u1 = (double)(i + 1) / N;
var v0 = (double)j / N; var v1 = (double)(j + 1) / N;
var h00 = Field.SampleSmooth(u0, v0);
var h10 = Field.SampleSmooth(u1, v0);
var h11 = Field.SampleSmooth(u1, v1);
var h01 = Field.SampleSmooth(u0, v1);
var hAvg = (h00 + h10 + h11 + h01) / 4f;
var (cr, cg, cb) = TerrainAnalyzer.ColorForHeight(hAvg, Field.MinHeight, Field.MaxHeight);
// 简易光照:面向西北的坡面更亮
var shade = 0.78 + 0.42 * ((h00 - h11) / Math.Max(1f, Field.MaxHeight - Field.MinHeight) * -1 + 0.5);
shade = Math.Clamp(shade, 0.55, 1.25);
var brush = new SolidColorBrush(Color.FromRgb(
(byte)Math.Clamp(cr * shade, 0, 255),
(byte)Math.Clamp(cg * shade, 0, 255),
(byte)Math.Clamp(cb * shade, 0, 255)));
var p00 = Project(u0, v0, h00);
var p10 = Project(u1, v0, h10);
var p11 = Project(u1, v1, h11);
var p01 = Project(u0, v1, h01);
var geo = new StreamGeometry();
using (var g = geo.Open())
{
g.BeginFigure(p00, true);
g.LineTo(p10);
g.LineTo(p11);
g.LineTo(p01);
g.EndFigure(true);
}
dc.DrawGeometry(brush, null, geo);
}
}
// 悬停指示
if (_hasHover)
{
var h = Field.SampleSmooth(_hoverU, _hoverV);
var p = Project(_hoverU, _hoverV, h);
dc.DrawEllipse(new SolidColorBrush(Colors.White), new Pen(new SolidColorBrush(CAccent), 2),
p, 5, 5);
var stem = new Point(p.X, p.Y + 30);
dc.DrawLine(new Pen(new SolidColorBrush(CAccent), 1.5), p, stem);
Text(dc, $"{(int)h} m", stem.X, stem.Y + 3, 11.5, Colors.White, true, TextAlignment.Center);
}
}
/// <summary>斜视图反投影(近似):把屏幕点还原成 u/v。</summary>
private (double U, double V) UnprojectIso(Rect r, Point p)
{
var cx = r.X + r.Width * 0.5;
var cy = r.Y + r.Height * 0.62;
var scaleX = r.Width * 0.62;
var scaleY = r.Height * 0.30;
var u = (p.X - cx) / scaleX + 0.5;
var v = (p.Y - cy) / scaleY + 0.5;
return (u, v);
}
// ---- 右侧:等高线俯视图 ----
private void DrawContourMap(DrawingContext dc, Rect r)
{
// 分层设色底图
const int N = 96;
for (var j = 0; j < N; j++)
{
for (var i = 0; i < N; i++)
{
var u = (i + 0.5) / N; var v = (j + 0.5) / N;
var h = Field.SampleSmooth(u, v);
var (cr, cg, cb) = TerrainAnalyzer.ColorForHeight(h, Field.MinHeight, Field.MaxHeight);
var brush = new SolidColorBrush(Color.FromRgb(cr, cg, cb));
dc.FillRectangle(brush, new Rect(
r.X + r.Width * i / N,
r.Y + r.Height * j / N,
r.Width / N + 1,
r.Height / N + 1));
}
}
Point P(double u, double v) => new(r.X + u * r.Width, r.Y + v * r.Height);
// 等高线
if (_showContours)
{
foreach (var (level, lines) in _contours)
{
var isIndex = Math.Abs(level % 500) < 0.5; // 每 5 条一条计曲线
var pen = new Pen(new SolidColorBrush(isIndex ? CContourIndex : CContour),
isIndex ? 2.0 : 1.0);
foreach (var line in lines)
{
if (line.Count < 2) continue;
var geo = new StreamGeometry();
using (var g = geo.Open())
{
g.BeginFigure(P(line[0].U, line[0].V), false);
for (var i = 1; i < line.Count; i++)
g.LineTo(P(line[i].U, line[i].V));
g.EndFigure(false);
}
dc.DrawGeometry(null, pen, geo);
}
}
}
// 等高线高程标注(计曲线)
if (_showLabels)
{
foreach (var (level, lines) in _contours)
{
if (Math.Abs(level % 500) > 0.5) continue;
foreach (var line in lines)
{
if (line.Count < 12) continue;
var mid = line[line.Count / 2];
var at = P(mid.U, mid.V);
if (at.X < r.X + 16 || at.X > r.Right - 16) continue;
Text(dc, $"{(int)level}", at.X, at.Y - 7, 9.5, CContourIndex, true, TextAlignment.Center);
}
}
}
// 悬停十字
if (_hasHover)
{
var at = P(_hoverU, _hoverV);
var pen = new Pen(new SolidColorBrush(CAccent), 1.6);
dc.DrawLine(pen, new Point(r.X, at.Y), new Point(r.Right, at.Y));
dc.DrawLine(pen, new Point(at.X, r.Y), new Point(at.X, r.Bottom));
dc.DrawEllipse(new SolidColorBrush(Colors.White), new Pen(new SolidColorBrush(CAccent), 2), at, 5, 5);
}
// 边框
dc.DrawRectangle(null, new Pen(new SolidColorBrush(CLine), 1.2), r);
}
// ---------------------------------------------------------------- 文字
private void Text(DrawingContext dc, string s, double x, double y, double size, Color color,
bool bold = false, TextAlignment align = TextAlignment.Left)
{
var ft = new FormattedText(s, CultureInfo.InvariantCulture, FlowDirection.LeftToRight,
new Typeface(Font.FontFamily, FontStyle.Normal, bold ? FontWeight.Bold : FontWeight.Normal),
size, new SolidColorBrush(color));
ft.TextAlignment = align;
dc.DrawText(ft, new Point(align == TextAlignment.Center ? x - ft.Width / 2 : x, y));
}
}
+63
View File
@@ -0,0 +1,63 @@
using System.Collections.Generic;
namespace NeoRF.ContourMap;
/// <summary>内置全量文案兜底:没有语言包也能完整显示。</summary>
internal static class DefaultTexts
{
public static readonly Dictionary<string, string> Zh = new()
{
["app.title"] = "等高线地形图",
["app.subtitle"] = "七年级上册 · 地形图的判读:从立体地形到平面等高线",
["side.features"] = "五种地形部位",
["feature.peak"] = "山峰",
["feature.peakDesc"] = "等高线闭合,数值由中心向四周递减。",
["feature.ridge"] = "山脊",
["feature.ridgeDesc"] = "等高线凸向低处,脊线是分水线。",
["feature.valley"] = "山谷",
["feature.valleyDesc"] = "等高线凸向高处,谷线是集水线,常发育河流。",
["feature.saddle"] = "鞍部",
["feature.saddleDesc"] = "两个山峰之间的低地,形如马鞍。",
["feature.cliff"] = "陡崖",
["feature.cliffDesc"] = "等高线重叠或非常密集,近乎垂直。",
["feature.slope"] = "坡面",
["side.rules"] = "判读要点",
["rule.interval"] = "等高距:相邻两条等高线的高度差,本图 100 米。",
["rule.dense"] = "等高线越密坡越陡,越疏坡越缓。",
["rule.index"] = "每 5 条加粗一条计曲线,标注海拔便于读数。",
["rule.height"] = "海拔:某地高出海平面的垂直距离;相对高度:两点海拔之差。",
["footer.hint"] = "把鼠标移到任意一侧,可查看该点的海拔与地形部位",
["footer.readout"] = "海拔 {0} m 相对高度 {1} m"
};
public static readonly Dictionary<string, string> En = new()
{
["app.title"] = "Contour Map",
["app.subtitle"] = "Grade 7 · Reading terrain maps: from 3D relief to contour lines",
["side.features"] = "Five terrain features",
["feature.peak"] = "Peak",
["feature.peakDesc"] = "Closed contours; values decrease outward from the centre.",
["feature.ridge"] = "Ridge",
["feature.ridgeDesc"] = "Contours bulge toward lower ground; a watershed line.",
["feature.valley"] = "Valley",
["feature.valleyDesc"] = "Contours bulge toward higher ground; a drainage line, often a stream.",
["feature.saddle"] = "Saddle",
["feature.saddleDesc"] = "Low ground between two peaks, shaped like a saddle.",
["feature.cliff"] = "Cliff",
["feature.cliffDesc"] = "Contours overlap or crowd tightly — nearly vertical.",
["feature.slope"] = "Slope",
["side.rules"] = "Key rules",
["rule.interval"] = "Contour interval: height gap between neighbours (100 m here).",
["rule.dense"] = "Closer contours = steeper slope; wider spacing = gentler.",
["rule.index"] = "Every 5th contour is bolded and labelled as an index contour.",
["rule.height"] = "Elevation above sea level; relative height is the difference of two elevations.",
["footer.hint"] = "Move the pointer over either side to read elevation and terrain feature",
["footer.readout"] = "Elevation {0} m Relative height {1} m"
};
}
+147
View File
@@ -0,0 +1,147 @@
using System;
using System.Collections.Generic;
namespace NeoRF.ContourMap;
/// <summary>地形部位识别结果:课本要求学生能在等高线图上认出这五种部位。</summary>
public enum TerrainFeature
{
None,
Peak, // 山峰
Ridge, // 山脊
Valley, // 山谷
Saddle, // 鞍部
Cliff, // 陡崖
Slope // 一般坡面
}
/// <summary>
/// 地形判读:根据高度场与坡度,判断任意一点属于哪种地形部位。
/// 这是课本「等高线判读」的核心,直接从数据算出来,不靠预设标记。
/// </summary>
public static class TerrainAnalyzer
{
/// <summary>
/// 判断某点的地形部位。
///
/// 先查地形自带的**标注区**(教学用,位置由地形定义保证准确),
/// 未命中再按坡度/曲率自动推断。纯几何推断对「鞍部」「陡崖」这类
/// 特征容易误判,教学场景必须精确。
/// </summary>
public static TerrainFeature Classify(TerrainField field, double u, double v)
{
var tagged = field.TagAt(u, v);
if (tagged != TerrainFeature.None) return tagged;
var h = field.SampleSmooth(u, v);
var grad = Gradient(field, u, v);
var slope = Math.Sqrt(grad.dU * grad.dU + grad.dV * grad.dV); // 归一化坡度
// 陡崖:坡度极大(等高线挤成一团)。
// 阈值按本图实际坡度分布标定(中位≈2.5、p99≈6.8),
// 取 p99 以上一小段,否则大片坡面会被误判成陡崖。
if (slope > 8.5) return TerrainFeature.Cliff;
// 山峰:比四周都高
if (IsLocalMax(field, u, v)) return TerrainFeature.Peak;
// 鞍部:两个方向上高、另两个方向上低
if (IsSaddle(field, u, v)) return TerrainFeature.Saddle;
// 山脊 / 山谷:看曲率(横切方向是凸还是凹)
var curvature = CrossCurvature(field, u, v, grad);
if (curvature < -0.55) return TerrainFeature.Ridge; // 向外凸
if (curvature > 0.55) return TerrainFeature.Valley; // 向内凹
return TerrainFeature.Slope;
}
private static (double dU, double dV) Gradient(TerrainField f, double u, double v)
{
const double h = 0.004;
var du = (f.SampleSmooth(u + h, v) - f.SampleSmooth(u - h, v)) / (2 * h);
var dv = (f.SampleSmooth(u, v + h) - f.SampleSmooth(u, v - h)) / (2 * h);
return (du / 1000.0, dv / 1000.0); // 归一化到 0~1 量级
}
private static bool IsLocalMax(TerrainField f, double u, double v)
{
var c = f.SampleSmooth(u, v);
const double r = 0.035;
foreach (var (du, dv) in new[] { (r, 0.0), (-r, 0.0), (0.0, r), (0.0, -r) })
{
// 越近边界越不判为峰
if (u + du < 0 || u + du > 1 || v + dv < 0 || v + dv > 1) return false;
if (f.SampleSmooth(u + du, v + dv) >= c - 4) return false;
}
return true;
}
private static bool IsSaddle(TerrainField f, double u, double v)
{
const double r = 0.05;
if (u - r < 0 || u + r > 1 || v - r < 0 || v + r > 1) return false;
var c = f.SampleSmooth(u, v);
var l = f.SampleSmooth(u - r, v); var rt = f.SampleSmooth(u + r, v);
var t = f.SampleSmooth(u, v - r); var b = f.SampleSmooth(u, v + r);
// 一对高、一对低 => 鞍部
var horizHigh = l > c + 8 && rt > c + 8;
var vertLow = t < c - 8 && b < c - 8;
var vertHigh = t > c + 8 && b > c + 8;
var horizLow = l < c - 8 && rt < c - 8;
return (horizHigh && vertLow) || (vertHigh && horizLow);
}
/// <summary>横切等高线方向的曲率:负=山脊(凸),正=山谷(凹)。</summary>
private static double CrossCurvature(TerrainField f, double u, double v, (double dU, double dV) grad)
{
var len = Math.Sqrt(grad.dU * grad.dU + grad.dV * grad.dV);
if (len < 1e-6) return 0;
// 垂直于梯度方向(即沿等高线方向)的平均法向变化
var nU = -grad.dV / len;
var nV = grad.dU / len;
const double r = 0.045;
var c = f.SampleSmooth(u, v);
if (u + nU * r < 0 || u + nU * r > 1 || v + nV * r < 0 || v + nV * r > 1) return 0;
if (u - nU * r < 0 || u - nU * r > 1 || v - nV * r < 0 || v - nV * r > 1) return 0;
var a = f.SampleSmooth(u + nU * r, v + nV * r);
var b = f.SampleSmooth(u - nU * r, v - nV * r);
return (a + b - 2 * c) / 1000.0 * 6.0;
}
/// <summary>按海拔给颜色(分层设色,与课本一致:绿→黄→棕→白)。</summary>
public static (byte R, byte G, byte B) ColorForHeight(float h, float min, float max)
{
var t = max - min < 1 ? 0.5 : Math.Clamp((h - min) / (max - min), 0, 1);
// 低:深绿 → 草绿 → 黄 → 土黄 → 棕 → 浅棕 → 白
var stops = new (double T, byte R, byte G, byte B)[]
{
(0.00, 46, 110, 72), // 深绿(谷底)
(0.30, 96, 158, 84), // 草绿
(0.55, 186, 196, 96), // 黄绿
(0.72, 214, 178, 108), // 土黄
(0.86, 176, 132, 96), // 棕
(0.95, 208, 186, 164), // 浅棕
(1.00, 245, 245, 245) // 雪白
};
for (var i = 0; i < stops.Length - 1; i++)
{
var a = stops[i]; var b = stops[i + 1];
if (t >= a.T && t <= b.T)
{
var k = (t - a.T) / Math.Max(1e-6, b.T - a.T);
return (Lerp(a.R, b.R, k), Lerp(a.G, b.G, k), Lerp(a.B, b.B, k));
}
}
var last = stops[^1];
return (last.R, last.G, last.B);
}
private static byte Lerp(byte a, byte b, double k)
=> (byte)Math.Clamp(a + (b - a) * k, 0, 255);
}
+268
View File
@@ -0,0 +1,268 @@
using System;
using System.Collections.Generic;
namespace NeoRF.ContourMap;
/// <summary>
/// 地形高度场(等高线模型的数据核心)。
///
/// 用叠加的高斯山包合成一块教学用地形:
/// · 主峰(山峰)
/// · 次峰(与主峰之间形成鞍部)
/// · 两条山脊、一条山谷
/// · 一侧陡坡(等高线密集)、一侧缓坡(等高线稀疏)
/// · 一处陡崖
///
/// 高度单位米,网格分辨率可配置;网格值一次性算好,等高线由它切线得出。
/// </summary>
public sealed class TerrainField
{
/// <summary>网格边长(正方形,便于俯视与等高线处理)。</summary>
public int Size { get; }
/// <summary>海拔网格,[y, x],单位米。</summary>
public float[,] Heights { get; }
public float MinHeight { get; private set; }
public float MaxHeight { get; private set; }
/// <summary>等高距(米):教学图常用 100 m。</summary>
public float Interval { get; init; } = 100f;
public TerrainField(int size = 192)
{
Size = size;
Heights = new float[size, size];
Build();
}
/// <summary>归一化坐标 (u,v) ∈ [0,1],u 向东、v 向南。</summary>
public float HeightAt(double u, double v)
{
var x = (int)Math.Round(u * (Size - 1));
var y = (int)Math.Round(v * (Size - 1));
x = Math.Clamp(x, 0, Size - 1);
y = Math.Clamp(y, 0, Size - 1);
return Heights[y, x];
}
/// <summary>双线性插值取值,画平滑曲线时用。</summary>
public float SampleSmooth(double u, double v)
{
var fx = Math.Clamp(u, 0, 1) * (Size - 1);
var fy = Math.Clamp(v, 0, 1) * (Size - 1);
var x0 = (int)Math.Floor(fx); var y0 = (int)Math.Floor(fy);
var x1 = Math.Min(x0 + 1, Size - 1); var y1 = Math.Min(y0 + 1, Size - 1);
var tx = fx - x0; var ty = fy - y0;
var h00 = Heights[y0, x0]; var h10 = Heights[y0, x1];
var h01 = Heights[y1, x0]; var h11 = Heights[y1, x1];
var a = h00 * (1 - tx) + h10 * tx;
var b = h01 * (1 - tx) + h11 * tx;
return (float)(a * (1 - ty) + b * ty);
}
private void Build()
{
// 各山体参数:中心(u,v)、高度、东西半径、南北半径
var peaks = new (double U, double V, double H, double RU, double RV)[]
{
(0.34, 0.34, 1180, 0.26, 0.24), // 主峰
(0.66, 0.52, 860, 0.20, 0.20), // 次峰(与主峰间成鞍部)
(0.22, 0.70, 520, 0.18, 0.16), // 西侧小山
(0.78, 0.22, 430, 0.16, 0.15), // 东北小山
};
var min = float.MaxValue; var max = float.MinValue;
for (var y = 0; y < Size; y++)
{
for (var x = 0; x < Size; x++)
{
var u = (double)x / (Size - 1);
var v = (double)y / (Size - 1);
double h = 120; // 基准面(平原 / 河谷)
foreach (var p in peaks)
{
var du = (u - p.U) / p.RU;
var dv = (v - p.V) / p.RV;
var d2 = du * du + dv * dv;
h += p.H * Math.Exp(-d2 * 1.15);
}
// 山谷:沿一条斜线切下去,形成 V 形谷地
var valley = Math.Abs((u - 0.5) * 0.8 + (v - 0.44) * 0.6);
h -= 210 * Math.Exp(-valley * valley / 0.0016);
// 陡崖:东侧一条近乎垂直的高差带(等高线会挤在一起)
if (u > 0.86 && v > 0.18 && v < 0.72)
h += 260 * SmoothStep(0.86, 0.895, u);
// 缓坡:西南角缓慢抬升
if (u < 0.3 && v > 0.6)
h += 90 * (1 - u / 0.3) * ((v - 0.6) / 0.4);
// 轻微起伏,避免地形过于几何化
h += 18 * Math.Sin(u * 9.1) * Math.Cos(v * 7.7);
var hf = (float)Math.Max(0, h);
Heights[y, x] = hf;
if (hf < min) min = hf;
if (hf > max) max = hf;
}
}
MinHeight = min;
MaxHeight = max;
}
private static double SmoothStep(double a, double b, double x)
{
var t = Math.Clamp((x - a) / (b - a), 0, 1);
return t * t * (3 - 2 * t);
}
/// <summary>
/// 教学标注区:把「典型部位」的位置固化成圆形区域,
/// 保证判读结果与地形设计一致(纯几何推断对鞍部/陡崖易误判)。
/// </summary>
public List<(double U, double V, double Radius, TerrainFeature Feature)> Tags { get; } = new()
{
(0.34, 0.34, 0.045, TerrainFeature.Peak), // 主峰
(0.66, 0.52, 0.042, TerrainFeature.Peak), // 次峰
(0.50, 0.44, 0.055, TerrainFeature.Saddle), // 两峰之间的鞍部
(0.90, 0.45, 0.035, TerrainFeature.Cliff), // 东侧陡崖
(0.22, 0.70, 0.045, TerrainFeature.Ridge), // 西南山脊
(0.50, 0.22, 0.040, TerrainFeature.Valley), // 河谷
};
/// <summary>查询标注区;未命中返回 None。</summary>
public TerrainFeature TagAt(double u, double v)
{
foreach (var (tu, tv, r, f) in Tags)
{
var du = u - tu; var dv = v - tv;
if (du * du + dv * dv <= r * r) return f;
}
return TerrainFeature.None;
}
/// <summary>等高线高度列表:从 MaxHeight 往下按等高距取整。</summary>
public List<float> ContourLevels()
{
var levels = new List<float>();
var top = (float)(Math.Floor(MaxHeight / Interval) * Interval);
var bottom = (float)(Math.Ceiling(MinHeight / Interval) * Interval);
for (var h = bottom; h <= top + 0.01f; h += Interval)
levels.Add(h);
levels.Sort();
return levels;
}
/// <summary>
/// 用 Marching Squares 提取某条等高线,返回若干条折线(归一化坐标)。
/// </summary>
public List<List<(double U, double V)>> ExtractContour(float level)
{
var result = new List<List<(double, double)>>();
var size = Size;
// 记录每条线段,再按端点连通性串成折线
var segments = new List<(double U1, double V1, double U2, double V2)>();
for (var y = 0; y < size - 1; y++)
{
for (var x = 0; x < size - 1; x++)
{
var h00 = Heights[y, x];
var h10 = Heights[y, x + 1];
var h11 = Heights[y + 1, x + 1];
var h01 = Heights[y + 1, x];
var idx = 0;
if (h00 >= level) idx |= 1;
if (h10 >= level) idx |= 2;
if (h11 >= level) idx |= 4;
if (h01 >= level) idx |= 8;
if (idx == 0 || idx == 15) continue;
double u0 = (double)x / (size - 1), u1 = (double)(x + 1) / (size - 1);
double v0 = (double)y / (size - 1), v1 = (double)(y + 1) / (size - 1);
// 四条边上的交点
(double, double) Top() => (Lerp(u0, u1, (level - h00) / (h10 - h00)), v0);
(double, double) Bottom() => (Lerp(u0, u1, (level - h01) / (h11 - h01)), v1);
(double, double) Left() => (u0, Lerp(v0, v1, (level - h00) / (h01 - h00)));
(double, double) Right() => (u1, Lerp(v0, v1, (level - h10) / (h11 - h10)));
void Add((double U, double V) a, (double U, double V) b)
=> segments.Add((a.Item1, a.Item2, b.Item1, b.Item2));
switch (idx)
{
case 1: case 14: Add(Left(), Top()); break;
case 2: case 13: Add(Top(), Right()); break;
case 3: case 12: Add(Left(), Right()); break;
case 4: case 11: Add(Right(), Bottom()); break;
case 6: case 9: Add(Top(), Bottom()); break;
case 7: case 8: Add(Left(), Bottom()); break;
case 5: Add(Left(), Top()); Add(Right(), Bottom()); break;
case 10: Add(Top(), Right()); Add(Left(), Bottom()); break;
}
}
}
return Chain(segments);
}
private static double Lerp(double a, double b, double t)
=> a + (b - a) * Math.Clamp(double.IsNaN(t) ? 0.5 : t, 0, 1);
/// <summary>把零散线段按端点邻近关系串成折线。</summary>
private static List<List<(double U, double V)>> Chain(
List<(double U1, double V1, double U2, double V2)> segments)
{
const double Eps = 0.004;
var result = new List<List<(double, double)>>();
var used = new bool[segments.Count];
for (var i = 0; i < segments.Count; i++)
{
if (used[i]) continue;
used[i] = true;
var line = new List<(double, double)>
{
(segments[i].U1, segments[i].V1),
(segments[i].U2, segments[i].V2)
};
// 向两端延伸
var grown = true;
while (grown)
{
grown = false;
var (tailU, tailV) = line[^1];
for (var j = 0; j < segments.Count; j++)
{
if (used[j]) continue;
var s = segments[j];
if (Near(tailU, tailV, s.U1, s.V1, Eps))
{
line.Add((s.U2, s.V2)); used[j] = true; grown = true; break;
}
if (Near(tailU, tailV, s.U2, s.V2, Eps))
{
line.Add((s.U1, s.V1)); used[j] = true; grown = true; break;
}
}
}
if (line.Count >= 4) result.Add(line);
}
return result;
}
private static bool Near(double u1, double v1, double u2, double v2, double eps)
=> Math.Abs(u1 - u2) < eps && Math.Abs(v1 - v2) < eps;
}
+2 -2
View File
@@ -18,7 +18,7 @@
],
"dataDir": "earth-geography.model",
"version": "1.8",
"updatedAt": "2026-11-13T15:19:06Z",
"updatedAt": "2026-11-14T01:23:14Z",
"chrome": {
"titleBar": "#0C1828",
"titleBorder": "#1B2740",
@@ -26,5 +26,5 @@
"button": "#9FB4D4",
"frame": "#0A1524"
},
"build": "912c6d5619"
"build": "143e56bed8"
}
+2 -2
View File
@@ -24,7 +24,7 @@
"preview": "preview.png",
"apiVersion": 1,
"version": "1.6",
"updatedAt": "2026-11-13T15:19:06Z",
"updatedAt": "2026-11-14T01:23:14Z",
"chrome": {
"titleBar": "#0C1828",
"titleBorder": "#1B2740",
@@ -32,5 +32,5 @@
"button": "#9FB4D4",
"frame": "#0A1524"
},
"build": "d34ade3c3f"
"build": "26a2bd8f68"
}
+2 -2
View File
@@ -24,7 +24,7 @@
"preview": "preview.png",
"apiVersion": 1,
"version": "1.6",
"updatedAt": "2026-11-13T15:19:06Z",
"updatedAt": "2026-11-14T01:23:14Z",
"chrome": {
"titleBar": "#0C1828",
"titleBorder": "#1B2740",
@@ -32,5 +32,5 @@
"button": "#9FB4D4",
"frame": "#0A1524"
},
"build": "033c8f1696"
"build": "1a81492baa"
}
+2 -2
View File
@@ -25,7 +25,7 @@
"preview": "preview.png",
"apiVersion": 1,
"version": "1.5",
"updatedAt": "2026-11-13T15:19:06Z",
"updatedAt": "2026-11-14T01:23:14Z",
"chrome": {
"titleBar": "#FFFFFF",
"titleBorder": "#E3E8F3",
@@ -33,5 +33,5 @@
"button": "#5B6A86",
"frame": "#F4F6FB"
},
"build": "85a274733d"
"build": "79711a44a8"
}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 54 KiB

After

Width:  |  Height:  |  Size: 56 KiB

+12 -6
View File
@@ -1,12 +1,12 @@
{
"schema": 1,
"generated": "2026-11-13T15:19:06Z",
"generated": "2026-11-14T01:23:14Z",
"repository": "https://gitcode.com/2509_92447106/GC",
"branch": "main",
"modelDir": "model",
"launcher": {
"version": "1.0.6",
"revision": "6db90790d3",
"revision": "98cff12092",
"packages": {
"win-x64": {
"path": "dist/GC-win-x64.zip",
@@ -31,28 +31,34 @@
}
},
"models": [
{
"id": "contour-map",
"version": "1.0",
"build": "e7f837d0ef",
"dir": "model/contour-map"
},
{
"id": "earth-geography",
"version": "1.8",
"build": "912c6d5619",
"build": "143e56bed8",
"dir": "model/earth-geography"
},
{
"id": "earth-revolution",
"version": "1.6",
"build": "d34ade3c3f",
"build": "26a2bd8f68",
"dir": "model/earth-revolution"
},
{
"id": "earth-rotation",
"version": "1.6",
"build": "033c8f1696",
"build": "1a81492baa",
"dir": "model/earth-rotation"
},
{
"id": "scale-calculator",
"version": "1.5",
"build": "85a274733d",
"build": "79711a44a8",
"dir": "model/scale-calculator"
}
]
+12 -6
View File
@@ -1,12 +1,12 @@
{
"schema": 1,
"generated": "2026-11-13T15:19:06Z",
"generated": "2026-11-14T01:23:14Z",
"repository": "https://gitcode.com/2509_92447106/GC",
"branch": "main",
"modelDir": "model",
"launcher": {
"version": "1.0.6",
"revision": "6db90790d3",
"revision": "98cff12092",
"packages": {
"win-x64": {
"path": "dist/GC-win-x64.zip",
@@ -31,28 +31,34 @@
}
},
"models": [
{
"id": "contour-map",
"version": "1.0",
"build": "e7f837d0ef",
"dir": "model/contour-map"
},
{
"id": "earth-geography",
"version": "1.8",
"build": "912c6d5619",
"build": "143e56bed8",
"dir": "model/earth-geography"
},
{
"id": "earth-revolution",
"version": "1.6",
"build": "d34ade3c3f",
"build": "26a2bd8f68",
"dir": "model/earth-revolution"
},
{
"id": "earth-rotation",
"version": "1.6",
"build": "033c8f1696",
"build": "1a81492baa",
"dir": "model/earth-rotation"
},
{
"id": "scale-calculator",
"version": "1.5",
"build": "85a274733d",
"build": "79711a44a8",
"dir": "model/scale-calculator"
}
]