Example #1
0
 public MainModel(ChannelsGraph channelsGraph)
 {
     _channelsGraph = channelsGraph;
     _channelsGraph.BFS(channel =>
     {
         _channels.Add(channel);
         _channelsById[channel.Id] = channel;
         foreach (var point in channel.Points)
         {
             _channelsByPoints[point] = channel;
         }
     });
 }
Example #2
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");
        }