public VectorPicture Clone()
 {
     var p = new VectorPicture {Polygons = new List<Polygon>(Polygons.Count)};
     foreach (var pol in Polygons)
     {
         p.Polygons.Add(pol.Clone());
     }
     return p;
 }
Exemple #2
0
        public VectorPicture Clone()
        {
            var p = new VectorPicture {
                Polygons = new List <Polygon>(Polygons.Count)
            };

            foreach (var pol in Polygons)
            {
                p.Polygons.Add(pol.Clone());
            }
            return(p);
        }
 int ScorePolygons(bool[,] donePixels, VectorPicture picture)
 {
     var totalError = 0;
     foreach (var polygon in Enumerable.Reverse(picture.Polygons))
     {
     foreach (var point in drawer(polygon).Where(point => !donePixels[point.X, point.Y]))
     {
     donePixels[point.X, point.Y] = true;
     totalError += algorithm.SourceData[point].GetAbsColorError(polygon.Color);
     }
     }
     return totalError;
 }
 public override VectorPicture GetInitialPicture(IAlgorithm algorithm)
 {
     var picture = new VectorPicture();
     var polygon = new Polygon(Color.White);
     picture.Polygons.Add(polygon);
     var x0 = (int) (algorithm.SourceData.Width*0.25);
     var x1 = (int) (algorithm.SourceData.Width*0.75);
     var y0 = (int) (algorithm.SourceData.Height*0.25);
     var y1 = (int) (algorithm.SourceData.Height*0.75);
     polygon.Points.Add(new IntVector2(x0, y0));
     polygon.Points.Add(new IntVector2(x0, y1));
     polygon.Points.Add(new IntVector2(x1, y1));
     polygon.Points.Add(new IntVector2(x1, y0));
     polygon.Color = new VColor(Color.White);
     return picture;
 }
 public override VectorPicture GetInitialPicture(IAlgorithm algorithm)
 {
     var source = algorithm.SourceData;
     var result = new VectorPicture();
     int x0 = (int) (source.Width*0.25);
     int x1 = (int) (source.Width*0.75);
     int y0 = (int) (source.Height*0.25);
     int y1 = (int) (source.Height*0.75);
     var points = new List<IntVector2>
         {
             new IntVector2(x0, y0),
             new IntVector2(x0, y1),
             new IntVector2(x1, y1),
             new IntVector2(x1 + 2, y1),
             new IntVector2(x1, y0),
             new IntVector2(x1 + 2, y0)
         };
     var polygon = new Polygon(points, new VColor(Color.White));
     result.Polygons.Add(polygon);
     return result;
 }
 public ErrorDataScoringAlgorithm(Bitmap image, VectorPicture initialPicture)
     : base(image, initialPicture, ScoringMethodEnum.ErrorDataScoring)
 {
 }
 public SavedState(Bitmap image, VectorPicture vectorPicture)
 {
     this.image = image;
     this.vectorPicture = vectorPicture;
 }
 public ErrorData(VectorPicture picture, ImageData source)
     : this(source)
 {
     AddPolygons(picture.Polygons);
     polygonOrder = picture.Polygons.ToList();
 }
 public PictureMutationPosingAsPicture(VectorPicture original, IPictureMutation mutation)
 {
     Original = original;
     Mutation = mutation;
 }
        void DrawVectorPicture(PaintEventArgs e, VectorPicture lastAttempt, CanvasBox canvasBox)
        {
            var buffer = new Bitmap(canvasBox.CanvasSize.Width, canvasBox.CanvasSize.Height, PixelFormat.Format24bppRgb);
            var bufferGraphics = Graphics.FromImage(buffer);
            bufferGraphics.SmoothingMode = SmoothingMode.HighQuality;

            var scale = new FloatVector2((float)canvasBox.CanvasSize.Width / TargetSize.X,
                (float)canvasBox.CanvasSize.Height / TargetSize.Y);
            lock (lastAttempt)
                lastAttempt.SmoothDraw(bufferGraphics, scale);
            e.Graphics.DrawImage(buffer, 0, 0);
        }
 public void ErrorDataFakeChangePolygonHasNoEffect()
 {
     foreach (var polygon in testPolygons)
     {
         var vectorPicture = new VectorPicture();
         vectorPicture.Polygons.Add(polygon);
         var mutation = new PolygonChanged(polygon, 0);
         var noMutation = new EmptyMutation();
         var testAlgorithms = testImages.Select(image => new TestAlgorithm(image, vectorPicture, PictureMutationAlgorithm.ScoringMethodEnum.FullEvaluationScoring));
         foreach (var scorer1 in testAlgorithms.Select(algorithm => new ErrorDataScoring(algorithm.SourceData)))
         {
             scorer1.FoundBetter(vectorPicture);
             Assert.AreEqual(scorer1.GetError(noMutation), scorer1.GetError(mutation));
         }
     }
 }
 public void ScoreMethodsAreEquivalentCase1()
 {
     var polygon = new Polygon(Color.White);
     polygon.AddPoint(8,13);
     polygon.AddPoint(7,1);
     polygon.AddPoint(11,14);
     var picture = new VectorPicture();
     picture.Polygons.Add(polygon);
     var mutationPolygon = new Polygon(Color.White);
     mutationPolygon.AddPoint(1, 4);
     mutationPolygon.AddPoint(13, 0);
     mutationPolygon.AddPoint(17, 15);
     mutationPolygon.AddPoint(2, 10);
     var mutation = new PolygonChanged(mutationPolygon, 0);
     CompareScoreMethods(picture,mutation,Resources.Polygon);
 }
 public void FoundBetter(VectorPicture picture)
 {
     errorData = new ErrorData(picture, image);
 }
 public TestAlgorithm(Bitmap image, VectorPicture initialPicture, ScoringMethodEnum scoringMethod)
     : base(scoringMethod)
 {
     this.initialPicture = initialPicture;
 }
 private void CompareScoreMethods(VectorPicture vectorPicture, PolygonChanged mutation, Bitmap image)
 {
     var algorithm = new TestAlgorithm(image, vectorPicture, PictureMutationAlgorithm.ScoringMethodEnum.FullEvaluationScoring);
     var scores = new List<double>(scorers.Length);
     foreach (var scorer in scorers.Select(sf => sf(algorithm)))
     {
         algorithm.SetInitial();
         scorer.FoundBetter(vectorPicture);
         scores.Add(scorer.GetError(mutation));
     }
     Assert.IsTrue(scores.Distinct().Count() == 1);
 }
 private void CompareScoreMethods(VectorPicture vectorPicture, PolygonChanged mutation)
 {
     foreach (var image in testImages)
     {
         CompareScoreMethods(vectorPicture,mutation,image);
     }
 }
 public void ScoreMethodsAreEquivalentWeak()
 {
     foreach (var polygon in testPolygons)
     {
         var vectorPicture = new VectorPicture();
         vectorPicture.Polygons.Add(polygon);
         var mutation = new PolygonChanged(polygon, 0);
         CompareScoreMethods(vectorPicture, mutation);
     }
 }
 public void ScoreMethodsAreEquivalentLeftRightPolygon()
 {
     var vectorPicture = new VectorPicture();
     vectorPicture.Polygons.Add(LeftPolygon());
     var mutation = new PolygonChanged(RightPolygon(), 0);
     CompareScoreMethods(vectorPicture,mutation,Properties.Resources.whiteRectangle);
 }
 public void ScoreMethodsAreEquivalentCase2()
 {
     var polygon = new Polygon(Color.White);
     polygon.AddPoint(5, 7);
     polygon.AddPoint(10, 5);
     polygon.AddPoint(7, 15);
     var picture = new VectorPicture();
     picture.Polygons.Add(polygon);
     var mutationPolygon = new Polygon(Color.White);
     mutationPolygon.AddPoint(6, 0);
     mutationPolygon.AddPoint(5, 0);
     mutationPolygon.AddPoint(19, 18);
     mutationPolygon.AddPoint(18, 1);
     var mutation = new PolygonChanged(mutationPolygon, 0);
     CompareScoreMethods(picture, mutation, Resources.Polygon);
 }
 public void FoundBetter(VectorPicture picture)
 {
 }
 public FullEvaluationScoringAlgorithm(Bitmap image, VectorPicture initialPicture)
     : base(image, initialPicture, ScoringMethodEnum.FullEvaluationScoring)
 {
 }
 public void ScoreMethodsAreEquivalent()
 {
     foreach (var polygonPair in testPolygons.ShakeHands())
     {
         var vectorPicture = new VectorPicture();
         vectorPicture.Polygons.Add(polygonPair.Item1);
         var mutation = new PolygonChanged(polygonPair.Item2, 0);
         CompareScoreMethods(vectorPicture, mutation);
     }
 }
 public VectorPicture ApplyToPicture(VectorPicture picture)
 {
     var copy = picture.Clone();
     copy.Polygons[index] = newPolygon;
     return copy;
 }
 public VectorPicture ApplyToPicture(VectorPicture picture)
 {
     return picture;
 }