Exemple #1
0
        ////////////////////////////////////////////////////////////

        // Tracing ImageData, then returning PaddedPaletteImage with tracedata in layers
        private static TracedImage PaddedPaletteImageToTraceData(Bitmap image, Tracing tracing, SvgRendering rendering)
        {
            // Selective Gaussian blur preprocessing
            //if (options.Blur.BlurRadius > 0)
            //{
            //    // TODO: This seems to not work currently.
            //    imgd = Blur(imgd, options.Blur.BlurRadius, options.Blur.BlurDelta);
            //}

            // 1. Color quantization
            var colors      = image.ChangeFormat(PixelFormat.Format32bppArgb).ToColorReferences();
            var colorGroups = ColorGrouping.Convert(colors, image.Width, image.Height, Palette);
            // 2. Layer separation and edge detection
            var rawLayers = Layering.Convert(colorGroups, image.Width, image.Height, Palette);
            // 3. Batch pathscan
            var pathPointLayers = rawLayers.ToDictionary(cl => cl.Key, cl => new Layer <PathPointPath>
            {
                Paths = Pathing.Scan(cl.Value, tracing.PathOmit).ToList()
            });
            // 4. Batch interpollation
            var interpolationPointLayers = pathPointLayers.ToDictionary(cp => cp.Key, cp => Interpolation.Convert(cp.Value));
            // 5. Batch tracing
            var sequenceLayers = interpolationPointLayers.ToDictionary(ci => ci.Key, ci => new Layer <SequencePath>
            {
                Paths = ci.Value.Paths.Select(path => new SequencePath
                {
                    Path      = path,
                    Sequences = Sequencing.Create(path.Points.Select(p => p.Direction).ToList()).ToList()
                }).ToList()
            });

            var segmentLayers = sequenceLayers.ToDictionary(ci => ci.Key, ci => new Layer <SegmentPath>
            {
                Paths = ci.Value.Paths.Select(path => new SegmentPath
                {
                    Segments = path.Sequences.Select(s => Segmentation.Fit(path.Path.Points, s, tracing, rendering)).SelectMany(s => s).ToList()
                }).ToList()
            });

            return(new TracedImage(segmentLayers, image.Width, image.Height));
        }
        private void Part7Button_Click(object sender, RoutedEventArgs e)
        {
            if (!_part7Complete)
            {
                _segmentLayers = _sequenceLayers.ToDictionary(ci => ci.Key, ci => new Layer <SegmentPath>
                {
                    Paths = ci.Value.Paths.Select(path => new SegmentPath
                    {
                        Segments = path.Sequences.Select(s => Segmentation.Fit(path.Path.Points, s, _options.Tracing, _options.SvgRendering)).SelectMany(s => s).ToList()
                    }).ToList()
                });
                var segments = _segmentLayers.SelectMany(cl => cl.Value.Paths.SelectMany(p => p.Segments.Select(s => new { Color = cl.Key, Type = s is LineSegment ? "Line" : (s is SplineSegment ? "Spline" : "Unknown") }))).ToList();
                Part7ComboBox.ItemsSource = segments.Select((cs, i) => new ColorSelectionItem(cs.Color, i)
                {
                    Type = $"{i} {cs.Type}"
                }).ToList();
                SegmentCount.Content = segments.Count;
                _part7Complete       = true;
            }

            if (true)
            {
                LineGrid.Children.Clear();
                double gridWidth  = _loadedImage.Width;
                double gridHeight = _loadedImage.Height;
                var    offset     = CalculateScaledOffsets(ref gridWidth, ref gridHeight);

                var indices      = _segmentLayers.SelectMany(cl => cl.Value.Paths.SelectMany(p => p.Segments)).ToList();
                var segmentLines = indices.SelectMany((s, i) => CreateSegmentLines(i, offset, false));

                LineGrid.Width  = gridWidth;
                LineGrid.Height = gridHeight;
                LineGrid.Children.AddRange(segmentLines);
                CanvasScroller.Visibility = Visibility.Hidden;
                ImageDisplay.Source       = BitmapToImageSource(CreateTransparentBitmap(_loadedImage.Width + 1, _loadedImage.Height + 1));
            }

            //Part7Button.IsEnabled = false;
        }