/**
         * Does the computation
         */
        protected override void SolveRabbitInstance(IGH_DataAccess DA)
        {
            //get the user-defined points that define custom Cell State
            List <GH_Point> userConfigurationGHPoints = new List <GH_Point>();

            DA.GetDataList(0, userConfigurationGHPoints);

            //Get the specified initial state:
            IGH_Goo gooCellStateValue = null;

            DA.GetData <IGH_Goo>(1, ref gooCellStateValue);
            //CellState initialCellState = new CellState(GH_TypeUtils.ConvertToSystemType(gooCellStateValue));
            CellState initialCellState = new GH_CellState(gooCellStateValue);

            //creates the Cellular space
            OnStateConfig stateConfig = new OnStateConfig(GH_PointUtils.ConvertToOnPoints(userConfigurationGHPoints), initialCellState);

            //set the output parameters
            DA.SetData(0, stateConfig);
        }
예제 #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);
        }
예제 #3
0
        /**
         * Does the computation
         */
        protected override void SolveRabbitInstance(IGH_DataAccess DA)
        {
            //Get the Structure of the Data of points, so that the underlying grid logic could be retrieved -------
            DA.DisableGapLogic();
            if (DA.Iteration > 0)
            {
                return;
            }

            //Get the points as GH Structure, because the dimensions of the space are based on the tree's structure:
            GH_Structure <GH_Point> ghPointsTree = (GH_Structure <GH_Point>) this.Params.Input[1].VolatileData;
            //get all points as a flat list:
            List <GH_Point> ghPointsList = ghPointsTree.FlattenData();

            //expects a 2D grid:
            int XDimension = ghPointsTree.Paths.Count;
            int YDimension = ghPointsList.Count / XDimension;


            IList <Point3d> latticePoints = GH_PointUtils.ConvertToOnPoints(ghPointsList);



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

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

            //Get the State configurations-----------------------------------------------------------------------------
            OnCellularGridBuilder gridBuilder = null;

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

            DA.GetDataList(2, stateConfigurations);

            foreach (GH_ObjectWrapper stateConfigWrapper in stateConfigurations)
            {
                if (stateConfigWrapper != null)    // Custom configuration defined
                {
                    if (stateConfigWrapper.Value.GetType() == typeof(OnStateConfig))
                    {
                        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, latticePoints);
                        stateConfig.SetPoints(realConfigurationPoints);
                        gridBuilder = new OnCellularGridBuilder(cellPrototype, latticePoints, XDimension, YDimension, stateConfig);
                    }
                    else if (stateConfigWrapper.Value.GetType() == typeof(RandomCAConfig))
                    {
                        RandomCAConfig stateConfig = (RandomCAConfig)stateConfigWrapper.Value;
                        gridBuilder = new OnCellularGridBuilder(cellPrototype, latticePoints, XDimension, YDimension, stateConfig);
                    }
                    else
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Not supported configuration type!");
                    }
                }
            }
            if (stateConfigurations.Count == 0)                                                                // no configuration defined
            {
                gridBuilder = new OnCellularGridBuilder(cellPrototype, latticePoints, XDimension, YDimension); //, new RandomCAConfig(cellPrototype.GetFiniteStates()));
            }
            //build the grid
            Grid2d <ICell> grid2d = gridBuilder.BuildCellularGrid();
            CA             ca     = new CA(grid2d);

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