Esempio n. 1
0
 public OnCellularGridBuilder(ICell cellPrototype, IList <Point3d> pointLattice, int XDimension, int YDimension, RandomCAConfig randomConfig)
     : this(cellPrototype, pointLattice, XDimension, YDimension)
 {
     random            = true;
     custom            = false;
     this.randomConfig = randomConfig;
 }
        /**
         * Does the computation
         */
        protected override void SolveRabbitInstance(IGH_DataAccess DA)
        {
            List <CellState> states = new List <CellState>();

            //get all Goo states
            List <IGH_Goo> gooStates = new List <IGH_Goo>();

            DA.GetDataList(0, gooStates);
            foreach (IGH_Goo gooState in gooStates)
            {
                states.Add(new GH_CellState(gooState));
            }

            //creates the Ranom configuration
            RandomCAConfig randomConfig = new RandomCAConfig(states);

            //set the output parameters
            DA.SetData(0, randomConfig);
        }
Esempio n. 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);
        }