コード例 #1
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!");
            }
        }
コード例 #2
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GH_WaveCollapseResults waveCollapseDataset = new GH_WaveCollapseResults();

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

            var wfcList = waveCollapseDataset.Value.Elements;
            var image   = Utils.generateRandomImage(wfcList[0].Superpositions.GetLength(0), wfcList[0].Superpositions.GetLength(1));

            float sumSuccessRate    = 0.0f;
            float successProportion = 0.0f;

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

            // Go through every wfc solution
            for (int i = 0; i < wfcList.Count; i++)
            {
                // Get last element of this solution
                var currentWFC         = wfcList[i];
                var currentSuccessRate = Utils.CountSuccessfullCellsInImageArea(image, currentWFC);
                sumSuccessRate += currentSuccessRate;

                succesRates.Add(currentSuccessRate);
            }

            successProportion = sumSuccessRate / wfcList.Count;

            DA.SetData(0, successProportion);
            DA.SetDataList(1, succesRates);
        }
コード例 #3
0
        // 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);
        }
コード例 #4
0
        public static List <WaveCollapseHistoryElement> GetObservedWave(GH_WaveCollapseResults results)
        {
            if (results.Value.Elements.Count == 0)
            {
                return(null);
            }
            //int index = results.Value.Elements.Count - 1;
            var waveElements = results.Value.Elements.ToList();

            return(waveElements);
        }
コード例 #5
0
        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);
            }
        }