From bee6f1539d633c0347f3f5f2460fe6676fb45a7c Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期一, 22 七月 2024 11:32:41 +0800
Subject: [PATCH] 1

---
 SimuTools/Tools/Handle.cs |   43 +++++++++++++++++++++++++++++--------------
 1 files changed, 29 insertions(+), 14 deletions(-)

diff --git a/SimuTools/Tools/Handle.cs b/SimuTools/Tools/Handle.cs
index 6882a03..7d65444 100644
--- a/SimuTools/Tools/Handle.cs
+++ b/SimuTools/Tools/Handle.cs
@@ -37,7 +37,7 @@
 
             CopeTerrain(terrainFile, outPath, layer);
             CopeWater(waterPath, outPath, layer);
-            //CopeFlow(flowPath, outPath, layer);
+            CopeFlow(flowPath, outPath, layer);
             CopeLayerJson(outPath, layer);
 
             if (Directory.Exists(temp)) Directory.Delete(temp, true);
@@ -184,7 +184,7 @@
         /// <summary>
         /// Tif鍊艰浆瀛樿嚦Png
         /// </summary>
-        private static void Tif2Png(Domain.Layer layer, string tif, string png, int width, int height)
+        private static void Tif2Png(Domain.Layer layer, string tif, string png, int width, int height, int heightOffset = 0)
         {
             Dataset ds = null;
             try
@@ -200,7 +200,7 @@
                 Graphics graphic = Graphics.FromImage(image);
                 graphic.Clear(Color.Transparent); // 濉厖閫忔槑鑹�
 
-                double perHeight = (layer.extension.maxHeight - layer.extension.minHeight) * 100 / 65536;
+                double perHeight = (layer.extension.maxHeight - layer.extension.minHeight + heightOffset) * 100 / 65536;
                 for (int x = 0; x < width; x++)
                 {
                     for (int y = 0; y < height; y++)
@@ -240,6 +240,14 @@
             SetWaterData(layer, files);
             if (files.Count != layer.waters.data.Count) return;
 
+            ProcessWaters(files, outPath, layer);
+        }
+
+        /// <summary>
+        /// 澶勭悊姘撮潰鏁版嵁
+        /// </summary>
+        private static void ProcessWaters(List<string> files, string outPath, Domain.Layer layer)
+        {
             /*for (int i = 0, c = files.Count; i < c; i++)
             {
                 Dataset ds = null;
@@ -293,7 +301,7 @@
                 }
 
                 string png = Path.Combine(waterPath, sizes[0] + "_" + sizes[1] + ".png");
-                Tif2Png(layer, tif, png, sizes[0], sizes[1]);
+                Tif2Png(layer, tif, png, sizes[0], sizes[1], 1);
             }
         }
 
@@ -414,17 +422,16 @@
                     for (int y = 0; y < height; y++)
                     {
                         int offset = x + y * width;
-                        if (float.IsNaN(vxBuffer[offset]) || vxBuffer[offset] < -999 ||
-                            float.IsNaN(vyBuffer[offset]) || vyBuffer[offset] < -999) continue;
+                        float fx = GetFloatValue(vxBuffer[offset]);
+                        float fy = GetFloatValue(vyBuffer[offset]);
 
-                        float vx = vxBuffer[offset], vy = vyBuffer[offset];
-                        //int val = Convert.ToInt32(vxBuffer[offset] * 100);
-                        //int r = val / 65536;
-                        //int g = (val - r * 65536) / 256;
-                        //int b = val % 256;
-                        int r = 0;
-                        int g = 0;
-                        int b = 0;
+                        double dx = fx * 0.5 + 0.5;
+                        double dy = fy * 0.5 + 0.5;
+                        double dv = Math.Sqrt(Math.Pow(fx, 2) + Math.Pow(fy, 2));
+
+                        int r = Convert.ToInt32(dv * 255);
+                        int g = Convert.ToInt32(dx * 255);
+                        int b = Convert.ToInt32(dy * 255);
 
                         Color color = Color.FromArgb(127, r, g, b);
                         image.SetPixel(x, y, color);
@@ -441,6 +448,14 @@
                 if (File.Exists(vyTif)) File.Delete(vyTif);
             }
         }
+
+        /// <summary>
+        /// 鑾峰彇Float鍊�
+        /// </summary>
+        private static float GetFloatValue(float val)
+        {
+            return (float.IsNaN(val) || val < -999) ? 0 : val;
+        }
         #endregion
 
         #region 鍏冩暟鎹�

--
Gitblit v1.9.3