/** * 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); }