public void Permute() { this.Strands.Clear(); if (_permutationLevel < _sourceInputKrystal.Level) { this.Strands.Clear(); foreach (PermutationNode pn in _permutationNodeList) { Debug.Assert(pn.SourceStrandNumber > 0 && pn.SourceStrandNumber <= _sourceInputKrystal.Strands.Count); this.Strands.Add(_sourceInputKrystal.Strands[pn.SourceStrandNumber - 1]); } } else // _permutationLevel == _sourceInputKrystal.Level { for (int i = 0; i < _sourceInputKrystal.Strands.Count; i++) { PermutationNode pn = this._permutationNodeList[i]; Strand strand = _sourceInputKrystal.Strands[i]; int density = strand.Values.Count; int[] contour = K.Contour(density, pn.Contour, pn.Axis); if (_sortFirst) { strand.Values.Sort(); } Strand newStrand = new Strand(strand.Level); for (int j = 0; j < density; j++) { newStrand.Values.Add(strand.Values[contour[j] - 1]); } this.Strands.Add(newStrand); } } this.Update(Strands); }
public void Modulate() { foreach (ModulationNode m in _modulationNodeList) { m.ModResult = _modulator.Array[m.X - 1, m.Y - 1]; } #region convert to a list of strands List <Strand> strandList = new List <Strand>(); List <uint> valueList = new List <uint>(); uint strandValueLevel = this.Level + 1; Strand s = new Strand(1, valueList); ModulationNode mNode; for (int index = 0; index < _modulationNodeList.Count; index++) { mNode = _modulationNodeList[index]; if (mNode.ModLevel < strandValueLevel && index > 0) { strandList.Add(s); valueList = new List <uint>(); s = new Strand((uint)mNode.ModLevel, valueList); } s.Values.Add((uint)mNode.ModResult); } strandList.Add(s); #endregion convert to a list of strands this.Update(strandList); }
private Strand ExpandStrand(int level, int density, List <TrammelMark> trammel) { Strand strand = new Strand((uint)level); SortedList <uint, TrammelMark> expansion = new SortedList <uint, TrammelMark>(); // First add each trammel mark's distance to its current position... for (int i = 0; i < trammel.Count; i++) { trammel[i].Position += trammel[i].Distance; uint positionKey = trammel[i].PositionKey; while (expansion.ContainsKey(positionKey)) { positionKey += 1; // resolves positions which would otherwise be identical } expansion.Add(positionKey, trammel[i]); } // Now construct the strand. for (int i = 0; i < density; i++) { TrammelMark tm = expansion.Values[0]; strand.Values.Add((uint)tm.Value); expansion.RemoveAt(0); tm.Position += tm.Distance; uint positionKey = tm.PositionKey; while (expansion.ContainsKey(positionKey)) { positionKey += 1; // resolves positions which would otherwise be identical } expansion.Add(positionKey, tm); } // The strand is complete. // Now reset the trammel so that the smallest trammel mark position is 0. // First, remove unused distances... expansion.Clear(); for (int i = 0; i < trammel.Count; i++) { trammel[i].Position -= trammel[i].Distance; uint positionKey = trammel[i].PositionKey; while (expansion.ContainsKey(positionKey)) { positionKey += 1; // resolves positions which would otherwise be identical } expansion.Add(positionKey, trammel[i]); } // Second, subtract the first trammel mark position from all trammel marks. uint minPos = expansion.Values[0].Position; foreach (TrammelMark tm in trammel) { tm.Position -= minPos; } return(strand); }
/// <summary> /// Constructor used when creating new constants /// </summary> /// <param name="originalName"></param> /// <param name="value"></param> public ConstantKrystal(string originalName, uint value) : base() { _name = originalName; _level = 0; _minValue = _maxValue = value; _numValues = 1; List <uint> valueList = new List <uint>(); valueList.Add(value); Strand strand = new Strand(0, valueList); _strands.Add(strand); }
/// <summary> /// This function returns 0 if the shape and numeric content are the same, /// Otherwise it compares the two names. /// </summary> /// <param name="otherKrystal"></param> /// <returns></returns> public int CompareTo(object other) { Krystal otherKrystal = other as Krystal; if (otherKrystal == null) { throw new ArgumentException(); } bool isEquivalent = false; if (this.Shape == otherKrystal.Shape && this.Strands.Count == otherKrystal.Strands.Count && this.Level == otherKrystal.Level && this.MaxValue == otherKrystal.MaxValue && this.MinValue == otherKrystal.MinValue && this.NumValues == otherKrystal.NumValues && this.MissingValues == otherKrystal.MissingValues) { isEquivalent = true; for (int i = 0; i < this.Strands.Count; i++) { Strand thisStrand = this.Strands[i]; Strand otherStrand = otherKrystal.Strands[i]; if (thisStrand.Values.Count != otherStrand.Values.Count || thisStrand.Level != otherStrand.Level) { isEquivalent = false; break; } for (int j = 0; j < thisStrand.Values.Count; j++) { if (thisStrand.Values[j] != otherStrand.Values[j]) { isEquivalent = false; break; } } } } if (isEquivalent == true) { return(0); } else { return(this.Name.CompareTo(otherKrystal.Name)); } }
/// <summary> /// Constructor used when creating new line krystals /// </summary> /// <param name="originalName"></param> /// <param name="values"></param> public LineKrystal(string originalName, string values) : base() { _name = originalName; _level = 1; List <uint> valueList = K.GetUIntList(values); _numValues = (uint)valueList.Count; _minValue = uint.MaxValue; _maxValue = uint.MinValue; foreach (uint value in valueList) { _minValue = _minValue < value ? _minValue : value; _maxValue = _maxValue > value ? _maxValue : value; } Strand strand = new Strand(1, valueList); _strands.Add(strand); }
public Krystal(string filepath) { string filename = Path.GetFileName(filepath); try { using (XmlReader r = XmlReader.Create(filepath)) { _name = Path.GetFileName(filepath); _minValue = uint.MaxValue; _maxValue = uint.MinValue; K.ReadToXmlElementTag(r, "krystal"); // check that this is a krystal // ignore the heredity info in the next element (<expansion> etc.) K.ReadToXmlElementTag(r, "strands"); // check that there is a "strands" element // get the strands and their related variables K.ReadToXmlElementTag(r, "s"); while (r.Name == "s") { Strand strand = new Strand(r); _level = (_level < strand.Level) ? strand.Level : _level; foreach (uint value in strand.Values) { _minValue = (_minValue < value) ? _minValue : value; _maxValue = (_maxValue < value) ? value : _maxValue; } _numValues += (uint)strand.Values.Count; _strands.Add(strand); } // r.Name is the end tag "strands" here } } catch (Exception ex) { throw (ex); } }
public PermutationTreeView(TreeView treeView, PermutationKrystal pk) { _treeView = treeView; int dKrystalLevel = (int)pk.Level - 1; #region line krystal inputs if (dKrystalLevel == 1) // line krystal { _treeView.BeginUpdate(); foreach (PermutationNode permutationNode in pk.PermutationNodeList) { permutationNode.Text = ": m1, a" + permutationNode.Axis.ToString() + ", c" + permutationNode.Contour.ToString(); _treeView.Nodes.Add(permutationNode); } _treeView.EndUpdate(); } #endregion line krystal inputs else #region higher level krystal inputs { // Construct the levels of the tree above the permutationNodeList, adding the PermutationNodes where // necessary. (The upper levels consist of pure TreeNodes and include the single root node.) TreeNode[] currentNode = new TreeNode[dKrystalLevel]; int[] localSectionNumber = new int[dKrystalLevel]; // does not include the local strand section numbers int localStrandSectionNumber = 0; for (int i = 0; i < pk.Strands.Count; i++) { Strand strand = pk.Strands[i]; PermutationNode permutationNode = pk.PermutationNodeList[i]; if (strand.Level <= dKrystalLevel) { localStrandSectionNumber = 0; int levelIndex = (int)strand.Level - 1; while (levelIndex < dKrystalLevel) { TreeNode tn = new TreeNode(); tn.Expand(); currentNode[levelIndex] = tn; if (levelIndex > 0) // there is only one node at levelIndex == 0, and it has no text { currentNode[levelIndex - 1].Nodes.Add(tn); localSectionNumber[levelIndex - 1]++; localSectionNumber[levelIndex] = 0; if (levelIndex == 1) { tn.Text = localSectionNumber[levelIndex - 1].ToString(); } else { tn.Text = tn.Parent.Text + "." + localSectionNumber[levelIndex - 1].ToString(); } } levelIndex++; } } localStrandSectionNumber++; currentNode[dKrystalLevel - 1].Nodes.Add(permutationNode); localSectionNumber[dKrystalLevel - 1]++; int moment = i + 1; int sourceMoment = permutationNode.SourceStrandNumber; int axis = permutationNode.Axis; int contour = permutationNode.Contour; permutationNode.Text = permutationNode.Parent.Text + "." + localStrandSectionNumber.ToString() + ": m" + moment.ToString(); if (sourceMoment > 0) { permutationNode.Text = permutationNode.Text + ", sm" + sourceMoment.ToString(); } else { permutationNode.Text = permutationNode.Text + ", a" + axis.ToString() + ", c" + contour.ToString(); } } // Now add the moment numbers to the pure TreeNode.Texts for (int i = 0; i < pk.Strands.Count; i++) { Strand strand = pk.Strands[i]; PermutationNode permutationNode = pk.PermutationNodeList[i]; if (strand.Level <= dKrystalLevel) { TreeNode tn = permutationNode.Parent; bool continueUp = true; while (continueUp) { if (tn.Text.EndsWith(".1") && tn.Level > 0) { continueUp = true; } else { continueUp = false; } int m = i + 1; tn.Text = tn.Text + ": m" + m.ToString(); if (continueUp) { tn = tn.Parent; } } } } _treeView.BeginUpdate(); _treeView.Nodes.Clear(); foreach (TreeNode n in currentNode[0].Nodes) { _treeView.Nodes.Add(n); } _treeView.EndUpdate(); } #endregion higher level krystal inputs }
public StrandObj(Strand strand, int originalMomentNumber) { _strand = strand; _originalMomentNumber = originalMomentNumber; }
private void Expand(List <StrandNode> strandNodeList, Expander expander) { #region preparation List <PointGroup> fixedInputPointGroups = expander.InputGamete.FixedPointGroups; List <PointGroup> fixedOutputPointGroups = expander.OutputGamete.FixedPointGroups; List <Planet> inputPlanets = expander.InputGamete.Planets; List <Planet> outputPlanets = expander.OutputGamete.Planets; List <TrammelMark> trammel = new List <TrammelMark>(); foreach (int value in expander.OutputGamete.Values) { TrammelMark tm = new TrammelMark(value); trammel.Add(tm); } uint[,] distances = new uint[expander.InputGamete.NumberOfValues, expander.OutputGamete.NumberOfValues]; CalculateFixedDistances(distances, fixedInputPointGroups, fixedOutputPointGroups); #endregion preparation #region expand strands int momentIndex = 0; foreach (StrandNode strandNode in strandNodeList) { int level = strandNode.strandLevel; int density = strandNode.strandDensity; int iPointValue = strandNode.strandPoint; int iPointIndex = iPointValue - 1; // the input point's index in the distances array #region calculate distances for planets where necessary. PointF?iPointPosition = null; if (inputPlanets.Count > 0) { iPointPosition = InputPlanetPosition(momentIndex, iPointValue, inputPlanets); } // iPointPosition == null if the current input point is not a planet // If the current input point is a planet, calculate distances to the fixed output points. if (iPointPosition != null && fixedOutputPointGroups.Count > 0) { CalculateInputPlanetDistances(distances, iPointIndex, (PointF)iPointPosition, fixedOutputPointGroups); } if (outputPlanets.Count > 0) { // If there are output planets, it is necessary to calculate their distances from the input point if (iPointPosition == null) // the input point is not a planet, so its a fixed point { iPointPosition = FixedInputPointPosition(iPointValue, fixedInputPointGroups); } if (iPointPosition == null) { throw new ApplicationException("Error finding the position of an input point."); } // There are output planets, so calculate their distances from the (planet or fixed)input point. CalculateOutputPlanetsDistances(momentIndex, distances, iPointIndex, (PointF)iPointPosition, outputPlanets); } #endregion calculate distances for planets where necessary foreach (TrammelMark tm in trammel) { tm.Distance = distances[iPointIndex, tm.DistancesIndex]; } Strand strand = ExpandStrand(level, density, trammel); _strands.Add(strand); momentIndex++; } #endregion expand strands }
public void Modulate() { foreach(ModulationNode m in _modulationNodeList) m.ModResult = _modulator.Array[m.X - 1, m.Y - 1]; #region convert to a list of strands List<Strand> strandList = new List<Strand>(); List<uint> valueList = new List<uint>(); uint strandValueLevel = this.Level + 1; Strand s = new Strand(1, valueList); ModulationNode mNode; for(int index = 0; index < _modulationNodeList.Count; index++) { mNode = _modulationNodeList[index]; if(mNode.ModLevel < strandValueLevel && index > 0) { strandList.Add(s); valueList = new List<uint>(); s = new Strand((uint)mNode.ModLevel, valueList); } s.Values.Add((uint)mNode.ModResult); } strandList.Add(s); #endregion convert to a list of strands this.Update(strandList); }
public StrandObj(Strand strand, int originalMomentNumber) { _strand = strand; _originalMomentNumber = originalMomentNumber; }
private Strand ExpandStrand(int level, int density, List<TrammelMark> trammel) { Strand strand = new Strand((uint) level); SortedList<uint, TrammelMark> expansion = new SortedList<uint, TrammelMark>(); // First add each trammel mark's distance to its current position... for(int i = 0 ; i < trammel.Count ; i++) { trammel[i].Position += trammel[i].Distance; uint positionKey = trammel[i].PositionKey; while(expansion.ContainsKey(positionKey)) positionKey += 1; // resolves positions which would otherwise be identical expansion.Add(positionKey, trammel[i]); } // Now construct the strand. for(int i = 0 ; i < density ; i++) { TrammelMark tm = expansion.Values[0]; strand.Values.Add((uint) tm.Value); expansion.RemoveAt(0); tm.Position += tm.Distance; uint positionKey = tm.PositionKey; while(expansion.ContainsKey(positionKey)) positionKey += 1; // resolves positions which would otherwise be identical expansion.Add(positionKey, tm); } // The strand is complete. // Now reset the trammel so that the smallest trammel mark position is 0. // First, remove unused distances... expansion.Clear(); for(int i = 0 ; i < trammel.Count ; i++) { trammel[i].Position -= trammel[i].Distance; uint positionKey = trammel[i].PositionKey; while(expansion.ContainsKey(positionKey)) positionKey += 1; // resolves positions which would otherwise be identical expansion.Add(positionKey, trammel[i]); } // Second, subtract the first trammel mark position from all trammel marks. uint minPos = expansion.Values[0].Position; foreach(TrammelMark tm in trammel) tm.Position -= minPos; return strand; }
public void Permute() { this.Strands.Clear(); if(_permutationLevel < _sourceInputKrystal.Level) { this.Strands.Clear(); foreach(PermutationNode pn in _permutationNodeList) { Debug.Assert(pn.SourceStrandNumber > 0 && pn.SourceStrandNumber <= _sourceInputKrystal.Strands.Count); this.Strands.Add(_sourceInputKrystal.Strands[pn.SourceStrandNumber - 1]); } } else // _permutationLevel == _sourceInputKrystal.Level { for(int i = 0; i < _sourceInputKrystal.Strands.Count; i++) { PermutationNode pn = this._permutationNodeList[i]; Strand strand = _sourceInputKrystal.Strands[i]; int density = strand.Values.Count; int[] contour = K.Contour(density, pn.Contour, pn.Axis); if(_sortFirst) strand.Values.Sort(); Strand newStrand = new Strand(strand.Level); for(int j = 0; j < density; j++) { newStrand.Values.Add(strand.Values[contour[j] - 1]); } this.Strands.Add(newStrand); } } this.Update(Strands); }