コード例 #1
0
        private void ApproximateGenetically(IEnumerable <Tree.Node> nodes, IEvolutionaryPopulation population)
        {
            var index     = 0;
            var nodesList = nodes.ToList();
            var count     = nodesList.Count;

            foreach (var node in nodesList)
            {
                var individual         = _geneticEllipseMatch.FindBestIndividual(node.PointSet, node.Parent?.Ellipse);
                var fitness            = population.FitnessFunction.GetValue(individual);
                var ellipticParameters = ((CollectivePhenotype <EllipticParameters>)individual.Phenotype).GetValue();
                var ellipse            = new Ellipsis(ellipticParameters, node.PointSet.Center.Z)
                {
                    Intensity = fitness
                };

                ellipse.SetFirstFocal(MathUtils.EDimension.X, ellipse.FirstFocal.X + node.PointSet.Center.X);
                ellipse.SetFirstFocal(MathUtils.EDimension.Y, ellipse.FirstFocal.Y + node.PointSet.Center.Y);

                ellipse.SetSecondFocal(MathUtils.EDimension.X, ellipse.SecondFocal.X + node.PointSet.Center.X);
                ellipse.SetSecondFocal(MathUtils.EDimension.Y, ellipse.SecondFocal.Y + node.PointSet.Center.Y);

                if (ellipse.Eccentricity < _eccentricityThreshold && fitness < _fitnessThreshold && double.IsNaN(fitness) == false)
                {
                    node.Ellipse = ellipse;
                }

                ProgressTracker.Progress(EProgressStage.TreeApproximation, "Approximating Tree segments", index++, count);
            }
        }
コード例 #2
0
        public static double Fitness(IPhenotype p)
        {
            var phenotype = (CollectivePhenotype <EllipticParameters>)p;

            var x = phenotype.GetValue();

            var ellipsis = new Ellipsis(x, AnalyzedPointSet.Center.Z);

            if (ellipsis.Eccentricity > EccentricityThreshold)
            {
                return(double.MaxValue);
            }

            double fitness     = 0;
            var    counter     = 0;
            double maxDistance = 0;

            var offsetFoci1 = x.F1 + AnalyzedPointSet.Center;
            var offsetFoci2 = x.F2 + AnalyzedPointSet.Center;

            foreach (var point in AnalyzedPointSet)
            {
                // Distance of point from Foci 1
                var pf1 = MathUtils.Distance(point, offsetFoci1, MathUtils.EDistanceMetric.Euclidean, MathUtils.EDimension.X,
                                             MathUtils.EDimension.Y);

                // Distance of point from Foci 2
                var pf2 = MathUtils.Distance(point, offsetFoci2, MathUtils.EDistanceMetric.Euclidean, MathUtils.EDimension.X,
                                             MathUtils.EDimension.Y);

                // Given two fixed points F1 and F2 called the foci, and a distance 2a, which is greater than the distance between the foci,
                // the ellipse is the set of points P such that the sum of the distances PF1, PF2 is equal to 2a:
                var dist = pf1 + pf2 - 2 * x.A;

                if (double.IsNaN(dist))
                {
                    return(double.MaxValue);
                }

                var absoluteDistance = Math.Abs(dist);
                if (absoluteDistance > BufferWidth)
                {
                    fitness += absoluteDistance;
                    counter++;
                }

                if (absoluteDistance > maxDistance)
                {
                    maxDistance = absoluteDistance;
                }
            }
            fitness /= counter;
            fitness += maxDistance;
            fitness /= 2;

            return(fitness);
        }
コード例 #3
0
ファイル: EllipsisTests.cs プロジェクト: radtek/Enlighten
        public void IsMatch(string input, Token expectedValue)
        {
            var Result = new Ellipsis().IsMatch(new TokenizableStream <char>(input?.ToCharArray() ?? Array.Empty <char>()));

            Assert.Equal(expectedValue?.EndPosition, Result?.EndPosition);
            Assert.Equal(expectedValue?.StartPosition, Result?.StartPosition);
            Assert.Equal(expectedValue?.TokenType, Result?.TokenType);
            Assert.Equal(expectedValue?.Value, Result?.Value);
        }
コード例 #4
0
        private void MainCAD_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left && chosenShape != Shapes.Point)
            {
                xEnd = e.X;
                yEnd = e.Y;
                int deltaX = xEnd - xStart;
                int deltaY = yEnd - yStart;

                switch (chosenShape)
                {
                case Shapes.Line:
                    Point start = new Point(xStart, yStart);
                    Point end   = new Point(xEnd, yEnd);
                    Line  line  = new Line(start, end, chosenColor);
                    line.Draw(toolStripContainer1.ContentPanel.CreateGraphics());
                    shapeList.Add(line);
                    break;

                case Shapes.Rectangle:
                    start = new Point(xStart, yStart);
                    Rectangle rectangle = new Rectangle(chosenColor, start, deltaX, deltaY);
                    rectangle.Draw(toolStripContainer1.ContentPanel.CreateGraphics());
                    shapeList.Add(rectangle);
                    break;

                case Shapes.Square:
                    start = new Point(xStart, yStart);
                    Square square = new Square(chosenColor, start, deltaX);
                    square.Draw(toolStripContainer1.ContentPanel.CreateGraphics());
                    shapeList.Add(square);
                    break;

                case Shapes.Ellipsis:

                    if (ctrlKeyDown)
                    {
                        deltaY = deltaX = Math.Max(deltaX, deltaY);
                    }

                    start = new Point(xStart, yStart);
                    Ellipsis ellipsis = new Ellipsis(chosenColor, start, deltaX, deltaY);
                    ellipsis.Draw(toolStripContainer1.ContentPanel.CreateGraphics());
                    shapeList.Add(ellipsis);
                    break;
                }
            }
        }
コード例 #5
0
        public static void ExportToStream(this Ellipsis ellipsis, ICloudStreamWriter writer, int size = 50, float resolution = 0.01f)
        {
            for (var x = -size; x < size; x++)
            {
                for (var y = -size; y < size; y++)
                {
                    var p = new CloudPoint(ellipsis.Center.X + x * resolution, ellipsis.Center.Y + y * resolution, ellipsis.Center.Z)
                    {
                        Intensity = (float)ellipsis.Intensity
                    };

                    if (ellipsis.Contains(p))
                    {
                        writer.WritePoint(p);
                    }
                }
            }
        }
コード例 #6
0
        public bool ConditionMatched(PointSet pointSet, int index, int total)
        {
            var bestPossibleIndividual = GeneticEllipseMatch.FindBestIndividual(pointSet);

            if (bestPossibleIndividual is null)
            {
                return(false);
            }
            var fitness           = GeneticEllipseMatch.GeneticAlgorithm.Population.FitnessFunction.GetValue(bestPossibleIndividual.Phenotype);
            var ellipseParameters = ((CollectivePhenotype <EllipticParameters>)bestPossibleIndividual.Phenotype).GetValue();
            var ellipse           = new Ellipsis(ellipseParameters, 0);

            foreach (var t in pointSet)
            {
                t.Intensity = (float)fitness;
            }

            return(ellipse.Eccentricity < EccentricityThreshold && fitness < FitnessThreshold);
        }
コード例 #7
0
ファイル: AliyunHelper.cs プロジェクト: pathrough/Flh
        public override string ToString()
        {
            var sb = new StringBuilder();

            sb.Append("summary_field:");
            sb.Append(FieldName);
            if (!String.IsNullOrWhiteSpace(Element))
            {
                sb.Append(",summary_element:");
                sb.Append(Element.Trim());
            }
            if (!String.IsNullOrWhiteSpace(Ellipsis))
            {
                sb.Append(",summary_ellipsis:");
                sb.Append(Ellipsis.Trim());
            }
            if (Snipped.HasValue)
            {
                sb.Append(",summary_snipped:");
                sb.Append(Snipped.Value.ToString());
            }
            if (Length.HasValue)
            {
                sb.Append(",summary_len:");
                sb.Append(Length.Value.ToString());
            }
            if (!String.IsNullOrWhiteSpace(Prefix) && !String.IsNullOrWhiteSpace(Postfix))
            {
                sb.Append(",summary_element_prefix:");
                sb.Append(Prefix.Trim());
                sb.Append(",summary_element_postfix:");
                sb.Append(Postfix.Trim());
            }

            return(sb.ToString());
        }
コード例 #8
0
ファイル: ExpTranslator.cs プロジェクト: melkordahrk/pytocs
 public CodeExpression VisitEllipsis(Ellipsis e)
 {
     throw new NotImplementedException();
 }
コード例 #9
0
ファイル: ExpNameDiscovery.cs プロジェクト: wheregone/pytocs
 public void VisitEllipsis(Ellipsis e)
 {
     throw new NotImplementedException();
 }
コード例 #10
0
 public DataType VisitEllipsis(Ellipsis e)
 {
     return(DataType.None);
 }
コード例 #11
0
ファイル: ExpNameDiscovery.cs プロジェクト: uxmal/pytocs
 public void VisitEllipsis(Ellipsis e)
 {
     throw new NotImplementedException();
 }
コード例 #12
0
        private void MainCAD_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                Point start = new Point(xStart, yStart, chosenColor);
                Point end   = new Point(xEnd, yEnd, chosenColor);
                int   deltaX;
                int   deltaY;

                switch (chosenShape)
                {
                case Shapes.Point:
                    end = new Point(e.X, e.Y, chosenColor);
                    end.Draw(toolStripContainer1.ContentPanel.CreateGraphics());
                    shapeList.Add(end);
                    break;

                case Shapes.Line:
                    //Cancella la vecchia linea disegnandone una nuova dello stesso colore
                    Line line = new Line(start, end, BackColor);
                    line.Draw(toolStripContainer1.ContentPanel.CreateGraphics());
                    //Disegna la nuova linea
                    xEnd = e.X;
                    yEnd = e.Y;
                    end  = new Point(xEnd, yEnd, chosenColor);
                    line = new Line(start, end, chosenColor);
                    line.Draw(toolStripContainer1.ContentPanel.CreateGraphics());
                    RenderRefresh();
                    break;

                case Shapes.Rectangle:
                {
                    //Cancella il vecchio rettangolo
                    deltaX = xEnd - xStart;
                    deltaY = yEnd - yStart;

                    Rectangle rectangle =
                        new Rectangle(BackColor, new Point(xStart, yStart, chosenColor), deltaX, deltaY);
                    rectangle.Draw(toolStripContainer1.ContentPanel.CreateGraphics());

                    //Aggiorna la posizione del mouse
                    xEnd      = e.X;
                    yEnd      = e.Y;
                    deltaX    = xEnd - xStart;
                    deltaY    = yEnd - yStart;
                    rectangle = new Rectangle(chosenColor, new Point(xStart, yStart, chosenColor), deltaX, deltaY);
                    rectangle.Draw(toolStripContainer1.ContentPanel.CreateGraphics());
                    RenderRefresh();
                }
                break;

                case Shapes.Square:
                    deltaX = xEnd - xStart;
                    Square square = new Square(BackColor, new Point(xStart, yStart), deltaX);
                    square.Draw(toolStripContainer1.ContentPanel.CreateGraphics());

                    xEnd   = e.X;
                    yEnd   = e.Y;
                    deltaX = xEnd - xStart;
                    square = new Square(chosenColor, new Point(xStart, yStart, chosenColor), deltaX);
                    square.Draw(toolStripContainer1.ContentPanel.CreateGraphics());
                    RenderRefresh();
                    break;

                case Shapes.Ellipsis:
                    deltaX = xEnd - xStart;
                    deltaY = yEnd - yStart;

                    if (ctrlKeyDown)
                    {
                        deltaX = deltaY = Math.Max(deltaX, deltaY);
                    }

                    Ellipsis ellipsis = new Ellipsis(BackColor, new Point(xStart, yStart, chosenColor), deltaX, deltaY);
                    ellipsis.Draw(toolStripContainer1.ContentPanel.CreateGraphics());

                    xEnd   = e.X;
                    yEnd   = e.Y;
                    deltaX = xEnd - xStart;
                    deltaY = yEnd - yStart;

                    if (ctrlKeyDown)
                    {
                        deltaY = deltaX = Math.Max(deltaX, deltaY);
                    }

                    ellipsis = new Ellipsis(chosenColor, new Point(xStart, yStart, chosenColor), deltaX, deltaY);
                    ellipsis.Draw(toolStripContainer1.ContentPanel.CreateGraphics());
                    RenderRefresh();
                    break;
                }
            }
        }
コード例 #13
0
 public CodeExpression VisitEllipsis(Ellipsis e)
 {
     return(new CodeDefaultExpression());
 }