コード例 #1
0
        public object Clone()
        {
            IterationInformation res = (IterationInformation)this.MemberwiseClone();

            this.weights.CopyTo(res.weights, 0);
            return(res);
        }
コード例 #2
0
 public CircleParameters(int imageWidth, int imageHeight, Color background, int circles,
                         string colors, IColorComparison colorMode, Dithering ditherMode, AverageMode averageMode,
                         IterationInformation iterationInformation, bool allowStretch = false) :
     base(imageWidth, imageHeight, background, colors, colorMode, ditherMode, averageMode, iterationInformation, allowStretch)
 {
     init(circles);
 }
コード例 #3
0
 public CircleParameters(string filepath, string imagepath, int circles,
                         string colors, IColorComparison colorMode, Dithering ditherMode, AverageMode averageMode,
                         IterationInformation iterationInformation, bool allowStretch = false) :
     base(filepath, imagepath, colors, colorMode, ditherMode, averageMode, iterationInformation, allowStretch)
 {
     init(circles);
 }
コード例 #4
0
 protected GeneralShapesProvider(int imageWidth, int imageHeight, Color background, string colors, IColorComparison comp, Dithering ditherMode,
                                 AverageMode averageMode, bool allowStretch, IterationInformation iterationInformation)
     : base(imageWidth, imageHeight, background, comp, ditherMode, colors, iterationInformation)
 {
     this.allowStretch = allowStretch;
     average           = averageMode;
 }
コード例 #5
0
 /// <summary>
 /// Erzeugt einen RectangleDominoProvider (Basiskonstruktor) mit den angegebenen Eigenschaften.
 /// </summary>
 /// <param name="bitmap"></param>
 /// <param name="colors"></param>
 /// <param name="comp"></param>
 /// <param name="useOnlyMyColors"></param>
 /// <param name="filter"></param>
 /// <param name="averageMode"></param>
 /// <param name="allowStretch"></param>
 protected GeneralShapesProvider(string filepath, string imagePath, string colors, IColorComparison comp, Dithering ditherMode,
                                 AverageMode averageMode, bool allowStretch, IterationInformation iterationInformation)
     : base(filepath, imagePath, comp, ditherMode, colors, iterationInformation)
 {
     this.allowStretch = allowStretch;
     average           = averageMode;
 }
コード例 #6
0
 public FieldParameters(string filepath, string imagePath, string colors, int horizontalDistance, int horizontalSize, int verticalSize, int verticalDistance, int width, int height,
     Inter scalingMode, IColorComparison colorMode, Dithering ditherMode, IterationInformation iterationInformation) : base(filepath)
 {
     ColorPath = colors;
     HorizontalDistance = horizontalDistance;
     HorizontalSize = horizontalSize;
     VerticalSize = verticalSize;
     VerticalDistance = verticalDistance;
     Length = width;
     Height = height;
     PrimaryImageTreatment = new FieldReadout(this, imagePath, scalingMode);
     PrimaryCalculation = new FieldCalculation(colorMode, ditherMode, iterationInformation);
     HasProtocolDefinition = true;
 }
コード例 #7
0
        public FieldParameters(int imageWidth, int imageHeight, Color background, string colors, int horizontalDistance, int horizontalSize, int verticalSize, int verticalDistance, int targetSize,
            Inter scalingMode, IColorComparison colorMode, Dithering ditherMode, IterationInformation iterationInformation)
        {

            ColorPath = colors;
            HorizontalDistance = horizontalDistance;
            HorizontalSize = horizontalSize;
            VerticalSize = verticalSize;
            VerticalDistance = verticalDistance;
            PrimaryImageTreatment = new FieldReadout(this, imageWidth, imageHeight, scalingMode);
            PrimaryImageTreatment.Background = background;
            TargetCount = targetSize;
            PrimaryCalculation = new FieldCalculation(colorMode, ditherMode, iterationInformation);
            HasProtocolDefinition = true;
        }
コード例 #8
0
 public CircularStructure(int imageWidth, int imageHeight, Color background, string colors,
                          IColorComparison colorMode, Dithering ditherMode, AverageMode averageMode, IterationInformation iterationInformation, bool allowStretch = false)
     : base(imageWidth, imageHeight, background, colors, colorMode, ditherMode, averageMode, allowStretch, iterationInformation)
 {
 }
コード例 #9
0
 public CircularStructure(string filepath, string bitmap, string colors,
                          IColorComparison colorMode, Dithering ditherMode, AverageMode averageMode, IterationInformation iterationInformation, bool allowStretch = false)
     : base(filepath, bitmap, colors, colorMode, ditherMode, averageMode, allowStretch, iterationInformation)
 {
 }
コード例 #10
0
 public SpiralParameters(int imageWidth, int imageHeight, Color background, int rotations, string colors,
                         IColorComparison colorMode, Dithering ditherMode, AverageMode averageMode, IterationInformation iterationInformation, bool allowStretch = false)
     : base(imageWidth, imageHeight, background, colors, colorMode, ditherMode, averageMode, iterationInformation, allowStretch)
 {
     HasProtocolDefinition = false;
     init(rotations);
 }
コード例 #11
0
 /// <summary>
 /// Generiert eine Spirale mit der angegebenen Zahl Viertelumdrehungen.
 /// </summary>
 /// <param name="bitmap">Das der Spirale zugrunde liegende Bild.</param>
 /// <param name="quarterRotations">Die Viertelumdrehungen der Spirale.</param>
 /// <param name="normalWidth">Breite eines Steins in tangentialer Richtung</param>
 /// <param name="tangentialWidth">Breite eines Steins in normaler Richtung</param>
 /// <param name="normalDistance">Abstand zwischen zwei Steinen in normaler Richtung</param>
 /// <param name="tangentialDistance">Abstand zwischen zwei Steinen in tangentialer Richtung</param>
 /// <param name="colors">Die Farben, die für dieses Objekt verwendet werden sollen.</param>
 /// <param name="colorMode">Der Interpolationsmodus, der zur Farberkennung verwendet wird.</param>
 /// <param name="averageMode">Gibt an, ob nur ein Punkt des Dominos (linke obere Ecke) oder ein Durchschnittswert aller Pixel unter dem Pfad verwendet werden soll, um die Farbe auszuwählen.</param>
 /// <param name="allowStretch">Gibt an, ob beim Berechnen die Struktur an das Bild angepasst werden darf.</param>
 /// <param name="useOnlyMyColors">Gibt an, ob die Farben nur in der angegebenen Menge verwendet werden sollen.
 /// Ist diese Eigenschaft aktiviert, kann das optische Ergebnis schlechter sein, das Objekt ist aber mit den angegeben Steinen erbaubar.</param>
 public SpiralParameters(string filepath, string bitmap, int rotations, string colors,
                         IColorComparison colorMode, Dithering ditherMode, AverageMode averageMode, IterationInformation iterationInformation, bool allowStretch = false) :
     base(filepath, bitmap, colors, colorMode, ditherMode, averageMode, iterationInformation, allowStretch)
 {
     HasProtocolDefinition = false;
     init(rotations);
 }
コード例 #12
0
 public StructureParameters(int imageWidth, int imageHeight, Color background, XElement definition,
                            int targetSize, String colors,
                            IColorComparison colorMode, Dithering ditherMode, AverageMode averageMode, IterationInformation iterationInformation, bool allowStretch = false)
     : base(imageWidth, imageHeight, background, colors, colorMode, ditherMode, averageMode, allowStretch, iterationInformation)
 {
     StructureDefinitionXML = definition;
     TargetCount            = targetSize;
 }
コード例 #13
0
 /// <summary>
 /// Generiert eine Struktur mit der angegebenen Steineanzahl.
 /// Dabei wird versucht, das Seitenverhältnis des Bildes möglichst anzunähern.
 /// </summary>
 /// <param name="bitmap">Das Bitmap, welchem der Struktur zugrunde liegen soll.</param>
 /// <param name="definition">Die XML-Strukturdefinition, die verwendet werden soll.</param>
 /// <param name="colors">Die Farben, die für dieses Objekt verwendet werden sollen.</param>
 /// <param name="colorMode">Der Interpolationsmodus, der zur Farberkennung verwendet wird.</param>
 /// <param name="averageMode">Gibt an, ob nur ein Punkt des Dominos (linke obere Ecke) oder ein Durchschnittswert aller Pixel unter dem Pfad verwendet werden soll, um die Farbe auszuwählen.</param>
 /// <param name="allowStretch">Gibt an, ob beim Berechnen die Struktur an das Bild angepasst werden darf.</param>
 /// <param name="useOnlyMyColors">Gibt an, ob die Farben nur in der angegebenen Menge verwendet werden sollen.
 /// Ist diese Eigenschaft aktiviert, kann das optische Ergebnis schlechter sein, das Objekt ist aber mit den angegeben Steinen erbaubar.</param>
 /// <param name="targetSize">Die Zielgröße des Objekts.</param>
 public StructureParameters(string filepath, string imagepath, XElement definition, int targetSize, String colors,
                            IColorComparison colorMode, Dithering ditherMode, AverageMode averageMode, IterationInformation iterationInformation, bool allowStretch = false)
     : this(filepath, imagepath, definition, 1, 1, colors, colorMode, ditherMode, averageMode, iterationInformation, allowStretch)
 {
     TargetCount = targetSize;
 }
コード例 #14
0
 /// <summary>
 /// Generiert eine Struktur mit den angegebenen Wiederholparametern in x- und y-Richtung.
 /// </summary>
 /// <param name="bitmap">Das Bitmap, welchem der Struk zugrunde liegen soll.</param>
 /// <param name="definition">Die XML-Strukturdefinition, die verwendet werden soll.</param>
 /// <param name="length">Die Anzahl der Wiederholung der mittleren Zelle in x-Richtung.</param>
 /// <param name="height">Die Anzahl der Wiederholung der mittleren Zelle in y-Richtung.</param>
 /// <param name="colors">Die Farben, die für dieses Objekt verwendet werden sollen.</param>
 /// <param name="colorMode">Der Interpolationsmodus, der zur Farberkennung verwendet wird.</param>
 /// <param name="averageMode">Gibt an, ob nur ein Punkt des Dominos (linke obere Ecke) oder ein Durchschnittswert aller Pixel unter dem Pfad verwendet werden soll, um die Farbe auszuwählen.</param>
 /// <param name="allowStretch">Gibt an, ob beim Berechnen die Struktur an das Bild angepasst werden darf.</param>
 /// <param name="useOnlyMyColors">Gibt an, ob die Farben nur in der angegebenen Menge verwendet werden sollen.
 /// Ist diese Eigenschaft aktiviert, kann das optische Ergebnis schlechter sein, das Objekt ist aber mit den angegeben Steinen erbaubar.</param>
 public StructureParameters(string filepath, string imagepath, XElement definition, int length, int height, string colors,
                            IColorComparison colorMode, Dithering ditherMode, AverageMode averageMode, IterationInformation iterationInformation, bool allowStretch = false) :
     base(filepath, imagepath, colors, colorMode, ditherMode, averageMode, allowStretch, iterationInformation)
 {
     StructureDefinitionXML = definition;
     this.Length            = length;
     this.Height            = height;
 }
コード例 #15
0
 public FieldParameters(string filepath, string imagePath, string colors, int horizontalDistance, int horizontalSize, int verticalSize, int verticalDistance, int targetSize,
                        SkiaSharp.SKFilterQuality scalingQuality, IColorComparison colorMode, Dithering ditherMode, IterationInformation iterationInformation)
     : this(filepath, imagePath, colors, horizontalDistance, horizontalSize, verticalSize, verticalDistance, 1, 1, scalingQuality, colorMode, ditherMode, iterationInformation)
 {
     TargetCount = targetSize;
 }
コード例 #16
0
        /// <summary>
        /// Weist jedem Shape die ideale Farbe zu, basierend auf den festgelegten Eigenschaften.
        /// </summary>
        /// <returns>ein Int-Array mit den Farbindizes</returns>
        internal override void CalculateColors()
        {
            var colors = this.colors.RepresentionForCalculation;

            //if (!shapesValid) throw new InvalidOperationException("Current shapes are invalid!");
            IterationInformation.weights = Enumerable.Repeat(1.0, colors.Length).ToArray();
            RTree <IDominoShape> tree = new RTree <IDominoShape>(9, new GuttmannQuadraticSplit <IDominoShape>());
            // wird nur beim Dithering benötigt und nur dann ausgeführt; sortiert alle Shapes nach deren Mittelpunktskoordinate
            // erst nach x, bei gleichem x nach y
            var list = shapes.dominoes.OrderByDescending(x =>
            {
                var container = x.GetContainer();
                return(container.y + container.height / 2);
            }).ThenBy(x =>
            {
                var container = x.GetContainer();
                return(container.x + container.width / 2);
            }).ToList();

            if (ditherMode.weights.GetLength(0) + ditherMode.weights.GetLength(1) > 2)
            {
                for (int i = 0; i < shapes.dominoes.Length; i++)
                {
                    tree.Insert(shapes.dominoes[i]);
                }
            }
            for (int iter = 0; iter < IterationInformation.maxNumberOfIterations; iter++)
            {
                if (ditherMode.weights.GetLength(0) + ditherMode.weights.GetLength(1) > 2)
                {
                    double extent_r = (ditherMode.matrix_width - ditherMode.start_first_row) * charLength;
                    double extent_l = (ditherMode.start_first_row - 1) * charLength;
                    double extent_u = (ditherMode.matrix_height - 1) * charLength;
                    // ditherColors im Baum ersetzen
                    for (int i = 0; i < list.Count; i++)
                    {
                        list[i].ditherColor = list[i].originalColor;
                    }
                    for (int i = 0; i < list.Count; i++)
                    {
                        var originalColor = list[i].ditherColor;
                        list[i].CalculateColor(colors, colorMode, TransparencySetting, IterationInformation.weights);
                        // Abweichung der beiden Farben bestimmen
                        int fehler_r = (int)(originalColor.Red - colors[list[i].color].mediaColor.R);
                        int fehler_g = (int)(originalColor.Green - colors[list[i].color].mediaColor.G);
                        int fehler_b = (int)(originalColor.Blue - colors[list[i].color].mediaColor.B);
                        // bestimme Abmessungen des Suchbereichs
                        DominoRectangle orig     = list[i].getBoundingRectangle();
                        double          orig_x   = orig.x + orig.width / 2;
                        double          orig_y   = orig.y + orig.height / 2;
                        DominoRectangle viewport = new DominoRectangle()
                        {
                            x      = orig_x - extent_l,
                            y      = orig_y - extent_u,
                            width  = extent_r + extent_l,
                            height = extent_u
                        };
                        var result  = tree.Search(viewport);
                        var weights = new double[result.Count];
                        // Rohgewichte aller gefundenen Shapes finden
                        for (int j = 0; j < result.Count; j++)
                        {
                            var bounding = result[j].getBoundingRectangle();
                            // alle rausschmeißen, die nicht komplett im Viewport liegen
                            double center_x = bounding.x + bounding.width / 2;
                            double center_y = bounding.y + bounding.height / 2;
                            // überprüfen, ob das Shape schon abgearbeitet wurde
                            if (center_y == orig_y && center_x <= orig_x)
                            {
                                continue;
                            }
                            if (center_y > orig_y)
                            {
                                continue;
                            }
                            weights[j] = ditherMode.Weight((center_x - orig_x) / charLength, (orig_y - center_y) / charLength);
                        }
                        var divisor = weights.Sum();
                        if (divisor == 0)
                        {
                        }
                        for (int j = 0; j < result.Count; j++)
                        {
                            if (weights[j] == 0)
                            {
                                continue;
                            }
                            ditherMode.AddToPixel(result[j],
                                                  (int)(fehler_r * weights[j] / divisor),
                                                  (int)(fehler_g * weights[j] / divisor),
                                                  (int)(fehler_b * weights[j] / divisor));
                        }
                    }
                }
                else
                {
                    ResetDitherColors(shapes.dominoes);
                    IterationInformation.numberofiterations = iter;
                    Console.WriteLine($"Iteration {iter}");
                    CancellationTokenSource cts = new CancellationTokenSource();
                    Parallel.For(0, shapes.dominoes.Length, new ParallelOptions()
                    {
                        MaxDegreeOfParallelism = -1, CancellationToken = cts.Token
                    }, (i) =>
                    {
                        try
                        {
                            shapes.dominoes[i].CalculateColor(colors, colorMode, TransparencySetting, IterationInformation.weights);
                        }
                        catch (Exception)
                        {
                            cts.Cancel();
                        }
                    });
                }
                // Farben zählen
                IterationInformation.EvaluateSolution(colors.ToArray(), shapes.dominoes);
                if (IterationInformation.colorRestrictionsFulfilled != false)
                {
                    break;
                }
            }
            last = new DominoTransfer(shapes.dominoes, this.colors);
        }