示例#1
0
        /// <summary>
        /// Calculate the density of alive cells for the given layer
        /// </summary>
        /// <returns></returns>
        private float CalculateDensity(CellLayer layer)
        {
            var cells      = layer.Cells;
            int aliveCount = 0;

            foreach (var cell in cells)
            {
                aliveCount += cell.State;
            }

            return((float)aliveCount / cells.Length);
        }
        /// <summary>
        ///
        /// </summary>
        public void UpdateAnalysis()
        {
            int       currentLayer = _model.CurrentLayer;
            CellLayer layer        = _model.Stack.Layers[currentLayer];

            //update layer current density
            var density = CalculateDensity(layer);

            layer.Density = density;
            _densitySum  += density; // add to running sum

            _currentLayer = currentLayer;
        }
示例#3
0
        /// <summary>
        ///
        /// </summary>
        private void InitializeCells()
        {
            _layers = new CellLayer[_layerCount];

            // instantiate layers
            for (int i = 0; i < _layerCount; i++)
            {
                CellLayer copy = Instantiate(_layerPrefab, transform);
                copy.transform.localPosition = new Vector3(0.0f, i, 0.0f);

                // create cell layer
                copy.Initialize(_cellPrefab, _rowCount, _columnCount);
                _layers[i] = copy;
            }

            // center at the world origin
            transform.localPosition = new Vector3(_columnCount, _layerCount, _rowCount) * -0.5f;
        }
        /// <summary>
        ///
        /// </summary>
        public void Update()
        {
            CellLayer currentLayer = _layers[_currentIndex];

            Cell[,] cells = currentLayer.Cells;

            //update highest cell age
            foreach (var cell in cells)
            {
                _maxAge = Math.Max(cell.Age, _maxAge);
            }

            //update layer current density
            currentLayer.Density = CalculateDensity(cells);

            //update density of stack overall so far
            _stackDensity = _layers.Take(_currentIndex + 1).Average(layer => layer.Density);

            _currentIndex++;
        }
示例#5
0
        /// <summary>
        ///
        /// </summary>
        private void DisplayStackDensity()
        {
            CellLayer[]   layers   = _manager.Layers;
            StackAnalyser analyser = _manager.Analyser;

            Index3[] neighb = Neighborhoods.Moore3Cen;

            //apply material props to each obj renderer
            for (int k = 0; k < layers.Length; k++)
            {
                CellLayer layer = layers[k];
                int       m     = layer.Rows;
                int       n     = layer.Columns;

                Cell[,] cells = layer.Cells;

                for (int i = 0; i < m; i++)
                {
                    // Note: keep the 2nd index on the inner loop for better cache locality
                    for (int j = 0; j < m; j++)
                    {
                        Cell cell = cells[i, j];

                        // skip dead cells
                        if (cell.State == 0)
                        {
                            continue;
                        }

                        // map density to color
                        int   sum   = analyser.GetNeighborSum3(i, j, k, neighb);
                        float value = Remap(sum, 0, neighb.Length, 0, 1);
                        Color color = Color.Lerp(Color.white, _stackDensityColor, value);

                        //change color of material property block
                        _materialprops.SetColor("_Color", color);
                        cell.Renderer.SetPropertyBlock(_materialprops);
                    }
                }
            }
        }
        /// <summary>
        ///
        /// </summary>
        public void UpdateAnalysis()
        {
            int       currentLayer = _model.CurrentLayer;
            CellLayer layer        = _model.Stack.Layers[currentLayer];

            _stackLayers.Add(layer);

            //update layer current density
            var density = CalculateDensity(layer);

            _layerDensity.Add(density);

            layer.Density = density;
            _densitySum  += density; // add to running sum

            //update oldest cell age
            foreach (var cell in layer.Cells)
            {
                _maxAge = Math.Max(cell.Age, _maxAge); //get the oldest age
            }

            _currentLayer = currentLayer;
        }