コード例 #1
0
        private static Color DefaultColorMapper(DiseaseNode node)
        {
            if (double.IsNaN(node.Population))
            {
                return(Color.Black);
            }

            if (node.Population < 0.001)
            {
                return(Color.Transparent);
            }

            double severity = Math.Min(Math.Abs(512 * (node.ContagiousAsymptomatic + node.ContagiousSymptomatic +
                                                       node.Killed) / node.Population), 255);

            if (severity < COLOR_THRESHOLD)
            {
                return(Color.Transparent);
            }


            double d = Math.Max(Math.Min(6.0, Math.Log(severity) + 3.0), 0); // zero to six

            if (d < 3.0)
            {
                return(Utility.Gradient(Color.Yellow, Color.Red, d / 3));         // Zero to 3 is yellow to red.
            }
            return(Utility.Gradient(Color.Red, Color.Black, Math.Min(((d - 3) / 6.0), 1.0)));
            //return Color.FromArgb(alpha, red, green, 0); // <--- TODO: Population can go negative. Fix this.
        }
コード例 #2
0
        private static Color XDefaultColorMapper(DiseaseNode node)
        {
            if (double.IsNaN(node.Population))
            {
                return(Color.Black);
            }

            if (node.Population < 0.001)
            {
                return(Color.Transparent);
            }

            double impact = Math.Abs(node.ContagiousAsymptomatic) + Math.Abs(node.ContagiousSymptomatic) + Math.Abs(node.NonContagiousInfected + node.Killed);

            if (impact == 0)
            {
                return(Color.Transparent);
            }

            double severity = Math.Sqrt(impact) / Math.Sqrt(node.Population);

            double d = Math.Max(Math.Min(6.0, Math.Log(severity) + 3), 0); // zero to six

            if (d < 3.0)
            {
                return(Utility.Gradient(Color.Yellow, Color.Red, d / 3));         // Zero to 3 is yellow to red.
            }
            return(Utility.Gradient(Color.Red, Color.Black, Math.Min(((d - 3) / 3.0), 1.0)));
            //return Color.FromArgb(alpha, red, green, 0); // <--- TODO: Population can go negative. Fix this.
        }
コード例 #3
0
        private void SelectCountry(object sender, MouseEventArgs args)
        {
            int x, y;

            GraphicalUtilities.GraphicsCoordsToMapCoords(m_mapControl1.Size, m_mapControl1.MyWorldModel.Size, args.X,
                                                         args.Y, out x,
                                                         out y);
            DiseaseNode    n  = m_mapControl1.MyWorldModel.NodeAt(x, y);
            SimCountryData cd = m_mapControl1.MyWorldModel.CountryForCode(n.MapCell.CountryCode);

            if (cd != null)
            {
                CountrySelected?.Invoke(cd);
            }
        }
コード例 #4
0
        private void ReportVoxelData(object sender, MouseEventArgs args)
        {
            double lat, lon;
            int    x, y;

            GraphicalUtilities.GraphicsCoordsToMapCoords(m_mapControl1.Size, m_mapControl1.MyWorldModel.Size, args.X,
                                                         args.Y, out x,
                                                         out y);
            m_mapControl1.MyWorldModel.MapData.DataXYToLatLon(x, y, out lat, out lon);

            DiseaseNode n = m_mapControl1.MyWorldModel.NodeAt(x, y);

            string where = n.MapCell.CountryCode;
            string text = $"data[{x},{y}] ({where}, Lat {lat:f2}/Lon {lon:f2} {n:d4}";

            ReportStatus(text);
        }
コード例 #5
0
        private void _Render(DiseaseNode[,] nodes, double[] routeContamination, List <RouteData> busyRoutes, List <OutbreakResponseTeam> orts)
        {
            int    dataWidth  = nodes.GetLength(0);
            int    dataHeight = nodes.GetLength(1);
            Bitmap image      = (Bitmap)m_foundation.Clone();

            // Add epidemic layer.
            for (int x = 0; x < dataWidth; x++)
            {
                for (int y = 0; y < dataHeight; y++)
                {
                    DiseaseNode theNode = nodes[x, y];
                    Color       c       = m_colorMapper(theNode);
                    if (c.A > 0)
                    {
                        image.SetPixel(x, y, c);
                    }
                }
            }


            // Add routes.
            int nActiveRoutes = 0;
            //Link Colors:
            Color linkRed    = Color.FromArgb(3, 255, 0, 0);
            Color linkOrange = Color.FromArgb(3, 255, 165, 0);
            Color linkGreen  = Color.FromArgb(3, 0, 255, 0);

            using (Graphics graphics = Graphics.FromImage(image))
            {
                IEnumerator <RouteData> rd = busyRoutes.GetEnumerator();
                for (int i = 0; i < routeContamination.Length; i++)
                {
                    Color  linkColor;
                    double trouble = routeContamination[i];
                    if (!double.IsNegativeInfinity(trouble))
                    {
                        if (trouble < .1)
                        {
                            linkColor = linkGreen;
                        }
                        else if (trouble < 2)
                        {
                            linkColor = linkOrange;
                        }
                        else
                        {
                            linkColor = linkRed;
                        }
                        rd.MoveNext();
                        RouteData route = rd.Current;
                        if (route != null)
                        {
                            int xf = route.From.MapX;
                            int yf = route.From.MapY;
                            int xt = route.To.MapX;
                            int yt = route.To.MapY;
                            graphics.DrawLine(new Pen(linkColor, 1.0f), xf, yf, xt, yt);
                            nActiveRoutes++;
                        }
                        else
                        {
                            throw new NullReferenceException();
                        }
                    }
                }

                // Now draw the Outbreak Response Teams.
                foreach (OutbreakResponseTeam ort in orts)
                {
                    graphics.DrawEllipse(new Pen(Color.Black, 1.0f), HWrap(ort.Location.X - 1), VWrap(ort.Location.Y - 1), 2, 2);
                    graphics.DrawEllipse(new Pen(ort.Color, 3.0f), HWrap(ort.Location.X - 2), VWrap(ort.Location.Y - 2), 4, 4);
                    graphics.DrawEllipse(new Pen(Color.White, 1.0f), HWrap(ort.Location.X - 3), VWrap(ort.Location.Y - 3), 6, 6);
                }
            }
            //Console.WriteLine($"There are {nActiveRoutes} active routes.");
            Image = image;
        }
コード例 #6
0
        private void InitialUI_Load(object sender, EventArgs e)
        {
            m_worldModel = new WorldModel(m_data, SimCountryData.LoadFrom(@"../../../Data/CountryData.dat"));
            m_mapControl.AssignWorldModel(m_worldModel);

            PlotForm dc1 = new PlotForm("Mortality");

            dc1.Bind(m_worldModel,
                     new[] {
                GetTotal(n => n.Killed),
                GetTotal(n => n.Dead)
            },
                     new[] {
                "Killed",
                "Dead"
            });

            PlotForm dc2 = new PlotForm("Disease Stages");

            dc2.Bind(m_worldModel,
                     new[] {
                GetTotal(n => n.ContagiousAsymptomatic),
                GetTotal(n => n.ContagiousSymptomatic),
                GetTotal(n => n.NonContagiousInfected),
                GetTotal(n => n.Immune),
            },
                     new[]
            {
                "ContagiousAsymptomatic",
                "ContagiousSymptomatic",
                "NonContagiousInfected",
                "Immune"
            });

            m_mapControl.Show();
            dc1.Show();
            dc2.Show();



            /*PlotForm m_plotWindow1 = new PlotForm("Killed");
             * m_plotWindow1.Bind(m_worldModel, GetTotal(n => n.Killed));
             * m_plotWindow1.Show();
             *
             * PlotForm m_plotWindow2 = new PlotForm("Immune");
             * m_plotWindow2.Bind(m_worldModel, GetTotal(n => n.Immune));
             * m_plotWindow2.Show();
             *
             * PlotForm m_plotWindow3 = new PlotForm("Total Population");
             * m_plotWindow3.Bind(m_worldModel, GetTotal(n => n.Population));
             * m_plotWindow3.Show();
             *
             * PlotForm m_plotWindow4 = new PlotForm("Immunization Effort");
             * m_plotWindow4.Bind(m_worldModel, GetTotal(n => n.Flows[2](n)));
             * m_plotWindow4.Show();*/


            m_mapControl.MouseMove += (o, args) =>
            {
                double lat, lon;
                int    x, y;
                GraphicalUtilities.GraphicsCoordsToMapCoords(panel1.Size, m_worldModel.Size, args.X, args.Y, out x,
                                                             out y);
                m_data.DataXYToLatLon(x, y, out lat, out lon);
                string where = ReverseGeocodeService.CountryNameForLatAndLong(lat, lon + 2) ?? "Unknown";
                DiseaseNode n = m_worldModel.NodeAt(x, y);
                toolStripStatusLabel1.Text = $"data[{x},{y}] is {where}, Lat {lat:f2}/Lon {lon:f2} {n:d4}";
                Console.WriteLine(toolStripStatusLabel1.Text);
            };

            toolStripStatusLabel1.TextChanged += (o, args) => Console.WriteLine(((ToolStripStatusLabel)o).Text);
        }