示例#1
0
        int GetIndexToVisualise(GH_WaveCollapseHistory timelapse, double frameLocation)
        {
            int index          = 0;
            var numberOfFrames = timelapse.Value.Elements.Count;

            index = (int)Math.Floor(frameLocation * numberOfFrames);
            return(index);
        }
示例#2
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GH_WaveCollapseHistory waveCollapseHistory = new GH_WaveCollapseHistory();

            DA.GetData <GH_WaveCollapseHistory>(0, ref waveCollapseHistory);

            var lastIteration = waveCollapseHistory.Value.Elements[waveCollapseHistory.Value.Elements.Count - 1];

            var image = Utils.generateRandomImage(lastIteration.Superpositions.GetLength(0), lastIteration.Superpositions.GetLength(1));

            float successRate = Utils.CountSuccessfullCellsInImageArea(image, lastIteration);

            DA.SetData(0, successRate);
        }
        // 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!");
            }
        }
示例#4
0
        WaveCollapseHistoryElement GetWaveAtSpecificTime(GH_WaveCollapseHistory waveCollapseHistory, double frameFromTimeLapse)
        {
            if (waveCollapseHistory.Value.Elements.Count == 0)
            {
                return(null);
            }

            int frameToVisualise = GetIndexToVisualise(waveCollapseHistory, frameFromTimeLapse);

            if (frameToVisualise == waveCollapseHistory.Value.Elements.Count && frameToVisualise != 0)
            {
                frameToVisualise = frameToVisualise - 1;
            }

            var waveElements = waveCollapseHistory.Value.Elements[frameToVisualise];

            return(waveElements);
        }
        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);
        }
示例#6
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GH_WaveCollapseHistory waveCollapseHistory = new GH_WaveCollapseHistory();

            DA.GetData <GH_WaveCollapseHistory>(0, ref waveCollapseHistory);

            double frameFromTimeLapse = new double();

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

            Brep surfaceType01 = new Brep();

            DA.GetData <Brep>(2, ref surfaceType01);

            Brep surfaceType02 = new Brep();

            DA.GetData <Brep>(3, ref surfaceType02);


            Brep surfaceType03 = new Brep();

            DA.GetData <Brep>(4, ref surfaceType03);


            double wavePositionX = new double();

            DA.GetData <double>(5, ref wavePositionX);

            double wavePositionY = new double();

            DA.GetData <double>(6, ref wavePositionY);

            Color tile01Colour = new Color();

            DA.GetData <Color>(7, ref tile01Colour);

            Color tile02Colour = new Color();

            DA.GetData <Color>(8, ref tile02Colour);

            Color tile03Colour = new Color();

            DA.GetData <Color>(9, ref tile03Colour);

            var waveElements = GetWaveAtSpecificTime(waveCollapseHistory, frameFromTimeLapse);

            var uncollapsed = waveElements.Uncollapsed;

            var tempUncollapsed = GetUncollapsedPoints(uncollapsed);

            var entropies         = waveElements.Entropies;
            var entropies_flatten = entropies.Cast <double>().ToArray();

            // move tiles on canvas
            var halfTilesRelocated = MovePointsOnCanvas((int)wavePositionX, (int)wavePositionY, waveElements.HalfTile);
            var fullTilesRelocated = MovePointsOnCanvas((int)wavePositionX, (int)wavePositionY, waveElements.FullTile);
            var emptyRelocated     = MovePointsOnCanvas((int)wavePositionX, (int)wavePositionY, waveElements.Empty);

            // change all lists to vectors
            var halfTilesRelocatedVectors  = pointsToVectors(halfTilesRelocated);
            var fullTilesRelocatedVectors  = pointsToVectors(fullTilesRelocated);
            var emptyTilesRelocatedVectors = pointsToVectors(emptyRelocated);

            // move uncollapsed on canvas
            var uncollapsedMoved            = MovePointsOnCanvas((int)wavePositionX, (int)wavePositionY, tempUncollapsed);
            var uncollapsedRelocatedVectors = pointsToVectors(uncollapsedMoved);


            // duplicate surfaces to calculated locations
            var duplicatedHalfSurfaces  = DuplicateTiles(surfaceType01, halfTilesRelocatedVectors);
            var duplicatedFullSurfaces  = DuplicateTiles(surfaceType02, fullTilesRelocatedVectors);
            var duplicatedEmptySurfaces = DuplicateTiles(surfaceType03, emptyTilesRelocatedVectors);
            var duplicatedUncollapsed   = DuplicateTiles(surfaceType01, uncollapsedRelocatedVectors);

            var colours = GetUncollapsedColors(uncollapsed, tile01Colour, tile02Colour, tile03Colour);

            DA.SetDataList(0, duplicatedHalfSurfaces);
            DA.SetDataList(1, duplicatedFullSurfaces);
            DA.SetDataList(2, duplicatedEmptySurfaces);
            DA.SetDataList(3, colours);
            DA.SetDataList(4, duplicatedUncollapsed);
            DA.SetDataList(5, waveElements.PatternOccurence);
            DA.SetDataList(6, entropies_flatten);
        }