Example #1
0
        private async Task <NeuronLevel> Define(Diagrams.Polygon front)
        {
            var frontPoints = front.ToPoints();

            // Initial hull
            var dispatcher = Dispatcher.CurrentDispatcher;
            var logger     = new DispatcherLogger(dispatcher, s => this.viewModel.Info = s);

            var hullSegments = await Bus.Query(new MakeConvexHull(frontPoints, dispatcher, logger));

            var hull = new Diagrams.Polygon(hullSegments);

            var level = new NeuronLevel {
                Include = hull
            };

            // Make sub hulls: hull - front
            var diffs = Diagrams.PolygonOperations.Difference(hull, front);

            foreach (var diff in diffs)
            {
                var l = await this.Define(diff);

                level.Excludes.Add(l);
            }

            return(level);
        }
Example #2
0
        private async void Triangulate_Click(object sender, RoutedEventArgs e)
        {
            var dispatcher = Dispatcher.CurrentDispatcher;
            var logger     = new DispatcherLogger(dispatcher, s => this.viewModel.Info = s);
            var features   =
                this.viewModel.DrawnCategories
                .Select(c => new KeyValuePair <Brush, List <Diagrams.Point> >(c.Brush, c.Features.Select(f => new Diagrams.Point(f.X, f.Y)).ToList()))
                .ToDictionary(k => k.Key, v => v.Value);

            var host = await Bus.Query(new CreateShapesContainer(this.Surface.ActualWidth, this.Surface.ActualHeight));

            if (this.SingleColor.IsChecked ?? false)
            {
                logger.Info("Making points");

                var points = this.viewModel.DrawnFeatures.Select(p => new Diagrams.Point(p.X, p.Y)).ToList();

                logger.Info("Sending points");

                await Bus.Send(new MakeTriangulation(points, host as IShapeComposite, dispatcher, logger));
            }
            else
            {
                logger.Info("Sending points");

                await Bus.Send(new MakeMultiColorTriangulation(features, host as IShapeComposite, dispatcher, logger));
            }

            await Bus.Send(new DrawPoints(features, host as IShapeComposite));

            this.Surface.Children.Clear();
            this.Surface.Children.Add(host);
        }
Example #3
0
        private async void ShowNNModelDiagram_Click(object sender, RoutedEventArgs e)
        {
            var dispatcher = Dispatcher.CurrentDispatcher;
            var logger     = new DispatcherLogger(dispatcher, s => this.viewModel.Info = s);

            var points     = this.viewModel.DrawnFeatures.Select(p => new Diagrams.Point(p.X, p.Y)).ToList();
            var categories =
                this.viewModel.DrawnCategories
                .Select(c => c.Features.Select(f => new Diagrams.Point(f.X, f.Y)).ToList()).ToList();
            var features =
                this.viewModel.DrawnCategories
                .Select(c => new KeyValuePair <Brush, List <Diagrams.Point> >(c.Brush, c.Features.Select(f => new Diagrams.Point(f.X, f.Y)).ToList()))
                .ToDictionary(k => k.Key, v => v.Value);

            var edges = await Bus.Query(new CalculateVoronoiEdges(points, this.Surface.ActualWidth, this.Surface.ActualHeight));

            var frontEdges = await Bus.Query(new FilterEdgesTouchingSameCategory(edges, categories));

            var host = await Bus.Query(new CreateShapesContainer(this.Surface.ActualWidth, this.Surface.ActualHeight));

            await Bus.Send(new DrawPoints(features, host as IShapeComposite));

            var frontEdgesLines = new List <Diagrams.LineSegment>();

            foreach (var edge in frontEdges)
            {
                frontEdgesLines.Add(new Diagrams.LineSegment(edge.Start, edge.End));
            }

            //// Draw front edges
            //await Bus.Send(new DrawPolygon(Brushes.Orange, new Diagrams.Polygon(frontEdgesLines), host as IShapeComposite));

            var lvl = await this.Define(new Polygon(frontEdgesLines));

            await this.DrawLevel(lvl, host as IShapeComposite);

            this.Surface.Children.Clear();
            this.Surface.Children.Add(host);

            var w = new NeuralNetworkTreeWindow(lvl)
            {
                ShowInTaskbar = false,
                Owner         = Application.Current.MainWindow,
            };

            w.Show();
        }
Example #4
0
        private async void ShowConvexHull_Click(object sender, RoutedEventArgs e)
        {
            var dispatcher = Dispatcher.CurrentDispatcher;
            var logger     = new DispatcherLogger(dispatcher, s => this.viewModel.Info = s);
            var points     = this.viewModel.DrawnFeatures.Select(p => new Diagrams.Point(p.X, p.Y)).ToList();

            var features =
                this.viewModel.DrawnCategories
                .Select(c => new KeyValuePair <Brush, List <Diagrams.Point> >(c.Brush, c.Features.Select(f => new Diagrams.Point(f.X, f.Y)).ToList()))
                .ToDictionary(k => k.Key, v => v.Value);

            var host = await Bus.Query(new CreateShapesContainer(this.Surface.ActualWidth, this.Surface.ActualHeight));

            var lineSegments = await Bus.Query(new MakeConvexHull(points, dispatcher, logger));

            await Bus.Send(new DrawLineSegments(new Dictionary <Brush, List <Diagrams.LineSegment> > {
                { Brushes.Blue, lineSegments }
            }, host as IShapeComposite));

            await Bus.Send(new DrawPoints(features, host as IShapeComposite));

            this.Surface.Children.Clear();
            this.Surface.Children.Add(host);
        }
Example #5
0
        private async void MakeRandom_Click(object sender, RoutedEventArgs e)
        {
            var category = this.CategoriesView.SelectedItem as FeatureCategoryViewModel;

            if (category == null)
            {
                return;
            }

            var txt = this.RandomPointCount.Text;

            if (!int.TryParse(txt, out int count))
            {
                return;
            }

            var dispatcher   = Dispatcher.CurrentDispatcher;
            var logger       = new DispatcherLogger(dispatcher, s => this.viewModel.Info = s);
            var placedPoints = this.viewModel.DrawnFeatures.Select(f => new Diagrams.Point(f.X, f.Y)).ToList();

            var points = await Bus.Query(new GenerateRandomPoints(count, this.Surface.ActualWidth, this.Surface.ActualHeight, placedPoints, dispatcher, logger));

            points.ForEach(p => this.viewModel.AddPoint(category.Color, p.X, p.Y));

            var features =
                this.viewModel.DrawnCategories
                .Select(c => new KeyValuePair <Brush, List <Diagrams.Point> >(c.Brush, c.Features.Select(f => new Diagrams.Point(f.X, f.Y)).ToList()))
                .ToDictionary(k => k.Key, v => v.Value);

            var host = await Bus.Query(new CreateShapesContainer(this.Surface.ActualWidth, this.Surface.ActualHeight));

            await Bus.Send(new DrawPoints(features, host as IShapeComposite));

            this.Surface.Children.Clear();
            this.Surface.Children.Add(host);
        }