Esempio n. 1
0
        public Grid2d <ICell> BuildCellularGrid()
        {
            //create the grid
            cellularGrid = CreateCellularGrid();

            //add cells to the grid:
            PopulateGrid();

            //initialize cell state:

            ICAConfig initialConfiguration = GetInitialConfiguration();

            if (initialConfiguration != null)
            {
                foreach (ICell cell in cellularGrid.GetObjects())
                {
                    cell.SetState(initialConfiguration.GetCellState(cell));
                }
            }


            //build neighborhoods:
            foreach (ICell cell in cellularGrid.GetObjects())
            {
                ((ICell)cell).SetNeighbors(GetNeighborhoodStrategy().BuildNeighborhood(cell));
            }

            //return the grid
            return(cellularGrid);
        }
        /**
         * Does the computation
         */
        protected override void SolveRabbitInstance(IGH_DataAccess DA)
        {
            //Get the INPUT
            //GH_ObjectWrapper CAWrapper = null;
            //DA.GetData<GH_ObjectWrapper>(1, ref CAWrapper);//param index, place holder
            //CA CA = (CA)CAWrapper.Value;

            GH_ObjectWrapper CAConfigurationWrapper = null;

            DA.GetData <GH_ObjectWrapper>(0, ref CAConfigurationWrapper);//param index, place holder
            ICAConfig CAConfiguration = (ICAConfig)CAConfigurationWrapper.Value;

            int time = CAConfiguration.GetAssociatedTime();// CA.GetMemory().GetTime(CAConfiguration);
            IEnumerable <ICell> cells = null;


            //Filter the cells, if filter is specified
            IGH_Goo filterStateValue = null;

            DA.GetData <IGH_Goo>(1, ref filterStateValue);
            if (filterStateValue == null)           //no filter specified
            {
                cells = CAConfiguration.GetCells(); //CA.GetGrid().GetObjects();
            }
            else
            {
                //filter cells with the specified state
                CellState filterCS = new GH_CellState(filterStateValue);
                //CellState filterCS = new CellState(true);
                cells = filterCells(CAConfiguration, CAConfiguration.GetCells(), filterCS);
            }


            //OUTPUT
            ArrayList cellTimes   = new ArrayList();
            ArrayList cellIndexes = new ArrayList();
            ArrayList cellStates  = new ArrayList();

            foreach (ICell cell in cells)
            {
                cellTimes.Add(time);
                //cellTimes.Add(CAConfiguration.GetCellState(cell).Equals(filterCS));
                //cellTimes.Add(new GH_Boolean(true).Value.Equals(new GH_Boolean(true).Value));
                //cellTimes.Add(new GH_Colour(255,0,0,0).Value.Equals(new GH_Colour(255,0,0,0).Value));
                //cellIndexes.Add(cell.GetId());
                cellIndexes.Add(cell.GetAttachedObject());
                //the value of the state is a GH_Goo instance
                cellStates.Add(CAConfiguration.GetCellState(cell).GetValue());//.GetValue().GetType());
            }

            //set the output parameters
            DA.SetDataList(0, cellIndexes);
            DA.SetDataList(1, cellStates);
            DA.SetDataList(2, cellTimes);
        }
        private IList <ICell> filterCells(ICAConfig CAConfiguration, IEnumerable <ICell> cells, CellState filterCS)
        {
            //TODO: use an utility class
            IList <ICell> filteredCells = new List <ICell>();

            foreach (ICell cell in cells)
            {
                if (CAConfiguration.GetCellState(cell).Equals(filterCS))
                {
                    filteredCells.Add(cell);
                }
            }

            return(filteredCells);
        }