| | |
| | | { |
| | | get |
| | | { |
| | | while (fitness == null) ; |
| | | //while (fitness == null) ; |
| | | if (fitness is double f) |
| | | //while (fitness == null) ; |
| | | //return fitness??0; |
| | |
| | | this.反选ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); |
| | | this.timer_draw = new System.Windows.Forms.Timer(this.components); |
| | | this.map = new Hydro.MapUI.DMap(); |
| | | this.CubeView = new Hydro.MapUI.DMap(); |
| | | this.statusStrip1.SuspendLayout(); |
| | | this.panel1.SuspendLayout(); |
| | | this.toolStrip1.SuspendLayout(); |
| | |
| | | this.map._newTemplate = null; |
| | | this.map.Dock = System.Windows.Forms.DockStyle.Fill; |
| | | this.map.Location = new System.Drawing.Point(0, 24); |
| | | this.map.mapOption = ((Hydro.MapView.MapDimensions)(resources.GetObject("map.mapOption"))); |
| | | this.map.mapOption = null; |
| | | this.map.Name = "map"; |
| | | this.map.Size = new System.Drawing.Size(1051, 554); |
| | | this.map.TabIndex = 8; |
| | | // |
| | | // CubeView |
| | | // |
| | | this.CubeView._newTemplate = null; |
| | | this.CubeView.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); |
| | | this.CubeView.BackColor = System.Drawing.SystemColors.GradientInactiveCaption; |
| | | this.CubeView.Location = new System.Drawing.Point(927, 26); |
| | | this.CubeView.mapOption = null; |
| | | this.CubeView.Name = "CubeView"; |
| | | this.CubeView.Size = new System.Drawing.Size(120, 120); |
| | | this.CubeView.TabIndex = 0; |
| | | // |
| | | // MapViewer |
| | | // |
| | | this.Controls.Add(this.CubeView); |
| | | this.Controls.Add(this.map); |
| | | this.Controls.Add(this.panel1); |
| | | this.Controls.Add(this.statusStrip1); |
| | |
| | | private DMap map; |
| | | private ToolStripMenuItem 计算局部损失ToolStripMenuItem; |
| | | private ToolStripButton btn_水量初分配; |
| | | private DMap CubeView; |
| | | } |
| | | } |
| | |
| | | using Hydro.MapView; |
| | | using Hydro.MapView.Base; |
| | | using Hydro.MapView.Common; |
| | | using System; |
| | | using System.Collections.Generic; |
| | |
| | | if (template == null) return; |
| | | var _Nodes = template.network.Nodes.ViewNodes; |
| | | var _Links = template.network.Links.ViewLinks; |
| | | |
| | | var _Areas = template.network.Areas; |
| | | var Cpoints = getCurclePoints(64).ToList(); |
| | | |
| | | var r = 1.73f / zoom; |
| | |
| | | Pen penClosed = new Pen(Color.OrangeRed, 2 * r); |
| | | Pen penHovered = new Pen(Color.DeepSkyBlue, 5 * r); |
| | | |
| | | |
| | | //绘制面 |
| | | using (Pen pen0 = new Pen(Color.FromArgb(0, 0, 255), 2 * r)) |
| | | { |
| | | foreach (var area in _Areas) |
| | | { |
| | | |
| | | if (!area.Visible) continue; |
| | | if (!IsFaceVisibleToCamera(area, GetCameraPosition())) continue; |
| | | if (area.Elev < minElve || area.Elev >= maxElve) continue; |
| | | |
| | | var p = new List<PointF>(); |
| | | foreach (var node in area.InnerNodes) |
| | | { |
| | | p.Add(WorldPointToMapPoint(node, template.OffSet)); |
| | | } |
| | | if (p.Count < 3) continue; |
| | | pen0.Color = penClosed.Color = area.color; |
| | | Pen pen = pen0; |
| | | if (area.Hovered) pen = penHovered; |
| | | bufferG.FillPolygon(pen.Brush, p.ToArray()); |
| | | bufferG.DrawPolygon(pen, p.ToArray()); |
| | | //显示area的名称 |
| | | var c = new PointF(p.Average(p0 => p0.X), p.Average(p0 => p0.Y)); |
| | | var brush=new SolidBrush(Color.White); |
| | | |
| | | |
| | | |
| | | |
| | | var gs = bufferG.Save(); |
| | | // 应用矩阵变换以抵消之前的翻转效果 |
| | | bufferG.ScaleTransform(1 / Zoom.X, 1 / Zoom.Y); |
| | | |
| | | Font font = new Font(FontFamily.GenericSansSerif, 10*10*zoom); |
| | | |
| | | SizeF textSize = bufferG.MeasureString(area.Name, font); |
| | | var center = new PointF(c.X * Zoom.X, c.Y * Zoom.Y); |
| | | float textLeft = center.X - textSize.Width / 2; |
| | | float textTop = center.Y - textSize.Height / 2; |
| | | PointF pd = new PointF(textLeft, textTop); |
| | | |
| | | bufferG.DrawString(area.Name, font, brush, pd); |
| | | // 恢复之前保存的绘图状态 |
| | | bufferG.Restore(gs); |
| | | } |
| | | } |
| | | |
| | | |
| | | // 绘制线 |
| | |
| | | |
| | | |
| | | #endregion |
| | | #region 计算三维相机 |
| | | public PointF3D GetCameraPosition( float distance=1) |
| | | { |
| | | // 将角度转换为弧度 |
| | | float rotationRadians = (float)Rotation * (float)Math.PI / 180; |
| | | float rotationFRadians = (float)RotationF * (float)Math.PI / 180; |
| | | |
| | | // 计算相机的球坐标系位置 |
| | | float x = distance * (float)Math.Sin(rotationFRadians) * (float)Math.Cos(rotationRadians); |
| | | float y = distance * (float)Math.Sin(rotationFRadians) * (float)Math.Sin(rotationRadians); |
| | | float z = distance * (float)Math.Cos(rotationFRadians); |
| | | |
| | | return new PointF3D(x, y, z); |
| | | } |
| | | public bool IsFaceVisibleToCamera(AreaViewModel area, PointF3D cameraPosition) |
| | | { |
| | | |
| | | //正面是2,右面是1,左面是3,背面是4 |
| | | //Rotation为0时,只显示正面,Rotation为90时,只显示右面,Rotation为180时,只显示背面,Rotation为270时,只显示左面 |
| | | int delta = 5; |
| | | bool flag = false; |
| | | switch (area.Name) |
| | | { |
| | | case "左": |
| | | //Rotation为0~180时显示 |
| | | if (RotationF<=90-delta && Rotation >= 0 + delta && Rotation <= 180 - delta) |
| | | flag = true; |
| | | break; |
| | | case "前": |
| | | //Rotation为0~180时显示 |
| | | if (RotationF <= 90 - delta && Rotation >= -90 + delta && Rotation <= 90 - delta) |
| | | flag = true; |
| | | break; |
| | | case "右": |
| | | //Rotation为0~180时显示 |
| | | if (RotationF <= 90 - delta && Rotation >= -180 + delta && Rotation <= 0 - delta) |
| | | flag = true; |
| | | break; |
| | | case "后": |
| | | //Rotation为0~180时显示 |
| | | if (RotationF <= 90 - delta && ((Rotation >= 90 + delta && Rotation<=180)||( Rotation>=-180 && Rotation <= -90 - delta))) |
| | | flag = true; |
| | | break; |
| | | case "上": |
| | | if (RotationF >= 0 + delta) |
| | | flag = true; |
| | | break; |
| | | case "下": |
| | | if (RotationF <= 0 - delta) |
| | | flag = true; |
| | | break; |
| | | } |
| | | return flag; |
| | | |
| | | var faceVertices = area.InnerNodes; |
| | | if (faceVertices.Count < 3) return false; |
| | | PointF3D faceVertexA = faceVertices[0].Position3D; |
| | | PointF3D faceVertexB = faceVertices[1].Position3D; |
| | | PointF3D faceVertexC = faceVertices[2].Position3D; |
| | | |
| | | // 计算法向量 |
| | | PointF3D AB = faceVertexB - faceVertexA; |
| | | PointF3D AC = faceVertexC - faceVertexA; |
| | | PointF3D normal = AB ^ AC; |
| | | |
| | | // 计算从相机位置到面的向量 |
| | | PointF3D PD = faceVertexA - cameraPosition; |
| | | |
| | | // 计算点积 |
| | | float dotProduct = normal * PD; |
| | | |
| | | // 判断面是否朝向相机 |
| | | bool isFacingCamera = dotProduct > 0; |
| | | return isFacingCamera; |
| | | } |
| | | |
| | | |
| | | #endregion |
| | | |
| | | #region 判断可见性 |
| | | private float Get_dist(PointF A, PointF B) |
| | |
| | | set |
| | | { |
| | | toolStripStatusLabel_rotation.Text = $"Rotation:({Rotation.ToString("0")},{RotationF.ToString("0")})"; |
| | | //将旋转角度转换为-180~180 |
| | | value = value % 360; |
| | | if (value > 180) |
| | | value -= 360; |
| | | else if (value < -180) |
| | | value += 360; |
| | | mapOption.rotation = value; |
| | | } |
| | | } |
| | |
| | | //using DevExpress.Utils.Extensions; |
| | | //using dict_py_Inner; |
| | | using Hydro.MapView; |
| | | using Hydro.MapView.Base; |
| | | using Hydro.MapView.Common; |
| | | using Newtonsoft.Json; |
| | | //using ReflectionManager_NameSpace; |
| | |
| | | |
| | | map.Init(TC,new DrawDelegate[] { Draw, Draw, DrawBackGroud, DrawH },new MouseDelegate[] { mapMouseDown, mapMouseMove, mapMouseUp, mapMouseWheel }); |
| | | |
| | | |
| | | |
| | | TContainer TCCube = new TContainer(); |
| | | TCCube.template = new Template(); |
| | | TCCube.template.network = new MapViewNetWork(); |
| | | TCCube.template.network.Areas = new List<AreaViewModel>(); |
| | | Cube cb=new Cube(); |
| | | foreach (var item in cb.FacesVertices) |
| | | { |
| | | AreaViewModel area = new AreaViewModel(); |
| | | area.ID = item.Key.ToString(); |
| | | area.InnerNodes = new List<NodeViewModel>(); |
| | | //area.Name= item.Key.ToString(); |
| | | |
| | | //6个面设置不一样的颜色 |
| | | switch (item.Key) |
| | | { |
| | | case 1: |
| | | area.color = Color.Red; |
| | | area.Name = "右"; |
| | | break; |
| | | case 2: |
| | | area.color = Color.SkyBlue; |
| | | area.Name = "左"; |
| | | break; |
| | | case 3: |
| | | area.color = Color.Green; |
| | | area.Name = "后"; |
| | | break; |
| | | case 4: |
| | | area.color = Color.DarkBlue; |
| | | area.Name = "前"; |
| | | break; |
| | | case 5: |
| | | area.color = Color.Purple; |
| | | area.Name = "上"; |
| | | break; |
| | | case 6: |
| | | area.color = Color.Orange; |
| | | area.Name = "下"; |
| | | break; |
| | | default: |
| | | area.color = Color.White; |
| | | break; |
| | | } |
| | | |
| | | foreach (var p in item.Value) |
| | | { |
| | | NodeViewModel node = new NodeViewModel(); |
| | | node.X = p.X; |
| | | node.Y = p.Y; |
| | | node.Elev = p.Z; |
| | | area.InnerNodes.Add(node); |
| | | } |
| | | TCCube.template.network.Areas.Add(area); |
| | | } |
| | | CubeView.Init(TCCube, new DrawDelegate[] { Draw, Draw, DrawBackGroud, DrawH }, new MouseDelegate[] { mapMouseDown, mapMouseMove, mapMouseUp, mapMouseWheel }); |
| | | |
| | | } |
| | | |
| | |
| | | if (_timerDraw && map.Status==DrawingStatus.Ready) |
| | | { |
| | | this.map.Invalidate(); |
| | | this.CubeView.Invalidate(); |
| | | _timerDraw = false; |
| | | } |
| | | |
| | |
| | | private NodeViewModelList _nodes = new NodeViewModelList(); |
| | | public NodeViewModelList Nodes { get { return _nodes; }set { base.Nodes = _nodes = value; } } |
| | | |
| | | private List<AreaViewModel> _areas = new List<AreaViewModel>(); |
| | | public List<AreaViewModel> Areas { get { return _areas; } set { _areas = value; } } |
| | | |
| | | public NodeViewModel StartPoint { get; set; } |
| | | |
| | | public NodeViewModel EndPoint { get; set; } |
| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Drawing; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | |
| | | [Serializable] |
| | | public class AreaViewModel : NodeViewModel, IBaseViewModel |
| | | { |
| | | public List<NodeViewModel> InnerNodes=new List<NodeViewModel>(); |
| | | |
| | | public Color color { get; set; } |
| | | } |
| | | } |
| | |
| | | Y = y; |
| | | Z = z; |
| | | } |
| | | //定义减法运算符 |
| | | public static PointF3D operator -(PointF3D p1, PointF3D p2) |
| | | { |
| | | return new PointF3D(p1.X - p2.X, p1.Y - p2.Y, p1.Z - p2.Z); |
| | | } |
| | | //定义加法运算符 |
| | | public static PointF3D operator +(PointF3D p1, PointF3D p2) |
| | | { |
| | | return new PointF3D(p1.X + p2.X, p1.Y + p2.Y, p1.Z + p2.Z); |
| | | } |
| | | //定义乘法运算符 |
| | | public static PointF3D operator *(PointF3D p1, float f) |
| | | { |
| | | return new PointF3D(p1.X * f, p1.Y * f, p1.Z * f); |
| | | } |
| | | //定义点乘运算符 |
| | | public static float operator *(PointF3D p1, PointF3D p2) |
| | | { |
| | | return p1.X * p2.X + p1.Y * p2.Y + p1.Z * p2.Z; |
| | | } |
| | | //定义叉乘运算符 |
| | | public static PointF3D operator ^(PointF3D p1, PointF3D p2) |
| | | { |
| | | return new PointF3D(p1.Y * p2.Z - p1.Z * p2.Y, p1.Z * p2.X - p1.X * p2.Z, p1.X * p2.Y - p1.Y * p2.X); |
| | | } |
| | | } |
| | | |
| | | public class Cube |
| | | { |
| | | public Dictionary<int, List<PointF3D>> FacesVertices { get; private set; } |
| | | public List<PointF3D> Vertices { get; private set; } |
| | | |
| | | public Cube() |
| | | { |
| | | InitializeVertices(); |
| | | InitializeFaces(); |
| | | } |
| | | |
| | | private void InitializeVertices() |
| | | { |
| | | Vertices = new List<PointF3D> |
| | | { |
| | | new PointF3D(200, 200, 200), // Vertex 0 |
| | | new PointF3D(200, 200, -200), // Vertex 1 |
| | | new PointF3D(200, -200, 200), // Vertex 2 |
| | | new PointF3D(200, -200, -200), // Vertex 3 |
| | | new PointF3D(-200, 200, 200), // Vertex 4 |
| | | new PointF3D(-200, 200, -200), // Vertex 5 |
| | | new PointF3D(-200, -200, 200), // Vertex 6 |
| | | new PointF3D(-200, -200, -200) // Vertex 7 |
| | | }; |
| | | } |
| | | |
| | | private void InitializeFaces() |
| | | { |
| | | FacesVertices = new Dictionary<int, List<PointF3D>> |
| | | { |
| | | { 1, new List<PointF3D> { Vertices[0], Vertices[1], Vertices[3], Vertices[2] } }, // Face 1 |
| | | { 2, new List<PointF3D> { Vertices[4], Vertices[5], Vertices[7], Vertices[6] } }, // Face 2 |
| | | { 3, new List<PointF3D> { Vertices[0], Vertices[1], Vertices[5], Vertices[4] } }, // Face 3 |
| | | { 4, new List<PointF3D> { Vertices[2], Vertices[3], Vertices[7], Vertices[6] } }, // Face 4 |
| | | { 5, new List<PointF3D> { Vertices[0], Vertices[2], Vertices[6], Vertices[4] } }, // Face 5 |
| | | { 6, new List<PointF3D> { Vertices[1], Vertices[3], Vertices[7], Vertices[5] } } // Face 6 |
| | | }; |
| | | } |
| | | } |
| | | } |
| | |
| | | [Category("默认视角")] |
| | | [DisplayName("视角")] |
| | | [Browsable(false)] |
| | | public MapDimensions view { get; set; } = null; |
| | | public MapDimensions view { get; set; } = new MapDimensions(); |
| | | |
| | | |
| | | [Category("默认视角")] |