Beispiel #1
0
        private static void Run(Options options)
        {
            var bitmap      = new Bitmap(options.ChannelsImagePath);
            var wasEnqueued = new HashSet <(int, int)>();
            var components  = new List <Channel>();
            var id          = 0;

            for (var x = 0; x < bitmap.Width; x++)
            {
                for (var y = 0; y < bitmap.Height; y++)
                {
                    var color = bitmap.GetPixel(x, y);
                    if (color == ORANGE && !wasEnqueued.Contains((x, y)))
                    {
                        components.Add(Parse(ref id, (x, y), bitmap, wasEnqueued));
                    }
                }
            }

            var contrastColors = new[]
            {
                Color.Red,
                Color.LightGreen,
                Color.Black,
                Color.Violet,
                Color.Blue,
                Color.Cyan,
                Color.Magenta
            };

            var debugBitmap = Drawing.DrawBitmap(bitmap.Width, bitmap.Height, g =>
            {
                for (var i = 0; i < components.Count; i++)
                {
                    DrawComponent(components[i], g, contrastColors[i]);
                }
            });

            debugBitmap.Save(options.DebugImgOutPath);

            var graph = new ChannelsGraph(components);

            ImproveConnections(graph, bitmap);

            CgInteraction.WriteChannelsGraphToCg(options.CGOutPath, graph);

            Console.WriteLine($"Found {components.Count} components");
        }
Beispiel #2
0
        private static void Run(Options options)
        {
            var graph = CgInteraction.ReadChannelsGraphFromCg(options.GraphPath);
            var flood = FloodseriesZip.Read(options.FloodPath, 20, 20);

            var hMap  = flood.Days[0].HMap;
            var vxMap = flood.Days[0].VxMap;
            var vyMap = flood.Days[0].VyMap;

            var channelById = new Dictionary <long, Channel>();
            var channels    = new List <Channel>();

            graph.BFS(channel =>
            {
                var direction      = GetChannelDirection(channel, flood.Days[0]);
                channel.Connecions = channel.Connecions.Where(child => {
                    var directionBetween = GetDirectionBetweenChannels(channel, child);
                    return(IsSodirected(direction, directionBetween));
                }).ToList();
                channelById[channel.Id] = channel;
                channels.Add(channel);
            });

            var interestingId = new List <long>()
            {
                74, 77, 87, 86, 90, 91, 109, 108, 151, 152, 103, 105, 104, 131, 130, 163, 164
            };

            var reportCsv = "id,q_entrance,q_exit,loss,is_source";

            foreach (var channel in channels)
            {
                var n = 3;

                var vxEntrance = 0d;
                var vyEntrance = 0d;
                var hEntrance  = 0d;

                for (var i = 0; i < n && i < channel.Points.Count; i++)
                {
                    var p = channel.Points[i];
                    vxEntrance += vxMap[p.X, p.Y - 1] / n;
                    vyEntrance += vyMap[p.X, p.Y - 1] / n;
                    hEntrance  += hMap[p.X, p.Y - 1] / n;
                }

                var qEntrance = Length(new Vec(vxEntrance, vyEntrance)) * 25 * hEntrance;

                var vxExit = 0d;
                var vyExit = 0d;
                var hExit  = 0d;

                for (var i = 0; i < n && i < channel.Points.Count; i++)
                {
                    var p = channel.Points[channel.Points.Count - i - 1];
                    vxExit += vxMap[p.X, p.Y - 1] / n;
                    vyExit += vyMap[p.X, p.Y - 1] / n;
                    hExit  += hMap[p.X, p.Y - 1] / n;
                }

                var qExit = Length(new Vec(vxExit, vyExit)) * 25 * hExit;

                reportCsv += $"\n{channel.Id},{qEntrance},{qExit},{qEntrance - qExit},{(channel.IsEntrance ? 1 : 0)}";
            }

            File.WriteAllText(options.ReportOutPath, reportCsv);
            CgInteraction.WriteChannelsGraphToCg(options.GraphOutPath, graph);
        }