Esempio n. 1
1
    /// <summary>
    /// Reads from the provided file name all parameters and data for a
    /// heightmap.  If the data for the heightmap does not exist, then
    /// no data is written to the provided texture.
    /// </summary>
    /// <param name='fileName'>
    /// The file name.  This can be relative or fully-qualified.
    /// </param>
    /// <param name='no'>
    /// The <see cref="NormalOptions" /> that will store read-in parameters.
    /// </param>
    /// <param name='co'>
    /// The <see cref="CloudOptions" /> that will store read-in parameters for
    /// <see cref="CloudFractal" />.
    /// </param>
    /// <param name='wo'>
    /// The <see cref="WorleyOptions" />  that will store read-in parameters for
    /// <see cref="WorleyNoise" />.
    /// </param>
    /// <param name='tex'>
    /// The <code>Texture2D</code> containing the heightmap data.
    /// </param>
    public static void Read(string fileName, ref NormalOptions no,
	                        ref CloudOptions co, ref VoronoiOptions vo,
							ref Texture2D tex)
    {
        using(BinaryReader r = new BinaryReader(File.OpenRead(fileName)))
        {
            no.size = r.ReadInt32();
            no.seed = r.ReadInt32();
            no.cloudInf = r.ReadSingle();
            no.voronoiInf = r.ReadSingle();
            no.useThermalErosion = r.ReadBoolean();
            no.useHydroErosion = r.ReadBoolean();
            no.showSeams = r.ReadBoolean();

            co.upperLeftStart = r.ReadSingle();
            co.lowerLeftStart = r.ReadSingle();
            co.lowerRightStart = r.ReadSingle();
            co.upperRightStart = r.ReadSingle();

            vo.metric = (DistanceFunctions.DistanceMetric)r.ReadInt32();
            vo.combiner = (CombinerFunctions.CombineFunction)r.ReadInt32();
            vo.numberOfFeaturePoints = r.ReadInt32();
            vo.numberOfSubregions = r.ReadInt32();
            vo.multiplier = r.ReadSingle();

            tex.Resize(no.size, no.size);
            int bLeft = (int)(r.BaseStream.Length - r.BaseStream.Position);
            if(bLeft > 0)
                tex.LoadImage(r.ReadBytes(bLeft));
        }
    }
Esempio n. 2
0
    public CloudFractal(int size, int seed, CloudOptions options)
    {
        _size = size;
        _startVals = options.GetStartArray();

        _lcg = new LCGRandom((uint)seed);
        _field = new float[(_size) * (_size)];
        for(int i=0; i<_field.Length; ++i)
            _field[i] = -1.0f;
    }
Esempio n. 3
0
        public void ConfigureTemplateExpiry()
        {
            // Set up the lifecycle rules for the bucket where we store Cloud Formation templates
            var cloudOptions   = new CloudOptions();
            var credentials    = AmbientCredentials.GetCredentials();
            var s3Client       = AWSClientFactory.CreateAmazonS3Client(credentials);
            var storageService = new StorageService(s3Client, new S3PathParser());

            storageService.CreateExpirationRule(
                cloudOptions.ConfigurationTemplateBucket,
                Conventions.ConfigurationTemplateBucketPrefix,
                7,
                "Cloud Formation Template Cleanup"
                );
        }
Esempio n. 4
0
 private static void ResolveImg(CloudOptions options, ContainerBuilder builder)
 {
     if (options.ImageWidth <= 0 || options.ImageHeight <= 0)
     {
         throw new ArgumentException(
                   $"Incorrect image size: ({options.ImageWidth}: {options.ImageHeight}) (sides should be positive)");
     }
     builder
     .Register(_ => new BitmapSettings(
                   new Size(
                       options.ImageWidth,
                       options.ImageHeight
                       ),
                   Color.FromName(options.BackgroundColor)))
     .AsSelf();
 }
Esempio n. 5
0
        public static void Main(string[] args)
        {
            var cmdOptions = new CommandLineOptions();

            if (!Parser.Default.ParseArguments(args, cmdOptions))
            {
                return;
            }
            Size canvasSize;

            if (cmdOptions.CanvasSide != null)
            {
                canvasSize = new Size((int)cmdOptions.CanvasSide, (int)cmdOptions.CanvasSide);
            }
            else
            {
                canvasSize = new Size(cmdOptions.CanvasSize[0], cmdOptions.CanvasSize[1]);
            }
            var center = new Point(cmdOptions.Center[0], cmdOptions.Center[1]);
            var defaultColorPalette = new[]
            {
                Color.CornflowerBlue, Color.BlueViolet, Color.IndianRed, Color.OliveDrab, Color.CadetBlue
            };

            string[] stopWords;
            stopWords = cmdOptions.StopWordsFile != null?
                        File.ReadAllLines(cmdOptions.StopWordsFile) : new string[0];

            var options = new CloudOptions(
                cmdOptions.InputFile,
                cmdOptions.OutputFile,
                cmdOptions.InputFormat,
                GetImageFormat(cmdOptions.OutputFormat),
                center,
                canvasSize,
                defaultColorPalette,
                cmdOptions.FontSize,
                cmdOptions.FontFamily,
                cmdOptions.MaxCount,
                cmdOptions.MaxWeight,
                stopWords
                );
            var di = GetDiContainer(options);

            RunProgram(di, options);
        }
Esempio n. 6
0
        private static IContainer GetDiContainer(CloudOptions options)
        {
            var builder = new ContainerBuilder();

            builder.RegisterType <BasicTagFactory>()
            .As <ITagFactory>();

            builder.RegisterInstance(new TxtStringsReader(options.InputFile, Encoding.UTF8))
            .As <IStringsReader>();

            builder.RegisterType <StopWordsFilter>()
            .WithParameter("stopWords", new HashSet <string>(options.StopWords))
            .As <IFilter>();
            builder.RegisterType <StringLengthFilter>()
            .WithParameter("threshold", 5)
            .As <IFilter>();

            builder.RegisterType <ToLowerStringsNormalizer>()
            .As <INormalizer>();
            builder.RegisterType <WordStemNormalizer>()
            .WithParameter("hunspell", new Hunspell("en_us.aff", "en_us.dic"))
            .As <INormalizer>();

            builder.RegisterType <StringCountStatistic>()
            .WithParameter("maxCount", options.MaxCount)
            .WithParameter("maxWeight", options.MaxWeight)
            .As <IStatistician>();

            builder.Register(c => new StringsStyler(
                                 new Font(options.FontFamily, options.FontEmSize, FontStyle.Regular),
                                 1f,
                                 options.ColorPalette))
            .As <IStyler>();

            builder.RegisterType <SpiralLayouter>()
            .WithParameter("center", options.Center)
            .As <ILayouter>();

            builder.Register(c => new BitmapRenderer(new Bitmap(options.CanvasSize.Width, options.CanvasSize.Height)))
            .As <IRenderer <Bitmap> >();

            return(builder.Build());
        }
Esempio n. 7
0
        private static void RunProgram(IContainer di, CloudOptions options)
        {
            var strings    = di.Resolve <IStringsReader>().ReadStrings();
            var normalized = di.Resolve <IEnumerable <INormalizer> >()
                             .Aggregate(strings, (current, normalizer) => normalizer.Normalize(current));
            var filtered = di.Resolve <IEnumerable <IFilter> >()
                           .Aggregate(normalized, (current, filter) => filter.Filter(current));
            IDictionary <string, int> statistics = di.Resolve <IStatistician>()
                                                   .GetStatistic(filtered)
                                                   .OrderByDescending(x => x.Value)
                                                   .Take(options.MaxCount)
                                                   .ToDictionary(x => x.Key, x => x.Value);
            var styled = di.Resolve <IStyler>()
                         .GetStyles(statistics);
            var layout = di.Resolve <ILayouter>()
                         .GetLayout(styled);
            Bitmap bitmap;

            using (var renderer = di.Resolve <IRenderer <Bitmap> >())
                bitmap = renderer.Render(layout);
            bitmap.Save(options.OutputFile, options.OutputFormat);
        }
Esempio n. 8
0
        private static void ResolveReader(
            CloudOptions options,
            ContainerBuilder builder)
        {
            builder
            .RegisterType <WordPreprocessor>()
            .AsSelf();
            builder
            .RegisterType <ProhibitingIfLengthLessThenRule>()
            .WithParameter("thresholdLength", 3)
            .As <IPreprocessingRule>();
            builder
            .RegisterType <ProhibitingIfLengthMoreThenRule>()
            .WithParameter("thresholdLength", 20)
            .As <IPreprocessingRule>();
            builder
            .RegisterType <LoweringRule>()
            .As <IPreprocessingRule>();
            builder
            .Register <Func <WeightedWord, WordDescription> >(
                _ => weightedWord =>
            {
                var font         = new Font("Courier New", 20 * (int)Math.Log2(weightedWord.Weight + 1));
                var brush        = ColoredBrushes[weightedWord.Weight % ColoredBrushes.Count];
                var stringFormat = StringFormat.GenericTypographic;
                return(new WordDescription(weightedWord.Word, stringFormat, brush, font));
            });

            if (SupportedReaderSources.TryGetValue(options.ReaderType.ToLower(), out var readerCreator))
            {
                builder.Register(c => readerCreator()).As <IWordReader>();
            }
            else
            {
                throw new ArgumentException($"Unresolved format: {options.ReaderType.ToLower()}");
            }
        }
Esempio n. 9
0
    /// <summary>
    /// Overload for <see cref="Write" /> that does not have texture data.
    /// </summary>
    /// <param name='fileName'>
    /// The file name.  This can be relative or fully-qualified.
    /// </param>
    /// <param name='no'>
    /// The <see cref="NormalOptions" /> to write.
    /// </param>
    /// <param name='co'>
    /// The <see cref="CloudOptions" /> to write.
    /// </param>
    /// <param name='wo'>
    /// The <see cref="WorleyOptions" /> to write.
    /// </param>
    /// <param name='tex'>
    /// The <code>Texture2D</code> containing the heightmap data.
    /// </param>
    public static void Write(string fileName, NormalOptions no, CloudOptions co,
	                         VoronoiOptions vo)
    {
        Write(fileName, no, co, vo, null);
    }
Esempio n. 10
0
    /// <summary>
    /// Write the specified the heightmap and all paramaters to the provided
    /// file name.
    /// </summary>
    /// <param name='fileName'>
    /// The file name.  This can be relative or fully-qualified.
    /// </param>
    /// <param name='no'>
    /// The <see cref="NormalOptions" /> to write.
    /// </param>
    /// <param name='co'>
    /// The <see cref="CloudOptions" /> to write.
    /// </param>
    /// <param name='wo'>
    /// The <see cref="WorleyOptions" /> to write.
    /// </param>
    /// <param name='tex'>
    /// The <code>Texture2D</code> containing the heightmap data.
    /// </param>
    /// <description>
    /// This uses a <code>BinaryWriter</code> to convert all data into binary
    /// data for writing.
    /// </description>
    public static void Write(string fileName, NormalOptions no, CloudOptions co,
								VoronoiOptions vo, Texture2D tex)
    {
        //if file already exists, will overwrite without warning
        using(BinaryWriter w = new BinaryWriter(File.Open(fileName+".emb",
                                                FileMode.Create)))
        {
            w.Write(no.size);
            w.Write(no.seed);
            w.Write(no.cloudInf);
            w.Write(no.voronoiInf);
            w.Write(no.useThermalErosion);
            w.Write(no.useHydroErosion);
            w.Write(no.showSeams);

            w.Write(co.upperLeftStart);
            w.Write(co.lowerLeftStart);
            w.Write(co.lowerRightStart);
            w.Write(co.upperRightStart);

            w.Write((int)vo.metric);
            w.Write((int)vo.combiner);
            w.Write(vo.numberOfFeaturePoints);
            w.Write(vo.numberOfSubregions);
            w.Write(vo.multiplier);

            if(tex != null)
                w.Write(tex.EncodeToPNG());
        }
    }
Esempio n. 11
0
 public AzureStorageQueueManager(IOptions <CloudOptions> cloudOptions)
 {
     this.cloudOptions = cloudOptions.Value;
 }
Esempio n. 12
0
 public TerrainGenerator(NormalOptions normalOpt, CloudOptions cloudOpt, VoronoiOptions voronoiOpt)
 {
     Init(normalOpt, cloudOpt, voronoiOpt);
 }
Esempio n. 13
0
    private void Init(NormalOptions normalOpt, CloudOptions cloudOpt, VoronoiOptions voronoiOpt)
    {
        _normalOpt = normalOpt;
        _cloudOpt = cloudOpt;
        _voronoiOpt = voronoiOpt;

        _cfGen = new CloudFractal(_normalOpt.size, _normalOpt.seed, _cloudOpt);
        _vnGen = new VoronoiDiagram(_normalOpt.size, _normalOpt.seed, _voronoiOpt);
        _heightMap = new float[_normalOpt.size * _normalOpt.size];
    }