/** * 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); }
/** * Does the computation */ protected override void SolveRabbitInstance(IGH_DataAccess DA) { /* * //Get the evolution rules of the cell * List<GH_ObjectWrapper> EvolutionRulesWrapper = new List<GH_ObjectWrapper>(); * DA.GetDataList(0, EvolutionRulesWrapper);//param index, place holder * * //init the list of evolution rules: * List<CellularRule> EvolutionRules = new List<CellularRule>(); * foreach (GH_ObjectWrapper EvolutionRuleWrapper in EvolutionRulesWrapper) * EvolutionRules.Add((CellularRule)EvolutionRuleWrapper.Value); */ //get the inputs List <int> bornRuleNeighbors = new List <int>(); DA.GetDataList <int>(0, bornRuleNeighbors);//param index, place holder List <int> survuveRuleNeighbors = new List <int>(); DA.GetDataList <int>(1, survuveRuleNeighbors);//param index, place holder if (bornRuleNeighbors.Count == 0 && survuveRuleNeighbors.Count == 0) { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Unsufficient evolution rules: At least one rule should be defined."); return; } //---------------------------------------------------------------------- //init the list of evolution rules: List <CellularRule> EvolutionRules = new List <CellularRule>(); //init the Born Rules(if any) if (bornRuleNeighbors.Count > 0) { //creates the Evolution Rule: BornRule bornRule = new BornRule(bornRuleNeighbors); EvolutionRules.Add(bornRule); } //Init the Survive Rules(if any) if (survuveRuleNeighbors.Count > 0) { //creates the Evolution Rule: SurviveRule surviveRule = new SurviveRule(survuveRuleNeighbors); EvolutionRules.Add(surviveRule); } //Create the Life-Like Cell Prototype CellState ghAliveState = new GH_CellState(new GH_Boolean(true)); CellState ghDeadState = new GH_CellState(new GH_Boolean(false)); LifeLikeCell prototype = new LifeLikeCell(-1, ghAliveState, ghDeadState, EvolutionRules); //set the output parameters DA.SetData(0, prototype); }
public override Boolean Equals(Object that) { if (that == null) { return(false); } if (that.GetType() != this.GetType()) { return(false); } //FIXME: use a reflection to get the Value property of the GH_Goo //if a value property is missing, it seems that we could not compare Goos (or different method should be used) // GH_Goo.Equals(GH_Goo) compare the GUIDs which are different in the common case // that's why we need to compare GH_Goo inner values // unfortunately the Value property is not generic for GH_Goo // only some GH_Goo have value assigned GH_CellState thatState = (GH_CellState)that; if (value.GetType() == GH_TypeLib.t_gh_colour) { GH_Colour thisGH_Colour = (GH_Colour)value; GH_Colour thatGH_Colour = (GH_Colour)thatState.value; return(thisGH_Colour.Value.Equals(thatGH_Colour.Value)); } else if (value.GetType() == GH_TypeLib.t_gh_bool) { GH_Boolean thisGH_Boolean = (GH_Boolean)this.value; GH_Boolean thatGH_Boolean = (GH_Boolean)thatState.value; return(thisGH_Boolean.Value.Equals(thatGH_Boolean.Value)); } else if (value.GetType() == GH_TypeLib.t_gh_int) { GH_Integer thisGH_Integer = (GH_Integer)this.value; GH_Integer thatGH_Integer = (GH_Integer)thatState.value; return(thisGH_Integer.Value.Equals(thatGH_Integer.Value)); } else if (value.GetType() == GH_TypeLib.t_gh_string) { GH_String thisGH_String = (GH_String)this.value; GH_String thatGH_String = (GH_String)thatState.value; return(thisGH_String.Value.Equals(thatGH_String.Value)); } throw new NotSupportedException("Could not compare GH_Goo type: " + value.GetType()); }
/** * 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); }
/** * Does the computation */ protected override void SolveRabbitInstance(IGH_DataAccess DA) { //Get the treshold int treshold = 0; DA.GetData <int>(0, ref treshold); //Get the resting colour IGH_Goo restingColour = null; DA.GetData <IGH_Goo>(1, ref restingColour); GH_CellState restingState = new GH_CellState(restingColour); //Get the excited states --------------------------------------------- List <IGH_Goo> excitedColours = new List <IGH_Goo>(); DA.GetDataList(2, excitedColours); List <CellState> excitedStates = new List <CellState>(); foreach (IGH_Goo colour in excitedColours) { excitedStates.Add(new GH_CellState(colour)); } //Get the refractory states ------------------------------------------ List <IGH_Goo> refractoryColours = new List <IGH_Goo>(); DA.GetDataList(3, refractoryColours);//param index, place holder List <CellState> refractoryStates = new List <CellState>(); foreach (IGH_Goo colour in refractoryColours) { refractoryStates.Add(new GH_CellState(colour)); } ExcitableCell prototype = new ExcitableCell(-1, restingState, refractoryStates, excitedStates, treshold);//, //EvolutionRules); //set the output parameters DA.SetData(0, prototype); }
/** * 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); }