public TAMImageDiagram Generate(TAMImageDiagram baseDiagram, TAMTone tone, TAMMipmapLevel mipmapLevel, int seed)
        {
            _strokesGenerator.ResetSeed(seed);
            _random = new System.Random(seed);

            var   diagram         = baseDiagram.Copy();
            float currentCoverage = ComputeCoverage(diagram, mipmapLevel);
            float targetCoverage  = _generationConfiguration.TargetCoverages[tone];

            while (targetCoverage > currentCoverage)
            {
                List <RankedPossibleStroke> possibleStrokes = new List <RankedPossibleStroke>();
                for (int i = 0; i < _generationConfiguration.TriesCount[mipmapLevel]; i++)
                {
                    TAMStroke            newStroke       = _strokesGenerator.CreateRandomStroke(new Vector2(_random.Next(), _random.Next()), tone);
                    RankedPossibleStroke rankedNewStroke = RankStroke(newStroke, diagram);
                    possibleStrokes.Add(rankedNewStroke);
                }

                var bestStroke = possibleStrokes.OrderBy(p => p.Rank).First();
                diagram.AddStroke(bestStroke.Stroke);
                currentCoverage = ComputeCoverage(diagram, mipmapLevel);
            }

            return(diagram);
        }
Пример #2
0
        public TAMStroke UpdatePerMipmapLevelStrokeParameters(TAMStroke tamStroke, TAMMipmapLevel level)
        {
            var reverseIndex = level.MipmapLevelsCount - level.LevelIndex - 1;
            var newHeight    = tamStroke.Height * Mathf.Pow(_generationConfiguration.PerMipmapLevelHeightMultiplier, reverseIndex);

            return(new TAMStroke(tamStroke.Center, newHeight, tamStroke.Length, tamStroke.Rotation, tamStroke.Id));
        }
        private RankedPossibleStroke RankStroke(TAMStroke newStroke, TAMImageDiagram diagram)
        {
            // rank the bigger, the better
            var distanceSum      = 0f;
            var intersectionArea = 0f;

            foreach (var stroke in diagram.Strokes)
            {
                var intersection = MyMathUtils.IntersectionAreaOfTwoCircles(newStroke.Length, newStroke.Center, stroke.Length, stroke.Center);
                intersectionArea += intersection;
                distanceSum      += Vector2.Distance(newStroke.Center, stroke.Center);
            }

            var intersectionPercent = intersectionArea / (Math.PI * Math.Pow(newStroke.Length, 2));

            var rank = Mathf.Pow(distanceSum, (float)(2 - intersectionPercent));

            return(new RankedPossibleStroke()
            {
                Rank = rank,
                Stroke = newStroke
            });
        }
Пример #4
0
 public void AddStroke(TAMStroke stroke)
 {
     _strokes.Add(stroke);
 }