コード例 #1
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;
 }
コード例 #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);
        }
コード例 #3
0
 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;
 }
コード例 #4
0
 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;
 }
コード例 #5
0
 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;
 }
コード例 #6
0
 public ErrorDataScoringAlgorithm(Bitmap image, VectorPicture initialPicture)
     : base(image, initialPicture, ScoringMethodEnum.ErrorDataScoring)
 {
 }
コード例 #7
0
 public SavedState(Bitmap image, VectorPicture vectorPicture)
 {
     this.image = image;
     this.vectorPicture = vectorPicture;
 }
コード例 #8
0
 public ErrorData(VectorPicture picture, ImageData source)
     : this(source)
 {
     AddPolygons(picture.Polygons);
     polygonOrder = picture.Polygons.ToList();
 }
コード例 #9
0
 public PictureMutationPosingAsPicture(VectorPicture original, IPictureMutation mutation)
 {
     Original = original;
     Mutation = mutation;
 }
コード例 #10
0
        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);
        }
コード例 #11
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));
         }
     }
 }
コード例 #12
0
 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);
 }
コード例 #13
0
 public void FoundBetter(VectorPicture picture)
 {
     errorData = new ErrorData(picture, image);
 }
コード例 #14
0
 public TestAlgorithm(Bitmap image, VectorPicture initialPicture, ScoringMethodEnum scoringMethod)
     : base(scoringMethod)
 {
     this.initialPicture = initialPicture;
 }
コード例 #15
0
 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);
 }
コード例 #16
0
 private void CompareScoreMethods(VectorPicture vectorPicture, PolygonChanged mutation)
 {
     foreach (var image in testImages)
     {
         CompareScoreMethods(vectorPicture,mutation,image);
     }
 }
コード例 #17
0
 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);
     }
 }
コード例 #18
0
 public void ScoreMethodsAreEquivalentLeftRightPolygon()
 {
     var vectorPicture = new VectorPicture();
     vectorPicture.Polygons.Add(LeftPolygon());
     var mutation = new PolygonChanged(RightPolygon(), 0);
     CompareScoreMethods(vectorPicture,mutation,Properties.Resources.whiteRectangle);
 }
コード例 #19
0
 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);
 }
コード例 #20
0
 public void FoundBetter(VectorPicture picture)
 {
 }
コード例 #21
0
 public FullEvaluationScoringAlgorithm(Bitmap image, VectorPicture initialPicture)
     : base(image, initialPicture, ScoringMethodEnum.FullEvaluationScoring)
 {
 }
コード例 #22
0
 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);
     }
 }
コード例 #23
0
 public VectorPicture ApplyToPicture(VectorPicture picture)
 {
     var copy = picture.Clone();
     copy.Polygons[index] = newPolygon;
     return copy;
 }
コード例 #24
0
 public VectorPicture ApplyToPicture(VectorPicture picture)
 {
     return picture;
 }