// This function run the WFC for iteration number of times, for different tile sizes.
        // Component returns how many times for iteration number of sizes it was successful
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GH_PatternsFromSample gh_patterns = new GH_PatternsFromSample();

            DA.GetData <GH_PatternsFromSample>(0, ref gh_patterns);

            double iterations = 0;

            DA.GetData <double>(1, ref iterations);

            bool backtrack = false;

            DA.GetData <bool>(2, ref backtrack);

            var patterns = gh_patterns.Value.Patterns;
            var weights  = gh_patterns.Value.TilesWeights;
            var N        = gh_patterns.Value.N;

            List <WaveCollapseHistoryElement> outputs = new List <WaveCollapseHistoryElement>();
            var return_value = new GH_WaveCollapseResults();

            List <int> successfulRuns = new List <int>();
            List <int> outputSizes    = new List <int>();


            var sb = getContradictionData(outputSizes, (int)iterations, patterns, N, weights, ref successfulRuns);

            string filePath = @"R:\csv\asd2_14_26.csv";

            System.IO.File.WriteAllText(filePath, sb.ToString());

            DA.SetDataList(0, successfulRuns);
            DA.SetDataList(1, outputSizes);
        }
Beispiel #2
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GH_PatternsFromSample gh_patterns = new GH_PatternsFromSample();

            DA.GetData <GH_PatternsFromSample>(0, ref gh_patterns);

            List <Point3d> wavePoints = new List <Point3d>();

            DA.GetDataList <Point3d>(1, wavePoints);

            double dataSize = 0;

            DA.GetData <double>(2, ref dataSize);

            bool backtrack = false;

            DA.GetData <bool>(3, ref backtrack);

            double iterations = 0;

            DA.GetData <double>(4, ref iterations);

            var patterns = gh_patterns.Value.Patterns;
            var weights  = gh_patterns.Value.TilesWeights;
            var N        = gh_patterns.Value.N;

            // Get width and height based on 2d array of points
            int width  = Utils.GetNumberofPointsInOneDimension(wavePoints[0].X, wavePoints[wavePoints.Count - 1].X);
            int height = Utils.GetNumberofPointsInOneDimension(wavePoints[0].Y, wavePoints[wavePoints.Count - 1].Y);

            List <WaveCollapseHistoryElement> outputs = new List <WaveCollapseHistoryElement>();

            var return_value = new GH_WaveCollapseResults();

            for (int i = 0; i < (int)dataSize; i++)
            {
                // RUN WAVEFUNCION COLLAPSE
                var wfc     = new WaveFunctionCollapseRunner();
                var history = wfc.Run(patterns, N, width, height, weights, backtrack, (int)iterations);

                if (history.Elements.Count == 0)
                {
                    continue;
                }

                var historyEndElement = history.Elements[history.Elements.Count - 1];

                outputs.Add(historyEndElement);
                return_value.Value.AddToList(historyEndElement);
            }

            if (true)
            {
                DA.SetData(0, return_value);
            }
            else
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Check the inputs you idiot!");
            }
        }
Beispiel #3
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // Get patterns from sample
            GH_PatternsFromSample gh_patterns = new GH_PatternsFromSample();

            DA.GetData <GH_PatternsFromSample>(0, ref gh_patterns);

            pManager.AddPointParameter("Wave", "", "", GH_ParamAccess.list);
            pManager.AddBooleanParameter("Backtrack", "", "", GH_ParamAccess.item);
            pManager.AddNumberParameter("Iterations", "", "", GH_ParamAccess.item);
        }
        // INSIDE
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GH_PatternsFromSample gh_patterns = new GH_PatternsFromSample();

            DA.GetData <GH_PatternsFromSample>(0, ref gh_patterns);

            List <Point3d> wavePoints = new List <Point3d>();

            DA.GetDataList <Point3d>(1, wavePoints);

            bool backtrack = false;

            DA.GetData <bool>(2, ref backtrack);

            double iterations = 0;

            DA.GetData <double>(3, ref iterations);

            var patterns = gh_patterns.Value.Patterns;
            var weights  = gh_patterns.Value.TilesWeights;
            var N        = gh_patterns.Value.N;

            int width  = Utils.GetNumberofPointsInOneDimension(wavePoints[0].X, wavePoints[wavePoints.Count - 1].X);
            int height = Utils.GetNumberofPointsInOneDimension(wavePoints[0].Y, wavePoints[wavePoints.Count - 1].Y);


            // RUN WAVEFUNCION COLLAPSE
            var wfc          = new WaveFunctionCollapseRunner();
            var history      = wfc.Run(patterns, N, width, height, weights, backtrack, (int)iterations);
            var return_value = new GH_WaveCollapseHistory(history);

            var patternsOccurence = wfc.GetPatternCounts();
            var collapseAverage   = wfc.GetAverageCollapseStep();

            if (true)
            {
                DA.SetData(0, patterns.Count);
                DA.SetData(1, return_value);
                DA.SetDataList(2, patternsOccurence);
                DA.SetData(3, collapseAverage);
            }
            else
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Check the inputs you idiot!");
            }
        }
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GH_WaveCollapseResults waveCollapseDataset = new GH_WaveCollapseResults();

            DA.GetData <GH_WaveCollapseResults>(0, ref waveCollapseDataset);

            GH_PatternsFromSample gh_patterns = new GH_PatternsFromSample();

            DA.GetData <GH_PatternsFromSample>(1, ref gh_patterns);

            string series = "";

            DA.GetData <string>(2, ref series);

            var waveElements = Utils.GetObservedWave(waveCollapseDataset);
            var patterns     = Utils.GetPatternsFromSample(gh_patterns);

            // Assign generic values for every image
            var sampleSuperpositions = waveElements[0].Superpositions;

            // Get picture width and height
            width  = sampleSuperpositions.GetLength(0);
            height = sampleSuperpositions.GetLength(1);

            // Allocate memory for picture
            biteSize     = (int)((width * 4) * height);
            _imageBuffer = new byte[biteSize];

            // Add image from series
            for (int i = 0; i < waveElements.Count; i++)
            {
                var superpositions = waveElements[i].Superpositions;

                // Get values for pixels
                var pixelsCodes = Utils.GetImageValuesFromWave(superpositions);

                // Change to rgb
                var pictureRGB = Utils.CellsValuesToRGBColours(pixelsCodes, white, blue, green);

                // Plot picture from rgb
                Utils.PlotPixelsFromRGB(pictureRGB, _imageBuffer);

                // Save ti file
                Utils.SaveToPicture(pictureRGB, i, series, _imageBuffer);
            }
        }
Beispiel #6
0
        public static PatternFromSampleElement GetPatternsFromSample(GH_PatternsFromSample patternFromSample)
        {
            var patterns = patternFromSample.Value;

            return(patterns);
        }
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // Get wave function collapse data
            GH_PatternsFromSample gh_patterns = new GH_PatternsFromSample();

            DA.GetData <GH_PatternsFromSample>(0, ref gh_patterns);

            List <Point3d> wavePoints = new List <Point3d>();

            DA.GetDataList <Point3d>(1, wavePoints);

            bool backtrack = false;

            DA.GetData <bool>(2, ref backtrack);

            double iterations = 0;

            DA.GetData <double>(3, ref iterations);

            // Get image data.
            GH_Image inputImage = new GH_Image();

            DA.GetData(4, ref inputImage);

            List <double> newWeights = new List <double>();

            DA.GetDataList(5, newWeights);

            bool applyWeights = false;

            DA.GetData(6, ref applyWeights);

            // Extract parameters to run Wave Function Collapse.
            var patterns = gh_patterns.Value.Patterns;
            var weights  = gh_patterns.Value.TilesWeights;
            var N        = gh_patterns.Value.N;

            int width  = Utils.GetNumberofPointsInOneDimension(wavePoints[0].X, wavePoints[wavePoints.Count - 1].X);
            int height = Utils.GetNumberofPointsInOneDimension(wavePoints[0].Y, wavePoints[wavePoints.Count - 1].Y);

            // Prepare image data.
            //var image = convertImageListToArray(rawImage, width, height);
            //var image = Utils.generateRandomImage(width, height);
            var image = inputImage.Value.Brightness;

            // Run Wave Function Collapse.
            var wfc     = new WaveFunctionCollapseRunner();
            var history = new WaveCollapseHistory();

            if (applyWeights)
            {
                history = wfc.Run(patterns, N, width, height, weights, (int)iterations, backtrack, image, newWeights);
            }
            else
            {
                history = wfc.Run(patterns, N, width, height, weights, (int)iterations, backtrack, image);
            }
            var return_value = new GH_WaveCollapseHistory(history);

            DA.SetData(0, return_value);
        }
Beispiel #8
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            string GANresult = "";

            DA.GetData(0, ref GANresult);

            GH_PatternsFromSample gh_patterns = new GH_PatternsFromSample();

            DA.GetData <GH_PatternsFromSample>(1, ref gh_patterns);

            Color empty = new Color();

            DA.GetData(2, ref empty);

            Color half = new Color();

            DA.GetData(3, ref half);

            Color full = new Color();

            DA.GetData(4, ref full);

            double width = 0;

            DA.GetData(5, ref width);

            double height = 0;

            DA.GetData(6, ref height);

            bool save = false;

            DA.GetData(7, ref save);

            Bitmap ganImage = (Bitmap)Image.FromFile(GANresult);
            var    patterns = gh_patterns.Value.Patterns;
            var    x        = patterns[0].MiniTile;

            // Folder
            DirectoryInfo di = new DirectoryInfo(@"R:\pix2pix\small_images\grasshopper_test");

            FileInfo[] Images = di.GetFiles("*.png");

            var files = Directory.GetFiles(@"R:\pix2pix\small_images\grasshopper_test", "*.png");

            List <float> successRates = new List <float>();

            // Rate for one image
            for (int i = 0; i < Images.Length; i++)
            {
                Bitmap image = (Bitmap)Image.FromFile(files[i]);
                float  resultFromOneImage = getConstrainsRate(image, (int)width, (int)height, empty, half, full, patterns);

                successRates.Add(resultFromOneImage);
            }


            var d  = successRates.Sum();
            var xd = successRates.Average();

            if (save)
            {
                Utils.SaveConstrainsCheckToFile(xd, successRates);
            }

            //patternOccurenceInGANResult()

            DA.SetData(0, xd);
            DA.SetDataList(1, successRates);
        }
Beispiel #9
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            //  TILES A: center points
            List <Point3d> tilesA = new List <Point3d>();

            DA.GetDataList <Point3d>(0, tilesA);

            // TILES B: center points
            List <Point3d> tilesB = new List <Point3d>();

            DA.GetDataList <Point3d>(1, tilesB);

            // ALL TILES (A+B+NULL): CENTER POINTS
            List <Point3d> allTiles = new List <Point3d>();

            DA.GetDataList <Point3d>(2, allTiles);

            // tiles SIZE
            double tileSize = 0;

            DA.GetData(3, ref tileSize);

            // rotate bool
            // tiles SIZE
            bool rotation = false;

            DA.GetData(4, ref rotation);

            float[] weights = GetWeights(tilesA, tilesB, allTiles);

            // tiles for patterns from sample
            var halfTilesForPatterns  = new List <Point3d>();
            var fullTilesForPatterns  = new List <Point3d>();
            var emptyTilesForPatterns = new List <Point3d>();

            PatternFromSampleExtractor patternsToGenerate = new PatternFromSampleExtractor(tilesA, tilesB, allTiles, weights, (int)tileSize, rotation);

            var patternsFromSample = patternsToGenerate.Extract();

            var result = new PatternFromSampleElement();

            result.Patterns            = patternsFromSample;
            result.UnitElementsOfType0 = tilesA;
            result.UnitElementsOfType1 = tilesB;
            result.UnitElementsCenters = allTiles;
            result.TilesWeights        = weights;
            result.N = (int)tileSize;


            int x = 20, y = 0, z = 0;


            for (var i = 0; i < result.Patterns.Count; i++)
            {
                var pattern  = result.Patterns[i];
                var instance = pattern.Instantiate(x + i * (int)tileSize * 4, y, z);


                halfTilesForPatterns.AddRange(instance[State.HALF_TILE]);
                fullTilesForPatterns.AddRange(instance[State.FULL_TILE]);
                emptyTilesForPatterns.AddRange(instance[State.EMPTY]);
            }

            var r = new GH_PatternsFromSample(result);

            DA.SetData(0, r);
            DA.SetDataList(1, halfTilesForPatterns);
            DA.SetDataList(2, fullTilesForPatterns);
            DA.SetDataList(3, emptyTilesForPatterns);
        }