Exemplo n.º 1
0
        /**
         * Does the computation
         */
        protected override void SolveRabbitInstance(IGH_DataAccess DA)
        {
            //Get the evolution rules of the cell
            Boolean rule111_state = false;

            DA.GetData <Boolean>(0, ref rule111_state);
            Boolean rule110_state = false;

            DA.GetData <Boolean>(1, ref rule110_state);
            Boolean rule101_state = false;

            DA.GetData <Boolean>(2, ref rule101_state);
            Boolean rule100_state = false;

            DA.GetData <Boolean>(3, ref rule100_state);
            Boolean rule011_state = false;

            DA.GetData <Boolean>(4, ref rule011_state);
            Boolean rule010_state = false;

            DA.GetData <Boolean>(5, ref rule010_state);
            Boolean rule001_state = false;

            DA.GetData <Boolean>(6, ref rule001_state);
            Boolean rule000_state = false;

            DA.GetData <Boolean>(7, ref rule000_state);

            ElementaryRule rule111 = new ElementaryRule(GH_ALIVE_STATE, GH_ALIVE_STATE, GH_ALIVE_STATE, (rule111_state)? GH_ALIVE_STATE : GH_DEAD_STATE);
            ElementaryRule rule110 = new ElementaryRule(GH_ALIVE_STATE, GH_ALIVE_STATE, GH_DEAD_STATE, (rule110_state) ? GH_ALIVE_STATE : GH_DEAD_STATE);
            ElementaryRule rule101 = new ElementaryRule(GH_ALIVE_STATE, GH_DEAD_STATE, GH_ALIVE_STATE, (rule101_state) ? GH_ALIVE_STATE : GH_DEAD_STATE);
            ElementaryRule rule100 = new ElementaryRule(GH_ALIVE_STATE, GH_DEAD_STATE, GH_DEAD_STATE, (rule100_state) ? GH_ALIVE_STATE : GH_DEAD_STATE);
            ElementaryRule rule011 = new ElementaryRule(GH_DEAD_STATE, GH_ALIVE_STATE, GH_ALIVE_STATE, (rule011_state) ? GH_ALIVE_STATE : GH_DEAD_STATE);
            ElementaryRule rule010 = new ElementaryRule(GH_DEAD_STATE, GH_ALIVE_STATE, GH_DEAD_STATE, (rule010_state) ? GH_ALIVE_STATE : GH_DEAD_STATE);
            ElementaryRule rule001 = new ElementaryRule(GH_DEAD_STATE, GH_DEAD_STATE, GH_ALIVE_STATE, (rule001_state) ? GH_ALIVE_STATE : GH_DEAD_STATE);
            ElementaryRule rule000 = new ElementaryRule(GH_DEAD_STATE, GH_DEAD_STATE, GH_DEAD_STATE, (rule000_state) ? GH_ALIVE_STATE : GH_DEAD_STATE);

            List <CellularRule> rules = new List <CellularRule>();

            rules.Add(rule111);
            rules.Add(rule110);
            rules.Add(rule101);
            rules.Add(rule100);
            rules.Add(rule011);
            rules.Add(rule010);
            rules.Add(rule001);
            rules.Add(rule000);



            ElementaryCell prototype = new ElementaryCell(-1, GH_ALIVE_STATE, GH_DEAD_STATE, rules);

            prototype.setIsPrototype(true);

            //set the output parameters
            DA.SetData(0, prototype);
        }
Exemplo n.º 2
0
        /**
         * Does the computation
         */
        protected override void SolveRabbitInstance(IGH_DataAccess DA)
        {
            List <GH_Point> pointsList = new List <GH_Point>();

            DA.GetDataList(1, pointsList);

            int XDimension = pointsList.Count;

            IList <Point3d> genericPoints = GH_PointUtils.ConvertToOnPoints(pointsList);


            //Get the cell prototype------------------------------------------------------------
            GH_ObjectWrapper cellPrototypeWrapper = null;

            DA.GetData <GH_ObjectWrapper>(0, ref cellPrototypeWrapper);
            ICell cellPrototype = (ICell)cellPrototypeWrapper.Value;

            //----------------------------------------------------------------------------------
            List <GH_ObjectWrapper> stateConfigurations = new List <GH_ObjectWrapper>();

            DA.GetDataList(2, stateConfigurations);

            GH_ObjectWrapper stateConfigWrapper1;
            OnStateConfig    stateConfig = null;

            foreach (GH_ObjectWrapper stateConfigWrapper in stateConfigurations)
            {
                if (stateConfigWrapper != null)// Custom configuration defined
                {
                    if (stateConfigWrapper.Value.GetType() == typeof(OnStateConfig))
                    {
                        stateConfig = (OnStateConfig)stateConfigWrapper.Value;
                        //get the user-defined points that define custom Cell State
                        IList <Point3d> userConfigurationGHPoints = stateConfig.GetPoints();
                        //get the real configuration points, by finding the points that are closer to the user defined configuration points
                        IList <Point3d> realConfigurationPoints = PointUtils.GetClosestPoints(userConfigurationGHPoints, genericPoints);
                        stateConfig.SetPoints(realConfigurationPoints);
                    }
                }
            }
            //----------------------------------------------------------------------------------

            //build the grid
            Grid1d <ICell> space1d = new Grid1d <ICell>(XDimension);

            CellState ghAliveState = new GH_CellState(new GH_Boolean(true));
            CellState ghDeadState  = new GH_CellState(new GH_Boolean(false));

            //populate the grid
            for (int i = 0; i < XDimension; i++)
            {
                ICell cell = cellPrototype.Clone();
                cell.SetId(i);//very important as this identifies the cell
                if (stateConfig != null)
                {
                    foreach (Point3d configurationPoint in stateConfig.GetPoints())
                    {
                        if (pointsList[i].Value.X == configurationPoint.X && pointsList[i].Value.Y == configurationPoint.Y && pointsList[i].Value.Z == configurationPoint.Z)
                        {
                            cell.SetState(stateConfig.GetState());
                        }
                    }
                }

                cell.SetAttachedObject(pointsList[i]);
                space1d.Add(cell, i);
            }

            //build neighborhood
            for (int i = 0; i < XDimension; i++)
            {
                ElementaryCell cell = (ElementaryCell)space1d.GetObjectAt(i);
                //IList<ICell> neighbors = new List<ICell>(2);
                if (i > 0)
                {
                    cell.SetLeftNeighbor((ElementaryCell)space1d.GetObjectAt(i - 1));//neighbors.Add(cells[(i - 1)%XDimension]);
                }
                else if (i == 0)
                {
                    cell.SetLeftNeighbor((ElementaryCell)space1d.GetObjectAt(XDimension - 1));//neighbors.Add(cells[(i - 1)%XDimension]);
                }
                if (i < XDimension - 1)
                {
                    cell.SetRightNeighbor((ElementaryCell)space1d.GetObjectAt(i + 1));//neighbors.Add(cells[(i + 1)%XDimension]);
                }
                else if (i == XDimension - 1)
                {
                    cell.SetRightNeighbor((ElementaryCell)space1d.GetObjectAt(0));
                }
            }


            CA ca = new CA(space1d);

            //set the output parameters
            DA.SetData(0, ca);
        }